public bool ChangeFeatureImage(Product_Model product, string NewImage)
        {
            bool result = false;

            result = FTPAction.sendFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                        FTPAction.localPathFeaturedImage, product.linkProduct + Functions.GetExtension(NewImage),
                                        Functions.GetPathFileName(NewImage), Functions.GetSafeFileName(NewImage)) &&
                     DBHandler.updateDataBase(ref conn,
                                              "`order_product`",
                                              "`linkFeaturedImage` = '" + product.linkProduct + Functions.GetExtension(NewImage) + "'",
                                              "`product_id` = " + product.product_id);
            return(result);
        }
        private bool SendImage(ref Web_Collections_Model obj, ref List <ImageAttachModel> lstImage, ref List <ImageAttachModel> DeleteImageList)
        {
            bool result = true;

            if (FeatureImage.IsLocal)
            {
                if (!FTPAction.sendFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                        FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id, obj.name + Common.Functions.GetExtension(FeatureImage.Link),
                                        Common.Functions.GetPathFileName(FeatureImage.Link), Common.Functions.GetSafeFileName(FeatureImage.Link)))
                {
                    return(false);
                }
                FeatureImage.IsLocal = false;
                FeatureImage.Link    = AppConfig.WebUrl + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id + "/" + obj.name + Common.Functions.GetExtension(FeatureImage.Link);
            }
            obj.featureimage = obj.name + Common.Functions.GetExtension(FeatureImage.Link);

            foreach (var item in lstImage)
            {
                if (item.IsLocal)
                {
                    if (!FTPAction.sendFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                            FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id, Common.Functions.GetSafeFileName(item.Link),
                                            Common.Functions.GetPathFileName(item.Link), Common.Functions.GetSafeFileName(item.Link)))
                    {
                        return(false);
                    }
                    item.IsLocal = false;
                    item.Link    = AppConfig.WebUrl + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id + "/" + Common.Functions.GetSafeFileName(item.Link);
                }
                obj.content = obj.content.Replace("[~" + item.id.ToString() + "]", item.Link);
            }
            foreach (var item in DeleteImageList)
            {
                if (!item.IsLocal)
                {
                    FTPAction.deleteFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                         FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + obj.id, Common.Functions.GetSafeFileName(item.Link));
                }
            }
            return(result);
        }
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (tb_LinkSP_direct.Text.Equals(string.Empty))
            {
                // TODO
                Functions.ShowMessgeError("Chưa nhập thông tin \"link sản phẩm\"");
                return;
            }
            if (tb_title.Text.Equals(string.Empty))
            {
                // TODO
                Functions.ShowMessgeError("Chưa nhập thông tin \"title sản phẩm\"");
                return;
            }
            if (rtb_content.Text.Equals(string.Empty))
            {
                // TODO
                Functions.ShowMessgeError("Chưa nhập thông tin \"content sản phẩm\"");
                return;
            }
            if (clb_style.CheckedItems.Count == 0)
            {
                // TODO
                Functions.ShowMessgeError("Chưa chọn bất cứ style nào cho sản phẩm");
                return;
            }


            // Gui anh design lên thu muc
            if (FrontDesign.IsLocal && FrontDesign.Link != string.Empty)
            {
                if (!FTPAction.sendFile(AppConfig.FTPHost,
                                        AppConfig.FTPUser,
                                        AppConfig.FTPPassword,
                                        FTPAction.localPathDesign,
                                        Functions.GetSafeFileName(FrontDesign.Link).Replace(" ", ""),
                                        Functions.GetPathFileName(FrontDesign.Link),
                                        Functions.GetSafeFileName(FrontDesign.Link)))
                {
                    //TODO
                    Functions.ShowMessgeError("Có lỗi xảy ra trong quá trình gửi ảnh design lên web");
                    return;
                }
                if (product.product_image_design.Split(',')[0] != Functions.GetSafeFileName(FrontDesign.Link) && product.product_image_design.Split(',')[0] != "None")
                {
                    FTPAction.deleteFile(AppConfig.FTPHost,
                                         AppConfig.FTPUser,
                                         AppConfig.FTPPassword,
                                         FTPAction.localPathDesign,
                                         product.product_image_design.Split(',')[0]);
                }
            }
            if (BehideDesign.Link != string.Empty && BehideDesign.IsLocal)
            {
                if (!FTPAction.sendFile(AppConfig.FTPHost,
                                        AppConfig.FTPUser,
                                        AppConfig.FTPPassword,
                                        FTPAction.localPathDesign,
                                        Functions.GetSafeFileName(BehideDesign.Link).Replace(" ", ""),
                                        Functions.GetPathFileName(BehideDesign.Link),
                                        Functions.GetSafeFileName(BehideDesign.Link)))
                {
                    //TODO
                    Functions.ShowMessgeError("Có lỗi xảy ra trong quá trình gửi ảnh design lên web");
                    return;
                }
                if (product.product_image_design.Split(',')[1] != Functions.GetSafeFileName(BehideDesign.Link) && product.product_image_design.Split(',')[1] != "None")
                {
                    FTPAction.deleteFile(AppConfig.FTPHost,
                                         AppConfig.FTPUser,
                                         AppConfig.FTPPassword,
                                         FTPAction.localPathDesign,
                                         product.product_image_design.Split(',')[1]);
                }
            }

            // Luu database
            string product_image_design = string.Empty;

            product_image_design += (!FrontDesign.IsLocal) ? product.product_image_design.Split(',')[0] : ((FrontDesign.Link == string.Empty) ? "None" : Functions.GetSafeFileName(FrontDesign.Link).Replace(" ", ""));
            product_image_design += ",";
            product_image_design += (!BehideDesign.IsLocal) ? product.product_image_design.Split(',')[1] : ((BehideDesign.Link == string.Empty) ? "None" : Functions.GetSafeFileName(BehideDesign.Link).Replace(" ", ""));

            Product_Model pd = new Product_Model()
            {
                product_id           = product.product_id,
                product_image_design = product_image_design,
                product_link         = tb_LinkSP_direct.Text.Replace("\'", "\\\'"),
                product_title        = tb_title.Text.Replace("\'", "\\\'"),
                product_content      = rtb_content.Text.Replace("\'", "\\\'").Replace("\n", "<br/>"),
                color_list           = getColorList(),
                style_list           = pn_Image.getStyleList(),
                style_design         = pn_Image.getStyleDesign(),
                rangcost             = "$" + getMinCostStyle() + " - $" + getMaxCostStyle()
            };

            if (controller.EditProduct(pd))
            {
                Functions.ShowMessgeInfo("Edit success");
                IsChange = true;

                product.product_image_design = pd.product_image_design;
                product.product_link         = pd.product_link;
                product.product_title        = tb_title.Text;
                product.product_content      = rtb_content.Text;
                product.color_list           = pd.color_list;
                product.style_list           = pd.style_list;
                product.style_design         = pd.style_design;
                product.rangcost             = pd.rangcost;

                if (FrontDesign.IsLocal && product.product_image_design.Split(',')[0] != Functions.GetSafeFileName(FrontDesign.Link) && product.product_image_design.Split(',')[0] != "None")
                {
                    FTPAction.deleteFile(AppConfig.FTPHost,
                                         AppConfig.FTPUser,
                                         AppConfig.FTPPassword,
                                         FTPAction.localPathDesign,
                                         product.product_image_design.Split(',')[0]);
                }
                if (BehideDesign.IsLocal && product.product_image_design.Split(',')[1] != Functions.GetSafeFileName(BehideDesign.Link) && product.product_image_design.Split(',')[1] != "None")
                {
                    FTPAction.deleteFile(AppConfig.FTPHost,
                                         AppConfig.FTPUser,
                                         AppConfig.FTPPassword,
                                         FTPAction.localPathDesign,
                                         product.product_image_design.Split(',')[1]);
                }
            }
        }
        private void Btn_Addproduct_Click(object sender, EventArgs e)
        {
            if (pn_Image != null)
            {
                if (tb_TenSP.Text.Equals(string.Empty))
                {
                    // TODO
                    Functions.ShowMessgeError("Chưa nhập thông tin \"tên sản phẩm\"");
                    return;
                }
                if (tb_LinkSP_direct.Text.Equals(string.Empty))
                {
                    // TODO
                    Functions.ShowMessgeError("Chưa nhập thông tin \"link sản phẩm\"");
                    return;
                }
                if (tb_title.Text.Equals(string.Empty))
                {
                    // TODO
                    Functions.ShowMessgeError("Chưa nhập thông tin \"title sản phẩm\"");
                    return;
                }
                if (rtb_content.Text.Equals(string.Empty))
                {
                    // TODO
                    Functions.ShowMessgeError("Chưa nhập thông tin \"content sản phẩm\"");
                    return;
                }
                if (clb_style.CheckedItems.Count == 0)
                {
                    // TODO
                    Functions.ShowMessgeError("Chưa chọn bất cứ style nào cho sản phẩm");
                    return;
                }
                string FeaturedImage          = string.Empty;
                bool   IsFeaturedProduct      = false;
                string ExtensionFeaturedImage = string.Empty;
                string Catogarys     = string.Empty;
                string HashTagString = string.Empty;
                bool   IsFront;
                using (AdditionalProductView view = new AdditionalProductView(getParent().controller))
                {
                    if (view.ShowDialog() == DialogResult.OK)
                    {
                        FeaturedImage          = view.ImageFileName;
                        IsFeaturedProduct      = view.IsFeaturedProduct;
                        ExtensionFeaturedImage = view.ExtensionImage;
                        Catogarys     = view.AllCatogary;
                        HashTagString = view.HashTagString;
                        IsFront       = view.IsFront;
                    }
                    else
                    {
                        return;
                    }
                }
                string ProductLink = CheckExistProductLink(Functions.getWebNameValid(tb_TenSP.Text));
                if (ProductLink == string.Empty)
                {
                    Functions.ShowMessgeError("Không có kết nối DB");
                    return;
                }
                // Gui anh Feature lên thu muc
                if (FeaturedImage != string.Empty)
                {
                    if (!FTPAction.sendFile(AppConfig.FTPHost,
                                            AppConfig.FTPUser,
                                            AppConfig.FTPPassword,
                                            FTPAction.localPathFeaturedImage,
                                            ProductLink + ExtensionFeaturedImage,
                                            Functions.GetPathFileName(FeaturedImage),
                                            Functions.GetSafeFileName(FeaturedImage)))
                    {
                        //TODO
                        Functions.ShowMessgeError("Có lỗi xảy ra trong quá trình gửi ảnh Featured lên web");
                        return;
                    }
                }

                // Gui anh design lên thu muc
                if (FrontDesignFileName != string.Empty)
                {
                    if (!FTPAction.sendFile(AppConfig.FTPHost,
                                            AppConfig.FTPUser,
                                            AppConfig.FTPPassword,
                                            FTPAction.localPathDesign,
                                            Functions.GetSafeFileName(FrontDesignFileName).Replace(" ", ""),
                                            Functions.GetPathFileName(FrontDesignFileName),
                                            Functions.GetSafeFileName(FrontDesignFileName)))
                    {
                        //TODO
                        Functions.ShowMessgeError("Có lỗi xảy ra trong quá trình gửi ảnh design lên web");
                        return;
                    }
                }
                if (BehideDesignFileName != string.Empty)
                {
                    if (!FTPAction.sendFile(AppConfig.FTPHost,
                                            AppConfig.FTPUser,
                                            AppConfig.FTPPassword,
                                            FTPAction.localPathDesign,
                                            Functions.GetSafeFileName(BehideDesignFileName).Replace(" ", ""),
                                            Functions.GetPathFileName(BehideDesignFileName),
                                            Functions.GetSafeFileName(BehideDesignFileName)))
                    {
                        //TODO
                        Functions.ShowMessgeError("Có lỗi xảy ra trong quá trình gửi ảnh design lên web");
                        return;
                    }
                }



                // Luu database
                string product_image_design = string.Empty;
                product_image_design += (FrontDesignFileName == string.Empty) ? "None" : Functions.GetSafeFileName(FrontDesignFileName).Replace(" ", "");
                product_image_design += ",";
                product_image_design += (BehideDesignFileName == string.Empty) ? "None" : Functions.GetSafeFileName(BehideDesignFileName).Replace(" ", "");

                Product_Model pd = new Product_Model()
                {
                    product_name         = tb_TenSP.Text.Replace("\'", "\\\'"),
                    product_image_design = product_image_design,
                    product_link         = tb_LinkSP_direct.Text.Replace("\'", "\\\'"),
                    product_title        = tb_title.Text.Replace("\'", "\\\'"),
                    product_content      = rtb_content.Text.Replace("\'", "\\\'").Replace("\n", "<br/>"),
                    color_list           = getColorList(),
                    style_list           = pn_Image.getStyleList(),
                    style_design         = pn_Image.getStyleDesign(),
                    linkFeaturedImage    = ProductLink + ExtensionFeaturedImage,
                    linkProduct          = ProductLink,
                    isFeaturedProduct    = IsFeaturedProduct,
                    Catogarys            = Catogarys,
                    rangcost             = "$" + getMinCostStyle() + " - $" + getMaxCostStyle(),
                    hashtag       = HashTagString,
                    isFrontVision = IsFront
                };
                if (!getParent().controller.Addproduct(pd))
                {
                    //TODO
                    Functions.ShowMessgeError("Có lỗi xảy ra trong quá trình ghi Database");
                    return;
                }

                //TODO Info
                Functions.ShowMessgeInfo("Add product thành công");
                Functions.ShowMaiQuynhAnh();
            }
        }