Beispiel #1
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;

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

            if (obj != null)
            {
                int itemId = (int)obj;

                ChoicesMgr cMgr = new ChoicesMgr();

                Choices.ItemOptionsInventoryViewDataTable options = cMgr.GetItemOptionInventory(itemId);

                if (options.Count == 0)
                {
                    this.Visible = false;
                }

                this.Items.Add(new ListItem(HeaderText, ""));

                foreach (Choices.ItemOptionsInventoryViewRow row in options)
                {
                    Items.Add(new ListItem(row.OptionNames, row.Key));
                }
            }

            base.DataBind();
        }
Beispiel #2
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);
        }