protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            int      id          = Convert.ToInt32(ViewState["ID"]);
            var      pv          = ProductVariableController.GetByID(id);

            if (pv != null)
            {
                string parentSKU = ViewState["productsku"].ToString();
                int    productID = ViewState["productid"].ToString().ToInt(0);

                bool   isHidden      = chkIsHidden.Checked;
                string SKU           = ViewState["SKU"].ToString();
                double Stock         = Convert.ToDouble(pv.Stock);
                double Regular_Price = Convert.ToDouble(pRegular_Price.Text);
                double CostOfGood    = Convert.ToDouble(pCostOfGood.Text);
                double RetailPrice   = Convert.ToDouble(pRetailPrice.Text);
                int    StockStatus   = Convert.ToInt32(pv.StockStatus);
                bool   ManageStock   = true;

                //Phần thêm ảnh đại diện sản phẩm
                string path         = "/uploads/images/";
                string ProductImage = ListProductThumbnail.Value;
                if (ProductThumbnailImage.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles)
                    {
                        var o = path + productID + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                        try
                        {
                            f.SaveAs(Server.MapPath(o));
                            ProductImage = o;
                        }
                        catch { }
                    }
                }

                if (ProductImage != ListProductThumbnail.Value)
                {
                    if (File.Exists(Server.MapPath(ListProductThumbnail.Value)))
                    {
                        File.Delete(Server.MapPath(ListProductThumbnail.Value));
                    }
                }

                ProductVariableController.Update(id, productID, parentSKU, SKU, Stock, StockStatus, Regular_Price,
                                                 CostOfGood, RetailPrice, ProductImage, ManageStock, isHidden, currentDate, username, Convert.ToInt32(pv.SupplierID),
                                                 pv.SupplierName, Convert.ToDouble(pMinimumInventoryLevel.Text),
                                                 Convert.ToDouble(pMaximumInventoryLevel.Text));
                PJUtils.ShowMessageBoxSwAlert("Cập nhật thuộc tính thành công", "s", true, Page);
            }
        }
예제 #2
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0)
                {
                    int  productID = ViewState["productid"].ToString().ToInt(0);
                    bool isHidden  = chkIsHidden.Checked;
                    ///Lưu ảnh
                    string path = "/uploads/images/";
                    string IMG  = "";
                    if (hinhDaiDien.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in hinhDaiDien.UploadedFiles)
                        {
                            var o = path + productID.ToString() + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                IMG = o;
                                ProductImageController.Insert(productID, IMG, isHidden, currentDate, username);
                            }
                            catch { }
                        }

                        PJUtils.ShowMessageBoxSwAlert("Thêm hình ảnh thành công", "s", true, Page);
                    }
                    else
                    {
                        PJUtils.ShowMessageBoxSwAlert("Vui lòng chọn hình ảnh", "e", true, Page);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Cập nhật hình ảnh không có mã SKU
        /// </summary>
        /// <param name="productID"></param>
        /// <param name="uploadedFile"></param>
        /// <returns>File Name</returns>
        private string _uploadImageClean(int productID, UploadedFile uploadedFile)
        {
            // Upload image
            var folder   = Server.MapPath("/uploads/images");
            var fileName = Slug.ConvertToSlug(Path.GetFileName(uploadedFile.FileName), isFile: true);
            var filePath = String.Format("{0}/{1}-clean-{2}", folder, productID, fileName);

            if (File.Exists(filePath))
            {
                filePath = String.Format("{0}/{1}-clean-{2}-{3}", folder, productID, DateTime.UtcNow.ToString("HHmmssffff"), fileName);
            }

            uploadedFile.SaveAs(filePath);

            // Thumbnail
            Thumbnail.create(filePath, 85, 113);
            Thumbnail.create(filePath, 159, 212);
            Thumbnail.create(filePath, 240, 320);
            Thumbnail.create(filePath, 350, 467);
            Thumbnail.create(filePath, 600, 0);

            return(Path.GetFileName(filePath));
        }
예제 #4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;
            int      cateID      = hdfParentID.Value.ToInt();

            if (cateID > 0)
            {
                int    CategoryID   = ddlCategory.Value.ToInt();
                var    category     = NotifyCategoryController.GetByID(CategoryID);
                string CategorySlug = category.Slug;
                string Title        = txtTitle.Text.Trim();
                string Slugs        = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Link         = txtLink.Text.Trim();
                string Content      = pContent.Content.ToString();
                string Summary      = HttpUtility.HtmlDecode(pSummary.Content.ToString());
                string Action       = ddlAction.SelectedValue.ToString();
                string ActionValue  = "";
                if (Action == "view_more")
                {
                    ActionValue = Slugs;
                }
                else if (Action == "show_web")
                {
                    ActionValue = Link;
                }
                bool AtHome = ddlAtHome.SelectedValue.ToBool();

                var newNotify = new NotifyNew()
                {
                    CategoryID   = CategoryID,
                    CategorySlug = CategorySlug,
                    Title        = Title,
                    Thumbnail    = "",
                    Summary      = Summary,
                    Content      = Content,
                    Action       = Action,
                    ActionValue  = ActionValue,
                    AtHome       = AtHome,
                    CreatedDate  = currentDate,
                    CreatedBy    = acc.Username,
                    ModifiedDate = currentDate,
                    ModifiedBy   = acc.Username,
                    AppUpdate    = currentDate
                };

                var post = NotifyController.Insert(newNotify);

                //Phần thêm ảnh đại diện
                string path  = "/uploads/images/posts/";
                string Image = "";
                if (PostPublicThumbnailImage.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile f in PostPublicThumbnailImage.UploadedFiles)
                    {
                        var o = path + "notify-" + post.ID.ToString() + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                        try
                        {
                            f.SaveAs(Server.MapPath(o));
                            Image = o;
                        }
                        catch { }
                    }
                }
                string updateImage = NotifyController.UpdateImage(post.ID, Image);

                if (post != null)
                {
                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo thông báo thành công", "s", true, "redirectTo(" + post.ID.ToString() + ")", Page);
                }
            }
        }
