예제 #1
0
 public DataTable GetEweCategories(int? parentCategoryID, int? categoryID)
 {
     EweDL eweDL = new EweDL();
     DataTable categories = eweDL.GetEweCategories(parentCategoryID, categoryID);
     if (parentCategoryID == null)
     {
         DataRow newRow = categories.NewRow();
         newRow["eweCategoryID"] = 0;
         newRow["name"] = "Odaberi kategoriju";
         newRow["parentID"] = 0;
         categories.Rows.InsertAt(newRow, 0);
     }
     return categories;
 }
예제 #2
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;
        }
예제 #3
0
 public DataTable GetNewCategories()
 {
     EweDL eweDL = new EweDL();
     return eweDL.GetNewCategories();
 }
예제 #4
0
 public int GetEweCategoryForCategory(int categoryID)
 {
     EweDL eweDL = new EweDL();
     return eweDL.GetEweCategoryForCategory(categoryID);
 }
예제 #5
0
 public int SaveSelected(string categoryIDs, string selected)
 {
     EweDL eweDL = new EweDL();
     return eweDL.SaveSelected(categoryIDs.Split(','), selected.Split(','));
 }
예제 #6
0
        public void UpdateEweCategories()
        {
            EweDL eweDL = new EweDL();
            XmlDocument xmlDoc = eweDL.GetXml(string.Empty, string.Empty, false, false);

            DeleteEweCategories();
            XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("product");
            foreach (XmlNode xmlNode in nodeList)
            {
                eweDL.SaveCategory(xmlNode.SelectSingleNode("category").InnerText.Trim(), null);
                eweDL.SaveCategory(xmlNode.SelectSingleNode("subcategory").InnerText.Trim(), xmlNode.SelectSingleNode("category").InnerText.Trim());
            }
        }
예제 #7
0
        public DataTable parseProductsToDataTable(string category, string[] subcategories)
        {
            EweDL eweDL = new EweDL();
            DataTable products = new DataTable();
            products.Columns.Add("code");
            products.Columns.Add("ean");
            products.Columns.Add("manufacturer");
            products.Columns.Add("name");
            products.Columns.Add("price", typeof(double));
            products.Columns.Add("exists", typeof(bool));
            ProductDL productDL = new ProductDL();
            DataRow newRow;

            for (int i = 0; i < subcategories.Length; i++)
            {
                XmlDocument xmlDoc = eweDL.GetXml(category, subcategories[i], false, false);
                if (xmlDoc != null)
                {
                    XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("product");

                    foreach (XmlNode xmlNode in nodeList)
                    {
                        newRow = products.NewRow();
                        foreach (XmlNode xmlChildNode in xmlNode.ChildNodes)
                        {
                            switch (xmlChildNode.Name)
                            {
                                case "id":
                                    {
                                        newRow["code"] = xmlChildNode.InnerText.Trim();
                                        break;
                                    }

                                case "ean":
                                    {
                                        newRow["ean"] = xmlChildNode.InnerText.Trim();
                                        break;
                                    }

                                case "manufacturer":
                                    {
                                        newRow["manufacturer"] = xmlChildNode.InnerText.Trim();
                                        break;
                                    }

                                case "name":
                                    {
                                        newRow["name"] = xmlChildNode.InnerText.Trim();
                                        break;
                                    }

                                case "price":
                                    {
                                        newRow["price"] = xmlChildNode.InnerText.Trim().Replace('.', ',');
                                        break;
                                    }
                            }
                        }
                        newRow["exists"] = (productDL.GetProductIDBySupplierCode(newRow["code"].ToString()) > 0) ? true : false;
                        products.Rows.Add(newRow);
                    }
                }
            }
            return products;
        }
예제 #8
0
 public int SaveEweCategoryForCategory(int categoryID, int eweCategoryID, bool isCategory)
 {
     EweDL eweDL = new EweDL();
     return eweDL.SaveEweCategoryForCategory(categoryID, eweCategoryID, isCategory);
 }
