Example #1
0
        public void grdSkus_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            Grid   grid     = (Grid)sender;
            int    rowIndex = ((System.Web.UI.WebControls.GridViewRow)((System.Web.UI.Control)e.CommandSource).NamingContainer).RowIndex;
            string text     = (string)grid.DataKeys[rowIndex].Value;

            System.Web.UI.WebControls.TextBox    textBox    = (System.Web.UI.WebControls.TextBox)grid.Rows[rowIndex].Cells[1].FindControl("txtNum");
            System.Web.UI.WebControls.LinkButton linkButton = (System.Web.UI.WebControls.LinkButton)grid.Rows[rowIndex].Cells[2].FindControl("lbtnAdd");
            int quantity;

            if (int.TryParse(textBox.Text.Trim(), out quantity) && int.Parse(textBox.Text.Trim()) > 0 && !textBox.Text.Trim().Contains("."))
            {
                if (e.CommandName == "add")
                {
                    if (linkButton.Text == "添加")
                    {
                        PurchaseShoppingCartItemInfo purchaseShoppingCartItemInfo = new PurchaseShoppingCartItemInfo();
                        purchaseShoppingCartItemInfo = this.AddPurchaseShoppingCartItemInfo(text, quantity);
                        if (purchaseShoppingCartItemInfo == null)
                        {
                            this.ShowMsg("商品库存不够", false);
                            return;
                        }
                        if (SubsiteSalesHelper.AddPurchaseItem(purchaseShoppingCartItemInfo))
                        {
                            this.BindData();
                            return;
                        }
                        this.ShowMsg("添加商品失败", false);
                        return;
                    }
                    else
                    {
                        if (SubsiteSalesHelper.DeletePurchaseShoppingCartItem(text))
                        {
                            this.BindData();
                            return;
                        }
                        this.ShowMsg("删除失败", false);
                    }
                }
                return;
            }
            this.ShowMsg("数量不能为空,必需为大于零的正整数", false);
        }
        public void grdSkus_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int        num;
            Grid       grid     = (Grid)sender;
            int        rowIndex = ((GridViewRow)((Control)e.CommandSource).NamingContainer).RowIndex;
            string     skuId    = (string)grid.DataKeys[rowIndex].Value;
            TextBox    box      = (TextBox)grid.Rows[rowIndex].Cells[1].FindControl("txtNum");
            LinkButton button   = (LinkButton)grid.Rows[rowIndex].Cells[2].FindControl("lbtnAdd");

            if ((!int.TryParse(box.Text.Trim(), out num) || (int.Parse(box.Text.Trim()) <= 0)) || box.Text.Trim().Contains("."))
            {
                ShowMsg("数量不能为空,必需为大于零的正整数", false);
            }
            else if (e.CommandName == "add")
            {
                if (button.Text == "添加")
                {
                    PurchaseShoppingCartItemInfo item = new PurchaseShoppingCartItemInfo();
                    item = AddPurchaseShoppingCartItemInfo(skuId, num);
                    if (item == null)
                    {
                        ShowMsg("商品库存不够", false);
                    }
                    else if (SubsiteSalesHelper.AddPurchaseItem(item))
                    {
                        BindData();
                    }
                    else
                    {
                        ShowMsg("添加商品失败", false);
                    }
                }
                else if (SubsiteSalesHelper.DeletePurchaseShoppingCartItem(skuId))
                {
                    BindData();
                }
                else
                {
                    ShowMsg("删除失败", false);
                }
            }
        }
        private void lkbtnAdddCheck_Click(object sender, EventArgs e)
        {
            int  num  = 0;
            bool flag = true;
            Dictionary <string, int> dictionary = new Dictionary <string, int>();

            foreach (GridViewRow row in grdAuthorizeProducts.Rows)
            {
                GridView view = row.FindControl("grdSkus") as GridView;
                foreach (GridViewRow row2 in view.Rows)
                {
                    CheckBox box  = (CheckBox)row2.FindControl("checkboxCol");
                    TextBox  box2 = row2.FindControl("txtNum") as TextBox;
                    if ((box != null) && box.Checked)
                    {
                        int num2;
                        num++;
                        if ((!int.TryParse(box2.Text.Trim(), out num2) || (int.Parse(box2.Text.Trim()) <= 0)) || box2.Text.Trim().Contains("."))
                        {
                            flag = false;
                            break;
                        }
                        dictionary.Add(view.DataKeys[row2.RowIndex].Value.ToString(), num2);
                    }
                }
                if (!flag)
                {
                    break;
                }
            }
            if (num == 0)
            {
                ShowMsg("请先选择要添加的商品", false);
            }
            else if (!flag)
            {
                ShowMsg("数量不能为空,必需为大于零的正整数", false);
            }
            else
            {
                int num3 = 0;
                foreach (KeyValuePair <string, int> pair in dictionary)
                {
                    PurchaseShoppingCartItemInfo item = new PurchaseShoppingCartItemInfo();
                    item = AddPurchaseShoppingCartItemInfo(pair.Key, Convert.ToInt32(pair.Value));
                    if (item == null)
                    {
                        ShowMsg("商品库存不够", false);
                        break;
                    }
                    if (!SubsiteSalesHelper.AddPurchaseItem(item))
                    {
                        break;
                    }
                    num3++;
                }
                if (num3 > 0)
                {
                    ShowMsg(string.Format("成功添加了{0}件商品", num3), true);
                    BindData();
                }
                else
                {
                    ShowMsg("添加商品失败", false);
                }
            }
        }
