示例#1
0
        public void ProcessRequest(HttpContext context)
        {
            System.Web.HttpRequest  Request  = context.Request;
            System.Web.HttpResponse Response = context.Response;



            int itemId = -1, qty = 1;

            if (Request.Form["ItemId"] != null)
            {
                try
                {
                    itemId = Int32.Parse(Request.Form["ItemId"]);
                }
                catch
                {
                }
            }
            else
            {
                if (Request.QueryString["ItemId"] != null)
                {
                    try
                    {
                        itemId = Int32.Parse(Request.QueryString["ItemId"]);
                    }
                    catch
                    {
                    }
                }
            }
            if (Request.Form["QTY"] != null)
            {
                try
                {
                    qty = Int32.Parse(Request.Form["QTY"]);
                }
                catch
                {
                }
            }
            else
            {
                if (Request.QueryString["QTY"] != null)
                {
                    try
                    {
                        qty = Int32.Parse(Request.QueryString["QTY"]);
                    }
                    catch
                    {
                    }
                }
            }



            lw.ShoppingCart.ShoppingCart sCart = new lw.ShoppingCart.ShoppingCart();
            sCart.Empty();
            string optionsKey = Request["Options"];

            optionsKey = String.IsNullOrEmpty(optionsKey)? "": optionsKey;

            ChoicesMgr cMgr = new ChoicesMgr();

            if (optionsKey == "")
            {
                DataTable dt = cMgr.GetItemOptions(itemId);
                if (dt.Rows.Count > 0)
                {
                    Config   cfg  = new Config();
                    ItemsMgr iMgr = new ItemsMgr();
                    DataRow  item = iMgr.GetItem(itemId);
                    string   ProductDetailsFolder = cfg.GetKey("ProductDetailsFolder");
                    string   red = string.Format("{2}/{1}/{0}.aspx",
                                                 item["UniqueName"],
                                                 ProductDetailsFolder,
                                                 WebContext.Root
                                                 );
                    Response.Redirect(red + "?err=" + lw.CTE.Errors.SelectItemOptions);
                }
            }

            sCart.AddItem(itemId, qty, optionsKey, "", "");
            Response.Redirect(WebContext.Root + "/shopping-cart/");
        }
示例#2
0
        public override void DataBind()
        {
            if (this._bound)
            {
                return;
            }
            _bound = true;

            object obj = DataBinder.Eval(this.NamingContainer, "DataItem.ItemId");

            if (obj != null && obj.ToString() != "")
            {
                _itemId = (int)obj;
            }


            ItemsMgr pMgr = new ItemsMgr();

            DataTable dt   = null;
            string    _key = "ItemParents" + _itemId.ToString();

            if (thisPage.PageContext[_key] != null)
            {
                dt = (DataTable)thisPage.PageContext[_key];
            }
            else
            {
                DataTable cats = pMgr.GetItemParents(_itemId);

                dt = pMgr.GetItems((int)cats.Rows[0]["CategoryId"]);

                thisPage.PageContext["ItemPrices"] = dt;
            }


            DataView dv = new DataView(dt, "", "ItemId ASC", DataViewRowState.CurrentRows);

            bool isNext = false;

            DataRow Item = null;

            foreach (DataRowView drv in dv)
            {
                if (isNext)
                {
                    _itemId = (int)drv["ItemId"];
                    Item    = pMgr.GetItem(_itemId);
                    break;
                }
                if ((int)drv["ItemId"] == _itemId)
                {
                    isNext = true;
                }
            }

            if (Item == null)
            {
                this.Visible = false;
                return;
            }


            object title = Item["Title"];
            object _prop = null;

            if (!StringUtils.IsNullOrWhiteSpace(Property))
            {
                _prop = Item[Property];
            }

            switch (Type)
            {
            case LinkType.Image:
                object image;
                if (ThumbImage)
                {
                    image = Item["ThumbImage"];
                }
                else
                {
                    image = Item["Image" + imageNumber.ToString()];
                }

                ItemImage img = new ItemImage(image, title, width, height);
                img.Type      = ImageType;
                img.FillColor = FillColor;
                this.Controls.Add(img);
                break;

            case LinkType.Title:
                if (StringUtils.IsNullOrWhiteSpace(Property))
                {
                    this.InnerHtml = title.ToString();
                }
                else
                {
                    this.InnerHtml = _prop.ToString();
                }
                break;

            default:
                this.InnerHtml = _innerText;
                break;
            }

            Config cfg = new Config();

            this.HRef = string.Format("{2}/{1}/{0}",
                                      Item["UniqueName"],
                                      path,
                                      WebContext.Root
                                      );

            base.DataBind();
        }
