Пример #1
0
        private static ProductGetOut _getProduct(tbl_Product product)
        {
            var quantity = StockManagerController.getQuantityStock2BySKU(product.ProductSKU);

            if (!quantity.HasValue || quantity.Value == 0)
            {
                return(null);
            }

            var result = new ProductGetOut()
            {
                ID                   = product.ID,
                ProductName          = product.ProductTitle,
                ProductVariable      = String.Empty,
                ProductVariableName  = String.Empty,
                ProductVariableValue = String.Empty,
                ProductStyle         = 1,
                ProductImage         = Thumbnail.getURL(product.ProductImage, Thumbnail.Size.Normal),
                ProductImageOrigin   = Thumbnail.getURL(product.ProductImage, Thumbnail.Size.Source),
                SKU                  = product.ProductSKU.Trim().ToUpper(),
                SupplierID           = product.SupplierID.HasValue ? product.SupplierID.Value : 0,
                SupplierName         = String.IsNullOrEmpty(product.SupplierName) ? String.Empty : product.SupplierName,
                WarehouseQuantity    = string.Format("{0:N0}", quantity),
                ParentID             = product.ID,
                ParentSKU            = product.ProductSKU
            };

            return(result);
        }
Пример #2
0
        private static ProductGetOut _getProduct(int warehouse, tbl_Product product)
        {
            var quantity  = PJUtils.TotalProductQuantityInstock(1, product.ProductSKU);
            var quantity2 = StockManagerController.getQuantityStock2BySKU(product.ProductSKU);

            if (warehouse == 1 && quantity == 0)
            {
                return(null);
            }

            if (warehouse == 2 && (!quantity2.HasValue && quantity2.Value == 0))
            {
                return(null);
            }

            var result = new ProductGetOut()
            {
                ID                   = product.ID,
                ProductName          = product.ProductTitle,
                ProductVariable      = String.Empty,
                ProductVariableName  = String.Empty,
                ProductVariableValue = String.Empty,
                ProductStyle         = 1,
                ProductImage         = Thumbnail.getURL(product.ProductImage, Thumbnail.Size.Normal),
                ProductImageOrigin   = Thumbnail.getURL(product.ProductImage, Thumbnail.Size.Source),
                SKU                  = product.ProductSKU.Trim().ToUpper(),
                WarehouseQuantity    = String.Format("{0:N0}", quantity),
                WarehouseQuantity2   = String.Format("{0:N0}", quantity2),
                ParentID             = product.ID,
                ParentSKU            = product.ProductSKU
            };

            return(result);
        }
Пример #3
0
        private static List <ProductGetOut> _getProductVariation(List <tbl_ProductVariable> variations, tbl_Product product = null)
        {
            var result = new List <ProductGetOut>();

            if (variations == null || variations.Count() == 0)
            {
                return(result);
            }

            if (product == null)
            {
                product = ProductController.GetBySKU(variations.FirstOrDefault().ParentSKU);
            }

            foreach (var variation in variations)
            {
                var attributes = ProductVariableValueController.GetByProductVariableSKU(variation.SKU);

                if (attributes.Count == 0)
                {
                    continue;
                }

                var variable      = String.Empty;
                var variablename  = String.Empty;
                var variablevalue = String.Empty;

                foreach (var attribute in attributes)
                {
                    variable      += attribute.VariableName.Trim() + ": " + attribute.VariableValue.Trim() + "|";
                    variablename  += attribute.VariableName.Trim() + "|";
                    variablevalue += attribute.VariableValue.Trim() + "|";
                }

                var quantity = StockManagerController.getQuantityStock2BySKU(variation.SKU);
                var item     = new ProductGetOut()
                {
                    ID                   = variation.ID,
                    ProductName          = product.ProductTitle,
                    ProductVariable      = variable,
                    ProductVariableName  = variablename,
                    ProductVariableValue = variablevalue,
                    ProductStyle         = 2,
                    ProductImage         = Thumbnail.getURL(variation.Image, Thumbnail.Size.Normal),
                    ProductImageOrigin   = Thumbnail.getURL(variation.Image, Thumbnail.Size.Source),
                    SKU                  = variation.SKU.Trim().ToUpper(),
                    SupplierID           = product.SupplierID.HasValue ? product.SupplierID.Value : 0,
                    SupplierName         = String.IsNullOrEmpty(product.SupplierName) ? String.Empty : product.SupplierName,
                    WarehouseQuantity    = string.Format("{0:N0}", quantity),
                    ParentID             = product.ID,
                    ParentSKU            = product.ProductSKU
                };
                result.Add(item);
            }

            return(result);
        }
