Пример #1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        String validFiles = "gif, jpg, bmp, png, GIF, JPG, BMP, PNG";

        if (FileUpload1.HasFile && FileUpload1.Enabled == true)
        {
            String         filename = FileUpload1.FileName;
            HttpPostedFile file     = FileUpload1.PostedFile;

            if (file.ContentLength > 0)
            {
                if (validFiles.IndexOf(filename.Substring(filename.LastIndexOf(".") + 1)) > 0)
                {
                    String filepath = Server.MapPath("Hinh Anh\\Quang Cao") + "\\" + filename;
                    FileUpload1.SaveAs(filepath);

                    XmlDocument Tai_lieu  = new XmlDocument();
                    XmlElement  Quang_cao = null;

                    Tai_lieu.Load(Server.MapPath("He Phuc Vu/QUANG_CAO.xml"));
                    Quang_cao = Tai_lieu.DocumentElement;

                    foreach (XmlElement Thong_tin in Quang_cao.ChildNodes)
                    {
                        if (Thong_tin.GetAttribute("Ten").CompareTo(Session["Ten_quang_cao"]) == 0)
                        {
                            Thong_tin.SetAttribute("Logo", "./Hinh Anh/Quang Cao/" + filename);
                            Tai_lieu.Save(Server.MapPath("He Phuc Vu/QUANG_CAO.xml"));
                            break;
                        }
                    }
                }
            }
        }
    }
    private void Cap_Nhat_Tinh_Trang()
    {
        XmlDocument Tai_lieu  = new XmlDocument();
        XmlElement  Quang_cao = null;

        Tai_lieu.Load(Server.MapPath("QUANG_CAO.xml"));
        Quang_cao = Tai_lieu.DocumentElement;

        foreach (XmlElement Thong_tin in Quang_cao.ChildNodes)
        {
            if (Thong_tin.GetAttribute("Ten").CompareTo(Request["Ten_cong_ty"]) == 0)
            {
                if (Request["Loai"] == "1")
                {
                    Thong_tin.SetAttribute("TinhTrang", "1");
                }
                else if (Request["Loai"] == "0")
                {
                    Thong_tin.SetAttribute("TinhTrang", "0");
                }
                break;
            }
        }

        Tai_lieu.Save(Server.MapPath("QUANG_CAO.xml"));
        XL_THE Kq = new XL_THE("Goc");

        XL_CHUOI.XuatXML(Response, Kq.Chuoi());
    }
    private void Cap_nhat_thong_tin()
    {
        XmlDocument Tai_lieu  = new XmlDocument();
        XmlElement  Quang_cao = null;

        Tai_lieu.Load(Server.MapPath("QUANG_CAO.xml"));
        Quang_cao = Tai_lieu.DocumentElement;

        foreach (XmlElement Thong_tin in Quang_cao.ChildNodes)
        {
            if (Thong_tin.GetAttribute("Ten").CompareTo(Session["Ten_cong_ty"]) == 0)
            {
                Session["Ten_cong_ty"] = Request["Ten_cong_ty"];

                Thong_tin.SetAttribute("Ten", Request["Ten_cong_ty"]);
                Thong_tin.SetAttribute("DiaChi", Request["Dia_chi"]);
                Thong_tin.SetAttribute("Website", Request["Website"]);

                //Thong_tin.SetAttribute("TrangXuatHien", Request["WebsiteTheHien"]);
                string      website_the_hien = Request["WebsiteTheHien"].ToString();
                string[]    arr       = website_the_hien.Split('-');
                XmlDocument Tai_lieu1 = new XmlDocument();
                XmlElement  website   = null;
                Tai_lieu1.Load(Server.MapPath("WEBSITE.xml"));
                website = Tai_lieu1.DocumentElement;

                String      strExp  = "//WEBSITE//ThongTin//QuangCao[@Ten='" + Thong_tin.GetAttribute("Ten") + "']";
                XmlNodeList nodeAdv = website.SelectNodes(strExp);
                foreach (XmlNode node in nodeAdv)
                {
                    XmlNode parent = node.ParentNode;
                    parent.RemoveChild(node);
                }

                for (int i = 0; i < arr.Length; i++)
                {
                    foreach (XmlElement Thong_tin1 in website.ChildNodes)
                    {
                        if (Thong_tin1.GetAttribute("Ten").CompareTo(arr[i]) == 0)
                        {
                            XmlElement _quangcao = Tai_lieu1.CreateElement("QuangCao");
                            _quangcao.SetAttribute("Ten", Request["Ten_cong_ty"]);
                            Thong_tin1.AppendChild(_quangcao);
                        }
                    }
                }
                Tai_lieu1.Save(Server.MapPath("WEBSITE.xml"));
                ////////////////////////////////////////////////////////////////////////////

                if (Request["Logo"] != null)
                {
                    Thong_tin.SetAttribute("Logo", Request["Logo"]);
                }

                Thong_tin.SetAttribute("TinhTrang", Request["Tinh_trang"]);

                Tai_lieu.Save(Server.MapPath("QUANG_CAO.xml"));
                XL_THE Kq = new XL_THE("Goc");
                XL_CHUOI.XuatXML(Response, Kq.Chuoi());

                break;
            }
        }
    }