示例#3
0
        public void ItemOptions(int ItemId, HttpRequest req)
        {
            Choices.ItemChoicesOptionsDataTable options = GetOptions();

            ItemsMgr iMgr   = new ItemsMgr();
            DataRow  item   = iMgr.GetItem(ItemId);
            string   folder = Path.Combine(WebContext.Server.MapPath(WebContext.Root + "/" + lw.CTE.Folders.ProductsImages), item["UniqueName"].ToString());

            folder = Path.Combine(folder, "Choices");

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            Config cfg = new Config();

            Dimension ThumbSize  = new Dimension(cfg.GetKey(Settings.ProductImage_ThumbSize));
            Dimension MediumSize = new Dimension(cfg.GetKey(Settings.ProductImage_MediumSize));
            Dimension LargeSize  = new Dimension(cfg.GetKey(Settings.ProductImage_LargeSize));

            foreach (DataRow option in options.Rows)
            {
                if (!String.IsNullOrWhiteSpace(req.Form[string.Format("o_{0}", option["OptionId"])]))
                {
                    string sql = string.Format(@"
if not exists (select * from ItemOptions where OptionId={1} and ItemId={0})
	Insert into ItemOptions (ItemId, OptionId, DisplayOnSite, Picture, SKU) values 
						({0}, {1}, {2}, '', '{3}') else 
	update ItemOptions set SKU='{3}',DisplayOnSite={2}  where ItemId={0} and OptionId={1};select * from ItemOptions where ItemId={0} and OptionId={1};
;",
                                               ItemId,
                                               option["OptionId"],
                                               !String.IsNullOrWhiteSpace(req[string.Format("display_o_{0}", option["OptionId"])])? 1: 0,
                                               StringUtils.SQLEncode(req[string.Format("sku_o_{0}", option["OptionId"])]));

                    DataRow optionRow = DBUtils.GetDataSet(sql, cte.lib).Tables[0].Rows[0];


                    bool   deleteOldPicture = !String.IsNullOrWhiteSpace(req[string.Format("delete_o_{0}", option["OptionId"])]);
                    string picture          = optionRow["Picture"].ToString();

                    HttpPostedFile pictureFile = req.Files[string.Format("picture_o_{0}", option["OptionId"])];

                    if (deleteOldPicture || pictureFile.ContentLength > 0)
                    {
                        string temp = Path.Combine(folder, picture).ToLower();
                        if (File.Exists(temp))
                        {
                            File.Delete(temp);
                        }
                        temp = temp.Replace(".jpg", "_m.jpg");
                        if (File.Exists(temp))
                        {
                            File.Delete(temp);
                        }

                        temp = temp.Replace("_m.jpg", "_s.jpg");
                        if (File.Exists(temp))
                        {
                            File.Delete(temp);
                        }
                    }



                    if (pictureFile.ContentLength > 0)
                    {
                        picture = StringUtils.ToURL(option["value"].ToString() + "_" + (new Random().Next(9999999)).ToString()) + ".Jpg";


                        deleteOldPicture = false;

                        string temp = Path.Combine(folder, picture).ToLower();
                        pictureFile.SaveAs(temp);

                        string large = temp;
                        temp = temp.Replace(".jpg", "_m.jpg");

                        if (MediumSize.Valid)
                        {
                            lw.GraphicUtils.ImageUtils.Resize(large, temp, MediumSize.IntWidth, MediumSize.IntHeight);
                        }
                        else
                        {
                            File.Copy(large, temp, true);
                        }

                        temp = temp.Replace("_m.jpg", "_s.jpg");
                        if (ThumbSize.Valid)
                        {
                            lw.GraphicUtils.ImageUtils.CreateThumb(large, temp, ThumbSize.IntWidth, ThumbSize.IntHeight, true);
                        }
                        else
                        {
                            File.Copy(large, temp, true);
                        }

                        if (LargeSize.Valid)
                        {
                            lw.GraphicUtils.ImageUtils.Resize(large, large, LargeSize.IntWidth, LargeSize.IntHeight);
                        }

                        sql = string.Format("Update ItemOptions set Picture = '{2}' where ItemId={0} and OptionId={1}",
                                            ItemId, option["OptionId"], StringUtils.SQLEncode(picture));

                        DBUtils.ExecuteQuery(sql, cte.lib);
                    }

                    if (deleteOldPicture)
                    {
                        sql = string.Format("Update ItemOptions set Picture = '' where ItemId={0} and OptionId={1}",
                                            ItemId, option["OptionId"]);

                        DBUtils.ExecuteQuery(sql, cte.lib);
                    }
                }
            }
            CreateInvntoryRecords(ItemId);
        }
