Exemplo n.º 1
0
        private void OnCommit()
        {
            if (Common.GetUserId() != Guid.Empty)
            {
                MessageBox.Messager(this.Page, lbtnSave, "请先登录再执行操作");
                return;
            }
            string addressId = hNId.Value.Trim();

            if (string.IsNullOrEmpty(addressId))
            {
                MessageBox.Messager(this.Page, lbtnSave, "请选择收货人信息", "操作错误", "error");
                return;
            }
            if (profile == null)
            {
                profile = new CustomProfileCommon();
            }
            UserAddressInfo addressModel = profile.UserAddress.GetModel(Guid.Parse(addressId));

            if (addressModel == null)
            {
                MessageBox.Messager(this.Page, lbtnSave, "不存在当前收货人信息记录,请检查", "操作错误", "error");
                return;
            }
            string payOption = selectPay.InnerText.Trim();

            if (string.IsNullOrEmpty(payOption))
            {
                MessageBox.Messager(this.Page, lbtnSave, "请选择支付及配送方式", "操作错误", "error");
                return;
            }

            int     totalCount = profile.ShoppingCart.Count;
            decimal totalPrice = profile.ShoppingCart.TotalPrice;

            if (totalCount < 1)
            {
                MessageBox.Messager(this.Page, lbtnSave, "商品清单不存在任何商品,请检查", "操作错误", "error");
                return;
            }

            string sProducts = "";
            ICollection <CartItemInfo> items = profile.ShoppingCart.CartItems;

            foreach (CartItemInfo item in items)
            {
                sProducts += string.Format("{2},{1},{0}|", item.Subtotal, item.Quantity, item.ProductId);
            }
            sProducts = sProducts.Trim('|');

            DateTime  dtime = DateTime.Now;
            OrderInfo model = new OrderInfo();

            model.OrderNum        = WebHelper.CustomsHelper.CreateDateTimeString();
            model.UserId          = Common.GetUserId();
            model.Receiver        = addressModel.Receiver;
            model.ProviceCity     = addressModel.ProvinceCity;
            model.Address         = addressModel.Address;
            model.Mobilephone     = addressModel.Mobilephone;
            model.Telephone       = addressModel.Telephone;
            model.Email           = addressModel.Email;
            model.Products        = sProducts;
            model.TotalCount      = totalCount;
            model.TotalPrice      = totalPrice;
            model.PayOption       = payOption;
            model.LastUpdatedDate = dtime;
            model.CreateDate      = dtime;

            string errorMsg = "";

            try
            {
                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = IsolationLevel.ReadUncommitted;
                options.Timeout        = TimeSpan.FromSeconds(90);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    if (bll == null)
                    {
                        bll = new BLL.Order();
                    }
                    if (bll.Insert(model) > 0)
                    {
                        profile.ShoppingCart.Clear();
                        profile.Save();
                    }

                    //提交事务
                    scope.Complete();
                }

                Response.Redirect(string.Format("AddOrderSucceed.aspx?oN={0}", HttpUtility.UrlEncode(model.OrderNum)), true);
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }
            if (!string.IsNullOrEmpty(errorMsg))
            {
                MessageBox.Messager(this.Page, lbtnSave, errorMsg, "系统异常提醒");
                return;
            }
        }
Exemplo n.º 2
0
        private void OnSave()
        {
            string sItemAppend = hItemAppend.Value.Trim();

            if (string.IsNullOrEmpty(sItemAppend))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "投注项不能为空", "错误提示");
                return;
            }

            string[] items = sItemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (items.Length < 1)
            {
                return;
            }

            BLL.RunLottery rlBll = new BLL.RunLottery();

            Model.RunLottery rlModel = rlBll.GetModel(nId);
            if (rlModel == null)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "不存在的开奖期,非法操作", "错误提示");
                return;
            }

            DateTime runDate = rlModel.RunDate;
            TimeSpan ts      = runDate - DateTime.Now;

            if ((ts.TotalMilliseconds - 8000) < 0)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "当前第" + rlModel.Period + "期,已停止投注", "温馨提示");
                return;
            }

            string[] itemArr = items[0].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            int totalBetNum = Int32.Parse(itemArr[1]);

            if (totalBetNum <= 0)
            {
                return;
            }

            object userId = WebHelper.Common.GetUserId();

            //获取当前用户的棋子数
            BLL.UserPoint   uBll   = new BLL.UserPoint();
            Model.UserPoint uModel = uBll.GetModelByUser(userId);
            if (uModel == null)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "您的棋子数不足,不能进行投注!", "系统提示");
                return;
            }

            if ((uModel.PointNum - totalBetNum) < 0)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "您的棋子数不足,不能进行投注!", "系统提示");
                return;
            }

            string itemAppend   = string.Empty;
            string betNumAppend = string.Empty;
            int    index        = 0;

            foreach (string s in items)
            {
                index++;
                if (index > 1)
                {
                    string[] nvArr = s.Split('|');
                    itemAppend   += nvArr[0] + ",";
                    betNumAppend += nvArr[1] + ",";
                }
            }

            BLL.Order            ublBll   = new BLL.Order();
            Model.UserBetLottery ublModel = new Model.UserBetLottery();
            ublModel.LastUpdatedDate = DateTime.Now;
            ublModel.UserID          = userId;
            ublModel.RunLotteryID    = rlModel.NumberID;
            ublModel.TotalPointNum   = totalBetNum;
            ublModel.ItemAppend      = itemAppend.Trim(',');
            ublModel.BetNumAppend    = betNumAppend.Trim(',');
            ublModel.WinPointNum     = 0;

            int effectCount = -1;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                uModel.PointNum = uModel.PointNum - totalBetNum;
                if (uBll.Update(uModel) > 0)
                {
                    ublBll.Insert(ublModel);
                    effectCount = 1;
                }

                scope.Complete();
            }

            if (effectCount > 0)
            {
                WebHelper.MessageBox.Show(this.Page, lbtnSave, "当前第" + rlModel.Period + "期,投注成功!", Request.Url.ToString());
            }
            else
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "当前第" + rlModel.Period + "期,投注失败,请检查", "系统提示");
            }
        }