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 SYSadmin_news_AdvertisementEDIT: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        Panel5.Visible = false;
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        switch (Request.QueryString["type"].ToString().Trim())
        { 
            case "0":
                this.Label1.Text = "轮显广告";
                this.Panel1.Visible = true;
                this.Panel2.Visible = false;
                this.Panel3.Visible = false;
                this.Panel4.Visible = false;
                this.addedit.Click+=new EventHandler(editlx_Click);

                if (!IsPostBack)
                {
                    SqlCommand cmd1 = new SqlCommand("select * from Advertisement where id=" + Request.QueryString["id"], conn);
                    SqlDataReader sdr1 = cmd1.ExecuteReader();
                    sdr1.Read();
                    if (sdr1.GetString(6).Trim() == "y")
                    {
                        this.y.Checked = true;
                    }
                    else
                    {
                        this.n.Checked = true;
                    }
                    this.TALL.Text = sdr1.GetString(3);
                    this.T1.Text = sdr1.GetString(20);
                    this.H1.Text = sdr1.GetString(13);
                    this.pic1.Text = sdr1.GetString(7);
                    this.Image1.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/lxAdvertisement/images/" + sdr1.GetString(7) + "')");

                    this.T2.Text = sdr1.GetString(21);
                    this.H2.Text = sdr1.GetString(14);
                    this.pic2.Text = sdr1.GetString(8);
                    this.Image2.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/lxAdvertisement/images/" + sdr1.GetString(8) + "')");

                    this.T3.Text = sdr1.GetString(22);
                    this.H3.Text = sdr1.GetString(15);
                    this.pic3.Text = sdr1.GetString(9);
                    this.Image3.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/lxAdvertisement/images/" + sdr1.GetString(9) + "')");

                    this.T4.Text = sdr1.GetString(23);
                    this.H4.Text = sdr1.GetString(16);
                    this.pic4.Text = sdr1.GetString(10);
                    this.Image4.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/lxAdvertisement/images/" + sdr1.GetString(10) + "')");

                    this.T5.Text = sdr1.GetString(24);
                    this.H5.Text = sdr1.GetString(17);
                    this.pic5.Text = sdr1.GetString(11);
                    this.Image5.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/lxAdvertisement/images/" + sdr1.GetString(11) + "')");

                    this.T6.Text = sdr1.GetString(25);
                    this.H6.Text = sdr1.GetString(18);
                    this.pic6.Text = sdr1.GetString(12);
                    this.Image6.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/lxAdvertisement/images/" + sdr1.GetString(12) + "')");

                    sdr1.Close();
                }
                break;
            case "1":
                this.Label1.Text = "对联广告";
                this.Panel1.Visible = false;
                this.Panel2.Visible = true;
                this.Panel3.Visible = false;
                this.Panel4.Visible = false;
                this.addedit.Click += new EventHandler(editdl_Click);

                if (!IsPostBack)
                {
                    SqlCommand smddl = new SqlCommand("select * from Advertisement where id=" + Request.QueryString["id"], conn);
                    SqlDataReader sdrdl = smddl.ExecuteReader();
                    sdrdl.Read();
                    this.TALL.Text = sdrdl.GetString(3);
                    if (sdrdl.GetString(6) == "y")
                    {
                        this.y.Checked = true;
                    }
                    else
                    {
                        this.n.Checked = true;
                    }
                    this.WIDTHDL.Text = Convert.ToString(sdrdl.GetInt32(4));
                    this.HEIGHTDL.Text = Convert.ToString(sdrdl.GetInt32(5));
                    this.dlt1.Text = sdrdl.GetString(20);
                    this.dlt2.Text = sdrdl.GetString(21);
                    this.dlh1.Text = sdrdl.GetString(13);
                    this.dlh2.Text = sdrdl.GetString(14);
                    this.dlpic1.Text = sdrdl.GetString(7);
                    this.dlpic2.Text = sdrdl.GetString(8);
                    this.Image7.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/dlAdvertisement/ad/" + sdrdl.GetString(7) + "')");
                    this.Image8.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/dlAdvertisement/ad/" + sdrdl.GetString(8) + "')");


                    conn.Close();
                }

                break;
            case "2":
                this.Label1.Text = "漂动广告";
                this.Panel1.Visible = false;
                this.Panel2.Visible = false;
                this.Panel3.Visible = true;
                this.Panel4.Visible = false;
                this.addedit.Click += new EventHandler(editpd_Click);
                if (!IsPostBack)
                {

                    SqlCommand smdpd = new SqlCommand("select * from Advertisement where id=" + Request.QueryString["id"], conn);
                    SqlDataReader sdrpd = smdpd.ExecuteReader();
                    sdrpd.Read();
                    this.TALL.Text = sdrpd.GetString(3);
                    if (sdrpd.GetString(6) == "y")
                    {
                        this.y.Checked = true;
                    }
                    else
                    {
                        this.n.Checked = true;
                    }
                    this.pdwidth.Text = Convert.ToString(sdrpd.GetInt32(4));
                    this.pdheight.Text = Convert.ToString(sdrpd.GetInt32(5));
                    this.pdtitle.Text = sdrpd.GetString(20);
                    this.pdhref.Text = sdrpd.GetString(13);
                    this.pdpicview.Text = sdrpd.GetString(7);
                    this.Image9.Attributes.Add("onclick", "window.open('../../WebMain/news/Advertisement/pdAdvertisement/images/" + sdrpd.GetString(7) + "')");


                    conn.Close();
                }

                break;
            case "3":
                this.Label2.Visible = false;
                this.Label1.Text = "弹出广告";
                this.Panel1.Visible = false;
                this.Panel2.Visible = false;
                this.Panel3.Visible = false;
                this.Panel4.Visible = true;
                this.addedit.Click += new EventHandler(edittc_Click);
                if (!IsPostBack)
                {

                    SqlCommand smdtc = new SqlCommand("select * from Advertisement where id=" + Request.QueryString["id"], conn);
                    SqlDataReader sdrtc = smdtc.ExecuteReader();
                    sdrtc.Read();
                    this.TALL.Text = sdrtc.GetString(3);
                    if (sdrtc.GetString(6) == "y")
                    {
                        this.y.Checked = true;
                    }
                    else
                    {
                        this.n.Checked = true;
                    }
                    this.tcwidth.Text = Convert.ToString(sdrtc.GetInt32(4));
                    this.tcheight.Text = Convert.ToString(sdrtc.GetInt32(5));
                    this.tctitle.Text = sdrtc.GetString(20);
                    this.Content.Text =Server.HtmlDecode(sdrtc.GetString(19));
                    conn.Close();
                }
                break;
        }
        conn.Close();
    }
    protected void editlx_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 = "";
        string pq1 = "", pq2 = "", pq3 = "", pq4 = "", pq5 = "", pq6 = "";
        int lblx;
        //播放速度
        int width = 500;
        int height = 500;
        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());
            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 图片上传
            SqlCommand remt = new SqlCommand("select picurl1,picurl2,picurl3,picurl4,picurl5,picurl6 from Advertisement where id=" + Request.QueryString["id"].ToString().Trim(), conn2);
            SqlDataReader sdremt = remt.ExecuteReader();
            sdremt.Read();
            //图1上传
            string fname1 = this.fu1.FileName;
            string fpath1 = this.fu1.PostedFile.FileName;
            if (fpath1 != "")
            {
                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();
                }
            }
            else
            {
                pq1 = sdremt.GetString(0);
                FileInfo lx1 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pq1);
                lx1.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/01.jpg"));

            }

            //图2上传
            string fname2 = this.fu2.FileName;
            string fpath2 = this.fu2.PostedFile.FileName;
            if (fpath2 != "")
            {
                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();
                }
            }
            else
            {
                pq2 = sdremt.GetString(1);
                FileInfo lx2 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pq2);
                lx2.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/02.jpg"));
            }
            //图3上传
            string fname3 = this.fu3.FileName;
            string fpath3 = this.fu3.PostedFile.FileName;
            if (fpath3 != "")
            {
                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();
                }
            }
            else
            {
                pq3 = sdremt.GetString(2);
                FileInfo lx3 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pq3);
                lx3.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/03.jpg"));
            }
            //图4上传
            string fname4 = this.fu4.FileName;
            string fpath4 = this.fu4.PostedFile.FileName;
            if (fpath4 != "")
            {
                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();
                }
            }
            else
            {
                pq4 = sdremt.GetString(3);
                FileInfo lx4 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pq4);
                lx4.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/04.jpg"));
            }

            //图5上传
            string fname5 = this.fu5.FileName;
            string fpath5 = this.fu5.PostedFile.FileName;
            if (fpath5 != "")
            {
                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();
                }
            }
            else
            {
                pq5 = sdremt.GetString(4);
                FileInfo lx5 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pq5);
                lx5.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/05.jpg"));
            }
            //图6上传
            string fname6 = this.fu6.FileName;
            string fpath6 = this.fu6.PostedFile.FileName;
            if (fpath6 != "")
            {
                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();
                }
            }
            else
            {
                pq6 = sdremt.GetString(5);
                FileInfo lx6 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/") + pq6);
                lx6.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/lxAdvertisement/images/06.jpg"));
            }
            sdremt.Close();
            conn2.Close();
            #endregion
            if (Doadmin.Exec("update Advertisement set title='" + tall + "',Condition='" + isfp + "',picurl1='01.jpg',picurl2='02.jpg',picurl3='03.jpg',picurl4='04.jpg',picurl5='05.jpg',picurl6='06.jpg',href1='" + h1 + "',href2='" + h2 + "',href3='" + h3 + "',href4='" + h4 + "',href5='" + h5 + "',href6='" + h6 + "',t1='" + t1 + "',t2='" + t2 + "',t3='" + t3 + "',t4='" + t4 + "',t5='" + t5 + "',t6='" + t6 + "' where id="+Request.QueryString["id"]))
            {
                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
        {    
            SqlConnection connfd=CDatabase.wtoconn();
            connfd.Open();
            SqlCommand smdfd = new SqlCommand("select Condition from Advertisement where id="+Request.QueryString["id"].Trim(), connfd);
            string condition = Convert.ToString(smdfd.ExecuteScalar());
            connfd.Close();
            if (condition == "n")
            {
                isfp = "n";
                # region 不立即发布
                //图1上传
                string fname1 = this.fu1.FileName;
                string fpath1 = this.fu1.PostedFile.FileName;
                if (fpath1 != "")
                {
                    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();
                    }

                }
                else
                {
                    pic1 = this.pic1.Text;
                }

                //图2上传
                string fname2 = this.fu2.FileName;
                string fpath2 = this.fu2.PostedFile.FileName;
                if (fpath2 != "")
                {
                    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();
                    }
                }
                else
                {
                    pic2 = this.pic2.Text;
                }
                //图3上传
                string fname3 = this.fu3.FileName;
                string fpath3 = this.fu3.PostedFile.FileName;
                if (fpath3 != "")
                {
                    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();
                    }
                }
                else
                {
                    pic3 = this.pic3.Text;
                }
                //图4上传
                string fname4 = this.fu4.FileName;
                string fpath4 = this.fu4.PostedFile.FileName;
                if (fpath4 != "")
                {
                    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();
                    }
                }
                else
                {
                    pic4 = this.pic4.Text;
                }
                //图5上传
                string fname5 = this.fu5.FileName;
                string fpath5 = this.fu5.PostedFile.FileName;
                if (fpath5 != "")
                {
                    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();
                    }
                }
                else
                {
                    pic5 = this.pic5.Text;
                }
                //图6上传
                string fname6 = this.fu6.FileName;
                string fpath6 = this.fu6.PostedFile.FileName;
                if (fpath6 != "")
                {
                    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();

                    }
                }
                else
                {
                    pic6 = this.pic6.Text;
                }
                if (Doadmin.Exec("update Advertisement set title='" + tall + "',Condition='" + isfp + "',picurl1='" + pic1 + "',picurl2='" + pic2 + "',picurl3='" + pic3 + "',picurl4='" + pic4 + "',picurl5='" + pic5 + "',picurl6='" + pic6 + "',href1='" + h1 + "',href2='" + h2 + "',href3='" + h3 + "',href4='" + h4 + "',href5='" + h5 + "',href6='" + h6 + "',t1='" + t1 + "',t2='" + t2 + "',t3='" + t3 + "',t4='" + t4 + "',t5='" + t5 + "',t6='" + t6 + "' where id=" + Request.QueryString["id"]))
                {
                    Response.Write("<script>alert('操作成功');location.href('../news/Advertisement.aspx')</script>");
                }
                else
                {
                    Response.Write("<script>alert('此次操作失败');</script>");
                }
                # endregion
            }
            else
            {
                Response.Write("<script>alert('此次操作不合法,需保留一个轮显广告.');location.href('../news/Advertisement.aspx')</script>");
            }
        }
        
    }
    protected void editdl_Click(object sender, EventArgs e)
    {
        string dltitle, dllb, dllbname, dlt1, dlt2, dlh1, dlh2, dlleft, dlright, isfp, picname1 = "", picname2 = "",picdlN1="",picdlN2="";
        dltitle = this.TALL.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;
            conn3.Open();
            SqlCommand dlmt = new SqlCommand("select picurl1,picurl2 from Advertisement where id=" + Request.QueryString["id"].ToString().Trim(), conn3);
            SqlDataReader sdrdl = dlmt.ExecuteReader();
            sdrdl.Read();
            if (fpathleft != "")
            {
                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();
                }
                picdlN1 = "left.jpg";
            }
            else
            {
                FileInfo ptodl1 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/")+sdrdl.GetString(0));
                ptodl1.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/left.jpg"));
                picdlN1 = "left.jpg";
            }

            //图二
            string fnameright = this.dlright.FileName;
            string fpathright = this.dlright.PostedFile.FileName;
            if (fpathright != "")
            {
                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();
                }
                picdlN2 = "right.jpg";
            }
            else
            {
                FileInfo ptodl2 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/") + sdrdl.GetString(1));
                ptodl2.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/right.jpg"));
                picdlN2 = "right.jpg";
            }
            sdrdl.Close();
            conn3.Close();
            if (Doadmin.Exec("update Advertisement set title='" + dltitle + "',width=" + width + ",height=" + height + ",Condition='" + isfp + "',picurl1='" + picdlN1 + "',picurl2='" + picdlN2 + "',href1= '" + dlh1 + "',href2='" + dlh2 + "',t1='" + dlt1 + "',t2='" + dlt2 + "' where id="+Request.QueryString["id"]))
            {
                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;
            if (fnameleft != "")
            {
                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();
                }
            }
            else
            {
                FileInfo ppdo11 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/" +this.dlpic1.Text));
                picname1 = DateTime.Now.ToString("ssssssMMddHHmmssffffMM") + ".jpg";
                ppdo11.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/"+picname1));
            }
            //图二
            string fnameright = this.dlright.FileName;
            string fpathright = this.dlright.PostedFile.FileName;
            if (fpathright != "")
            {
                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();
                }
            }
            else
            {
                FileInfo ppdo12 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/" + this.dlpic2.Text));
                picname2 = DateTime.Now.ToString("ssssddssHHmmssffffMM") + ".jpg";
                ppdo12.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/dlAdvertisement/ad/" + picname2));
            }

            if (Doadmin.Exec("update Advertisement set title='" + dltitle + "',width=" + width + ",height=" + height + ",Condition='" + isfp + "',picurl1='" +picname1+ "',picurl2='" + picname2 + "',href1= '" + dlh1 + "',href2='" + dlh2 + "',t1='" + dlt1 + "',t2='" + dlt2 + "' where id=" + Request.QueryString["id"]))
            {
                Response.Write("<script>alert('操作成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败');</script>");
            }
            # endregion
        }


    }
    protected void editpd_Click(object sender, EventArgs e)
    {
        string pdtitle, pdlb, pdlbname, pdt1, pdh1, isfp, pdpico1 = "";
        pdtitle = this.TALL.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上传
            conn4.Open();
            SqlCommand pdmt = new SqlCommand("select picurl1 from Advertisement where id=" + Request.QueryString["id"].ToString().Trim(), conn4);
            SqlDataReader sdrpd = pdmt.ExecuteReader();
            sdrpd.Read();
            string fnamepd = this.pdpic.FileName;
            string fpathpd = this.pdpic.PostedFile.FileName;
            if (fpathpd != "")
            {
                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();
                }
            }
            else
            {
                FileInfo ptopd = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/pdAdvertisement/images/") + sdrpd.GetString(0));
                ptopd.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/pdAdvertisement/images/pic.jpg"));
                pdpico1 = "pic.jpg";
            }
            if (Doadmin.Exec("update Advertisement set title='" + pdtitle + "',width=" + pdwidth + ",height=" + pdheight + ",Condition='" + isfp + "',picurl1='pic.jpg',href1='" + pdt1 + "' where id="+Request.QueryString["id"]))
            {
                Response.Write("<script>alert('操作成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败1');</script>");
            }
            # endregion

        }
        else
        {
            isfp = "n";
            #region 对联广告不发布
            //图1上传
            string pdname = this.pdpic.FileName;
            string pdhath = this.pdpic.PostedFile.FileName;
            if (pdhath != "")
            {
                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();
                }
            }
            else
            {
                FileInfo ppdo11 = new FileInfo(Server.MapPath("~/WebMain/news/Advertisement/pdAdvertisement/images/" + this.pdpicview.Text));
                pdpico1 = DateTime.Now.ToString("ssssssMMddHHmmssffffMM") + ".jpg";
                ppdo11.MoveTo(Server.MapPath("~/WebMain/news/Advertisement/pdAdvertisement/images/" + pdpico1));
            }
            if (Doadmin.Exec("update Advertisement set title='" + pdtitle + "',width=" + pdwidth + ",height=" + pdheight + ",Condition='" + isfp + "',picurl1='" + pdpico1 + "',href1='" + pdt1 + "' where id=" + Request.QueryString["id"]))
            {
                Response.Write("<script>alert('操作成功');location.href('../news/Advertisement.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('此次操作失败2');</script>");
            }
            # endregion
        }
    }
    protected void edittc_Click(object sender, EventArgs e)
    {
        string tcalltitle, tclbname, tclbtype, isfptc, tctitle, tcwidth, tcheigh, conent;
        tcalltitle = this.TALL.Text;
        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("update Advertisement set title='" + tcalltitle + "',width=" + tcwidth + ",height=" + tcheigh + ",Condition='" + isfptc + "',content='" + conent + "',t1='" + tctitle + "' where type='3' and id="+Request.QueryString["id"]))
        {
            Response.Write("<script>alert('操作成功');location.href('../news/Advertisement.aspx')</script>");
        }
        else
        {
            Response.Write("<script>alert('此次操作失败');</script>");
        }
    }
}