示例#4
0
        public void AddItem(int ItemId, decimal qty, string optionsKey, string priceOption, string category)
        {
            ItemsMgr itemsMgr = new ItemsMgr();


            DataRow item        = itemsMgr.GetItem(ItemId);
            string  description = "";

            if (!String.IsNullOrWhiteSpace(optionsKey))
            {
                ChoicesMgr cMgr    = new ChoicesMgr();
                DataTable  options = cMgr.GetItemOptionInventory(ItemId, optionsKey);
                if (options.Rows.Count > 0)
                {
                    description = options.Rows[0]["OptionNames"].ToString();
                }
            }

            UserStatus memberStatus = UserStatus.Enabled;

            //if (lw.Security.User.LoggedIn)
            //	memberStatus = lw.Members.MembersManager.GetUserStatus(lw.Security.User.LoggedInUser);


            decimal price = 0, salePrice = 0, resellerPrice = 0;

            if (lw.Products.Tools.CheckStatus(ItemStatus.ForSale, item))
            {
                if (String.IsNullOrWhiteSpace(priceOption))
                {
                    if (item["Price"] != System.DBNull.Value)
                    {
                        price = (decimal)item["Price"];
                    }

                    if (item["SalePrice"] != System.DBNull.Value)
                    {
                        salePrice = (decimal)item["SalePrice"];
                    }

                    if (item["ResellerPrice"] != System.DBNull.Value)
                    {
                        resellerPrice = (decimal)item["ResellerPrice"];
                    }
                }
                else
                {
                    ItemPricesAdp itemPricesAdp = new ItemPricesAdp();
                    DataRow       priceRow      = itemPricesAdp.GetItemPrice(ItemId, priceOption);

                    if (priceRow["Price"] != System.DBNull.Value)
                    {
                        price = (decimal)priceRow["Price"];
                    }

                    if (priceRow["SalePrice"] != System.DBNull.Value)
                    {
                        salePrice = (decimal)priceRow["SalePrice"];
                    }

                    if (priceRow["ResellerPrice"] != System.DBNull.Value)
                    {
                        resellerPrice = (decimal)priceRow["ResellerPrice"];
                    }
                }
                if (Tools.CheckStatus(ItemStatus.OnSale, item))
                {
                    price = salePrice > 0 ? salePrice : price;
                }
                else
                {
                    switch (memberStatus)
                    {
                    case UserStatus.Reseller:
                        price = resellerPrice > 0 ? resellerPrice : price;
                        break;

                    default:
                        break;
                    }
                }
            }

            DataRow[] rows = this.ShoppingItems.BasketItems.Select(string.Format("ItemId={0} and OptionsKey='{1}' and PriceFor='{2}'",
                                                                                 ItemId,
                                                                                 StringUtils.SQLEncode(optionsKey),
                                                                                 StringUtils.SQLEncode(priceOption)
                                                                                 ));
            if (rows.Length > 0)
            {
                rows[0]["Quantity"] = (decimal)rows[0]["Quantity"] + qty;
            }
            else
            {
                DataRow row = ShoppingItems.BasketItems.NewRow();

                decimal weight = 0;
                if (item["ShippingWeight"] != DBNull.Value)
                {
                    weight = decimal.Parse(item["ShippingWeight"].ToString());
                }

                if (item["ShippingVWeight"] != DBNull.Value)
                {
                    weight = Math.Max(weight, decimal.Parse(item["ShippingVWeight"].ToString()));
                }


                row["Weight"] = weight;

                row["ItemId"]      = ItemId;
                row["Title"]       = item["Title"].ToString();
                row["ItemNumber"]  = item["ProductNumber"].ToString();
                row["Quantity"]    = qty;
                row["UnitPrice"]   = price;
                row["Discount"]    = 0;
                row["UniqueName"]  = item["UniqueName"].ToString();
                row["OptionsKey"]  = optionsKey;
                row["Description"] = description;
                row["Tax"]         = 0;

                row["UniqueName"] = item["UniqueName"].ToString();
                row["PriceFor"]   = priceOption;
                row["Category"]   = category;

                this.ShoppingItems.BasketItems.Rows.Add(row);

                this.ShoppingItems.BasketItems.AcceptChanges();
            }
            this.AdjustTotals(true);
        }