コード例 #1
0
        protected void chkActive_CheckChanged(object sender, EventArgs e)
        {
            CheckBox chkActive = (CheckBox)sender;
            GridViewRow row = (GridViewRow)chkActive.NamingContainer;

            ProductBL productBL = new ProductBL();
            productBL.SetActive(int.Parse(((Label)row.FindControl("lblProductID")).Text), bool.Parse(((CheckBox)row.FindControl("chkActive")).Checked.ToString()));
        }
コード例 #2
0
 protected void btnApproveAll_Click(object sender, EventArgs e)
 {
     ProductBL productBL=new ProductBL();
     for (int i = 0; i < dgvProducts.Rows.Count; i++)
     {
         if (((CheckBox)dgvProducts.Rows[i].FindControl("chkSelect")).Checked)
             productBL.SetApproved(int.Parse(((Label)dgvProducts.Rows[i].FindControl("lblProductID")).Text), true);
     }
 }
コード例 #3
0
        protected void chkApproved_CheckChanged(object sender, EventArgs e)
        {
            CheckBox chkApproved = (CheckBox)sender;
            GridViewRow row = (GridViewRow)chkApproved.NamingContainer;

            ProductBL productBL = new ProductBL();
            if (productBL.SetApproved(int.Parse(((Label)row.FindControl("lblProductID")).Text), bool.Parse(((CheckBox)row.FindControl("chkApproved")).Checked.ToString())) > 0)
            {
                setStatus("Proizvod uspešno izmenjen", System.Drawing.Color.Green, true);
            }
        }
コード例 #4
0
        protected void btnImageUpload_Click(object sender, EventArgs e)
        {
            if (fluImage.HasFile)
            {
                int imageID = new ProductBL().GetMaxImageID() + (ViewState["images"] != null ? ((List<string>)ViewState["images"]).Count : 0);
                string directory = createImageUrl(imageID);
                if (!System.IO.Directory.Exists(Server.MapPath("~") + directory))
                    System.IO.Directory.CreateDirectory(Server.MapPath("~") + directory);
                //fluImage.SaveAs(Server.MapPath("~") + "/images/" + fluImage.FileName);
                fluImage.SaveAs(Server.MapPath("~") + directory + imageID.ToString() + ".jpg");
                //System.Drawing.Image original = System.Drawing.Image.FromFile(Server.MapPath("~") + "/images/" + fluImage.FileName);
                System.Drawing.Image original = System.Drawing.Image.FromFile(Server.MapPath("~") + directory + imageID.ToString() + ".jpg");
                int x = original.Width;
                int y = original.Height;

                string path=Server.MapPath("~")+"/images/";
                //System.Drawing.Image thumb = original.GetThumbnailImage(290, (int)((290*y)/x), null, IntPtr.Zero);
                System.Drawing.Image thumb = Common.CreateThumb(original, 290, 220);
                //thumb.Save(path + fluImage.FileName.Substring(0, fluImage.FileName.IndexOf(".jpg")) + "-main.jpg");
                //thumb.Save(path + fluImage.FileName.Substring(0, fluImage.FileName.IndexOf(".jpg")) + "-large.jpg");
                thumb.Save(Server.MapPath("~") + directory + imageID.ToString() + "-large.jpg");

                //thumb = original.GetThumbnailImage(110, (int)((75*y)/x), null, IntPtr.Zero);
                thumb = Common.CreateThumb(original, 160, 120);
                //thumb.Save(path + fluImage.FileName.Substring(0, fluImage.FileName.IndexOf(".jpg")) + "-list.jpg");
                //thumb.Save(path + fluImage.FileName.Substring(0, fluImage.FileName.IndexOf(".jpg")) + "-home.jpg");
                thumb.Save(Server.MapPath("~") + directory + imageID.ToString() + "-home.jpg");

                //thumb = original.GetThumbnailImage(30, (int)((10*y)/x), null, IntPtr.Zero);
                thumb = Common.CreateThumb(original, 70, 52);
                //thumb.Save(path + fluImage.FileName.Substring(0, fluImage.FileName.IndexOf(".jpg")) + "-thumb.jpg");
                //thumb.Save(Server.MapPath("~") + directory + imageID.ToString() + "-thumb.jpg");
                thumb.Save(Server.MapPath("~") + directory + imageID.ToString() + "-small.jpg");

                original.Dispose();

                List<string> images;
                if (ViewState["images"] != null)
                    images = (List<string>)ViewState["images"];
                else
                    images = new List<string>();

                images.Add(directory + imageID.ToString() + ".jpg");

                ViewState.Add("images",images);

                loadImages();
            }
        }
