コード例 #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lnkDelete_Click(object sender, EventArgs e)
        {
            OrdersBiz biz     = new OrdersBiz();
            GiftBiz   giftBiz = new GiftBiz();

            LinkButton lnk = sender as LinkButton;

            Orders_DetailInfo model     = biz.GetOrders_DetailModel(int.Parse(lnk.CommandArgument));
            GiftInfo          giftModel = giftBiz.GetModel(model.GiftId);

            //删除订单明细后,更新礼品信息
            giftModel.Quantity += model.GiftCount;

            if (biz.DeleteOrders_Detail(int.Parse(lnk.CommandArgument)) > 0 && giftBiz.UpdateGift(giftModel) > 0)
            {
                ShowMessage("更新成功!");
            }
            else
            {
                ShowMessage("更新失败!");
            }
        }
コード例 #2
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lnkEdit_Click(object sender, EventArgs e)
        {
            OrdersBiz biz     = new OrdersBiz();
            GiftBiz   giftBiz = new GiftBiz();

            LinkButton  lnk          = sender as LinkButton;
            GridViewRow row          = lnk.Parent.Parent as GridViewRow;
            TextBox     txtGiftCount = row.FindControl("txtGiftCount") as TextBox;
            TextBox     txtUsage     = row.FindControl("txtUsage") as TextBox;

            int newCount = int.Parse(txtGiftCount.Text.Trim());

            Orders_DetailInfo model     = biz.GetOrders_DetailModel(int.Parse(lnk.CommandArgument));
            GiftInfo          giftModel = giftBiz.GetModel(model.GiftId);

            //更新数量的话,更新礼品信息
            int newQuantity = giftModel.Quantity;

            newQuantity -= newCount - model.GiftCount;

            if (newQuantity < 0)
            {
                lErrorInfo.Text = "礼品【" + giftModel.Title + "】数量不足,剩余数量为:" + giftModel.Quantity.ToString() + "!";
                return;
            }
            giftModel.Quantity = newQuantity;
            model.GiftCount    = newCount;
            model.Usage        = txtUsage.Text.Trim();

            if (biz.UpdateOrders_Detail(model) > 0 && giftBiz.UpdateGift(giftModel) > 0)
            {
                ShowMessage("更新成功!");
            }
            else
            {
                ShowMessage("更新失败!");
            }
        }
コード例 #3
0
ファイル: ShoppingCart.aspx.cs プロジェクト: rongcheng/benz
        /// <summary>
        /// 生成订单,并指定订单状态
        /// </summary>
        private string CreateOrder(int orderState)
        {
            OrdersBiz biz        = new OrdersBiz();
            OrderInfo orderModel = new OrderInfo();
            GiftBiz   giftBiz    = new GiftBiz();

            //添加订单信息
            orderModel.OrderId   = biz.GetNewOrderId();
            orderModel.UserId    = CurrentUser.UserId.ToString();
            orderModel.Operator  = CurrentUser.OperatorId.ToString();
            orderModel.State     = orderState;
            orderModel.Address   = address.Text;
            orderModel.Contactor = Contactor.Text;
            orderModel.Tel       = Tel.Text;
            orderModel.Email     = Email.Text;

            Orders_DetailInfo[] details      = new Orders_DetailInfo[gvShoppingCartList.Rows.Count];
            GiftInfo[]          giftInfoList = new GiftInfo[gvShoppingCartList.Rows.Count];
            int i = 0;

            //添加订单明细,先检查数量是否足够
            foreach (GridViewRow row in gvShoppingCartList.Rows)
            {
                Label   lblGiftId = row.FindControl("lblGiftId") as Label;
                TextBox txtCount  = row.FindControl("txtCount") as TextBox;
                TextBox txtUsage  = row.FindControl("txtUsage") as TextBox;

                Orders_DetailInfo detailModel = new Orders_DetailInfo();
                detailModel.OrderId   = orderModel.OrderId;
                detailModel.GiftId    = lblGiftId.Text;
                detailModel.GiftCount = int.Parse(txtCount.Text);
                detailModel.Usage     = txtUsage.Text;

                GiftInfo giftModel = giftBiz.GetModel(detailModel.GiftId);

                if (giftModel.Quantity < detailModel.GiftCount)
                {
                    lErrorInfo.Text = "礼品【" + giftModel.Title + "】数量不足,剩余数量为:" + giftModel.Quantity.ToString() + "!";
                    return(string.Empty);
                }

                giftInfoList[i] = giftModel;
                details[i]      = detailModel;
                i++;
            }

            //遍历更新
            for (i = 0; i < details.Length; i++)
            {
                biz.AddOrders_Detail(details[i]);
                giftInfoList[i].Quantity -= details[i].GiftCount;
                giftBiz.UpdateGift(giftInfoList[i]);
            }
            biz.AddOrders(orderModel);

            //清除购物车
            HttpCookie cookie = Request.Cookies["ShoppingCart"];

            cookie.Expires = DateTime.Now.AddHours(-2);
            Response.Cookies.Add(cookie);
            return(orderModel.OrderId);
        }