using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Xml;

public partial class WTOSYSadmin_news_AdvertisementAdd: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        if (!IsPostBack)
        {
            this.Panel1.Visible = true;
            this.Panel2.Visible = false;
            this.Panel3.Visible = false;
            this.Panel4.Visible = false;
            this.Panel5.Visible = false;
            this.title.Text = "轮显广告";
        }
        if (IsPostBack)
        {
            string showp;
            showp = this.lbname.SelectedItem.Value.ToString();
            switch (showp)
            { //轮显
                case "0":
                    this.Panel1.Visible = true;
                    this.Panel2.Visible = false;
                    this.Panel3.Visible = false;
                    this.Panel4.Visible = false;
                    this.Panel5.Visible = false;
                    this.addedit.Click+=new EventHandler(addlx_Click);
                    this.title.Text = "轮显广告";
                    break;
                //对联广告
                case "1":
                    this.Panel1.Visible = false;
                    this.Panel2.Visible = true;
                    this.Panel3.Visible = false;
                    this.Panel4.Visible = false;
                    this.Panel5.Visible = false;
                    this.addedit.Click+=new EventHandler(adddl_Click);
                    this.title.Text = "对联广告";
                    break;
                //漂动广告
                case "2":
                    this.Panel1.Visible = false;
                    this.Panel2.Visible = false;
                    this.Panel3.Visible = true;
                    this.Panel4.Visible = false;
                    this.Panel5.Visible = false;
                    this.addedit.Click+=new EventHandler(addpd_Click);
                    this.title.Text = "漂动广告";
                    break;
                //弹出式广告
                case "3":
                    this.Panel1.Visible = false;
                    this.Panel2.Visible = false;
                    this.Panel3.Visible = false;
                    this.Panel4.Visible = true;
                    this.Panel5.Visible = false;
                    this.addedit.Click+=new EventHandler(addtc_Click);
                    this.title.Text = "弹出式广告";
                    break;
                //大型首页广告
                case "4":
                    this.Panel1.Visible = false;
                    this.Panel2.Visible = false;
                    this.Panel3.Visible = false;
                    this.Panel4.Visible = false;
                    this.Panel5.Visible = true;
                    this.addedit.Click+=new EventHandler(adddx_Click);
                    this.title.Text = "大型首页广告";
                    break;
            }
        }

    }
    //轮显提交
    protected void addlx_Click(object sender, EventArgs e)
    {
        string isfp,lbname,tall,t1, t2, t3, t4, t5, t6, h1, h2, h3, h4, h5, h6, fu1, fu2, fu3, fu4, fu5, fu6;
        string pic1="",pic2="",pic3="",pic4="",pic5="",pic6="";
        int lblx;
        //播放速度
        int width = 500;
        int height = 500;
        lbname = this.lbname.SelectedItem.Text.ToString();
        lblx = Convert.ToInt32(this.lbname.SelectedItem.Value.ToString());
        tall = this.TALL.Text.ToString();
        t1 = this.T1.Text.ToString();
        t2 = this.T2.Text.ToString();
        t3 = this.T3.Text.ToString();
        t4 = this.T4.Text.ToString();
        t5 = this.T5.Text.ToString();
        t6 = this.T6.Text.ToString();

        h1 = this.H1.Text.ToString();
        h2 = this.H2.Text.ToString();
        h3 = this.H3.Text.ToString();
        h4 = this.H4.Text.ToString();
        h5 = this.H5.Text.ToString();
        h6 = this.H6.Text.ToString();
       string autoPlayTime ="10";
        //----
        if (this.y.Checked)
        {
            SqlConnection conn2=CDatabase.wtoconn();
            conn2.Open();
            SqlCommand cmdcount = new SqlCommand("select count(*) from Advertisement where Condition='y' and Type='0'", conn2);
            int count =Convert.ToInt32(cmdcount.ExecuteScalar());
            conn2.Close();
            if (count!= 0)
            {
                FileInfo p1 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/01.jpg"));
                string pc1 = DateTime.Now.ToString("yyyyMMddHHmmssffffMMyyyy") + ".jpg";
                p1.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pc1);

                FileInfo p2 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/02.jpg"));
                string pc2 = DateTime.Now.ToString("yyyyMMddHHmmssffffMMssss") + ".jpg";
                p2.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pc2);

                FileInfo p3 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/03.jpg"));
                string pc3 = DateTime.Now.ToString("yyyyMMddHHmmssffffMM") + ".jpg";
                p3.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pc3);

                FileInfo p4 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/04.jpg"));
                string pc4 = DateTime.Now.ToString("yyyyMMddHHmmssffffMMffff") + ".jpg";
                p4.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pc4);

                FileInfo p5 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/05.jpg"));
                string pc5 = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
                p5.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pc5);

                FileInfo p6 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/06.jpg"));
                string pc6 = DateTime.Now.ToString("yyyyMMddHHmmssssyyyy") + ".jpg";
                p6.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pc6);
                Doadmin.Exec("update Advertisement set Condition='n',picurl1='" + pc1 + "',picurl2='" + pc2 + "',picurl3='" + pc3 + "',picurl4='" + pc4 + "',picurl5='" + pc5 + "',picurl6='" + pc6 + "' where Condition='y' and type='0'");

            }
            isfp = "y";
            # region 立即发布
            # region 图片上传
            //图1上传
            string fname1 = this.fu1.FileName;
            string fpath1 = this.fu1.PostedFile.FileName;
            string ftype1 = this.fu1.PostedFile.ContentType;
            string[] type1 = ftype1.Split('/');
            string[] fn1 = fname1.Split('.');
            if (type1[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                string pt1 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/01.jpg");
                this.fu1.SaveAs(pt1);
                this.fu1.Dispose();
            }
            //图2上传
            string fname2 = this.fu2.FileName;
            string fpath2 = this.fu2.PostedFile.FileName;
            string ftype2 = this.fu2.PostedFile.ContentType;
            string[] type2 = ftype2.Split('/');
            string[] fn2 = fname2.Split('.');
            if (type2[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                string pt2 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/02.jpg");
                this.fu2.SaveAs(pt2);
                this.fu2.Dispose();
            }
            //图3上传
            string fname3 = this.fu3.FileName;
            string fpath3 = this.fu3.PostedFile.FileName;
            string ftype3 = this.fu3.PostedFile.ContentType;
            string[] type3 = ftype3.Split('/');
            string[] fn3 = fname3.Split('.');
            if (type3[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                string pt3 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/03.jpg");
                this.fu3.SaveAs(pt3);
                this.fu3.Dispose();
            }
            //图4上传
            string fname4 = this.fu4.FileName;
            string fpath4 = this.fu4.PostedFile.FileName;
            string ftype4 = this.fu4.PostedFile.ContentType;
            string[] type4 = ftype4.Split('/');
            string[] fn4 = fname4.Split('.');
            if (type4[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                string pt4 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/04.jpg");
                this.fu4.SaveAs(pt4);
                this.fu4.Dispose();
            }

            //图5上传
            string fname5 = this.fu5.FileName;
            string fpath5 = this.fu5.PostedFile.FileName;
            string ftype5 = this.fu5.PostedFile.ContentType;
            string[] type5 = ftype5.Split('/');
            string[] fn5 = fname5.Split('.');
            if (type5[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                string pt5 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/05.jpg");
                this.fu5.SaveAs(pt5);
                this.fu5.Dispose();
            }
            //图6上传
            string fname6 = this.fu6.FileName;
            string fpath6 = this.fu6.PostedFile.FileName;
            string ftype6 = this.fu6.PostedFile.ContentType;
            string[] type6 = ftype6.Split('/');
            string[] fn6 = fname6.Split('.');
            if (type6[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                string pt6 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/06.jpg");
                this.fu6.SaveAs(pt6);
                this.fu6.Dispose();
            }

            #endregion
            if (Doadmin.Exec("insert into Advertisement(Type,name,title,width,height,Condition,picurl1,picurl2,picurl3,picurl4,picurl5,picurl6,href1,href2,href3,href4,href5,href6,t1,t2,t3,t4,t5,t6) values (" + lblx + ",'" + lbname + "','" + tall + "'," + width + "," + height + ",'" + isfp + "','01.jpg','02.jpg','03.jpg','04.jpg','05.jpg','06.jpg','" + h1 + "','" + h2 + "','" + h3 + "','" + h4 + "','" + h5 + "','" + h6 + "','" + t1 + "','" + t2 + "','" + t3 + "','" + t4 + "','" + t5 + "','" + t6 + "')"))
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/xml/bcastr.xml"));
                XmlNodeList nodeList = xmlDoc.SelectSingleNode("bcaster").ChildNodes;//获取bookstore节点的所有子节点

                foreach (XmlNode xn in nodeList)//遍历所有子节点
                {
                    XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型
                    XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点
                    XmlElement xe2 = (XmlElement)xn;
                    switch (xe2.GetAttribute("item_url"))
                    {
                        case "images/01.jpg":
                            xe2.SetAttribute("link", h1);
                            xe2.SetAttribute("itemtitle", t1);
                            break;
                        case "images/02.jpg":
                            xe2.SetAttribute("link", h2);
                            xe2.SetAttribute("itemtitle", t2);
                            break;
                        case "images/03.jpg":
                            xe2.SetAttribute("link", h3);
                            xe2.SetAttribute("itemtitle", t3);
                            break;
                        case "images/04.jpg":
                            xe2.SetAttribute("link", h4);
                            xe2.SetAttribute("itemtitle", t4);

                            break;
                        case "images/05.jpg":
                            xe2.SetAttribute("link", h5);
                            xe2.SetAttribute("itemtitle", t5);
                            break;
                        case "images/06.jpg":
                            xe2.SetAttribute("link", h6);
                            xe2.SetAttribute("itemtitle", t6);
                            break;
                    }

                }
                xmlDoc.Save(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/xml/bcastr.xml"));//保存
                Response.Write("<script>alert('添加成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败');</script>");
            }
            # endregion
        }
        else
        {
            isfp = "n";
            # region 不立即发布
            //图1上传
            string fname1 = this.fu1.FileName;
            string fpath1 = this.fu1.PostedFile.FileName;
            string ftype1 = this.fu1.PostedFile.ContentType;
            string[] type1 = ftype1.Split('/');
            string[] fn1 = fname1.Split('.');
            if (type1[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                pic1 = DateTime.Now.ToString("yyyyMMddHHmmssffffMMyyyy") + ".jpg";
                string pt1 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/" + pic1);
                this.fu1.SaveAs(pt1);
                this.fu1.Dispose();
            }
            //图2上传
            string fname2 = this.fu2.FileName;
            string fpath2 = this.fu2.PostedFile.FileName;
            string ftype2 = this.fu2.PostedFile.ContentType;
            string[] type2 = ftype2.Split('/');
            string[] fn2 = fname2.Split('.');
            if (type2[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                pic2 = DateTime.Now.ToString("yyyyMMyyyyddHHmmssffffMM") + ".jpg";
                string pt2 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/" +pic2);
                this.fu2.SaveAs(pt2);
                this.fu2.Dispose();
            }
            //图3上传
            string fname3 = this.fu3.FileName;
            string fpath3 = this.fu3.PostedFile.FileName;
            string ftype3 = this.fu3.PostedFile.ContentType;
            string[] type3 = ftype3.Split('/');
            string[] fn3 = fname3.Split('.');
            if (type3[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                pic3 = DateTime.Now.ToString("yyyyMMddHHmmssssffffMM")+".jpg";
                string pt3 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/" +pic3);
                this.fu3.SaveAs(pt3);
                this.fu3.Dispose();
            }
            //图4上传
            string fname4 = this.fu4.FileName;
            string fpath4 = this.fu4.PostedFile.FileName;
            string ftype4 = this.fu4.PostedFile.ContentType;
            string[] type4 = ftype4.Split('/');
            string[] fn4 = fname4.Split('.');
            if (type4[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                pic4 = DateTime.Now.ToString("yyyyMMddHHmmssffffssMM") + ".jpg";
                string pt4 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/" +pic4);
                this.fu4.SaveAs(pt4);
                this.fu4.Dispose();
            }

            //图5上传
            string fname5 = this.fu5.FileName;
            string fpath5 = this.fu5.PostedFile.FileName;
            string ftype5 = this.fu5.PostedFile.ContentType;
            string[] type5 = ftype5.Split('/');
            string[] fn5 = fname5.Split('.');
            if (type5[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                pic5 = DateTime.Now.ToString("yyyyMMddHHmmssffffMMssyyyy") + ".jpg";
                string pt5 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/"+pic5);
                this.fu5.SaveAs(pt5);
                this.fu5.Dispose();
            }
            //图6上传
            string fname6 = this.fu6.FileName;
            string fpath6 = this.fu6.PostedFile.FileName;
            string ftype6 = this.fu6.PostedFile.ContentType;
            string[] type6 = ftype6.Split('/');
            string[] fn6 = fname6.Split('.');
            if (type6[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                pic6 = DateTime.Now.ToString("yyyyssMMddHHmmssffffMM") + ".jpg";
                string pt6 = Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/" +pic6);
                this.fu6.SaveAs(pt6);
                this.fu6.Dispose();
                
            }
            if (Doadmin.Exec("insert into Advertisement(Type,name,title,width,height,Condition,picurl1,picurl2,picurl3,picurl4,picurl5,picurl6,href1,href2,href3,href4,href5,href6,t1,t2,t3,t4,t5,t6) values (" + lblx + ",'" + lbname + "','" + tall + "'," + width + "," + height + ",'" + isfp + "','" + pic1 + "','" + pic2 + "','" + pic3 + "','" + pic4 + "','" + pic5 + "','" + pic6 + "','" + h1 + "','" + h2 + "','" + h3 + "','" + h4 + "','" + h5 + "','" + h6 + "','" + t1 + "','" + t2 + "','" + t3 + "','" + t4 + "','" + t5 + "','" + t6 + "')"))
            {
                Response.Write("<script>alert('添加成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败');</script>");
            }
            # endregion
        }
        
        }
    //对联广告
    protected void adddl_Click(object sender, EventArgs e)
    {
        string dltitle, dllb,dllbname,dlt1,dlt2,dlh1,dlh2,dlleft,dlright,isfp,picname1="",picname2="";
        dltitle = this.TALL.Text;
        dllb = this.lbname.SelectedItem.Value;
        dllbname = this.lbname.SelectedItem.Text;
        dlt1 = this.dlt1.Text;
        dlt2 = this.dlt2.Text;
        dlh1 = this.dlh1.Text;
        dlh2 = this.dlh2.Text;
        int width = Convert.ToInt32(this.WIDTHDL.Text);
        int height = Convert.ToInt32(this.HEIGHTDL.Text);
        if (y.Checked)
        {
            isfp = "y";
            
            #region 对联广告立即发布
            SqlConnection conn3=CDatabase.wtoconn();
            conn3.Open();
            SqlCommand cmdcount1 = new SqlCommand("select count(*) from Advertisement where  Condition='y' and  Type='1'", conn3);
            int count1 =Convert.ToInt32(cmdcount1.ExecuteScalar());
            conn3.Close();
            if (count1 != 0)
            {
                FileInfo dl1 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/left.jpg"));
                string dlpc1 = DateTime.Now.ToString("yyyyMMddHHmmssffffMMyyyy") + ".jpg";
                dl1.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/") + dlpc1);

                FileInfo dl2 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/right.jpg"));
                string dlpc2 = DateTime.Now.ToString("yyyyssssMMddHHmmffffMMyyyy") + ".jpg";
                dl2.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/") + dlpc2);
                Doadmin.Exec("update Advertisement set Condition='n',picurl1='" + dlpc1 + "',picurl2='" + dlpc2 + "' where Condition='y' and type='1'");
                
            }

                //图1上传
                string fnameleft = this.dlleft.FileName;
                string fpathleft = this.dlleft.PostedFile.FileName;
                string ftypeleft = this.dlleft.PostedFile.ContentType;
                string[] typeleft = ftypeleft.Split('/');
                string[] fnleft = fnameleft.Split('.');
                if (typeleft[0].ToString() != "image")
                {
                    Response.Write("文件格式错误！");
                }
                else
                {
                    string ptleft = Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/left.jpg");
                    this.dlleft.SaveAs(ptleft);
                    this.dlleft.Dispose();
                }
                //图二
                string fnameright = this.dlright.FileName;
                string fpathright = this.dlright.PostedFile.FileName;
                string ftyperight = this.dlright.PostedFile.ContentType;
                string[] typeright = ftyperight.Split('/');
                string[] fnright = fnameright.Split('.');
                if (typeright[0].ToString() != "image")
                {
                    Response.Write("文件格式错误！");
                }
                else
                {
                    string ptright = Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/right.jpg");
                    this.dlright.SaveAs(ptright);
                    this.dlright.Dispose();
                }

                if (Doadmin.Exec("insert into Advertisement(Type,name,title,width,height,Condition,picurl1,picurl2,href1,href2,t1,t2) values (" + dllb + ",'" + dllbname + "','" + dltitle + "'," + width + "," + height + ",'" + isfp + "','left.jpg','right.jpg','" + dlh1 + "','" + dlh2 + "','" + dlt1 + "','" + dlt2 + "')"))
                {
                    Response.Write("<script>alert('添加成功');location.href('../news/Advertisement.aspx')</script>");
                }
                else
                {
                    Response.Write("<script>alert('此次操作失败');</script>");
                }
            # endregion

        }
        else
        {
            isfp = "n";
            #region 对联广告不发布
            //图1上传
            string fnameleft = this.dlleft.FileName;
            string fpathleft = this.dlleft.PostedFile.FileName;
            string ftypeleft = this.dlleft.PostedFile.ContentType;
            string[] typeleft = ftypeleft.Split('/');
            string[] fnleft = fnameleft.Split('.');
            if (typeleft[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                picname1 = DateTime.Now.ToString("yyyyssMMddHHmmssffffMM") + ".jpg";
                string ptleft = Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/"+picname1);
                this.dlleft.SaveAs(ptleft);
                this.dlleft.Dispose();
            }
            //图二
            string fnameright = this.dlright.FileName;
            string fpathright = this.dlright.PostedFile.FileName;
            string ftyperight = this.dlright.PostedFile.ContentType;
            string[] typeright = ftyperight.Split('/');
            string[] fnright = fnameright.Split('.');
            if (typeright[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                picname2 = DateTime.Now.ToString("yyyyssMMddHHssffffssMM") + ".jpg";
                string ptright = Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/" + picname2);
                this.dlright.SaveAs(ptright);
                this.dlright.Dispose();
            }

            if (Doadmin.Exec("insert into Advertisement(Type,name,title,width,height,Condition,picurl1,picurl2,href1,href2,t1,t2) values (" + dllb + ",'" + dllbname + "','" + dltitle + "'," + width + "," + height + ",'" + isfp + "','"+picname1+"','"+picname2+"','" + dlh1 + "','" + dlh2 + "','" + dlt1 + "','" + dlt2 + "')"))
            {
                Response.Write("<script>alert('添加成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败');</script>");
            }
            # endregion
        }





    }
    //漂动广告
    protected void addpd_Click(object sender, EventArgs e)
    {
        string pdtitle, pdlb, pdlbname, pdt1, pdh1,isfp,pdpico1="";
        pdtitle = this.TALL.Text;
        pdlb = this.lbname.SelectedItem.Value;
        pdlbname = this.lbname.SelectedItem.Text;
        pdt1 = this.pdtitle.Text;
        pdh1 = this.pdhref.Text;
        int pdwidth = Convert.ToInt32(this.pdwidth.Text);
        int pdheight = Convert.ToInt32(this.pdheight.Text);

        if (y.Checked)
        {
            isfp = "y";

            #region 对联广告立即发布
            SqlConnection conn4 = CDatabase.wtoconn();
            conn4.Open();
            SqlCommand cmdcount4 = new SqlCommand("select count(*) from Advertisement where  Condition='y' and  Type='2'", conn4);
            int count4 = Convert.ToInt32(cmdcount4.ExecuteScalar());
            conn4.Close();
            if (count4 != 0)
            {
                FileInfo pd1 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/pdAdvertisement/images/pic.jpg"));
                string pdpic1 = DateTime.Now.ToString("yyyyMMddHHmmssffffMMyyyy") + ".jpg";
                pd1.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/pdAdvertisement/images/") + pdpic1);
                Doadmin.Exec("update Advertisement set Condition='n',picurl1='" + pdpic1 + "' where Condition='y' and type='2'");
            }





            //图1上传
            string fnamepd = this.pdpic.FileName;
            string fpathpd = this.pdpic.PostedFile.FileName;
            string ftypepd = this.pdpic.PostedFile.ContentType;
            string[] typepd = ftypepd.Split('/');
            string[] fnpd = fnamepd.Split('.');
            if (typepd[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                string ptpd = Server.MapPath("~/WebMain/news/Advertisement/pdAdvertisement/images/pic.jpg");
                this.pdpic.SaveAs(ptpd);
                this.pdpic.Dispose();
            }


            if (Doadmin.Exec("insert into Advertisement(Type,name,title,width,height,Condition,picurl1,href1,t1) values (" + pdlb + ",'" + pdlbname + "','" + pdtitle + "'," + pdwidth + "," + pdheight + ",'" + isfp + "','pic.gif','" + pdh1 + "','" + pdt1 + "')"))
            {
                Response.Write("<script>alert('添加成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败');</script>");
            }
            # endregion

        }
        else
        {
            isfp = "n";
            #region 对联广告不发布
            //图1上传
            string pdname = this.pdpic.FileName;
            string pdhath = this.pdpic.PostedFile.FileName;
            string pdtype3 = this.pdpic.PostedFile.ContentType;
            string[] pdty = pdtype3.Split('/');
            if (pdty[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");
            }
            else
            {
                pdpico1 = DateTime.Now.ToString("yyyyssMMddHHmmssffffMM") + ".jpg";
                string ptleft = Server.MapPath("~/WebMain/news/Advertisement/pdAdvertisement/images/" + pdpico1);
                this.pdpic.SaveAs(ptleft);
                this.pdpic.Dispose();
            }
            if (Doadmin.Exec("insert into Advertisement(Type,name,title,width,height,Condition,picurl1,href1,t1) values (" + pdlb + ",'" + pdlbname + "','" + pdtitle + "'," + pdwidth + "," + pdheight + ",'" + isfp + "','" + pdpico1 + "','" + pdh1 + "','" + pdt1 + "')"))
            {
                Response.Write("<script>alert('添加成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败');</script>");
            }
            # endregion
        }
    }
    //弹出式广告
    protected void addtc_Click(object sender, EventArgs e)
    {
        string tcalltitle, tclbname, tclbtype, isfptc, tctitle, tcwidth, tcheigh, conent;
        tcalltitle = this.TALL.Text;
        tclbtype = this.lbname.SelectedItem.Value.ToString().Trim();
        tclbname = this.lbname.SelectedItem.Text.ToString().Trim();
        if (y.Checked)
        {
            isfptc = "y";
        }
        else
        {
            isfptc = "n";
        }
        tctitle=this.tctitle.Text;
        tcwidth = this.tcwidth.Text;
        tcheigh = this.tcheight.Text;
        conent = Server.HtmlEncode(this.Content.Text.ToString().Replace("'", "''")).Replace("\n", "<br />");
      if (Doadmin.Exec("insert into Advertisement(Type,name,title,width,height,Condition,content,t1) values('" + tclbtype + "','" + tclbname + "','" + tcalltitle + "'," + tcwidth + "," + tcheigh + ",'" + isfptc + "','" + conent + "','" + tctitle + "')"))
            {
                Response.Write("<script>alert('添加成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败');</script>");
            }

    }
    //大型首页广告
    protected void adddx_Click(object sender, EventArgs e)
    {

    }


}