예제 #5
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;
            int      cateID      = hdfParentID.Value.ToInt();

            if (cateID > 0)
            {
                string Title    = txtTitle.Text.Trim();
                string PostSlug = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Content  = pContent.Content.ToString();

                var newPost = new tbl_Post()
                {
                    Title        = Title,
                    Content      = Content,
                    Image        = "",
                    Featured     = ddlFeatured.SelectedValue.ToInt(),
                    CategoryID   = cateID,
                    Status       = 1,
                    CreatedBy    = acc.Username,
                    CreatedDate  = currentDate,
                    ModifiedBy   = acc.Username,
                    ModifiedDate = currentDate,
                    WebPublish   = false,
                    WebUpdate    = currentDate,
                    Slug         = PostSlug
                };

                var post = PostController.Insert(newPost);

                if (post != null)
                {
                    //Phần thêm ảnh đại diện
                    string path  = "/uploads/images/posts/";
                    string Image = "";
                    if (ProductThumbnailImage.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles)
                        {
                            var o = path + "post-" + post.ID + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                Image = o;
                            }
                            catch { }
                        }
                    }

                    string updateImage = PostController.UpdateImage(post.ID, Image);

                    //Phần thêm thư viện ảnh
                    string IMG = "";
                    if (hinhDaiDien.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in hinhDaiDien.UploadedFiles)
                        {
                            var o = path + "post-" + post.ID + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                IMG = o;
                                PostImageController.Insert(post.ID, IMG, username, currentDate);
                            }
                            catch { }
                        }
                    }

                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo bài viết thành công", "s", true, "redirectTo(" + post.ID + ")", Page);
                }
            }
        }