예제 #9
0
        public string parseProductsStockPrice(string eweCategory, string[] eweSubcategories, int categoryID, int supplierID)
        {
            EweDL eweDL = new EweDL();
            ProductDL productDL = new ProductDL();
            CategoryBL categoryBL = new CategoryBL();
            Category category = categoryBL.GetCategory(categoryID);
            productDL.SetInStock(supplierID, false, categoryID);
            int status = 0;

            for (int i = 0; i < eweSubcategories.Length; i++)
            {
                XmlDocument xmlDoc = eweDL.GetXml(eweCategory, eweSubcategories[i], false, false);
                XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("product");

                foreach (XmlNode xmlNode in nodeList)
                {
                    string supplierCode = xmlNode.SelectSingleNode("id").InnerText.Trim();
                    int productID;
                    if ((productID = productDL.GetProductIDBySupplierCode(supplierCode)) > 0)
                    {
                        if (!productDL.IsLocked(productID))
                        {
                            double price = calculatePrice(double.Parse(xmlNode.SelectSingleNode("price").InnerText.Replace('.', ',').Trim()), category.PricePercent);
                            double webPrice = calculatePrice(double.Parse(xmlNode.SelectSingleNode("price").InnerText.Replace('.', ',').Trim()), category.WebPricePercent);
                            status += productDL.UpdatePriceAndStock(productID, price, webPrice, true);
                        }
                    }
                }
            }
            return "Uspešno izmenjeno " + status.ToString() + " artikala.";
        }
예제 #10
0
 public int DeleteEweCategories()
 {
     EweDL eweDL = new EweDL();
     return eweDL.DeleteEweCategories();
 }
예제 #11
0
 public int DeleteCategoryEweCategory(int categoryID)
 {
     EweDL eweDL = new EweDL();
     return eweDL.DeleteCategoryEweCategory(categoryID);
 }
예제 #12
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;
        }
예제 #13
0
파일: EweBL.cs 프로젝트: yoorke/pinshop
        public int ParseProductsForSaving(string category, string[] subcategories)
        {
            DataTable products = new DataTable();
            products.Columns.Add("code");
            products.Columns.Add("brand");
            products.Columns.Add("name");
            products.Columns.Add("price");
            products.Columns.Add("priceRebate");
            products.Columns.Add("vat");
            products.Columns.Add("category");
            products.Columns.Add("ean");
            products.Columns.Add("images");
            products.Columns.Add("specification");
            products.Columns.Add("subcategory");

            DataRow newRow;
            for(int i=0;i<subcategories.Length;i++)
            {
                XmlDocument xmlDoc = new EweDL().GetXml(category, subcategories[i], true, true);
                if(xmlDoc != null) {
                XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("product");

                foreach(XmlNode xmlNode in nodeList)
                {
                    newRow = products.NewRow();
                    newRow["code"] = xmlNode.SelectSingleNode("id").InnerText.Trim();
                    newRow["brand"] = xmlNode.SelectSingleNode("manufacturer").InnerText.Trim();
                    newRow["name"] = xmlNode.SelectSingleNode("name").InnerText.Trim();
                    newRow["price"] = xmlNode.SelectSingleNode("price").InnerText.Replace('.',',').Trim();
                    newRow["priceRebate"] = xmlNode.SelectSingleNode("price_rebate").InnerText.Trim();
                    newRow["vat"] = xmlNode.SelectSingleNode("vat").InnerText.Trim();
                    newRow["category"] = xmlNode.SelectSingleNode("category").InnerText.Trim();
                    newRow["ean"] = xmlNode.SelectSingleNode("ean").InnerText.Trim();
                    newRow["images"] = xmlNode.SelectSingleNode("images").OuterXml.Trim();
                    newRow["specification"] = xmlNode.SelectSingleNode("specifications") != null ? xmlNode.SelectSingleNode("specifications").OuterXml.Trim() : string.Empty;
                    newRow["subcategory"] = xmlNode.SelectSingleNode("subcategory").InnerText.Trim();
                    if(xmlNode.SelectSingleNode("subcategory").InnerText.Trim() != string.Empty)
                        products.Rows.Add(newRow);
                }
                }
            }

            return new EweDL().SaveProducts(products, category);
        }