Example #4
0
        private void lkbtnAdddCheck_Click(object sender, System.EventArgs e)
        {
            int  num  = 0;
            bool flag = true;

            System.Collections.Generic.Dictionary <string, int> dictionary = new System.Collections.Generic.Dictionary <string, int>();
            foreach (System.Web.UI.WebControls.GridViewRow gridViewRow in this.grdAuthorizeProducts.Rows)
            {
                System.Web.UI.WebControls.GridView gridView = gridViewRow.FindControl("grdSkus") as System.Web.UI.WebControls.GridView;
                foreach (System.Web.UI.WebControls.GridViewRow gridViewRow2 in gridView.Rows)
                {
                    System.Web.UI.WebControls.CheckBox checkBox = (System.Web.UI.WebControls.CheckBox)gridViewRow2.FindControl("checkboxCol");
                    System.Web.UI.WebControls.TextBox  textBox  = gridViewRow2.FindControl("txtNum") as System.Web.UI.WebControls.TextBox;
                    if (checkBox != null && checkBox.Checked)
                    {
                        num++;
                        int value;
                        if (!int.TryParse(textBox.Text.Trim(), out value) || int.Parse(textBox.Text.Trim()) <= 0 || textBox.Text.Trim().Contains("."))
                        {
                            flag = false;
                            break;
                        }
                        dictionary.Add(gridView.DataKeys[gridViewRow2.RowIndex].Value.ToString(), value);
                    }
                }
                if (!flag)
                {
                    break;
                }
            }
            if (num == 0)
            {
                this.ShowMsg("请先选择要添加的商品", false);
                return;
            }
            if (!flag)
            {
                this.ShowMsg("数量不能为空,必需为大于零的正整数", false);
                return;
            }
            int num2 = 0;

            foreach (System.Collections.Generic.KeyValuePair <string, int> current in dictionary)
            {
                PurchaseShoppingCartItemInfo purchaseShoppingCartItemInfo = new PurchaseShoppingCartItemInfo();
                purchaseShoppingCartItemInfo = this.AddPurchaseShoppingCartItemInfo(current.Key, System.Convert.ToInt32(current.Value));
                if (purchaseShoppingCartItemInfo == null)
                {
                    this.ShowMsg("商品库存不够", false);
                    break;
                }
                if (SubsiteSalesHelper.AddPurchaseItem(purchaseShoppingCartItemInfo))
                {
                    num2++;
                }
            }
            if (num2 > 0)
            {
                this.ShowMsg(string.Format("成功添加了{0}件商品", num2), true);
                this.BindData();
                return;
            }
            this.ShowMsg("添加商品失败", false);
        }