Exemplo n.º 1
0
        /// <summary>
        /// Tải danh sách các tag
        /// </summary>
        /// <param name="productID"></param>
        private void _loadTags(int productID)
        {
            var tags = ProductTagController.get(productID, 0);

            if (tags.Count > 0)
            {
                hdfTags.Value = JsonConvert.SerializeObject(tags);
            }
            else
            {
                hdfTags.Value = String.Empty;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cập nhật table Tags
        /// </summary>
        /// <param name="product"></param>
        /// <param name="acc"></param>
        private void _updateTag(tbl_Product product, tbl_Account acc)
        {
            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         = product.ID,
                    ProductVariableID = 0,
                    SKU         = product.ProductSKU,
                    CreatedBy   = acc.ID,
                    CreatedDate = DateTime.Now
                }
                    )
                                 .ToList();

                ProductTagController.update(product.ID, productTag);
            }
            else
            {
                ProductTagController.delete(product.ID);
            }
        }
Exemplo n.º 3
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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void LoadData()
        {
            string username = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            int    id  = Request.QueryString["id"].ToInt(0);
            string sku = Request.QueryString["sku"];

            var p = new tbl_Product();

            if (id > 0)
            {
                p = ProductController.GetByID(id);
            }
            else if (id == 0)
            {
                int variableid = Request.QueryString["variableid"].ToInt(0);
                if (variableid != 0)
                {
                    p = ProductController.GetByVariableID(variableid);
                }
                else
                {
                    if (sku != "")
                    {
                        p = ProductController.GetBySKU(sku);
                        if (p == null)
                        {
                            p = ProductController.GetByVariableSKU(sku);
                        }
                    }
                }
            }

            if (p == null)
            {
                PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy sản phẩm " + id, "e", true, "/tat-ca-san-pham", Page);
            }
            else
            {
                this.Title = String.Format("{0} - Sản phẩm", p.ProductSKU.ToTitleCase());

                ViewState["ID"]     = id;
                ViewState["cateID"] = p.CategoryID;
                ViewState["SKU"]    = p.ProductSKU;

                ltrEdit1.Text = "";
                if (acc.RoleID == 0 || acc.RoleID == 1 || acc.Username == "nhom_zalo502")
                {
                    ltrEdit1.Text += "<a href='/thong-tin-san-pham?id=" + p.ID + "' class='btn primary-btn fw-btn not-fullwidth'><i class='fa fa-pencil-square-o' aria-hidden='true'></i> Chỉnh sửa</a>";
                    ltrEdit1.Text += "<a href='/tao-san-pham' class='btn primary-btn fw-btn not-fullwidth print-invoice-merged'><i class='fa fa-file-text-o' aria-hidden='true'></i> Thêm mới</a>";
                    if (p.ShowHomePage == 1)
                    {
                        ltrEdit1.Text += "<a href='javascript:;' onclick='showProductSyncModal(`" + p.ProductSKU + "`, " + p.ID + ", " + p.CategoryID + ");' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-upload' aria-hidden='true'></i> Đồng bộ</a>";
                    }
                }
                ltrEdit1.Text += "<a href='javascript:;' onclick='copyProductInfo(" + p.ID + ")' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-files-o'></i> Copy thông tin</a>";
                ltrEdit1.Text += "<a href='javascript:;' onclick='getAllProductImage(`" + p.ProductSKU + "`);' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-cloud-download'></i> Tải tất cả hình ảnh</a>";

                if (acc.RoleID == 0 || acc.Username == "nhom_zalo502")
                {
                    ltrEdit1.Text += "<a href='javascript:;' onclick='deleteProduct(" + p.ID + ");' class='btn primary-btn not-fullwidth print-invoice-merged btn-red'><i class='fa fa-times'></i> Xóa sản phẩm</a>";
                    ltrEdit1.Text += "<a href='javascript:;' data-toggle='modal' data-target='#modalUpdateProductSKU' data-backdrop='static' data-keyboard='false' class='btn primary-btn not-fullwidth print-invoice-merged btn-blue'><i class='fa fa-times'></i> Sửa mã sản phẩm</a>";
                }

                ltrEdit2.Text = ltrEdit1.Text;

                lbProductTitle.Text = p.ProductTitle;
                pContent.Text       = p.ProductContent;
                lblSKU.Text         = p.ProductSKU;
                txtOldSKU.Text      = p.ProductSKU;

                // Create order fileter
                var filter = new ProductFilterModel()
                {
                    search = p.ProductSKU
                };
                // Create pagination
                var page = new PaginationMetadataModel();
                var a    = ProductController.GetAllSql(filter, ref page);
                if (page.totalCount > 0)
                {
                    foreach (var item in a)
                    {
                        lbProductStock.Text          = item.TotalProductInstockQuantityLeft.ToString();
                        ddlStockStatus.SelectedValue = item.StockStatus.ToString();
                    }
                }
                else
                {
                    lbProductStock.Text = "0";
                }

                lbOldPrice.Text     = string.Format("{0:N0}", p.Old_Price);
                lbRegularPrice.Text = string.Format("{0:N0}", p.Regular_Price);

                ltrCostOfGood.Text = "";
                if (acc.RoleID == 0)
                {
                    ltrCostOfGood.Text += "<div class='form-row'>";
                    ltrCostOfGood.Text += "    <div class='row-left'>";
                    ltrCostOfGood.Text += "        Giá vốn";
                    ltrCostOfGood.Text += "    </div>";
                    ltrCostOfGood.Text += "    <div class='row-right'>";
                    ltrCostOfGood.Text += "        <span class='form-control'>" + string.Format("{0:N0}", p.CostOfGood) + "</span>";
                    ltrCostOfGood.Text += "    </div>";
                    ltrCostOfGood.Text += "</div>";
                }

                lbRetailPrice.Text        = string.Format("{0:N0}", p.Retail_Price);
                ddlSupplier.SelectedValue = p.SupplierID.ToString();
                ddlCategory.SelectedValue = p.CategoryID.ToString();
                lbMaterials.Text          = p.Materials;
                lbColor.Text = p.Color;

                // Hàng order
                ddlPreOrder.SelectedValue = p.PreOrder ? "1" : "0";

                // thư viện ảnh
                var image = ProductImageController.GetByProductID(id);
                imageGallery.Text  = "<ul class='image-gallery'>";
                imageGallery.Text += "<li><img src='" + Thumbnail.getURL(p.ProductImage, Thumbnail.Size.Normal) + "'><a href='" + Thumbnail.getURL(p.ProductImage, Thumbnail.Size.Source) + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>";
                if (image != null)
                {
                    foreach (var img in image)
                    {
                        if (img.ProductImage != p.ProductImage)
                        {
                            imageGallery.Text += "<li><img src='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Normal) + "'><a href='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Source) + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>";
                        }
                    }
                }
                imageGallery.Text += "</ul>";


                hdfTable.Value = p.ProductStyle.ToString();

                // Init Tag
                var tagIDList = ProductTagController.get(p.ID, 0)
                                .Select(x => x.name)
                                .ToList();
                hdfTags.Value = String.Join(",", tagIDList);

                List <tbl_ProductVariable> b = new List <tbl_ProductVariable>();

                b = ProductVariableController.SearchProductID(p.ID, "");
                if (b != null)
                {
                    pagingall(b, Convert.ToInt32(acc.RoleID));
                }
            }
        }