예제 #6
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;

            int PostID = ViewState["ID"].ToString().ToInt(0);
            var post   = PostPublicController.GetByID(PostID);

            if (post != null)
            {
                int    CategoryID   = hdfParentID.Value.ToInt();
                var    category     = PostPublicCategoryController.GetByID(CategoryID);
                string CategorySlug = category.Slug;
                string Title        = txtTitle.Text.Trim();
                string Slugs        = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Link         = txtLink.Text.Trim();
                string Content      = pContent.Content.ToString();
                string Summary      = HttpUtility.HtmlDecode(pSummary.Content.ToString());
                string Action       = ddlAction.SelectedValue.ToString();
                string ActionValue  = "";
                if (Action == "view_more")
                {
                    ActionValue = Slugs;
                }
                else if (Action == "show_web")
                {
                    ActionValue = Link;
                }
                bool AtHome   = ddlAtHome.SelectedValue.ToBool();
                bool IsPolicy = ddlIsPolicy.SelectedValue.ToBool();

                //Phần thêm ảnh đại diện sản phẩm
                string path      = "/uploads/images/posts/";
                string Thumbnail = ListPostPublicThumbnail.Value;
                if (PostPublicThumbnailImage.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile f in PostPublicThumbnailImage.UploadedFiles)
                    {
                        var o = path + "post-app-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                        try
                        {
                            f.SaveAs(Server.MapPath(o));
                            Thumbnail = o;
                        }
                        catch { }
                    }
                }

                // Delete Image Gallery
                string deleteImageGallery = hdfDeleteImageGallery.Value;
                if (deleteImageGallery != "")
                {
                    string[] deletelist = deleteImageGallery.Split(',');

                    for (int i = 0; i < deletelist.Length - 1; i++)
                    {
                        var img = PostPublicImageController.GetByID(Convert.ToInt32(deletelist[i]));
                        if (img != null)
                        {
                            string delete = PostPublicImageController.Delete(img.ID);
                        }
                    }
                }

                // Update post
                var oldPostPublic = new PostPublic()
                {
                    ID           = PostID,
                    CategoryID   = CategoryID,
                    CategorySlug = CategorySlug,
                    Title        = Title,
                    Thumbnail    = Thumbnail,
                    Summary      = Summary,
                    Content      = Content,
                    Action       = Action,
                    ActionValue  = ActionValue,
                    AtHome       = AtHome,
                    IsPolicy     = IsPolicy,
                    CreatedDate  = post.CreatedDate,
                    CreatedBy    = acc.Username,
                    ModifiedDate = currentDate,
                    ModifiedBy   = acc.Username
                };

                var updatePost = PostPublicController.Update(oldPostPublic);

                if (updatePost != null)
                {
                    // Cập nhật thư viện ảnh cho bài viết
                    if (UploadImages.HasFiles)
                    {
                        foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles)
                        {
                            var o = path + "post-app-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(uploadedFile.FileName), isFile: true);
                            uploadedFile.SaveAs(Server.MapPath(o));
                            PostPublicImageController.Insert(PostID, o, username, DateTime.Now);
                        }
                    }

                    // tạo phiên bản cho wordpress
                    if (!String.IsNullOrEmpty(hdfPostVariants.Value))
                    {
                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        var variants = serializer.Deserialize <List <PostClone> >(hdfPostVariants.Value);
                        if (variants != null)
                        {
                            foreach (var item in variants)
                            {
                                var getpostClone = PostCloneController.Get(updatePost.ID, item.Web);
                                if (getpostClone == null)
                                {
                                    continue;
                                }

                                var oldPostClone = new PostClone()
                                {
                                    ID           = getpostClone.ID,
                                    PostPublicID = updatePost.ID,
                                    Web          = getpostClone.Web,
                                    PostWebID    = getpostClone.PostWebID,
                                    CategoryName = category.Name,
                                    CategoryID   = updatePost.CategoryID,
                                    Title        = !String.IsNullOrEmpty(item.Title) ? item.Title : updatePost.Title,
                                    Summary      = updatePost.Summary,
                                    Content      = updatePost.Content,
                                    Thumbnail    = updatePost.Thumbnail,
                                    CreatedBy    = getpostClone.CreatedBy,
                                    CreatedDate  = getpostClone.CreatedDate,
                                    ModifiedDate = currentDate,
                                    ModifiedBy   = acc.Username
                                };

                                PostCloneController.Update(oldPostClone);
                            }
                        }
                    }

                    PJUtils.ShowMessageBoxSwAlertCallFunction("Cập nhật bài viết thành công", "s", true, "redirectTo(" + updatePost.ID.ToString() + ")", Page);
                }
            }
        }
