示例#1
0
 public int SaveBrand(Brand brand)
 {
     BrandDL brandDL=new BrandDL();
     if (brand.BrandID > 0)
     {
         return brandDL.UpdateBrand(brand);
     }
     else
         return brandDL.SaveBrand(brand);
 }
示例#2
0
文件: BrandDL.cs 项目: yoorke/pinshop
 public Brand GetBrandByName(string name)
 {
     Brand brand = null;
     using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString))
     {
         using (SqlCommand objComm = new SqlCommand("SELECT brandID, name FROM brand WHERE name=@name", objConn))
         {
             objConn.Open();
             objComm.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = name;
             using (SqlDataReader reader = objComm.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     brand = new Brand();
                     brand.BrandID = reader.GetInt32(0);
                     brand.Name = reader.GetString(1);
                 }
             }
         }
     }
     return brand;
 }
示例#3
0
文件: BrandDL.cs 项目: yoorke/pinshop
        public int UpdateBrand(Brand brand)
        {
            int status = 0;
            using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString))
            {
                using (SqlCommand objComm = new SqlCommand("updateBrand", objConn))
                {
                    objConn.Open();
                    objComm.CommandType = CommandType.StoredProcedure;
                    objComm.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = brand.Name;
                    objComm.Parameters.Add("@brandID", SqlDbType.Int).Value = brand.BrandID;

                    status = objComm.ExecuteNonQuery();
                }
            }
            return status;
        }
示例#4
0
文件: BrandDL.cs 项目: yoorke/pinshop
 public int SaveBrand(Brand brand)
 {
     int brandID;
     using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString))
     {
         using (SqlCommand objComm = new SqlCommand("INSERT INTO brand (name) VALUES (@name);SELECT SCOPE_IDENTITY()", objConn))
         {
             objConn.Open();
             objComm.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = brand.Name;
             brandID = int.Parse(objComm.ExecuteScalar().ToString());
         }
     }
     return brandID;
 }
示例#5
0
        private void loadProductSliders(Brand brand, Category category)
        {
            sliderBrand.NumberOfProducts = 6;
            //sliderBrand.Products = new ProductBL().GetProducts(-1, -1, string.Empty, string.Empty, brand.BrandID);
            sliderBrand.Products = new ProductBL().GetProductsForFirstPage(-1, brand.BrandID, 12, "Slučajni");
            sliderBrand.Name = "Ostali proizvodi kompanije " + brand.Name;
            ((Literal)sliderBrand.FindControl("lblPrev")).Text = @"<a id=""prev"" runat=""server"" href=""#carouselBrand"" data-slide=""prev""><img src=" + Page.ResolveUrl("~/images/prev_next.gif") + @" alt=""Prethodni"" /></a>";
            ((Literal)sliderBrand.FindControl("lblNext")).Text = @"<a id=""next"" runat=""server"" href=""#carouselBrand"" data-slide=""next"" class=""next_button""><img src=" + Page.ResolveUrl("~/images/prev_next.gif") + @" alt=""Sledeći"" /></a>";
            ((Literal)sliderBrand.FindControl("lblCarousel")).Text = @"<div id=""carouselBrand"" class=""carousel slide"" data-ride="""" runat=""server"">";
            ((Literal)sliderBrand.FindControl("lblCarouselClose")).Text = "</div>";

            sliderCategory.NumberOfProducts = 6;
            //sliderCategory.Products = new ProductBL().GetProductsForCategory(category.CategoryID, true, true);
            sliderCategory.Products = new ProductBL().GetProductsForFirstPage(category.CategoryID, -1, 12, "Slučajni");
            sliderCategory.Name = category.Name;
            ((Literal)sliderCategory.FindControl("lblPrev")).Text = @"<a id=""prev"" runat=""server"" href=""#carouselCategory"" data-slide=""prev""><img src=" + Page.ResolveUrl("~/images/prev_next.gif") + @" alt=""Prethodni"" /></a>";
            ((Literal)sliderCategory.FindControl("lblNext")).Text = @"<a id=""next"" runat=""server"" href=""#carouselCategory"" data-slide=""next"" class=""next_button""><img src=" + Page.ResolveUrl("~/images/prev_next.gif") + @" alt=""Sledeći"" /></a>";
            ((Literal)sliderCategory.FindControl("lblCarousel")).Text = @"<div id=""carouselCategory"" class=""carousel slide"" data-ride="""" runat=""server"">";
            ((Literal)sliderCategory.FindControl("lblCarouselClose")).Text = "</div>";
        }
