public bool DeleteProduct(Product_Model product)
        {
            bool result = false;

            try
            {
                // delete Database
                if (DBHandler.deleteDataBase(ref conn,
                                             "`order_product`",
                                             "`product_id` = " + product.product_id))
                {
                    result = true;

                    //Delete Feature Image
                    FTPAction.deleteFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                         FTPAction.localPathFeaturedImage, product.linkFeaturedImage);
                    //Delete Design Image
                    foreach (var item in product.product_image_design.Split(','))
                    {
                        if (!item.Equals("None"))
                        {
                            FTPAction.deleteFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword,
                                                 FTPAction.localPathDesign, product.linkFeaturedImage);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogFile.writeLog(LogFile.DIR, "Exception" + LogFile.getTimeStringNow() + ".txt", LogFile.Filemode.GHIDE, ex.Message);
            }

            return(result);
        }
示例#2
0
        public void DeleteFileCollection(Web_Collections_Model Obj)
        {
            List <string> lstImage = FTPAction.getListFiles(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id, string.Empty);

            foreach (var item in lstImage)
            {
                FTPAction.deleteFile(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id, item);
            }
            FTPAction.deleteDirectory(AppConfig.FTPHost, AppConfig.FTPUser, AppConfig.FTPPassword, FTPAction.localSourceWeb + "/" + Common.AppConfig.PathImageCollections + "/" + Obj.id);
        }
        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]);
                }
            }
        }