예제 #7
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 1 || acc.Username == "nhom_zalo502")
                {
                    int cateID = hdfParentID.Value.ToInt();
                    if (cateID > 0)
                    {
                        string ProductSKU   = txtProductSKU.Text.Trim().ToUpper();
                        var    check        = true;
                        var    productcheck = ProductController.GetBySKU(ProductSKU);
                        if (productcheck != null)
                        {
                            check = false;
                        }
                        else
                        {
                            var productvariable = ProductVariableController.GetBySKU(ProductSKU);
                            if (productvariable != null)
                            {
                                check = false;
                            }
                        }

                        if (check == false)
                        {
                            PJUtils.ShowMessageBoxSwAlert("Mã sản phẩm đã tồn tại, hãy kiểm tra lại", "e", false, Page);
                        }
                        else
                        {
                            string ProductTitle   = Regex.Replace(txtProductTitle.Text.Trim(), @"\s*\,\s*|\s*\;\s*", " - ");
                            string ProductContent = pContent.Content.ToString();

                            double ProductStock  = 0;
                            int    StockStatus   = 3;
                            double Regular_Price = Convert.ToDouble(pRegular_Price.Text);
                            double CostOfGood    = Convert.ToDouble(pCostOfGood.Text);
                            double Retail_Price  = Convert.ToDouble(pRetailPrice.Text);
                            int    supplierID    = ddlSupplier.SelectedValue.ToInt(0);
                            string supplierName  = ddlSupplier.SelectedItem.ToString();
                            string mainColor     = ddlColor.SelectedValue.Trim();
                            int    a             = 1;
                            var    preOrder      = ddlPreOrder.SelectedValue == "1" ? true : false;
                            double Old_Price     = String.IsNullOrEmpty(pOld_Price.Text) ? 0 : Convert.ToDouble(pOld_Price.Text);

                            double MinimumInventoryLevel = pMinimumInventoryLevel.Text.ToInt(0);
                            double MaximumInventoryLevel = pMaximumInventoryLevel.Text.ToInt(0);

                            if (hdfsetStyle.Value == "2")
                            {
                                MinimumInventoryLevel = 0;
                                MaximumInventoryLevel = 0;
                                a = hdfsetStyle.Value.ToInt();
                            }

                            int ShowHomePage = ddlShowHomePage.SelectedValue.ToInt(0);

                            var prodNew = new tbl_Product()
                            {
                                CategoryID            = cateID,
                                ProductOldID          = 0,
                                ProductTitle          = ProductTitle,
                                ProductContent        = ProductContent,
                                ProductSKU            = ProductSKU,
                                ProductStock          = ProductStock,
                                StockStatus           = StockStatus,
                                ManageStock           = true,
                                Regular_Price         = Regular_Price,
                                CostOfGood            = CostOfGood,
                                Retail_Price          = Retail_Price,
                                ProductImage          = String.Empty,
                                ProductType           = a,
                                IsHidden              = false,
                                CreatedDate           = currentDate,
                                CreatedBy             = username,
                                SupplierID            = supplierID,
                                SupplierName          = supplierName,
                                Materials             = txtMaterials.Text,
                                MinimumInventoryLevel = MinimumInventoryLevel,
                                MaximumInventoryLevel = MaximumInventoryLevel,
                                ProductStyle          = a,
                                ShowHomePage          = ShowHomePage,
                                Color     = mainColor,
                                PreOrder  = preOrder,
                                Old_Price = Old_Price
                            };

                            string kq = ProductController.Insert(prodNew);
                            prodNew.ID = Convert.ToInt32(kq);

                            if (!String.IsNullOrEmpty(hdfTags.Value))
                            {
                                var tagList = JsonConvert.DeserializeObject <List <TagModel> >(hdfTags.Value);

                                if (tagList.Count > 0)
                                {
                                    // Get tag new
                                    var tagNew = TagController.insert(tagList, acc);

                                    var productTag = tagList
                                                     .GroupJoin(
                                        tagNew,
                                        t => t.name.ToLower(),
                                        n => n.Name.ToLower(),
                                        (t, n) => new { t, n }
                                        )
                                                     .SelectMany(
                                        x => x.n.DefaultIfEmpty(),
                                        (parent, child) => new ProductTag
                                    {
                                        TagID             = child != null ? child.ID : parent.t.id,
                                        ProductID         = prodNew.ID,
                                        ProductVariableID = 0,
                                        SKU         = prodNew.ProductSKU,
                                        CreatedBy   = acc.ID,
                                        CreatedDate = currentDate
                                    }
                                        )
                                                     .ToList();

                                    ProductTagController.insert(productTag);
                                }
                            }

                            //Phần thêm ảnh đại diện sản phẩm
                            string path         = "/uploads/images/";
                            string ProductImage = "";
                            if (ProductThumbnailImage.UploadedFiles.Count > 0)
                            {
                                foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles)
                                {
                                    var o = path + kq + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                                    if (!File.Exists(Server.MapPath(o)))
                                    {
                                        f.SaveAs(Server.MapPath(o));
                                        // Thumbnail
                                        Thumbnail.create(Server.MapPath(o), 85, 113);
                                        Thumbnail.create(Server.MapPath(o), 159, 212);
                                        Thumbnail.create(Server.MapPath(o), 240, 320);
                                        Thumbnail.create(Server.MapPath(o), 350, 467);
                                        Thumbnail.create(Server.MapPath(o), 600, 0);
                                    }

                                    ProductImage = Path.GetFileName(Server.MapPath(o));
                                }
                            }
                            string updateImage = ProductController.UpdateImage(kq.ToInt(), ProductImage);

                            //Phần thêm ảnh đại diện sản phẩm sạch không có đóng dấu
                            string ProductImageClean = "";
                            if (ProductThumbnailImageClean.UploadedFiles.Count > 0)
                            {
                                foreach (UploadedFile f in ProductThumbnailImageClean.UploadedFiles)
                                {
                                    var o = path + kq + "-clean-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                                    if (!File.Exists(Server.MapPath(o)))
                                    {
                                        f.SaveAs(Server.MapPath(o));
                                        // Thumbnail
                                        Thumbnail.create(Server.MapPath(o), 85, 113);
                                        Thumbnail.create(Server.MapPath(o), 159, 212);
                                        Thumbnail.create(Server.MapPath(o), 240, 320);
                                        Thumbnail.create(Server.MapPath(o), 350, 467);
                                        Thumbnail.create(Server.MapPath(o), 600, 0);
                                    }

                                    ProductImageClean = Path.GetFileName(Server.MapPath(o));
                                }
                            }
                            string updateImageClean = ProductController.UpdateImageClean(kq.ToInt(), ProductImageClean);

                            //Phần thêm thư viện ảnh sản phẩm
                            string IMG = "";
                            if (hinhDaiDien.UploadedFiles.Count > 0)
                            {
                                foreach (UploadedFile f in hinhDaiDien.UploadedFiles)
                                {
                                    var o = path + kq + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                                    if (!File.Exists(Server.MapPath(o)))
                                    {
                                        f.SaveAs(Server.MapPath(o));
                                        // Thumbnail
                                        Thumbnail.create(Server.MapPath(o), 85, 113);
                                        Thumbnail.create(Server.MapPath(o), 159, 212);
                                        Thumbnail.create(Server.MapPath(o), 240, 320);
                                        Thumbnail.create(Server.MapPath(o), 350, 467);
                                        Thumbnail.create(Server.MapPath(o), 600, 0);
                                    }

                                    IMG = Path.GetFileName(Server.MapPath(o));
                                    ProductImageController.Insert(kq.ToInt(), IMG, false, currentDate, username);
                                }
                            }


                            if (kq.ToInt(0) > 0)
                            {
                                int ProductID = kq.ToInt(0);

                                string variable = hdfVariableListInsert.Value;
                                if (!string.IsNullOrEmpty(variable))
                                {
                                    string[] items = variable.Split(',');
                                    for (int i = 0; i < items.Length - 1; i++)
                                    {
                                        string   item        = items[i];
                                        string[] itemElement = item.Split(';');

                                        string   datanameid             = itemElement[0];
                                        string[] datavalueid            = itemElement[1].Split('|');
                                        string   datanametext           = itemElement[2];
                                        string   datavaluetext          = itemElement[3];
                                        string   productvariablesku     = itemElement[4].Trim().ToUpper();
                                        string   regularprice           = itemElement[5];
                                        string   costofgood             = itemElement[6];
                                        string   retailprice            = itemElement[7];
                                        string[] datanamevalue          = itemElement[8].Split('|');
                                        string   imageUpload            = itemElement[4];
                                        int      _MaximumInventoryLevel = itemElement[9].ToInt(0);
                                        int      _MinimumInventoryLevel = itemElement[10].ToInt(0);

                                        int stockstatus = itemElement[11].ToInt();

                                        HttpPostedFile postedFile = Request.Files["" + imageUpload + ""];
                                        string         image      = "";
                                        if (postedFile != null && postedFile.ContentLength > 0)
                                        {
                                            var o = path + kq + '-' + Slug.ConvertToSlug(Path.GetFileName(postedFile.FileName), isFile: true);
                                            if (!File.Exists(Server.MapPath(o)))
                                            {
                                                postedFile.SaveAs(Server.MapPath(o));
                                                // Thumbnail
                                                Thumbnail.create(Server.MapPath(o), 85, 113);
                                                Thumbnail.create(Server.MapPath(o), 159, 212);
                                                Thumbnail.create(Server.MapPath(o), 240, 320);
                                                Thumbnail.create(Server.MapPath(o), 350, 467);
                                                Thumbnail.create(Server.MapPath(o), 600, 0);
                                            }

                                            image = Path.GetFileName(Server.MapPath(o));
                                        }

                                        string kq1 = ProductVariableController.Insert(ProductID, ProductSKU, productvariablesku, 0, stockstatus, Convert.ToDouble(regularprice),
                                                                                      Convert.ToDouble(costofgood), Convert.ToDouble(retailprice), image, true, false, currentDate, username,
                                                                                      supplierID, supplierName, _MinimumInventoryLevel, _MaximumInventoryLevel);

                                        string color             = "";
                                        string size              = "";
                                        int    ProductVariableID = 0;

                                        if (kq1.ToInt(0) > 0)
                                        {
                                            ProductVariableID = kq1.ToInt(0);
                                            color             = datavalueid[0];
                                            size = datavalueid[1];
                                            string[] Data      = datanametext.Split('|');
                                            string[] DataValue = datavaluetext.Split('|');
                                            for (int k = 0; k < Data.Length - 2; k++)
                                            {
                                                int    variablevalueID   = datavalueid[k].ToInt();
                                                string variableName      = Data[k];
                                                string variableValueName = DataValue[k];
                                                ProductVariableValueController.Insert(ProductVariableID, productvariablesku, variablevalueID,
                                                                                      variableName, variableValueName, false, currentDate, username);
                                            }
                                        }
                                        ProductVariableController.UpdateColorSize(ProductVariableID, color, size);
                                    }
                                }

                                PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo sản phẩm thành công", "s", true, "redirectTo(" + kq + ")", Page);
                            }
                        }
                    }
                }
            }
        }
