protected void btnAddAttributeValue_Click(object sender, EventArgs e) { switch(lblType.Value) { case "attribute": { AttributeBL attributeBL = new AttributeBL(); attributeBL.SaveAttributeValue(new AttributeValue(-1, txtAttributeValue.Text, int.Parse(lblAttributeID.Value), 0, string.Empty, 0), false); foreach (object control in pnlAttributes.Controls) if (control is customControls.AttributeControl) if (((customControls.AttributeControl)control).ID == lblAttributeName.Value) ((customControls.AttributeControl)control).setValues(); break; } case "supplier": { SupplierBL supplierBL = new SupplierBL(); supplierBL.SaveSupplier(new Supplier(-1, txtAttributeValue.Text)); loadSupplier(); break; } case "brand": { BrandBL brandBL = new BrandBL(); brandBL.SaveBrand(new Brand(-1, txtAttributeValue.Text)); loadBrands(); break; } } txtAttributeValue.Text = string.Empty; }
protected void dgvAttributeValues_RowDeleting(object sender, GridViewDeleteEventArgs e) { AttributeBL attributeBL = new AttributeBL(); attributeBL.DeleteAttributeValue(int.Parse(dgvAttributeValues.DataKeys[e.RowIndex].Values[0].ToString())); loadValues(); }
public int getAttributeValueID(int attributeID, string value) { AttributeBL attributeBL = new AttributeBL(); List<AttributeValue> attributeValues = attributeBL.GetAttributeValues(attributeID); int attributeValueID = 0; bool exists = false; if (attributeValues != null) { for (int i = 0; i < attributeValues.Count; i++) if (attributeValues[i].Value == value) { attributeValueID = attributeValues[i].AttributeValueID; exists = true; break; } } if (!exists) { AttributeValue attributeValue = new AttributeValue(-1, value, attributeID, 0, string.Empty, 0); attributeValueID = attributeBL.SaveAttributeValue(attributeValue, false); } return attributeValueID; }
protected void chkIsDescription_CheckedChanged(object sender, EventArgs e) { CheckBox checkBox = (CheckBox)sender; GridViewRow row = (GridViewRow)checkBox.NamingContainer; AttributeBL attributeBL = new AttributeBL(); attributeBL.SetIsDescription(int.Parse(lblCategoryID.Value), int.Parse(((Label)row.FindControl("lblAttributeID")).Text), bool.Parse(((CheckBox)row.FindControl("chkIsDescription")).Checked.ToString())); }
public void setValues() { AttributeBL attributeBL = new AttributeBL(); cmbAttribute.DataSource = attributeBL.GetAttributeValues(_attributeID); cmbAttribute.DataValueField = "attributeValueID"; cmbAttribute.DataTextField = "value"; cmbAttribute.DataBind(); cmbAttribute.SelectedValue = cmbAttribute.Items.FindByText("NP").Value; lblAttributeID.Value = _attributeID.ToString(); }
protected void btnAddValue_Click(object sender, EventArgs e) { AttributeValue attributeValue = new AttributeValue(); attributeValue.Value = txtValue.Text; attributeValue.AttributeID = int.Parse(lblAttributeID.Value); AttributeBL attributeBL = new AttributeBL(); attributeBL.SaveAttributeValue(attributeValue, false); loadValues(); }
protected void btnSavePositions_Click(object sender, EventArgs e) { int categoryID = int.Parse(lblCategoryID.Value); AttributeBL attributeBL = new AttributeBL(); for (int i = 0; i < dgvAttributes.Rows.Count; i++) { int attributeID = int.Parse(((Label)dgvAttributes.Rows[i].FindControl("lblAttributeID")).Text); int position = 0; int.TryParse(((TextBox)dgvAttributes.Rows[i].FindControl("txtPosition")).Text, out position); attributeBL.SaveAttributePositionForCategory(attributeID, categoryID, position); } }
protected void btnSaveAttribute_Click(object sender, EventArgs e) { eshopBE.Attribute attribute = new eshopBE.Attribute(); attribute.Name = txtName.Text; attribute.IsDescription = chkIsDescription.Checked; if (lblAttributeID.Value != string.Empty) attribute.AttributeID = int.Parse(lblAttributeID.Value); AttributeBL attributeBL = new AttributeBL(); attributeBL.SaveAttribute(attribute); Response.Redirect("/administrator/attributes.aspx"); }
protected void btnAddAttribute_Click(object sender, EventArgs e) { try { AttributeBL attributeBL = new AttributeBL(); attributeBL.SaveAttributeForCategory(int.Parse(lblCategoryID.Value), int.Parse(cmbAttribute.SelectedValue)); loadAttributes(); } catch (BLException blException) { setStatus(blException.Message, System.Drawing.Color.Red, true); } }
protected void dgvAttributes_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { AttributeBL attributeBL = new AttributeBL(); attributeBL.DeleteAttribute(int.Parse(dgvAttributes.DataKeys[e.RowIndex].Values[0].ToString())); loadAttributes(); } catch (BLException ex) { setStatus(ex.Message, System.Drawing.Color.Red, true); } }
private int addAttribute(int categoryID, string attributeName) { AttributeBL attributeBL = new AttributeBL(); eshopBE.Attribute attribute = new eshopBE.Attribute(); attribute.Name = attributeName; attribute.Filter = false; int attributeID = attributeBL.SaveAttribute(attribute); CategoryBL categoryBL = new CategoryBL(); attributeBL.SaveAttributeForCategory(categoryID, attributeID); return attributeID; }
private void loadIntoForm() { CategoryBL categoryBl = new CategoryBL(); cmbParent.DataSource = categoryBl.GetCategories(); cmbParent.DataTextField = "name"; cmbParent.DataValueField = "categoryID"; cmbParent.DataBind(); AttributeBL attributeBL = new AttributeBL(); cmbAttribute.DataSource = attributeBL.GetAllAttributes(); cmbAttribute.DataTextField = "name"; cmbAttribute.DataValueField = "attributeID"; cmbAttribute.DataBind(); cmbCriterion.Items.Add("Novi"); cmbCriterion.Items.Add("Ceni"); cmbCriterion.Items.Add("Slučajni"); txtPricePercent.Text = "0,00"; txtWebPricePercent.Text = "0,00"; cmbSlider.DataSource = new SliderBL().GetSliders(true); cmbSlider.DataTextField = "name"; cmbSlider.DataValueField = "sliderID"; cmbSlider.DataBind(); }
private void loadCategory(int categoryID) { CategoryBL categoryBL = new CategoryBL(); Category category = categoryBL.GetCategory(categoryID); txtName.Text = category.Name; txtUrl.Text = category.Url; txtImageUrl.Text = category.ImageUrl; cmbParent.SelectedValue = cmbParent.Items.FindByValue(category.ParentCategoryID.ToString()).Value; txtSortOrder.Text = category.SortOrder.ToString(); lblCategoryID.Value = category.CategoryID.ToString(); txtPricePercent.Text = category.PricePercent.ToString(); txtWebPricePercent.Text = category.WebPricePercent.ToString(); chkShowOnFirstPage.Checked = category.ShowOnFirstPage; txtNumber.Text = category.NumberOfProducts.ToString(); txtSortOrderFirstPage.Text = category.firstPageSortOrder.ToString(); if (category.firstPageOrderBy != string.Empty && category.firstPageOrderBy != null) cmbCriterion.SelectedValue = cmbCriterion.Items.FindByText(category.firstPageOrderBy).Value; setFirstPageControls(category.ShowOnFirstPage); Page.Title = category.Name + " | Admin panel"; ViewState.Add("pageTitle", Page.Title); txtDescription.Text = category.Description; chkActive.Checked = category.Active; if(category.Slider != null) { cmbSlider.SelectedValue = category.Slider.SliderID.ToString(); } if (lblCategoryID.Value != string.Empty) { AttributeBL attributeBL = new AttributeBL(); dgvAttributes.DataSource = attributeBL.GetAttributesForCategory(categoryID); dgvAttributes.DataBind(); } }
private void loadAttributes() { AttributeBL attributeBL = new AttributeBL(); dgvAttributes.DataSource = attributeBL.GetAttributesForCategory(int.Parse(lblCategoryID.Value)); dgvAttributes.DataBind(); }
private void createControls() { AttributeBL attributeBL = new AttributeBL(); List<eshopBE.Attribute> attributes = attributeBL.GetAttributesForCategory(int.Parse(cmbCategory.SelectedValue)); pnlAttributes.Controls.Add(new LiteralControl("<br />")); pnlAttributes.Controls.Clear(); int count = 1; if (attributes != null) { foreach (eshopBE.Attribute attribute in attributes) { pnlAttributes.Controls.Add(new LiteralControl("<div class='form-group'>")); pnlAttributes.Controls.Add(new LiteralControl("<label for='cmbAttribute" + (count++).ToString() + "'>")); Literal name = new Literal(); name.Text = attribute.Name + ": "; pnlAttributes.Controls.Add(name); name = new Literal(); name.Text = attribute.AttributeID.ToString(); name.Visible = false; pnlAttributes.Controls.Add(name); pnlAttributes.Controls.Add(new LiteralControl("</label>")); /*DropDownList dropDownAttribute = new DropDownList(); dropDownAttribute.ID = "cmbAttribute" + (count++).ToString(); dropDownAttribute.DataSource = attributeBL.GetAttributeValues(attribute.AttributeID); dropDownAttribute.DataTextField = "value"; dropDownAttribute.DataValueField = "attributeValueID"; dropDownAttribute.DataBind(); dropDownAttribute.EnableViewState = true; pnlAttributes.Controls.Add(dropDownAttribute);*/ //attribute user control //UserControl attributeControl = (UserControl)Page.LoadControl("customControls/AttributeControl.ascx"); Control ac = new Control(); ac = LoadControl("customControls/AttributeControl.ascx"); ac.ID = "cmbAttribute" + (count++).ToString(); ((customControls.AttributeControl)ac).AttributeID = attribute.AttributeID; pnlAttributes.Controls.Add(ac); pnlAttributes.Controls.Add(new LiteralControl("</div><!--form-group-->")); } } Session.Add("dropDownCount", count - 1); }
private void loadAttribute(int attributeID) { AttributeBL attributeBL = new AttributeBL(); eshopBE.Attribute attribute = attributeBL.GetAttribute(attributeID); txtName.Text = attribute.Name; lblAttributeID.Value = attribute.AttributeID.ToString(); Page.Title = attribute.Name + " | Admin panel"; chkIsDescription.Checked = attribute.IsDescription; loadValues(); }
private void loadAttributes() { AttributeBL attributeBL = new AttributeBL(); dgvAttributes.DataSource = (cmbCategory.SelectedIndex > 0) ? attributeBL.GetAttributesForCategory(int.Parse(cmbCategory.SelectedValue)) : attributeBL.GetAllAttributes(); dgvAttributes.DataBind(); }
private void loadValues() { AttributeBL attributeBL = new AttributeBL(); dgvAttributeValues.DataSource = attributeBL.GetAttributeValues(int.Parse(lblAttributeID.Value)); dgvAttributeValues.DataBind(); }
private int getAttributeKimtecValue(int attributeID, string value) { DataTable attributeValuesForKimtec = new AttributeDL().GetAttributeValuesForKimtec(attributeID); int attributeValueID = 0; bool exists = false; if (attributeValuesForKimtec != null) { for (int i = 0; i < attributeValuesForKimtec.Rows.Count; i++) { if (attributeValuesForKimtec.Rows[i]["kimtecValue"].ToString().Equals(value) || attributeValuesForKimtec.Rows[i]["value"].ToString().Equals(value)) { attributeValueID = int.Parse(attributeValuesForKimtec.Rows[i]["attributeValueID"].ToString()); exists = true; break; } } if (!exists) { attributeValueID = new AttributeBL().SaveAttributeValue(new AttributeValue(-1, value, attributeID, 0, string.Empty, 0), true); } } return attributeValueID; }
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; }
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; }