Пример #4
0
        public static string getProduct(string textsearch)
        {
            List <ProductGetOut> ps = new List <ProductGetOut>();
            string username         = HttpContext.Current.Request.Cookies["userLoginSystem"].Value;
            var    acc = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID  = Convert.ToInt32(acc.AgentID);
                var products = ProductController.GetBySKU(textsearch.Trim().ToUpper());

                if (products != null)
                {
                    var productvariable = ProductVariableController.GetByParentSKU(products.ProductSKU);

                    if (productvariable.Count > 0)
                    {
                        foreach (var pv in productvariable)
                        {
                            string SKU = pv.SKU.Trim().ToUpper();

                            var check = StockManagerController.GetBySKU(AgentID, SKU);

                            if (check.Count > 0)
                            {
                                double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);

                                if (total > 0)
                                {
                                    var variables = ProductVariableValueController.GetByProductVariableSKU(pv.SKU);

                                    if (variables.Count > 0)
                                    {
                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        foreach (var v in variables)
                                        {
                                            variable      += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|";
                                            variablename  += v.VariableName.Trim() + "|";
                                            variablevalue += v.VariableValue.Trim() + "|";
                                        }

                                        ProductGetOut p = new ProductGetOut();
                                        p.ID                   = pv.ID;
                                        p.ProductName          = products.ProductTitle;
                                        p.ProductVariable      = variable;
                                        p.ProductVariableName  = variablename;
                                        p.ProductVariableValue = variablevalue;
                                        p.ProductType          = 2;

                                        var product = ProductController.GetBySKU(pv.ParentSKU);

                                        if (!string.IsNullOrEmpty(pv.Image))
                                        {
                                            p.ProductImage       = "<img src=\"" + pv.Image + "\" />";
                                            p.ProductImageOrigin = pv.Image;
                                        }
                                        else if (!string.IsNullOrEmpty(product.ProductImage))
                                        {
                                            p.ProductImage       = "<img src=\"" + product.ProductImage + "\" />";
                                            p.ProductImageOrigin = product.ProductImage;
                                        }
                                        else
                                        {
                                            p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                            p.ProductImageOrigin = "";
                                        }

                                        p.QuantityInstock       = total;
                                        p.QuantityInstockString = string.Format("{0:N0}", total);
                                        p.SKU = SKU;
                                        int supplierID = 0;
                                        if (pv.SupplierID != null)
                                        {
                                            supplierID = pv.SupplierID.ToString().ToInt(0);
                                        }
                                        p.SupplierID = supplierID;
                                        string supplierName = "";
                                        if (!string.IsNullOrEmpty(pv.SupplierName))
                                        {
                                            supplierName = pv.SupplierName;
                                        }
                                        p.SupplierName = supplierName;
                                        ps.Add(p);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        string SKU   = products.ProductSKU.Trim().ToUpper();
                        var    check = StockManagerController.GetBySKU(AgentID, SKU);
                        if (check.Count > 0)
                        {
                            double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                            if (total > 0)
                            {
                                string variablename  = "";
                                string variablevalue = "";
                                string variable      = "";

                                ProductGetOut p = new ProductGetOut();
                                p.ID                   = products.ID;
                                p.ProductName          = products.ProductTitle;
                                p.ProductVariable      = variable;
                                p.ProductVariableName  = variablename;
                                p.ProductVariableValue = variablevalue;
                                p.ProductType          = 1;
                                var img = ProductImageController.GetFirstByProductID(products.ID);

                                if (!string.IsNullOrEmpty(products.ProductImage))
                                {
                                    p.ProductImage       = "<img src=\"" + products.ProductImage + "\" />";
                                    p.ProductImageOrigin = products.ProductImage;
                                }
                                else if (img != null)
                                {
                                    p.ProductImage       = "<img src=\"" + img.ProductImage + "\" />";
                                    p.ProductImageOrigin = img.ProductImage;
                                }
                                else
                                {
                                    p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                    p.ProductImageOrigin = "";
                                }

                                p.SKU                   = SKU;
                                p.QuantityInstock       = total;
                                p.QuantityInstockString = string.Format("{0:N0}", total);
                                int supplierID = 0;
                                if (products.SupplierID != null)
                                {
                                    supplierID = products.SupplierID.ToString().ToInt(0);
                                }
                                p.SupplierID = supplierID;
                                string supplierName = "";
                                if (!string.IsNullOrEmpty(products.SupplierName))
                                {
                                    supplierName = products.SupplierName;
                                }
                                p.SupplierName = supplierName;
                                ps.Add(p);
                            }
                        }
                    }
                }
                else
                {
                    var productvariable = ProductVariableController.GetAllBySKU(textsearch.Trim().ToUpper());

                    if (productvariable != null)
                    {
                        foreach (var value in productvariable)
                        {
                            string SKU = value.SKU.Trim().ToUpper();

                            var check = StockManagerController.GetBySKU(AgentID, SKU);
                            if (check.Count > 0)
                            {
                                double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                if (total > 0)
                                {
                                    var variables = ProductVariableValueController.GetByProductVariableSKU(value.SKU);

                                    if (variables.Count > 0)
                                    {
                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        foreach (var v in variables)
                                        {
                                            variable      += v.VariableName + ": " + v.VariableValue + "|";
                                            variablename  += v.VariableName + "|";
                                            variablevalue += v.VariableValue + "|";
                                        }

                                        ProductGetOut p = new ProductGetOut();
                                        p.ID = value.ID;

                                        var product = ProductController.GetBySKU(value.ParentSKU);

                                        if (product != null)
                                        {
                                            p.ProductName = product.ProductTitle;
                                        }
                                        p.ProductVariable      = variable;
                                        p.ProductVariableName  = variablename;
                                        p.ProductVariableValue = variablevalue;
                                        p.ProductType          = 2;

                                        if (!string.IsNullOrEmpty(value.Image))
                                        {
                                            p.ProductImage       = "<img src=\"" + value.Image + "\" />";
                                            p.ProductImageOrigin = value.Image;
                                        }
                                        else if (!string.IsNullOrEmpty(product.ProductImage))
                                        {
                                            p.ProductImage       = "<img src=\"" + product.ProductImage + "\" />";
                                            p.ProductImageOrigin = product.ProductImage;
                                        }
                                        else
                                        {
                                            p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                            p.ProductImageOrigin = "";
                                        }

                                        p.SKU                   = value.SKU.Trim().ToUpper();
                                        p.QuantityInstock       = total;
                                        p.QuantityInstockString = string.Format("{0:N0}", total);
                                        int supplierID = 0;
                                        if (value.SupplierID != null)
                                        {
                                            supplierID = value.SupplierID.ToString().ToInt(0);
                                        }
                                        p.SupplierID = supplierID;
                                        string supplierName = "";
                                        if (!string.IsNullOrEmpty(value.SupplierName))
                                        {
                                            supplierName = value.SupplierName;
                                        }
                                        p.SupplierName = supplierName;
                                        ps.Add(p);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(ps));
        }
Пример #5
0
        public static string getProduct(string textsearch, int gettotal)
        {
            List <ProductGetOut> ps = new List <ProductGetOut>();
            string username         = HttpContext.Current.Request.Cookies["userLoginSystem"].Value;
            var    acc = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID = Convert.ToInt32(acc.AgentID);
                var product = ProductController.GetBySKU(textsearch.Trim().ToUpper());

                // Kiểm tra sản phẩm có trong table Product không?
                if (product != null) // Nếu sản phẩm có trong table Product thì...
                {
                    var productvariable = ProductVariableController.GetByParentSKU(product.ProductSKU);

                    // Kiểm tra sản phẩm cha là variable hay simple?
                    if (productvariable.Count > 0) // Nếu sản phẩm cha là variable thì...
                    {
                        foreach (var pv in productvariable)
                        {
                            string SKU = pv.SKU.Trim().ToUpper();

                            var variables = ProductVariableValueController.GetByProductVariableSKU(pv.SKU);

                            if (variables.Count > 0)
                            {
                                string variablename  = "";
                                string variablevalue = "";
                                string variable      = "";
                                string variablesave  = "";
                                foreach (var v in variables)
                                {
                                    variable      += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "<br/>";
                                    variablesave  += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|";
                                    variablename  += v.VariableName.Trim() + "|";
                                    variablevalue += v.VariableValue.Trim() + "|";
                                }

                                ProductGetOut p = new ProductGetOut();
                                p.ID                   = pv.ID;
                                p.ProductName          = product.ProductTitle;
                                p.ProductVariable      = variable;
                                p.ProductVariableSave  = variablesave;
                                p.ProductVariableName  = variablename;
                                p.ProductVariableValue = variablevalue;
                                p.ProductType          = 2;

                                if (!string.IsNullOrEmpty(pv.Image))
                                {
                                    p.ProductImage       = "<img src=\"" + pv.Image + "\" />";
                                    p.ProductImageOrigin = pv.Image;
                                }
                                else if (!string.IsNullOrEmpty(product.ProductImage))
                                {
                                    p.ProductImage       = "<img src=\"" + product.ProductImage + "\" />";
                                    p.ProductImageOrigin = product.ProductImage;
                                }
                                else
                                {
                                    p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                    p.ProductImageOrigin = "";
                                }

                                if (gettotal == 1)
                                {
                                    double total     = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                    var    mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);
                                    p.QuantityMainInstock       = mainstock;
                                    p.QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                    p.QuantityInstock           = total;
                                    p.QuantityInstockString     = string.Format("{0:N0}", total);
                                }

                                p.SKU            = SKU;
                                p.Giabansi       = Convert.ToDouble(pv.Regular_Price);
                                p.stringGiabansi = string.Format("{0:N0}", pv.Regular_Price);
                                p.Giabanle       = Convert.ToDouble(pv.RetailPrice);
                                p.stringGiabanle = string.Format("{0:N0}", pv.RetailPrice);
                                ps.Add(p);
                            }
                        }
                    }
                    else // Nếu sản phẩm cha là simple thì...
                    {
                        string SKU       = product.ProductSKU.Trim().ToUpper();
                        double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                        ProductGetOut p = new ProductGetOut();
                        p.ID                   = product.ID;
                        p.ProductName          = product.ProductTitle;
                        p.ProductVariable      = "";
                        p.ProductVariableSave  = "";
                        p.ProductVariableName  = "";
                        p.ProductVariableValue = "";
                        p.ProductType          = 1;

                        if (!string.IsNullOrEmpty(product.ProductImage))
                        {
                            p.ProductImage       = "<img src=\"" + product.ProductImage + "\" />";
                            p.ProductImageOrigin = product.ProductImage;
                        }
                        else
                        {
                            p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                            p.ProductImageOrigin = "";
                        }

                        p.SKU = SKU;
                        p.QuantityMainInstock       = mainstock;
                        p.QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                        p.QuantityInstock           = mainstock;
                        p.QuantityInstockString     = string.Format("{0:N0}", mainstock);
                        p.Giabansi       = Convert.ToDouble(product.Regular_Price);
                        p.stringGiabansi = string.Format("{0:N0}", product.Regular_Price);
                        p.Giabanle       = Convert.ToDouble(product.Retail_Price);
                        p.stringGiabanle = string.Format("{0:N0}", product.Retail_Price);
                        ps.Add(p);
                    }
                }
                else // Nếu không nằm trong table Product thì...
                {
                    var productvariable = ProductVariableController.GetBySKU(textsearch.Trim().ToUpper());

                    // Nếu sản phẩm là con (nằm trong table ProductVariable) thì...
                    if (productvariable != null)
                    {
                        string SKU = productvariable.SKU.Trim().ToUpper();

                        var variables = ProductVariableValueController.GetByProductVariableSKU(SKU);

                        if (variables.Count > 0)
                        {
                            string variablename  = "";
                            string variablevalue = "";
                            string variable      = "";
                            string variablesave  = "";

                            foreach (var v in variables)
                            {
                                variable      += v.VariableName + ": " + v.VariableValue + "<br/>";
                                variablesave  += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|";
                                variablename  += v.VariableName + "|";
                                variablevalue += v.VariableValue + "|";
                            }

                            double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                            ProductGetOut p = new ProductGetOut();
                            p.ID = productvariable.ID;

                            var _product = ProductController.GetBySKU(productvariable.ParentSKU);
                            if (_product != null)
                            {
                                p.ProductName = _product.ProductTitle;
                            }

                            p.ProductVariable      = variable;
                            p.ProductVariableSave  = variablesave;
                            p.ProductVariableName  = variablename;
                            p.ProductVariableValue = variablevalue;
                            p.ProductType          = 2;

                            if (!string.IsNullOrEmpty(productvariable.Image))
                            {
                                p.ProductImage       = "<img src=\"" + productvariable.Image + "\" />";
                                p.ProductImageOrigin = productvariable.Image;
                            }
                            else if (_product != null && !string.IsNullOrEmpty(_product.ProductImage))
                            {
                                p.ProductImage       = "<img src=\"" + _product.ProductImage + "\" />";
                                p.ProductImageOrigin = _product.ProductImage;
                            }
                            else
                            {
                                p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                p.ProductImageOrigin = "";
                            }

                            p.SKU = SKU;
                            p.QuantityMainInstock       = mainstock;
                            p.QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                            p.QuantityInstock           = mainstock;
                            p.QuantityInstockString     = string.Format("{0:N0}", mainstock);
                            p.Giabansi       = Convert.ToDouble(productvariable.Regular_Price);
                            p.stringGiabansi = string.Format("{0:N0}", productvariable.Regular_Price);
                            p.Giabanle       = Convert.ToDouble(productvariable.Regular_Price);
                            p.stringGiabanle = string.Format("{0:N0}", productvariable.Regular_Price);
                            ps.Add(p);
                        }
                    }
                }
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(ps));
        }
Пример #6
0
        public static string getProduct(string textsearch, int typeinout)
        {
            List <ProductGetOut> ps = new List <ProductGetOut>();
            string username         = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value;
            var    acc = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID = Convert.ToInt32(acc.AgentID);
                if (typeinout == 1)
                {
                    var products = ProductController.GetByTextSearchIsHidden(textsearch.Trim(), false);
                    if (products.Count > 0)
                    {
                        foreach (var item in products)
                        {
                            var productvariable = ProductVariableController.GetProductID(item.ID);
                            if (productvariable.Count > 0)
                            {
                                foreach (var pv in productvariable)
                                {
                                    string SKU   = pv.SKU.Trim().ToUpper();
                                    var    check = StockManagerController.GetBySKU(AgentID, SKU);
                                    if (check.Count > 0)
                                    {
                                        double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                        if (total > 0)
                                        {
                                            var variables = ProductVariableValueController.GetByProductVariableID(pv.ID);
                                            if (variables.Count > 0)
                                            {
                                                string variablename  = "";
                                                string variablevalue = "";
                                                string variable      = "";

                                                foreach (var v in variables)
                                                {
                                                    variable      += v.VariableName.Trim() + ":" + v.VariableValue.Trim() + "|";
                                                    variablename  += v.VariableName.Trim() + "|";
                                                    variablevalue += v.VariableValue.Trim() + "|";
                                                }

                                                ProductGetOut p = new ProductGetOut();
                                                p.ID                    = pv.ID;
                                                p.ProductName           = item.ProductTitle;
                                                p.ProductVariable       = variable;
                                                p.ProductVariableName   = variablename;
                                                p.ProductVariableValue  = variablevalue;
                                                p.ProductType           = 2;
                                                p.ProductImage          = "<img src=\"" + Thumbnail.getURL(pv.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\" />";
                                                p.ProductImageOrigin    = Thumbnail.getURL(pv.Image, Thumbnail.Size.Small);
                                                p.QuantityInstock       = total;
                                                p.QuantityInstockString = string.Format("{0:N0}", total);
                                                p.SKU                   = SKU;
                                                int supplierID = 0;
                                                if (pv.SupplierID != null)
                                                {
                                                    supplierID = pv.SupplierID.ToString().ToInt(0);
                                                }
                                                p.SupplierID = supplierID;
                                                string supplierName = "";
                                                if (!string.IsNullOrEmpty(pv.SupplierName))
                                                {
                                                    supplierName = pv.SupplierName;
                                                }
                                                p.SupplierName = supplierName;
                                                ps.Add(p);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                string SKU   = item.ProductSKU.Trim().ToUpper();
                                var    check = StockManagerController.GetBySKU(AgentID, SKU);
                                if (check.Count > 0)
                                {
                                    double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                    if (total > 0)
                                    {
                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        ProductGetOut p = new ProductGetOut();
                                        p.ID                   = item.ID;
                                        p.ProductName          = item.ProductTitle;
                                        p.ProductVariable      = variable;
                                        p.ProductVariableName  = variablename;
                                        p.ProductVariableValue = variablevalue;
                                        p.ProductType          = 1;
                                        var img = ProductImageController.GetFirstByProductID(item.ID);
                                        if (img != null)
                                        {
                                            p.ProductImage       = "<img src=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\"  />";
                                            p.ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small);
                                        }
                                        else
                                        {
                                            p.ProductImage       = "";
                                            p.ProductImageOrigin = "";
                                        }
                                        p.QuantityInstock       = total;
                                        p.QuantityInstockString = string.Format("{0:N0}", total);
                                        p.SKU = SKU;
                                        int supplierID = 0;
                                        if (item.SupplierID != null)
                                        {
                                            supplierID = item.SupplierID.ToString().ToInt(0);
                                        }
                                        p.SupplierID = supplierID;
                                        string supplierName = "";
                                        if (!string.IsNullOrEmpty(item.SupplierName))
                                        {
                                            supplierName = item.SupplierName;
                                        }
                                        p.SupplierName = supplierName;
                                        ps.Add(p);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    var products = ProductController.GetBySKU(textsearch);
                    if (products != null)
                    {
                        var productvariable = ProductVariableController.GetProductID(products.ID);
                        if (productvariable.Count > 0)
                        {
                            foreach (var pv in productvariable)
                            {
                                string SKU   = pv.SKU.Trim().ToUpper();
                                var    check = StockManagerController.GetBySKU(AgentID, SKU);
                                if (check.Count > 0)
                                {
                                    double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);

                                    if (total > 0)
                                    {
                                        var variables = ProductVariableValueController.GetByProductVariableID(pv.ID);
                                        if (variables.Count > 0)
                                        {
                                            string variablename  = "";
                                            string variablevalue = "";
                                            string variable      = "";

                                            foreach (var v in variables)
                                            {
                                                variable      += v.VariableName.Trim() + ":" + v.VariableValue.Trim() + "|";
                                                variablename  += v.VariableName.Trim() + "|";
                                                variablevalue += v.VariableValue.Trim() + "|";
                                            }

                                            ProductGetOut p = new ProductGetOut();
                                            p.ID                    = pv.ID;
                                            p.ProductName           = products.ProductTitle;
                                            p.ProductVariable       = variable;
                                            p.ProductVariableName   = variablename;
                                            p.ProductVariableValue  = variablevalue;
                                            p.ProductType           = 2;
                                            p.ProductImage          = "<img src=\"" + Thumbnail.getURL(pv.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\"  />";
                                            p.ProductImageOrigin    = Thumbnail.getURL(pv.Image, Thumbnail.Size.Small);
                                            p.QuantityInstock       = total;
                                            p.QuantityInstockString = string.Format("{0:N0}", total);
                                            p.SKU                   = SKU;
                                            int supplierID = 0;
                                            if (pv.SupplierID != null)
                                            {
                                                supplierID = pv.SupplierID.ToString().ToInt(0);
                                            }
                                            p.SupplierID = supplierID;
                                            string supplierName = "";
                                            if (!string.IsNullOrEmpty(pv.SupplierName))
                                            {
                                                supplierName = pv.SupplierName;
                                            }
                                            p.SupplierName = supplierName;
                                            ps.Add(p);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            string SKU   = products.ProductSKU.Trim().ToUpper();
                            var    check = StockManagerController.GetBySKU(AgentID, SKU);
                            if (check.Count > 0)
                            {
                                double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                if (total > 0)
                                {
                                    string variablename  = "";
                                    string variablevalue = "";
                                    string variable      = "";

                                    ProductGetOut p = new ProductGetOut();
                                    p.ID                   = products.ID;
                                    p.ProductName          = products.ProductTitle;
                                    p.ProductVariable      = variable;
                                    p.ProductVariableName  = variablename;
                                    p.ProductVariableValue = variablevalue;
                                    p.ProductType          = 1;
                                    var img = ProductImageController.GetFirstByProductID(products.ID);
                                    if (img != null)
                                    {
                                        p.ProductImage       = "<img src=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\"  />";
                                        p.ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small);
                                    }
                                    else
                                    {
                                        p.ProductImage       = "";
                                        p.ProductImageOrigin = "";
                                    }
                                    p.SKU                   = SKU;
                                    p.QuantityInstock       = total;
                                    p.QuantityInstockString = string.Format("{0:N0}", total);
                                    int supplierID = 0;
                                    if (products.SupplierID != null)
                                    {
                                        supplierID = products.SupplierID.ToString().ToInt(0);
                                    }
                                    p.SupplierID = supplierID;
                                    string supplierName = "";
                                    if (!string.IsNullOrEmpty(products.SupplierName))
                                    {
                                        supplierName = products.SupplierName;
                                    }
                                    p.SupplierName = supplierName;
                                    ps.Add(p);
                                }
                            }
                        }
                    }
                    else
                    {
                        var productvariable = ProductVariableController.GetBySKU(textsearch);
                        if (productvariable != null)
                        {
                            string SKU   = productvariable.SKU.Trim().ToUpper();
                            var    check = StockManagerController.GetBySKU(AgentID, SKU);
                            if (check.Count > 0)
                            {
                                double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                if (total > 0)
                                {
                                    var variables = ProductVariableValueController.GetByProductVariableID(productvariable.ID);

                                    if (variables.Count > 0)
                                    {
                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        foreach (var v in variables)
                                        {
                                            variable      += v.VariableName + ":" + v.VariableValue + "|";
                                            variablename  += v.VariableName + "|";
                                            variablevalue += v.VariableValue + "|";
                                        }

                                        ProductGetOut p = new ProductGetOut();
                                        p.ID = productvariable.ID;
                                        var product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));
                                        if (product != null)
                                        {
                                            p.ProductName = product.ProductTitle;
                                        }
                                        p.ProductVariable      = variable;
                                        p.ProductVariableName  = variablename;
                                        p.ProductVariableValue = variablevalue;
                                        p.ProductType          = 2;
                                        p.ProductImage         = "<img src=\"" + Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width:50px;\" />";
                                        p.ProductImageOrigin   = Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small);
                                        p.SKU                   = productvariable.SKU.Trim().ToUpper();
                                        p.QuantityInstock       = total;
                                        p.QuantityInstockString = string.Format("{0:N0}", total);
                                        int supplierID = 0;
                                        if (productvariable.SupplierID != null)
                                        {
                                            supplierID = productvariable.SupplierID.ToString().ToInt(0);
                                        }
                                        p.SupplierID = supplierID;
                                        string supplierName = "";
                                        if (!string.IsNullOrEmpty(productvariable.SupplierName))
                                        {
                                            supplierName = productvariable.SupplierName;
                                        }
                                        p.SupplierName = supplierName;
                                        ps.Add(p);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(ps));
        }
Пример #7
0
        public static string getProduct(string textsearch)
        {
            List <ProductGetOut> ps = new List <ProductGetOut>();
            string username         = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value;
            var    acc = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID  = Convert.ToInt32(acc.AgentID);
                var products = ProductController.GetBySKU(textsearch.Trim().ToUpper());

                if (products != null)
                {
                    var productvariable = ProductVariableController.GetByParentSKU(products.ProductSKU);

                    if (productvariable.Count > 0)
                    {
                        foreach (var pv in productvariable)
                        {
                            var variables = ProductVariableValueController.GetByProductVariableSKU(pv.SKU);

                            if (variables.Count > 0)
                            {
                                string variablename  = "";
                                string variablevalue = "";
                                string variable      = "";

                                foreach (var v in variables)
                                {
                                    variable      += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|";
                                    variablename  += v.VariableName.Trim() + "|";
                                    variablevalue += v.VariableValue.Trim() + "|";
                                }

                                ProductGetOut p = new ProductGetOut();
                                p.ID                   = pv.ID;
                                p.ProductName          = products.ProductTitle;
                                p.ProductVariable      = variable;
                                p.ProductVariableName  = variablename;
                                p.ProductVariableValue = variablevalue;
                                p.ProductType          = 2;

                                p.ProductImage       = "<img onclick='openImage($(this))' src='" + Thumbnail.getURL(pv.Image, Thumbnail.Size.Normal) + "'>";
                                p.ProductImageOrigin = Thumbnail.getURL(pv.Image, Thumbnail.Size.Source);

                                p.SKU = pv.SKU.Trim().ToUpper();

                                int supplierID = 0;
                                if (pv.SupplierID != null)
                                {
                                    supplierID = pv.SupplierID.ToString().ToInt(0);
                                }
                                p.SupplierID = supplierID;

                                string supplierName = "";

                                if (!string.IsNullOrEmpty(pv.SupplierName))
                                {
                                    supplierName = pv.SupplierName;
                                }
                                p.SupplierName = supplierName;

                                double total = PJUtils.TotalProductQuantityInstock(AgentID, pv.SKU);
                                p.WarehouseQuantity = string.Format("{0:N0}", total);
                                ps.Add(p);
                            }
                        }
                    }
                    else
                    {
                        string variablename  = "";
                        string variablevalue = "";
                        string variable      = "";

                        ProductGetOut p = new ProductGetOut();
                        p.ID                   = products.ID;
                        p.ProductName          = products.ProductTitle;
                        p.ProductVariable      = variable;
                        p.ProductVariableName  = variablename;
                        p.ProductVariableValue = variablevalue;
                        p.ProductType          = 1;

                        p.ProductImage       = "<img onclick='openImage($(this))' src='" + Thumbnail.getURL(products.ProductImage, Thumbnail.Size.Normal) + "'>";
                        p.ProductImageOrigin = Thumbnail.getURL(products.ProductImage, Thumbnail.Size.Source);

                        p.SKU = products.ProductSKU.Trim().ToUpper();
                        int supplierID = 0;
                        if (products.SupplierID != null)
                        {
                            supplierID = products.SupplierID.ToString().ToInt(0);
                        }
                        p.SupplierID = supplierID;
                        string supplierName = "";
                        if (!string.IsNullOrEmpty(products.SupplierName))
                        {
                            supplierName = products.SupplierName;
                        }
                        p.SupplierName = supplierName;

                        double total = PJUtils.TotalProductQuantityInstock(AgentID, products.ProductSKU);

                        p.WarehouseQuantity = string.Format("{0:N0}", total);
                        ps.Add(p);
                    }
                }
                else
                {
                    var productvariable = ProductVariableController.GetAllBySKU(textsearch.Trim().ToUpper());

                    if (productvariable != null)
                    {
                        foreach (var value in productvariable)
                        {
                            var variables = ProductVariableValueController.GetByProductVariableSKU(value.SKU);

                            if (variables.Count > 0)
                            {
                                string variablename  = "";
                                string variablevalue = "";
                                string variable      = "";

                                foreach (var v in variables)
                                {
                                    variable      += v.VariableName + ": " + v.VariableValue + "|";
                                    variablename  += v.VariableName + "|";
                                    variablevalue += v.VariableValue + "|";
                                }

                                ProductGetOut p = new ProductGetOut();
                                p.ID = value.ID;

                                var product = ProductController.GetBySKU(value.ParentSKU);
                                if (product != null)
                                {
                                    p.ProductName = product.ProductTitle;
                                }

                                p.ProductVariable      = variable;
                                p.ProductVariableName  = variablename;
                                p.ProductVariableValue = variablevalue;
                                p.ProductType          = 2;

                                p.ProductImage       = "<img onclick='openImage($(this))' src='" + Thumbnail.getURL(value.Image, Thumbnail.Size.Normal) + "'>";
                                p.ProductImageOrigin = Thumbnail.getURL(value.Image, Thumbnail.Size.Source);

                                p.SKU = value.SKU.Trim().ToUpper();
                                int supplierID = 0;
                                if (value.SupplierID != null)
                                {
                                    supplierID = value.SupplierID.ToString().ToInt(0);
                                }
                                p.SupplierID = supplierID;
                                string supplierName = "";
                                if (!string.IsNullOrEmpty(value.SupplierName))
                                {
                                    supplierName = value.SupplierName;
                                }
                                p.SupplierName = supplierName;

                                double total = PJUtils.TotalProductQuantityInstock(AgentID, value.SKU);

                                p.WarehouseQuantity = string.Format("{0:N0}", total);
                                ps.Add(p);
                            }
                        }
                    }
                }
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(ps));
        }