예제 #8
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;
            int      cateID      = hdfParentID.Value.ToInt();

            if (cateID > 0)
            {
                int    CategoryID   = ddlCategory.Value.ToInt();
                var    category     = PostPublicCategoryController.GetByID(CategoryID);
                string CategorySlug = category.Slug;
                string Title        = txtTitle.Text.Trim();
                string Slugs        = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Link         = txtLink.Text.Trim();
                string Content      = pContent.Content.ToString();
                string Summary      = HttpUtility.HtmlDecode(pSummary.Content.ToString());
                string Action       = ddlAction.SelectedValue.ToString();
                string ActionValue  = "";
                if (Action == "view_more")
                {
                    ActionValue = Slugs;
                }
                else if (Action == "show_web")
                {
                    ActionValue = Link;
                }
                bool AtHome   = ddlAtHome.SelectedValue.ToBool();
                bool IsPolicy = false;

                var newPostPublic = new PostPublic()
                {
                    CategoryID   = CategoryID,
                    CategorySlug = CategorySlug,
                    Title        = Title,
                    Thumbnail    = "",
                    Summary      = Summary,
                    Content      = Content,
                    Action       = Action,
                    ActionValue  = ActionValue,
                    AtHome       = AtHome,
                    IsPolicy     = IsPolicy,
                    CreatedDate  = currentDate,
                    CreatedBy    = acc.Username,
                    ModifiedDate = currentDate,
                    ModifiedBy   = acc.Username
                };

                var post = PostPublicController.Insert(newPostPublic);

                if (post != null)
                {
                    // Thêm ảnh đại diện
                    string path  = "/uploads/images/posts/";
                    string Image = "";
                    if (PostPublicThumbnailImage.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in PostPublicThumbnailImage.UploadedFiles)
                        {
                            var o = path + "post-app-" + post.ID.ToString() + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                Image = o;
                            }
                            catch { }
                        }
                    }
                    string updateImage = PostPublicController.UpdateImage(post.ID, Image);

                    // Thêm thư viện ảnh
                    string IMG = "";
                    if (ImageGallery.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in ImageGallery.UploadedFiles)
                        {
                            var o = path + "post-app-" + post.ID.ToString() + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                IMG = o;
                                PostPublicImageController.Insert(post.ID, IMG, username, currentDate);
                            }
                            catch { }
                        }
                    }

                    // Copy bài viết vào hệ thống gốc
                    if (ddlCopyToSystem.SelectedValue == "True" && post.Action == "view_more")
                    {
                        var categorySystem = PostCategoryController.GetByName(category.Name);
                        var postSystem     = new tbl_Post()
                        {
                            Title        = post.Title,
                            Content      = post.Content,
                            Image        = Image,
                            Featured     = 1,
                            CategoryID   = categorySystem != null ? categorySystem.ID : 0,
                            Status       = 1,
                            CreatedBy    = post.CreatedBy,
                            CreatedDate  = post.CreatedDate,
                            ModifiedBy   = post.ModifiedBy,
                            ModifiedDate = post.ModifiedDate,
                            WebPublish   = true,
                            WebUpdate    = post.CreatedDate,
                            Slug         = post.ActionValue
                        };

                        PostController.Insert(postSystem);

                        // Copy image
                        if (postSystem != null)
                        {
                            var imagePostPublic = PostPublicImageController.GetByPostID(post.ID);
                            if (imagePostPublic.Count > 0)
                            {
                                foreach (var item in imagePostPublic)
                                {
                                    PostImageController.Insert(postSystem.ID, item.Image, postSystem.CreatedBy, DateTime.Now);
                                }
                            }
                        }
                    }


                    // Tạo phiên bản cho wordpress
                    if (!String.IsNullOrEmpty(hdfPostVariants.Value))
                    {
                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        var variants = serializer.Deserialize <List <PostClone> >(hdfPostVariants.Value);
                        if (variants != null)
                        {
                            foreach (var item in variants)
                            {
                                var newPostClone = new PostClone()
                                {
                                    PostPublicID = post.ID,
                                    Web          = item.Web,
                                    PostWebID    = 0,
                                    CategoryID   = post.CategoryID,
                                    CategoryName = category.Name,
                                    Title        = !String.IsNullOrEmpty(item.Title) ? item.Title : post.Title,
                                    Summary      = post.Summary,
                                    Content      = post.Content,
                                    Thumbnail    = Image,
                                    CreatedDate  = post.CreatedDate,
                                    CreatedBy    = acc.Username,
                                    ModifiedDate = post.ModifiedDate,
                                    ModifiedBy   = acc.Username
                                };

                                PostCloneController.Insert(newPostClone);
                            }
                        }
                    }

                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo bài viết thành công", "s", true, "redirectTo(" + post.ID.ToString() + ")", Page);
                }
            }
        }
