Exemple #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 skuId    = (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 num;

            if (int.TryParse(textBox.Text.Trim(), out num) && int.Parse(textBox.Text.Trim()) > 0 && !textBox.Text.Trim().Contains("."))
            {
                if (e.CommandName == "add" && linkButton.Text == "添加")
                {
                    PurchaseShoppingCartItemInfo purchaseShoppingCartItemInfo  = new PurchaseShoppingCartItemInfo();
                    System.Data.DataTable        skuContentBySkuBuDistorUserId = ProductHelper.GetSkuContentBySkuBuDistorUserId(skuId, this.distorUserId);
                    if (num > (int)skuContentBySkuBuDistorUserId.Rows[0]["Stock"])
                    {
                        this.ShowMsg("商品库存不够", false);
                        return;
                    }
                    foreach (System.Data.DataRow dataRow in skuContentBySkuBuDistorUserId.Rows)
                    {
                        if (!string.IsNullOrEmpty(dataRow["AttributeName"].ToString()) && !string.IsNullOrEmpty(dataRow["ValueStr"].ToString()))
                        {
                            PurchaseShoppingCartItemInfo expr_190 = purchaseShoppingCartItemInfo;
                            object sKUContent = expr_190.SKUContent;
                            expr_190.SKUContent = string.Concat(new object[]
                            {
                                sKUContent,
                                dataRow["AttributeName"],
                                ":",
                                dataRow["ValueStr"],
                                "; "
                            });
                        }
                    }
                    purchaseShoppingCartItemInfo.SkuId     = skuId;
                    purchaseShoppingCartItemInfo.ProductId = (int)skuContentBySkuBuDistorUserId.Rows[0]["ProductId"];
                    if (skuContentBySkuBuDistorUserId.Rows[0]["SKU"] != System.DBNull.Value)
                    {
                        purchaseShoppingCartItemInfo.SKU = (string)skuContentBySkuBuDistorUserId.Rows[0]["SKU"];
                    }
                    if (skuContentBySkuBuDistorUserId.Rows[0]["Weight"] != System.DBNull.Value)
                    {
                        purchaseShoppingCartItemInfo.ItemWeight = (decimal)skuContentBySkuBuDistorUserId.Rows[0]["Weight"];
                    }
                    purchaseShoppingCartItemInfo.ItemPurchasePrice = (decimal)skuContentBySkuBuDistorUserId.Rows[0]["PurchasePrice"];
                    purchaseShoppingCartItemInfo.Quantity          = num;
                    purchaseShoppingCartItemInfo.ItemListPrice     = (decimal)skuContentBySkuBuDistorUserId.Rows[0]["SalePrice"];
                    purchaseShoppingCartItemInfo.ItemDescription   = (string)skuContentBySkuBuDistorUserId.Rows[0]["ProductName"];
                    if (skuContentBySkuBuDistorUserId.Rows[0]["CostPrice"] != System.DBNull.Value)
                    {
                        purchaseShoppingCartItemInfo.CostPrice = (decimal)skuContentBySkuBuDistorUserId.Rows[0]["CostPrice"];
                    }
                    if (skuContentBySkuBuDistorUserId.Rows[0]["ThumbnailUrl40"] != System.DBNull.Value)
                    {
                        purchaseShoppingCartItemInfo.ThumbnailsUrl = (string)skuContentBySkuBuDistorUserId.Rows[0]["ThumbnailUrl40"];
                    }
                    if (SalesHelper.AddPurchaseOrderItem(purchaseShoppingCartItemInfo, this.purchaseOrderId))
                    {
                        this.UpdatePurchaseOrder();
                        this.BindOrderItems();
                        this.ReBindData(true, false);
                        this.ShowMsg("添加规格商品成功", true);
                        return;
                    }
                    this.ShowMsg("添加规格商品失败", false);
                }
                return;
            }
            this.ShowMsg("数量不能为空,必需为大于零的正整数", false);
        }
Exemple #2
0
        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") && (button.Text == "添加"))
            {
                PurchaseShoppingCartItemInfo item       = new PurchaseShoppingCartItemInfo();
                DataTable skuContentBySkuBuDistorUserId = ProductHelper.GetSkuContentBySkuBuDistorUserId(skuId, distorUserId);
                if (num > ((int)skuContentBySkuBuDistorUserId.Rows[0]["Stock"]))
                {
                    ShowMsg("商品库存不够", false);
                }
                else
                {
                    foreach (DataRow row in skuContentBySkuBuDistorUserId.Rows)
                    {
                        if (!(string.IsNullOrEmpty(row["AttributeName"].ToString()) || string.IsNullOrEmpty(row["ValueStr"].ToString())))
                        {
                            object sKUContent = item.SKUContent;
                            item.SKUContent = string.Concat(new object[] { sKUContent, row["AttributeName"], ":", row["ValueStr"], "; " });
                        }
                    }
                    item.SkuId     = skuId;
                    item.ProductId = (int)skuContentBySkuBuDistorUserId.Rows[0]["ProductId"];
                    if (skuContentBySkuBuDistorUserId.Rows[0]["SKU"] != DBNull.Value)
                    {
                        item.SKU = (string)skuContentBySkuBuDistorUserId.Rows[0]["SKU"];
                    }
                    if (skuContentBySkuBuDistorUserId.Rows[0]["Weight"] != DBNull.Value)
                    {
                        item.ItemWeight = (int)skuContentBySkuBuDistorUserId.Rows[0]["Weight"];
                    }
                    item.ItemPurchasePrice = (decimal)skuContentBySkuBuDistorUserId.Rows[0]["PurchasePrice"];
                    item.Quantity          = num;
                    item.ItemListPrice     = (decimal)skuContentBySkuBuDistorUserId.Rows[0]["SalePrice"];
                    item.ItemDescription   = (string)skuContentBySkuBuDistorUserId.Rows[0]["ProductName"];
                    if (skuContentBySkuBuDistorUserId.Rows[0]["CostPrice"] != DBNull.Value)
                    {
                        item.CostPrice = (decimal)skuContentBySkuBuDistorUserId.Rows[0]["CostPrice"];
                    }
                    if (skuContentBySkuBuDistorUserId.Rows[0]["ThumbnailUrl40"] != DBNull.Value)
                    {
                        item.ThumbnailsUrl = (string)skuContentBySkuBuDistorUserId.Rows[0]["ThumbnailUrl40"];
                    }
                    if (SalesHelper.AddPurchaseOrderItem(item, purchaseOrderId))
                    {
                        UpdatePurchaseOrder();
                        BindOrderItems();
                        ReBindData(true, false);
                        ShowMsg("添加规格商品成功", true);
                    }
                    else
                    {
                        ShowMsg("添加规格商品失败", false);
                    }
                }
            }
        }