コード例 #5
0
ファイル: Default.aspx.cs プロジェクト: yoorke/pinshop
 protected void rptPromotions_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         //Repeater rptProducts = (Repeater)e.Item.FindControl("rptProducts");
        user_controls.product_slider productSlider = (user_controls.product_slider)e.Item.FindControl("productSlider1");
         ProductBL productBL = new ProductBL();
         productSlider.NumberOfProducts = 4;
         productSlider.Products = productBL.GetProductsForPromotion(int.Parse(((HiddenField)e.Item.FindControl("lblPromotionID")).Value));
         //((HtmlControl)productSlider.FindControl("carouselexample")).Attributes["id"] = "carousel" + ((HiddenField)e.Item.FindControl("lblPromotionID")).Value;
         ((Literal)productSlider.FindControl("lblPrev")).Text = @"<a id=""prev"" runat=""server"" href=" + "#carousel" + ((HiddenField)e.Item.FindControl("lblPromotionID")).Value + @" data-slide=""prev""><img src=" + Page.ResolveUrl("~/images/prev_next.gif") + @" alt=""Prethodni"" /></a>";
         ((Literal)productSlider.FindControl("lblNext")).Text = @"<a id=""next"" runat=""server"" href=" + "#carousel" + ((HiddenField)e.Item.FindControl("lblPromotionID")).Value + @" data-slide=""next"" class=""next_button""><img src=" + Page.ResolveUrl("~/images/prev_next.gif") + @" alt=""Sledeći"" /></a>";
         ((Literal)productSlider.FindControl("lblCarousel")).Text = @"<div id=" + "carousel" + ((HiddenField)e.Item.FindControl("lblPromotionID")).Value + @" class=""carousel slide"" data-ride="""" runat=""server"">";
         //rptProducts.DataSource = productBL.GetProductsForPromotion(int.Parse(((HiddenField)e.Item.FindControl("lblPromotionID")).Value));
         //rptProducts.DataBind();
     }
 }
コード例 #6
0
ファイル: CartBL.cs プロジェクト: yoorke/pinshop
        public void ApplyCoupon(string cartID)
        {
            Coupon coupon = new CouponBL().GetCoupon(GetCartCoupon(cartID));
            if (coupon != null)
            {
                DataTable cart = GetProducts(cartID);
                if (coupon.Objects != null && coupon.Objects.Count > 0)
                {
                    for (int i = 0; i < cart.Rows.Count; i++)
                    {
                        Product product = new ProductBL().GetProduct(int.Parse(cart.Rows[i]["productID"].ToString()), string.Empty, false);
                        bool[] couponObjectStatus = new bool[coupon.Objects.Count];
                        for (int j = 0; j < coupon.Objects.Count; j++)
                        {
                            //category
                            if (coupon.Objects[j].ObjectTypeID == 1)
                            {
                                List<Category> categories = new CategoryBL().GetAllSubCategories(coupon.Objects[j].ObjectID);
                                foreach(Category category in categories)
                                    if(category.CategoryID == product.Categories[0].CategoryID)
                                    {
                                        couponObjectStatus[j] = true;
                                        break;
                                    }
                            }
                            //brand
                            if (coupon.Objects[j].ObjectTypeID == 2 && product.Brand.BrandID == coupon.Objects[j].ObjectID)
                                couponObjectStatus[j] = true;
                            //product
                            if (coupon.Objects[j].ObjectTypeID == 3 && product.ProductID == coupon.Objects[j].ObjectID)
                                couponObjectStatus[j] = true;
                        }
                        bool status = true;
                        foreach (bool objectStatus in couponObjectStatus)
                            status = status && objectStatus;

                        if (status)
                        {
                            double productPrice = double.Parse(cart.Rows[i]["productPrice"].ToString());
                            double discountPrice = coupon.CouponType.CouponTypeID == 1 ? productPrice * (1 - coupon.Discount / 100) : productPrice - coupon.Discount;
                            UpdateCartProduct(cartID, product.ProductID, double.Parse(cart.Rows[i]["quantity"].ToString()), double.Parse(cart.Rows[i]["productPrice"].ToString()), discountPrice, coupon.CouponID);
                        }
                    }
                }
            }
        }
コード例 #7
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;
        }
コード例 #8
0
 public static string SaveProductFromExternalApplication(string barcode, string name, string quantity, string price)
 {
     bool status = new ProductBL().SaveProductFromExternalApplication(barcode, name, double.Parse(quantity), double.Parse(price));
     return status ? "Saved" : "Error";
 }
コード例 #9
0
        private void loadProducts()
        {
            int categoryID = -1;
            if (cmbCategory.SelectedIndex > 0)
                categoryID = int.Parse(cmbCategory.SelectedValue);

            int supplierID = -1;
            if (cmbSupplier.SelectedIndex > 0)
                supplierID = int.Parse(cmbSupplier.SelectedValue);

            int? brandID = null;
            if (cmbBrand.SelectedIndex > 1)
                brandID = int.Parse(cmbBrand.SelectedValue);

            ProductBL productsBL = new ProductBL();

            List<Product> products = productsBL.GetProducts(categoryID, supplierID, cmbApproved.SelectedItem.Text, cmbActive.SelectedItem.Text, brandID);

            if (txtSearch.Text.Length > 0)
            {
                var productsList = (from product in products
                                    where product.Name.ToLower().Contains(txtSearch.Text.ToLower())
                                    select product);

                dgvProducts.DataSource = productsList.ToList();
                lblProductsCount.Text = productsList.Count().ToString();
            }
            else
            {
                dgvProducts.DataSource = products;
                lblProductsCount.Text = products != null ? products.Count.ToString() : "0";
            }
            dgvProducts.DataBind();
        }
コード例 #10
0
        protected void dgvProducts_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            ProductBL productBL = new ProductBL();
            productBL.DeleteProduct(int.Parse(dgvProducts.DataKeys[e.RowIndex].Values[0].ToString()));

            Page.Response.Redirect("/administrator/products.aspx");
        }
コード例 #11
0
        private void loadPrices()
        {
            cmbPriceFrom.Items.Add("-");
            cmbPriceTo.Items.Add("-");

            double[] prices = new ProductBL().GetMinMaxPrice(ViewState["category"].ToString());

            for (int i = (int)prices[0]; i < (int)prices[1]; i += (int)(prices[1] - prices[0]) / 10)
            {
                cmbPriceFrom.Items.Add(string.Format("{0:N2}", i));
                cmbPriceTo.Items.Add(string.Format("{0:N2}", i));
            }
        }
コード例 #12
0
        private void createQueryString()
        {
            List<string> brands = new List<string>();
            List<AttributeValue> attributes = new System.Collections.Generic.List<AttributeValue>();
            int attributeID = 0;

            foreach (ListItem value in chkBrands.Items)
                if (value.Selected)
                    brands.Add(value.Value);

            foreach(RepeaterItem repeaterItem in rptFilter.Items)
                foreach (Control control in repeaterItem.Controls)
                {
                    if (control is HiddenField)
                        attributeID = int.Parse(((HiddenField)control).Value);
                    if (control is CheckBoxList)
                        foreach (ListItem value in ((CheckBoxList)control).Items)
                            if (value.Selected)
                                attributes.Add(new AttributeValue(int.Parse(value.Value), value.Text, attributeID, 0, string.Empty, 0));
                }

            List<Product> products = new ProductBL().GetProducts(ViewState["categoryUrl"].ToString(), brands, attributes, sort, cmbPriceFrom.SelectedItem.Text, cmbPriceTo.SelectedItem.Text);

            PagedDataSource pagedDataSource = new PagedDataSource();
            pagedDataSource.DataSource = products;
            pagedDataSource.AllowPaging = true;
            pagedDataSource.PageSize = pageSize;
            //if (currentPage >= pagedDataSource.PageCount)
                //currentPage = pagedDataSource.PageCount - 1;
            //if (currentPage < 0)
                //currentPage = 0;
            pagedDataSource.CurrentPageIndex = currentPage;
            ViewState["totalPages"] = pagedDataSource.PageCount;

            if (products != null)
            {
                pgrPager.TotalPages = int.Parse(ViewState["totalPages"].ToString());
                pgrPager.currentPage = this.currentPage;
                pgrPager.doPaging();
                pgrPager1.TotalPages = int.Parse(ViewState["totalPages"].ToString());
                pgrPager1.currentPage = this.currentPage;
                pgrPager1.doPaging();

                rptProducts.DataSource = pagedDataSource;
                rptProducts.DataBind();
            }
            else
            {
                rptProducts.DataSource = null;
                rptProducts.DataSourceID = null;
                rptProducts.DataBind();
                divStatus.Visible = true;
            }
        }
コード例 #13
0
        private void loadProduct(int productID)
        {
            ProductBL productBL = new ProductBL();
            Product product = productBL.GetProduct(productID, string.Empty);

            //images = product.Images;
            priProductImages.Images = product.Images;
            priProductImages.ShowImages();

            lblBrand.Text = product.Brand.Name;
            lblName.Text = product.Name;
            lblDescription.Text = product.Description;
            lblPrice.Text = "MP cena: " + string.Format("{0:N2}", product.Price) + " din";
            lblWebPrice.Text = string.Format("{0:N2}", product.WebPrice) + " din";
            lblSaving.Text = "Ušteda: " + string.Format("{0:N2}", product.Price - product.WebPrice) + " din";
            lblSpecification.Text = !product.Specification.Contains("<table class='table table-striped'><tbody></table>") ? product.Specification : "Nema podataka";
            lblDescription.Text = product.Description;
            if (product.Promotion != null)
            {
                imgPromotion.ImageUrl = "/images/" + product.Promotion.ImageUrl;
                imgPromotion.Visible = true;
            }
            lblProductID.Value = product.ProductID.ToString();
            Page.Title = product.Brand.Name + " " + product.Name;
            ViewState.Add("pageTitle", Page.Title);
            ViewState.Add("productDescription", product.Description);
            ViewState.Add("image", product.Images[0]);
        }
コード例 #14
0
        private void loadProduct(int productID)
        {
            ProductBL productBL = new ProductBL();
            Product product = productBL.GetProduct(productID, string.Empty, false);

            lblProductID.Value = product.ProductID.ToString();
            txtCode.Text = product.Code;
            txtSupplierCode.Text = product.SupplierCode;
            txtName.Text = product.Name;
            cmbBrand.SelectedValue = cmbBrand.Items.FindByValue(product.Brand.BrandID.ToString()).Value;
            txtDescription.Text = product.Description;
            txtPrice.Text = string.Format("{0:N2}", product.Price);
            txtWebPrice.Text = string.Format("{0:N2}", product.WebPrice);
            txtInsertDate.Text = product.InsertDate.ToString();
            txtUpdateDate.Text = product.UpdateDate.ToString();
            cmbVat.SelectedValue = cmbVat.Items.FindByValue(product.VatID.ToString()).Value;
            cmbSupplier.SelectedValue = cmbSupplier.Items.FindByValue(product.SupplierID.ToString()).Value;
            chkApproved.Checked = product.IsApproved;
            chkActive.Checked = product.IsActive;
            chkLocked.Checked = product.IsLocked;
            chkInStock.Checked = product.IsInStock;
            txtEan.Text = product.Ean;
            txtSpecification.Text = product.Specification;
            Page.Title = product.Name + " | Admin panel";
            ViewState.Add("pageTitle", Page.Title);

            if (product.Promotion != null)
            {
                cmbPromotions.SelectedValue = cmbPromotions.Items.FindByValue(product.Promotion.PromotionID.ToString()).Value;
                txtPromotionPrice.Text = product.Promotion.Price.ToString();
            }

            if (product.Categories != null)
            {
                cmbCategory.SelectedValue = cmbCategory.Items.FindByValue(product.Categories[0].CategoryID.ToString()).Value;
                createControls();
                int i = 0;
                if (product.Attributes != null)
                {
                    int attributeID = -1;
                    foreach (object control in pnlAttributes.Controls)
                    {
                        if (control is Literal)
                        {
                            int.TryParse(((Literal)control).Text, out attributeID);
                        }
                        if (control is customControls.AttributeControl)
                        {
                            int index;
                            if ((index = hasAttribute(product.Attributes, attributeID)) > -1)
                                ((customControls.AttributeControl)control).AttributeValueID = product.Attributes[index].AttributeValueID;
                            else
                                ((customControls.AttributeControl)control).AttributeValue = "NP";
                        }
                    }
                }
            }

            if (product.Images != null)
            {
                ViewState.Add("images", product.Images);
                loadImages();

                string imageUrl = product.Images[0].Substring(0, product.Images[0].IndexOf(".jpg"));
                imgProduct.ImageUrl = createImageUrl(imageUrl, "");
                imgHome.ImageUrl = createImageUrl(imageUrl, "home");
                imgLarge.ImageUrl = createImageUrl(imageUrl, "large");
                imgThumb.ImageUrl = createImageUrl(imageUrl, "thumb");
            }
            /*rptImages.DataSource = product.Images;
            rptImages.DataBind();*/
        }
コード例 #15
0
        private void searchProducts()
        {
            string searchString = ViewState["searchString"].ToString();
            List<Product> products = new ProductBL().SearchProducts(searchString, sort);
            PagedDataSource pagedDataSource = new PagedDataSource();
            pagedDataSource.DataSource = products;
            pagedDataSource.AllowPaging = true;
            pagedDataSource.PageSize = pageSize;
            pagedDataSource.CurrentPageIndex = currentPage;
            ViewState["totalPages"] = pagedDataSource.PageCount;

            if(products != null)
            {
                pager1.TotalPages = int.Parse(ViewState["totalPages"].ToString());
                pager1.currentPage = currentPage;
                pager1.doPaging();

                rptProducts.DataSource = pagedDataSource;
                rptProducts.DataBind();
            }
            else
            {
                rptProducts.DataSource = null;
                rptProducts.DataSourceID = null;
                rptProducts.DataBind();
            }
        }
コード例 #16
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;
        }
コード例 #17
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 };
        }
コード例 #18
0
        protected void chkLocked_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkIsLocked = (CheckBox)sender;
            GridViewRow gridViewRow = (GridViewRow)chkIsLocked.NamingContainer;

            ProductBL productBL = new ProductBL();
            productBL.SetLocked(int.Parse(((Label)gridViewRow.FindControl("lblProductID")).Text), bool.Parse(((CheckBox)gridViewRow.FindControl("chkLocked")).Checked.ToString()));
        }
コード例 #19
0
        private void loadProduct(int productID)
        {
            ProductBL productBL = new ProductBL();
            Product product = productBL.GetProduct(productID, string.Empty, true);

            //images = product.Images;
            priProductImages.Images = product.Images;
            priProductImages.ShowImages();

            lblBrand.Text = product.Brand.Name;
            lblName.Text = product.Name;
            lblNamePrimary.Text = product.Name;
            lblDescription.Text = product.Description;
            lblPrice.Text = "MP cena: " + string.Format("{0:N2}", product.Price) + " din";
            lblWebPrice.Text = (product.Promotion == null) ? string.Format("{0:N2}", product.WebPrice) + " din" : string.Format("{0:N2}", product.Promotion.Price) + " din";
            lblSaving.Text = "Ušteda: " + string.Format("{0:N2}", product.Price - double.Parse(lblWebPrice.Text.Substring(0, lblWebPrice.Text.IndexOf(" din")))) + " din";
            lblSpecification.Text = (product.Specification != null) ? (!product.Specification.Contains("<table class='table table-striped'><tbody></table>") ? product.Specification : "Nema podataka") : "Nema podataka";
            lblDescription.Text = product.Description;
            if (product.Promotion != null)
            {
                imgPromotion.ImageUrl = "/images/" + product.Promotion.ImageUrl;
                imgPromotion.Visible = true;
            }
            lblProductID.Value = product.ProductID.ToString();
            Page.Title = product.Brand.Name + " " + product.Name;
            ViewState.Add("pageTitle", Page.Title);
            ViewState.Add("productDescription", product.Description);
            ViewState.Add("image", product.Images != null ? product.Images[0] : string.Empty);

            lnkCategory.NavigateUrl = "/proizvodi/" + product.Categories[0].Url;
            lnkCategory.Text = product.Categories[0].Name;
            ViewState["productUrl"] = product.Url;
            loadProductSliders(product.Brand, product.Categories[0]);
        }
コード例 #20
0
        private void loadPrices(string categoryUrl, string priceFrom, string priceTo, bool includeChildrenCategories)
        {
            cmbPriceFrom.Items.Add("-");
            cmbPriceTo.Items.Add("-");

            double[] prices = new ProductBL().GetMinMaxPrice(categoryUrl, includeChildrenCategories);
            for (int i = (int)prices[0]; i < (int)prices[1]; i += (int)(prices[1] - prices[0]) / 10)
            {
                cmbPriceFrom.Items.Add(string.Format("{0:N2}", i));
                cmbPriceTo.Items.Add(string.Format("{0:N2}", i));
            }
            if (priceFrom != string.Empty)
                cmbPriceFrom.SelectedValue = priceFrom;
            if (priceTo != string.Empty)
                cmbPriceTo.SelectedValue = priceTo;
        }
コード例 #21
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;
        }