예제 #9
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);
            int    cateID   = ViewState["cateID"].ToString().ToInt(0);
            int    PostID   = ViewState["ID"].ToString().ToInt(0);

            if (cateID > 0)
            {
                string Title      = txtTitle.Text.Trim();
                string PostSlug   = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Content    = pContent.Content.ToString();
                int    CategoryID = hdfParentID.Value.ToInt();

                //Phần thêm ảnh đại diện sản phẩm
                string path      = "/uploads/images/posts/";
                string PostImage = ListPostThumbnail.Value;
                if (PostThumbnailImage.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile f in PostThumbnailImage.UploadedFiles)
                    {
                        var o = path + "post-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                        try
                        {
                            f.SaveAs(Server.MapPath(o));
                            PostImage = o;
                        }
                        catch { }
                    }
                }

                // Delete Image Gallery
                string deleteImageGallery = hdfDeleteImageGallery.Value;
                if (deleteImageGallery != "")
                {
                    string[] deletelist = deleteImageGallery.Split(',');

                    for (int i = 0; i < deletelist.Length - 1; i++)
                    {
                        var img = PostImageController.GetByID(Convert.ToInt32(deletelist[i]));
                        if (img != null)
                        {
                            string delete = PostImageController.Delete(img.ID);
                        }
                    }
                }

                // Update post
                string kq = PostController.Update(PostID, Title, Content, PostImage, ddlFeatured.SelectedValue.ToInt(), CategoryID, 1, PostSlug, username, DateTime.Now);

                // Upload image gallery
                if (UploadImages.HasFiles)
                {
                    foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles)
                    {
                        var o = path + "post-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(uploadedFile.FileName), isFile: true);
                        uploadedFile.SaveAs(Server.MapPath(o));
                        PostImageController.Insert(PostID, o, username, DateTime.Now);
                    }
                }

                if (kq.ToInt(0) > 0)
                {
                    PJUtils.ShowMessageBoxSwAlertCallFunction("Cập nhật bài viết thành công", "s", true, "redirectTo(" + kq + ")", Page);
                }
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;

            bool   check        = true;
            string SKU          = txtProductSKU.Text.Trim().ToUpper();
            var    productcheck = ProductController.GetBySKU(SKU);

            if (productcheck != null)
            {
                check = false;
            }
            else
            {
                var productvariable = ProductVariableController.GetBySKU(SKU);
                if (productvariable != null)
                {
                    check = false;
                }
            }
            if (check == false)
            {
                PJUtils.ShowMessageBoxSwAlert("Trùng mã sản phẩm vui lòng kiểm tra lại", "e", false, Page);
            }
            else
            {
                int parentID = ViewState["productid"].ToString().ToInt(0);

                var parentProduct = ProductController.GetByID(parentID);

                bool isHidden = false;

                double Stock         = 0;
                double Regular_Price = Convert.ToDouble(pRegular_Price.Text);
                double CostOfGood    = Convert.ToDouble(pCostOfGood.Text);
                double RetailPrice   = Convert.ToDouble(pRetailPrice.Text);
                int    StockStatus   = 1;
                bool   ManageStock   = true;

                //Phần thêm ảnh đại diện sản phẩm
                string path         = "/uploads/images/";
                string ProductImage = "";
                if (ProductThumbnailImage.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles)
                    {
                        var o = path + parentID.ToString() + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                        try
                        {
                            f.SaveAs(Server.MapPath(o));
                            ProductImage = o;
                        }
                        catch { }
                    }
                }
                ProductVariableController.Insert(parentProduct.ID, parentProduct.ProductSKU, SKU, Stock, StockStatus, Regular_Price,
                                                 CostOfGood, RetailPrice, ProductImage, ManageStock, isHidden, currentDate, username, Convert.ToInt32(parentProduct.SupplierID),
                                                 parentProduct.SupplierName, Convert.ToDouble(pMinimumInventoryLevel.Text),
                                                 Convert.ToDouble(pMaximumInventoryLevel.Text));

                PJUtils.ShowMessageBoxSwAlert("Thêm biến thể sản phẩm thành công", "s", true, Page);
            }
        }