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();
         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 string ButtonUpload_UploadClick(object sender, WebControls.UploadButtonEventArgs e)
 {
     string message = "";
     try
     {
         if (Session["SSIdProUpload"] == null)
         {
             message = "Xin bạn hãy chọn sản phẩm muốn upload ảnh.";
             return message;
         }
         else
         {
             string strIdAndName = Session["SSIdProUpload"].ToString();
             string[] arrvalue = strIdAndName.Split(',');
             CvalidateImageForPost imgProcess = new CvalidateImageForPost();
             FileUpload file = e.FileUploadControl;
             string file_name = file.PostedFile.FileName;
             if (file_name.Length == 0)
             {
                 message = "Xin bạn hãy chọn file ảnh";
                 return message;
             }
             else
             {
                 if (!imgProcess.TestTypeFile(file))
                 {
                     message = "File Không hợp lệ";
                     return message;
                 }
                 else if (imgProcess.TestMaxSizeImage(file, 20480))
                 {
                     message = "Kích thước ảnh không quá 20 KB";
                     return message;
                 }
                 else
                 {
                     string _path = Server.MapPath("../image/img_pro/");
                     string namepro = "_";
                     if (arrvalue.Length == 3)
                     {
                         namepro = arrvalue[2];
                         namepro = namepro.Replace(" ", "");
                     }
                     string strgetTime = new CGetDataCommon().GetStrMonthDayYearSecondMinuteHour();
                     string nameNew = "pro_" + arrvalue[0] + "_" + strgetTime + "." + imgProcess.GetExtension(file_name);
                     Boolean isUpload = imgProcess.UploadFile(file, _path + nameNew);
                     if (isUpload)
                     {
                         ProductSystem ManagerPro = new ProductSystem();
                         Boolean isUpdate = ManagerPro.ProductUpdateImage(int.Parse(arrvalue[0]), nameNew);
                         if (isUpdate)
                         {
                             message = "";
                             //Xóa ảnh cũ đi:
                             imgProcess.DeleteFile(_path + arrvalue[1]);
                             return message;
                         }
                         else
                         {
                             //Lỗi không thể cập nhật vào cơ sở dữ liệu. Xóa ảnh vừa upload lên đi.
                             imgProcess.DeleteFile(_path + nameNew);
                             message = "Lỗi kết nối SQL server. Không thể cập nhật được ảnh. Xin hãy thử lại";
                             return message;
                         }
                     }
                     else
                     {
                         message = "Lỗi mạng hoặc không có quyền tạo file trong thư mục ảnh sản phẩm. Không thể Upload file ảnh. Xin bạn hãy thử lại";
                         return message;
                     }
                 }
             }
         }
     }
     catch
     {
         message = "Có các lỗi sau đây: Không có quyền tạo file trong thư mục ảnh sản phẩm. Hoặc không cập nhật được vào CSDL. Hoặc ảnh bạn chọn không còn tồn tại. Xin bạn hãy thử lại";
     }
     return message;
 }
    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 đề";
        }
    }