protected void btadd_ServerClick(object sender, EventArgs e)
 {
     try
     {
         string title = txttitle.Value.Trim();
         string link = txtlink.Value.Trim();
         int sort = int.Parse(slsort.Value);
         string ishow = "0";
         if (checkshow.Checked)
         {
             ishow = "1";
         }
         string note = txtnote.Value.Trim();
         if (title.Length == 0)
         {
             diverror.Visible = true;
             diverror.InnerHtml = "<div class='diverror'>Xin hãy nhập tiêu đề liên kết</div>";
             return;
         }
         else if (link.Length == 0)
         {
             diverror.Visible = true;
             diverror.InnerHtml = "<div class='diverror'>Xin hãy nhập Link liên kết</div>";
             return;
         }
         else
         {
             string nameImage = "";
             DateTime time = new DateTime();
             time = DateTime.Now;
             CvalidateImageForPost manageImage = new CvalidateImageForPost();
             if (ImageArticle.PostedFile.FileName.Length > 0)
             {
                 nameImage = "advertise" + time.Ticks + "." + manageImage.GetExtension(ImageArticle.PostedFile.FileName);
             }
             if (advertise.AdvertiseInsert(title,sort, link, nameImage,ishow,note))
             {
                 diverror.Visible = true;
                 diverror.InnerHtml = "<div class='diverror'>Liên kết đã được thêm mới</div>";
                 //UpdateArticle:
                 txttitle.Value = "";
                 txtnote.Value = "";
                 txtlink.Value = "";
                 checkshow.Checked = true;
                 Application["appAdvertiset"] = null;
                 SetAdvertise();
                 if (ImageArticle.PostedFile.FileName.Length > 0)
                 {
                     if (manageImage.TestTypeFile(ImageArticle))
                     {
                         if (manageImage.TestMaxSizeImage(ImageArticle, 102400))
                         {
                             diverror.InnerHtml += "<div class='diverror'>Ảnh không quá 100KB</div>";
                         }
                         else
                         {
                             string path = Server.MapPath("../image/advertise/");
                             manageImage.UploadFile_server(ImageArticle, path + nameImage);
                         }
                     }
                     else
                     {
                         diverror.InnerHtml += "<div class='diverror'>Chỉ hỗ trợ file dạng: gif, png, jpg, bmp, swf</div>";
                     }
                 }
                 return;
             }
             else
             {
                 diverror.Visible = true;
                 diverror.InnerHtml = "<div class='diverror'>Lỗi kết nối, không thể thêm mới liên kết</div>";
                 return;
             }
         }
     }
     catch
     { }
 }
    protected void btedit_ServerClick(object sender, EventArgs e)
    {
        try
        {
            string title = txttitle.Value.Trim();
            string sum = txtsumcontent.Value.Trim();
            content = Request.Form["txtContent"].ToString();
            string source = txtsource.Value.Trim();
            string link = txtlink.Value.Trim();
            int idgroup=int.Parse(slGroup.Value);
            string ishow = "0";
            if (checkshow.Checked)
            {
                ishow = "1";
            }
            if (title.Length == 0)
            {
                diverror.Visible = true;
                diverror.InnerHtml = "<div class='diverror'>Xin bạn hãy nhập tiêu đề tin</div>";
                return;
            }
            else if (sum.Length == 0)
            {
                diverror.Visible = true;
                diverror.InnerHtml = "<div class='diverror'>Xin hãy nhập mô tả ngắn gọn tin tức</div>";
                return;
            }
            else
            {
                DataSet dsArticle = Articles.AdminArticleTestExsit(id, title);
                if (dsArticle.Tables.Count > 0)
                {
                    if (dsArticle.Tables[0].Rows.Count > 0)
                    {
                        Boolean isUpdate = false;
                        if (dsArticle.Tables[1].Rows.Count > 0)
                        {
                            if (dsArticle.Tables[1].Rows[0]["id"].ToString() == id.ToString())
                            {
                                //Update:
                                isUpdate = true;
                            }
                            else
                            {
                                diverror.Visible = true;
                                diverror.InnerHtml = "<div class='diverror'>Tiêu đề tin đã tồn tại, xin hãy nhập tiêu đề khác</div>";
                                return;
                            }
                        }
                        else
                        {
                            //Update:
                            isUpdate = true;
                        }
                        string nameImage="";
                        DateTime time=new DateTime();
                        time=DateTime.Now;
                        CvalidateImageForPost manageImage = new CvalidateImageForPost();
                        nameImage=dsArticle.Tables[0].Rows[0]["urlImage"].ToString();
                        if(ImageArticle.PostedFile.FileName.Length>0)
                        {
                            nameImage = "article_image_" + id + "." + manageImage.GetExtension(ImageArticle.PostedFile.FileName);
                        }
                        if (isUpdate)
                        {
                            if(Articles.AdminArticleUpdate(id,idgroup,title,sum,content,nameImage,time,source,link,ishow))
                            {
                                diverror.Visible = true;
                                diverror.InnerHtml = "<div class='diverror'>Tin tức đã được chỉnh sửa</div>";
                                //UpdateArticle:
                                if (ImageArticle.PostedFile.FileName.Length > 0)
                                {
                                    string path = Server.MapPath("../image/img_article/");
                                    if (dsArticle.Tables[0].Rows[0]["urlImage"].ToString().Length > 0)
                                    {
                                        manageImage.DeleteFile(path + dsArticle.Tables[0].Rows[0]["urlImage"].ToString().Length);
                                    }
                                    if (manageImage.TestMaxSizeImage(ImageArticle, 71680))
                                    {
                                        diverror.InnerHtml += "<div class='diverror'>Ảnh không quá 70 KB</div>";
                                    }
                                    else
                                    {

                                        manageImage.UploadFile_server(ImageArticle, path + nameImage);
                                    }
                                }
                                return;
                            }else
                            {
                                diverror.Visible = true;
                                diverror.InnerHtml = "<div class='diverror'>Lỗi kết nối, không thể thêm mới tin tức</div>";
                                return;
                            }
                        }
                    }
                    else
                    {
                        Response.Redirect("AdminWebsite.aspx?menu=grouparticle");
                    }
                }
                else
                {
                    Response.Redirect("AdminWebsite.aspx?menu=grouparticle");
                }
            }
        }
        catch
        { }
    }
    protected void btadd_ServerClick(object sender, EventArgs e)
    {
        try
        {
            string title = txttitle.Value.Trim();
            int idBrand = int.Parse(slBrand.Value);
            content = Request.Form["txtContent"].ToString().Trim();
            string link = txtlink.Value.Trim();
            string Url1 = nameurl1;
            string Url2 = nameurl2;
            int sort = int.Parse(slsort.Value.ToString().Trim());
            if (title.Length > 0)
            {
                DateTime time = new DateTime();
                time = DateTime.Now;
                CvalidateImageForPost manageImage = new CvalidateImageForPost();
                AdvertiseSystem Advertise = new AdvertiseSystem();
                if (ImageArticle1.PostedFile.FileName.Length > 0)
                {
                    Url1 = "special_1" + time.Ticks + "." + manageImage.GetExtension(ImageArticle1.PostedFile.FileName);
                }
                if (ImageArticle2.PostedFile.FileName.Length > 0)
                {
                    Url2 = "special_2" + time.Ticks + "." + manageImage.GetExtension(ImageArticle2.PostedFile.FileName);
                }
                Boolean test = Advertise.SpecialUpdate(id, idBrand, title, content, Url1, Url2, link, sort);
                if (test)
                {
                    diverror.Visible = true;
                    diverror.InnerHtml = "Quảng cáo đặc biệt đã được chỉnh sửa";
                    string path = Server.MapPath("../image/advertise/");
                    if (ImageArticle1.PostedFile.FileName.Length > 0)
                    {
                        if (manageImage.TestTypeFile(ImageArticle1))
                        {
                            if (manageImage.TestMaxSizeImage(ImageArticle1, 84280))
                            {
                                diverror.InnerHtml += "<br />Ảnh nhỏ không quá 70KB";
                            }
                            else
                            {
                                manageImage.UploadFile_server(ImageArticle1, path + Url1);
                                manageImage.DeleteFile(path + nameurl1);
                                urlOld1 = "../image/advertise/" + Url1;
                            }
                        }
                        else
                        {
                            diverror.InnerHtml += "<br />Chỉ hỗ trợ file dạng: gif, png, jpg, bmp, swf";
                        }
                    }

                    if (ImageArticle2.PostedFile.FileName.Length > 0)
                    {
                        if (manageImage.TestTypeFile(ImageArticle2))
                        {
                            if (manageImage.TestMaxSizeImage(ImageArticle2, 122880))
                            {
                                diverror.InnerHtml += "<br />Ảnh to không quá 120KB";
                            }
                            else
                            {
                                manageImage.UploadFile_server(ImageArticle2, path + Url2);
                                manageImage.DeleteFile(path + nameurl2);
                                urlOld2 = "../image/advertise/" + Url2;
                            }
                        }
                        else
                        {
                            diverror.InnerHtml += "<br />Chỉ hỗ trợ file dạng: gif, png, jpg, bmp, swf";
                        }
                    }

                }
                else
                {
                    diverror.Visible = true;
                    diverror.InnerHtml = "Lỗi kết nối, xin hãy thử lại";
                }
            }
            else
            {
                diverror.Visible = true;
                diverror.InnerHtml = "Xin hãy nhập tiêu đề";
            }
        }
        catch
        {
            diverror.Visible = true;
            diverror.InnerHtml = "Xin hãy nhập tiêu đề";
        }
    }