示例#1
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;
        }
示例#2
0
        private void saveProduct()
        {
            //main data
            Product product = new Product();
            product.Name = txtName.Text;
            product.Code = txtCode.Text;
            product.SupplierCode = txtSupplierCode.Text;
            product.Brand = new Brand();
            product.Brand.BrandID = int.Parse(cmbBrand.SelectedValue);
            product.Description = txtDescription.Text;
            product.Price = double.Parse(txtPrice.Text);
            product.WebPrice = double.Parse(txtWebPrice.Text);
            product.VatID = int.Parse(cmbVat.SelectedValue);
            //product.InsertDate = product.UpdateDate = DateTime.Now;
            product.SupplierID = int.Parse(cmbSupplier.SelectedValue);
            product.IsApproved = chkApproved.Checked;
            product.IsActive = chkActive.Checked;
            product.IsLocked = chkLocked.Checked;
            product.IsInStock = chkInStock.Checked;
            product.Ean = txtEan.Text;
            product.Specification = txtSpecification.Text;
            product.ProductID = (lblProductID.Value != string.Empty) ? int.Parse(lblProductID.Value) : 0;

            if (cmbPromotions.SelectedIndex > 0)
            {
                product.Promotion = new Promotion();
                product.Promotion.PromotionID = int.Parse(cmbPromotions.SelectedValue);
                product.Promotion.Price = double.Parse(txtPromotionPrice.Text);
            }

            //category and attributes
            if (cmbCategory.SelectedIndex > -1)
            {
                product.Categories = new List<Category>();
                product.Categories.Add(new Category(int.Parse(cmbCategory.SelectedValue), cmbCategory.SelectedItem.Text, 0, string.Empty, string.Empty, 0, 0, 0, string.Empty, -1));
                product.Attributes = new List<AttributeValue>();

                //foreach (object obj in TabContainer1.Controls)
                //{
                //if (obj is AjaxControlToolkit.TabPanel)
                //{
                //AjaxControlToolkit.TabPanel tabPanel = obj as AjaxControlToolkit.TabPanel;

                //if (tabPanel.ID == "tbpCategories")
                //{

                foreach (object control in pnlAttributes.Controls)
                    if (control is customControls.AttributeControl)
                    {
                        //Control c = tpControl as Control;
                        //foreach (object innerCtrl in c.Controls)
                        //{
                        //if (innerCtrl is DropDownList)
                        //if (((DropDownList)tpControl).ID != "cmbCategory")
                        product.Attributes.Add(new AttributeValue(((customControls.AttributeControl)control).AttributeValueID, ((customControls.AttributeControl)control).AttributeValue, -1, 0, string.Empty, 0));
                        //}

                    }
                //}
                //}
                //}
            }

            //images
            if (rptImages.Items.Count > 0)
            {
                product.Images = new List<string>();
                List<string> images = (List<string>)ViewState["images"];
                foreach (string imageUrl in images)
                {
                    product.Images.Add(imageUrl);
                }
            }

            ProductBL productBL = new ProductBL();
            string productID = productBL.SaveProduct(product).ToString();
            if (lblProductID.Value == "")
                lblProductID.Value = productID;
        }
示例#3
0
        public int[] SaveProduct(System.Web.UI.WebControls.GridViewRow row, int categoryID, bool isApproved, bool isActive, int kimtecCategoryID)
        {
            Category category = new CategoryBL().GetCategory(categoryID);
            ProductBL productBL = new ProductBL();
            Product product = new Product();
            product.ProductID = productBL.GetProductIDBySupplierCode(((Label)row.FindControl("lblCode")).Text);
            bool isLocked = productBL.IsLocked(product.ProductID);
            int newProducts = 0;
            int updatedProducts = 0;
            bool isNew = product.ProductID <= 0;

            if (!isLocked)
            {
                product.Code = ((Label)row.FindControl("lblCode")).Text;
                product.SupplierCode = ((Label)row.FindControl("lblCode")).Text;
                product.Brand = GetBrand(((Label)row.FindControl("lblBrand")).Text);
                product.Name = ((Label)row.FindControl("lblName")).Text;
                product.Description = ((Label)row.FindControl("lblDescription")).Text;
                product.Price = calculatePrice(double.Parse(((Label)row.FindControl("lblPartnerPrice")).Text != string.Empty ? ((Label)row.FindControl("lblPartnerPrice")).Text : "0,00"), category.PricePercent);
                product.WebPrice = calculatePrice(double.Parse(((Label)row.FindControl("lblPartnerPrice")).Text != string.Empty ? ((Label)row.FindControl("lblPartnerPrice")).Text : "0,00"), category.WebPricePercent);
                product.Images = new List<string>();
                product.Images.Add(saveProductImage(((Label)row.FindControl("lblImageUrl")).Text));
                product.Attributes = GetProductAttributes(product.Code, kimtecCategoryID);
                product.Categories = new List<Category>();
                product.Categories.Add(category);
                product.SupplierID = 1004;
                product.IsApproved = isApproved;
                product.IsActive = isActive;
                product.VatID = 4;
                product.Specification = string.Empty;
                product.IsInStock = int.Parse(((Label)row.FindControl("lblStock")).Text != string.Empty ? ((Label)row.FindControl("lblStock")).Text : "0") > 0 ? true : false;
                product.Ean = ((Label)row.FindControl("lblBarcode")).Text;

                if (productBL.SaveProduct(product) > 0)
                {
                    if (isNew)
                        newProducts++;
                    else
                        updatedProducts++;
                }
            }
            return new int[] { newProducts, updatedProducts };
        }