示例#6
0
        public string parseProducts(string getCategory, string[] getSubcategories, bool getImages, bool getAttributes, string categoryName, int categoryID, bool overwrite, string[] codes, bool isActive, bool isApproved)
        {
            try
            {
                ErrorLog.LogMessage("parsing products");
                EweDL eweDL = new EweDL();
                List<eshopBE.Attribute> attributes = null;
                ProductBL productBL = new ProductBL();
                AttributeBL attributeBL = new AttributeBL();
                attributes = attributeBL.GetAttributesForCategory(categoryID);
                CategoryDL categoryDL = new CategoryDL();
                Category category = categoryDL.GetCategory(categoryID);
                //productBL.SetInStock(1, false, categoryID);
                int newProducts = 0;
                int updatedProducts = 0;
                bool isNew = false;

                /*List<string> subcategory = new List<string>();
                string categoryString=string.Empty;
                foreach (XmlNode xmlNode in nodeList)
                    foreach (XmlNode xmlChildNode in xmlNode.ChildNodes)
                    {
                        if (xmlChildNode.Name == "category")
                        {
                            categoryString = xmlChildNode.InnerText;
                        }
                        if (xmlChildNode.Name == "subcategory")
                        {
                            categoryString += "-" + xmlChildNode.InnerText;
                            subcategory.Add(categoryString);
                        }
                    }
                string prethodni = string.Empty;
                using (StreamWriter sw = new StreamWriter(Server.MapPath("~") + "categories.txt"))
                {
                    foreach (string category in subcategory)
                    {
                        if (prethodni != category)
                            sw.WriteLine(category);
                        prethodni = category;
                    }
                }*/

                for (int j = 0; j < getSubcategories.Length; j++)
                {
                    XmlDocument xmlDoc = eweDL.GetXml(getCategory, getSubcategories[j], getImages, getAttributes);
                    XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("product");
                    ErrorLog.LogMessage("preuzeti proizvodi");
                    foreach (XmlNode xmlNode in nodeList)
                    {
                        string code = xmlNode.SelectSingleNode("id").InnerText.Trim();
                        bool save = false;
                        for (int i = 0; i < codes.Length; i++)
                        {
                            if (codes[i] == code)
                            {
                                save = true;
                                break;
                            }
                        }
                        if (save)
                        {
                            Product product = new Product();
                            product.IsApproved = isApproved;
                            product.IsActive = isActive;
                            product.SupplierID = 1;
                            product.VatID = 4;
                            product.Categories = new List<Category>();
                            product.Categories.Add(category);
                            if (getAttributes)
                                product.Specification = specificationToHtml(xmlNode.SelectSingleNode("specifications").OuterXml);
                            else
                                product.Specification = string.Empty;
                            product.IsInStock = true;
                            bool isLocked = true;
                            isNew = false;

                            foreach (XmlNode xmlChildNode in xmlNode.ChildNodes)
                            {
                                switch (xmlChildNode.Name)
                                {
                                    case "id":
                                        {
                                            product.SupplierCode = xmlChildNode.InnerText.Trim();
                                            product.ProductID = productBL.GetProductIDBySupplierCode(product.SupplierCode);
                                            isLocked = productBL.IsLocked(product.ProductID);
                                            if (product.ProductID <= 0)
                                                isNew = true;
                                            break;
                                        }
                                    case "manufacturer":
                                        {
                                            if (!isLocked)
                                            {
                                                //if (product.ProductID <= 0)
                                                //{
                                                BrandBL brandBL = new BrandBL();
                                                Brand brand = brandBL.GetBrandByName(xmlChildNode.InnerText.Trim());
                                                if (brand == null)
                                                {
                                                    brand = new Brand();
                                                    brand.Name = xmlChildNode.InnerText.Trim();
                                                    brand.BrandID = brandBL.SaveBrand(brand);
                                                    //product.Brand.BrandID = brand.BrandID;
                                                }
                                                if (product.Brand == null)
                                                    product.Brand = new Brand();
                                                product.Brand.BrandID = brand.BrandID;
                                                //}
                                            }
                                            break;

                                        }
                                    case "name":
                                        {
                                            if (!isLocked)
                                                product.Name = xmlChildNode.InnerText.Trim();
                                            break;
                                        }

                                    case "category":
                                        {
                                            break;
                                        }

                                    /*case "subcategory":
                                        {
                                            CategoryBL categoryBL = new CategoryBL();
                                            //string categoryName = getSubcategory;  //(xmlChildNode.InnerText.Trim() == "NOTEBOOK") ? "LAPTOP" : xmlChildNode.InnerText.Trim();
                                            Category category = categoryBL.GetCategory(categoryName);
                                            product.Categories = new System.Collections.Generic.List<Category>();
                                            product.Categories.Add(category);

                                            break;
                                        }*/

                                    case "price":
                                        {
                                            if (!isLocked)
                                            {
                                                product.Price = calculatePrice(double.Parse(xmlChildNode.InnerText.Replace('.', ',').Trim()), category.PricePercent);
                                                product.WebPrice = calculatePrice(double.Parse(xmlChildNode.InnerText.Replace('.', ',').Trim()), category.WebPricePercent);
                                            }
                                            break;
                                        }

                                    case "price_rebate":
                                        {
                                            break;
                                        }

                                    case "vat":
                                        {
                                            if (!isLocked)
                                            {
                                                switch (xmlChildNode.InnerText.Trim())
                                                {
                                                    case "20": { product.VatID = 4; break; }
                                                }
                                            }
                                            break;
                                        }

                                    case "ean":
                                        {
                                            if (!isLocked)
                                                product.Ean = xmlChildNode.InnerText.Trim();
                                            break;
                                        }

                                    case "images":
                                        {
                                            if (!isLocked)
                                            {
                                                //if (product.ProductID <= 0 || overwrite)
                                                //{
                                                foreach (XmlNode xmlImageNode in xmlChildNode.ChildNodes)
                                                {
                                                    if (product.Images == null)
                                                        product.Images = new System.Collections.Generic.List<string>();
                                                    if (xmlImageNode.Name == "image")
                                                    {
                                                        if (saveImageFromUrl(xmlImageNode.InnerText.Trim()))
                                                            product.Images.Add(Path.GetFileName(xmlImageNode.InnerText.Trim()));
                                                    }
                                                }
                                                //}
                                            }
                                            break;

                                        }

                                    case "specifications":
                                        {
                                            if (!isLocked)
                                            {
                                                if (product.ProductID <= 0 || overwrite)
                                                {
                                                    if (product.Categories != null)
                                                        if (product.Categories[0] != null)
                                                        {

                                                            //List<AttributeValue> attributeValues;
                                                            int attributeID;
                                                            foreach (XmlNode xmlSpecificationNode in xmlChildNode.ChildNodes)
                                                            {
                                                                if (xmlSpecificationNode.Name == "attribute_group")
                                                                {
                                                                    string attributeGroup = xmlSpecificationNode.Attributes[0].Value;
                                                                    foreach (XmlNode xmlAttributeNode in xmlSpecificationNode.ChildNodes)
                                                                    {
                                                                        if (xmlAttributeNode.Attributes[0].Value != "Programi / Ekskluzivne aplikacije / Servisi")
                                                                        {
                                                                            if ((attributeID = getAttributeID(attributes, attributeGroup + "-" + xmlAttributeNode.Attributes[0].Value)) == 0)
                                                                            {
                                                                                attributeID = addAttribute(product.Categories[0].CategoryID, attributeGroup + "-" + xmlAttributeNode.Attributes[0].Value);
                                                                                //attributes = attributeBL.GetAttributesForCategory(product.Categories[0].CategoryID);
                                                                                if (attributes == null)
                                                                                    attributes = new List<eshopBE.Attribute>();
                                                                                attributes.Add(new eshopBE.Attribute(attributeID, attributeGroup + "-" + xmlAttributeNode.Attributes[0].Value, false, false, 0));
                                                                            }

                                                                            if (product.Attributes == null)
                                                                                product.Attributes = new List<AttributeValue>();

                                                                            int attributeValueID = getAttributeValueID(attributeID, xmlAttributeNode.InnerText.Trim());
                                                                            product.Attributes.Add(new AttributeValue(attributeValueID, xmlAttributeNode.InnerText.Trim(), attributeID, 0, string.Empty, 0));
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                }
                                            }
                                            break;
                                        }
                                }
                            }
                            product.Code = product.SupplierCode;
                            product.Description = string.Empty;

                            if (!isLocked)
                                if (productBL.SaveProduct(product) > 0)
                                    if (isNew)
                                        newProducts++;
                                    else
                                        updatedProducts++;
                        }
                    }
                }

                return "Dodato " + newProducts.ToString() + " proizvoda. Izmenjeno " + updatedProducts.ToString() + " proizvoda";
            }
            catch (Exception ex)
            {
                ErrorLog.LogError(ex);
            }
            return string.Empty;
        }
示例#7
0
 private Brand GetBrand(string brandName)
 {
     BrandBL brandBL = new BrandBL();
     Brand brand = brandBL.GetBrandByName(brandName);
     if (brand == null)
     {
         brand = new Brand();
         brand.Name = brandName;
         brand.BrandID = brandBL.SaveBrand(brand);
         //product.Brand.BrandID = brand.BrandID;
     }
     return brand;
 }
示例#8
0
        public bool SaveProduct(string code, bool isActive, bool isApproved, int categoryID, int kimtecCategoryID)
        {
            //int newProducts = 0;
            //int updatedProducts = 0;

            DataTable kimtecProduct = new KimtecDL().GetProductBySupplierCode(code);
            Category category = new CategoryDL().GetCategory(categoryID);

            Product product = new Product();
            product.IsApproved = isApproved;
            product.IsActive = isActive;
            product.SupplierID = 1004;
            product.SupplierCode = code;
            product.VatID = 4;
            product.Categories = new List<Category>();
            product.Categories.Add(category);
            product.Specification = string.Empty;
            product.IsInStock = true;
            bool isNew = false;
            bool isLocked = false;
            product.Code = code;

            product.ProductID = new ProductDL().GetProductIDBySupplierCode(code);
            if (product.ProductID <= 0)
                isNew = true;
            isLocked = new ProductDL().IsLocked(product.ProductID);

            Brand brand = new BrandDL().GetBrandByName(kimtecProduct.Rows[0]["brand"].ToString());
            if(brand == null)
            {
                brand = new Brand();
                brand.Name = kimtecProduct.Rows[0]["brand"].ToString();
                brand.BrandID = new BrandDL().SaveBrand(brand);
            }
            if (product.Brand == null)
                product.Brand = new Brand();
            product.Brand = brand;

            product.Name = kimtecProduct.Rows[0]["name"].ToString();
            product.Price = calculatePrice(double.Parse(kimtecProduct.Rows[0]["partnerPrice"].ToString()), category.PricePercent);
            product.WebPrice = calculatePrice(double.Parse(kimtecProduct.Rows[0]["partnerPrice"].ToString()), category.WebPricePercent);
            product.Ean = kimtecProduct.Rows[0]["barcodeValue"].ToString();
            product.SupplierPrice = double.Parse(kimtecProduct.Rows[0]["partnerPrice"].ToString());
            product.Images = new List<string>();
            product.Images.Add(saveProductImage(kimtecProduct.Rows[0]["imageUrl"].ToString()));
            product.Attributes = GetProductAttributes(code, kimtecCategoryID);
            product.Description = kimtecProduct.Rows[0]["marketingDescription"].ToString();

            if (!isLocked)
                if (new ProductBL().SaveProduct(product) > 0)
                    return true;

            return false;

            //return new int[] { newProducts, updatedProducts };
        }
示例#9
0
文件: EweBL.cs 项目: yoorke/pinshop
        public bool SaveProduct(string supplierCode, bool isApproved, bool isActive, int categoryID)
        {
            DataTable eweProduct = new EweDL().GetProductBySupplierCode(supplierCode);

            Category category = new CategoryBL().GetCategory(categoryID);
            List<eshopBE.Attribute> attributes = new AttributeBL().GetAttributesForCategory(categoryID);

            Product product = new Product();
            product.IsApproved = isApproved;
            product.IsActive = isActive;
            product.SupplierID = 1;
            product.SupplierCode = supplierCode;
            product.VatID = 4;
            product.Categories = new List<Category>();
            product.Categories.Add(category);
            product.Specification = specificationToHtml(eweProduct.Rows[0]["specification"].ToString());
            product.IsInStock = true;
            bool isNew = false;
            bool isLocked = false;
            product.Code = product.SupplierCode;
            product.Description = string.Empty;

            product.ProductID = new ProductBL().GetProductIDBySupplierCode(product.SupplierCode);
            if (product.ProductID <= 0)
                isNew = true;
            isLocked = new ProductBL().IsLocked(product.ProductID);

            Brand brand = new BrandBL().GetBrandByName(eweProduct.Rows[0]["brand"].ToString());
            if(brand == null)
            {
                brand = new Brand();
                brand.Name = eweProduct.Rows[0]["brand"].ToString();
                brand.BrandID = new BrandBL().SaveBrand(brand);
            }
            if (product.Brand == null)
                product.Brand = new Brand();
            product.Brand.BrandID = brand.BrandID;

            product.Name = eweProduct.Rows[0]["name"].ToString();
            product.Price = calculatePrice(double.Parse(eweProduct.Rows[0]["price"].ToString()), category.PricePercent);
            product.WebPrice = calculatePrice(double.Parse(eweProduct.Rows[0]["price"].ToString()), category.WebPricePercent);
            product.Ean = eweProduct.Rows[0]["ean"].ToString();
            product.SupplierPrice = double.Parse(eweProduct.Rows[0]["price"].ToString());

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(eweProduct.Rows[0]["images"].ToString());
            XmlNode xmlImagesNode = xmlDoc.SelectSingleNode("images");
            foreach (XmlNode xmlImageNode in xmlImagesNode.ChildNodes)
            {
                if (product.Images == null)
                    product.Images = new List<string>();
                if(xmlImageNode.Name == "image")
                {
                    if (saveImageFromUrl(xmlImageNode.InnerText.Trim()))
                        product.Images.Add(Path.GetFileName(xmlImageNode.InnerText.Trim()));
                }
            }

            int attributeID;
            if(eweProduct.Rows[0]["specification"].ToString() != string.Empty) {
                xmlDoc.LoadXml(eweProduct.Rows[0]["specification"].ToString());
                XmlNode xmlSpecificationsNode = xmlDoc.SelectSingleNode("specifications");
                foreach(XmlNode xmlSpecificationNode in xmlSpecificationsNode.ChildNodes)
                {
                    if(xmlSpecificationNode.Name == "attribute_group")
                    {
                        string attributeGroup = xmlSpecificationNode.Attributes[0].Value;
                        foreach(XmlNode xmlAttributeNode in xmlSpecificationNode.ChildNodes)
                        {
                            if(xmlAttributeNode.Attributes[0].Value != "Programi / Ekskluzivne aplikacije / Servisi")
                            {
                                if((attributeID = getAttributeID(attributes, attributeGroup + "-" + xmlAttributeNode.Attributes[0].Value)) == 0)
                                {
                                    attributeID = addAttribute(product.Categories[0].CategoryID, attributeGroup + "-" + xmlAttributeNode.Attributes[0].Value);
                                    if (attributes == null)
                                        attributes = new List<eshopBE.Attribute>();
                                    attributes.Add(new eshopBE.Attribute(attributeID, attributeGroup + "-" + xmlAttributeNode.Attributes[0].Value, false, false, 0));
                                }
                                if (product.Attributes == null)
                                    product.Attributes = new List<AttributeValue>();

                                int attributeValueID = getAttributeValueID(attributeID, xmlAttributeNode.InnerText.Trim());
                                product.Attributes.Add(new AttributeValue(attributeValueID, xmlAttributeNode.InnerText.Trim(), attributeID, 0, string.Empty, 0));
                            }
                        }
                    }
                }
            }

            if (!isLocked)
                if (new ProductBL().SaveProduct(product) > 0)
                    return true;
            return false;
        }