Beispiel #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 Lay_danh_sach_website()
    {
        XmlDocument Tai_lieu = new XmlDocument();
        XmlElement  Website  = null;

        Tai_lieu.Load(Server.MapPath("WEBSITE.xml"));
        Website = Tai_lieu.DocumentElement;

        XL_THE Kq = new XL_THE("WEBSITE");

        foreach (XmlElement Thong_tin in Website.ChildNodes)
        {
            if (Thong_tin.GetAttribute("TinhTrang").ToString() == "0")
            {
                continue;
            }

            XL_THE Kq1 = new XL_THE("ThongTin");

            XL_THUOC_TINH Thuoc_tinh = new XL_THUOC_TINH("Ten_website", Thong_tin.GetAttribute("Ten"));
            Kq1.Danh_sach_thuoc_tinh.Add(Thuoc_tinh);

            Kq.Danh_sach_the.Add(Kq1);
        }

        XL_CHUOI.XuatXML(Response, Kq.Chuoi());
    }
    private void Hien_thi_cap_nhat()
    {
        if (Session["Ten_cong_ty"].ToString() != "")
        {
            XmlDocument Tai_lieu  = new XmlDocument();
            XmlElement  Quang_cao = null;

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

            XL_THE Kq = new XL_THE("THONG_TIN");

            foreach (XmlElement Thong_tin in Quang_cao.ChildNodes)
            {
                if (Thong_tin.GetAttribute("Ten").CompareTo(Session["Ten_cong_ty"]) == 0)
                {
                    XL_THUOC_TINH Thuoc_tinh = new XL_THUOC_TINH("Ten_cong_ty", Thong_tin.GetAttribute("Ten"));
                    Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh);
                    Thuoc_tinh = new XL_THUOC_TINH("Dia_chi", Thong_tin.GetAttribute("DiaChi"));
                    Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh);
                    Thuoc_tinh = new XL_THUOC_TINH("Website", Thong_tin.GetAttribute("Website"));
                    Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh);
                    Thuoc_tinh = new XL_THUOC_TINH("Logo", Thong_tin.GetAttribute("Logo"));
                    Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh);

                    string website_the_hien = "";

                    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);
                    int         i       = 0;
                    foreach (XmlNode node in nodeAdv)
                    {
                        XmlNode parent = node.ParentNode;
                        website_the_hien += parent.Attributes["Ten"].Value;
                        if (i < nodeAdv.Count - 1)
                        {
                            website_the_hien += '-';
                        }
                        i++;
                    }

                    Thuoc_tinh = new XL_THUOC_TINH("WebsiteTheHien", website_the_hien);
                    Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh);

                    Thuoc_tinh = new XL_THUOC_TINH("Tinh_trang", Thong_tin.GetAttribute("TinhTrang"));
                    Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh);

                    break;
                }
            }

            XL_CHUOI.XuatXML(Response, Kq.Chuoi());
        }
    }
    private void Xoa_Quang_Cao()
    {
        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)
            {
                Quang_cao.RemoveChild(Thong_tin);

                //xoa trong website
                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);
                }

                Tai_lieu1.Save(Server.MapPath("WEBSITE.xml"));

                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;
            }
        }
    }