Exemple #1
0
        private void btnAddBalance_Click(object sender, System.EventArgs e)
        {
            int num = 0;

            if (this.txtReCharge.Text.Trim().IndexOf(".") > 0)
            {
                num = this.txtReCharge.Text.Trim().Substring(this.txtReCharge.Text.Trim().IndexOf(".") + 1).Length;
            }
            decimal num2;

            if (!decimal.TryParse(this.txtReCharge.Text.Trim(), out num2) || num > 2)
            {
                this.ShowMsg("本次充值要给当前客户加款的金额只能是数值,且不能超过2位小数", false);
                return;
            }
            if (num2 < -10000000m || num2 > 10000000m)
            {
                this.ShowMsg("金额大小必须在正负1000万之间", false);
                return;
            }
            int userId = int.Parse(this.currentUserId.Value);

            Hidistro.Membership.Context.Member member = Hidistro.Membership.Context.Users.GetUser(userId, false) as Hidistro.Membership.Context.Member;
            if (member == null || !member.IsOpenBalance)
            {
                this.ShowMsg("本次充值已失败,该用户的预付款还没有开通", false);
                return;
            }
            decimal           balance           = num2 + member.Balance;
            BalanceDetailInfo balanceDetailInfo = new BalanceDetailInfo();

            balanceDetailInfo.UserId    = userId;
            balanceDetailInfo.UserName  = member.Username;
            balanceDetailInfo.TradeDate = System.DateTime.Now;
            balanceDetailInfo.TradeType = TradeTypes.BackgroundAddmoney;
            balanceDetailInfo.Income    = new decimal?(num2);
            balanceDetailInfo.Balance   = balance;
            balanceDetailInfo.Remark    = Globals.HtmlEncode(this.txtRemark.Text.Trim());
            ValidationResults validationResults = Validation.Validate <BalanceDetailInfo>(balanceDetailInfo, new string[]
            {
                "ValBalanceDetail"
            });
            string text = string.Empty;

            if (!validationResults.IsValid)
            {
                foreach (ValidationResult current in (System.Collections.Generic.IEnumerable <ValidationResult>)validationResults)
                {
                    text += Formatter.FormatErrorMessage(current.Message);
                }
                this.ShowMsg(text, false);
                return;
            }
            if (UnderlingHelper.AddUnderlingBalanceDetail(balanceDetailInfo))
            {
                this.txtReCharge.Text = "";
                this.ReBind(false);
            }
        }
        private void btnAddBalance_Click(object sender, EventArgs e)
        {
            decimal num;
            int     length = 0;

            if (txtReCharge.Text.Trim().IndexOf(".") > 0)
            {
                length = txtReCharge.Text.Trim().Substring(txtReCharge.Text.Trim().IndexOf(".") + 1).Length;
            }
            if (!(decimal.TryParse(txtReCharge.Text.Trim(), out num) && (length <= 2)))
            {
                ShowMsg("本次充值要给当前客户加款的金额只能是数值,且不能超过2位小数", false);
            }
            else if ((num < -10000000M) || (num > 10000000M))
            {
                ShowMsg("金额大小必须在正负1000万之间", false);
            }
            else
            {
                int    userId = int.Parse(currentUserId.Value);
                Member user   = Users.GetUser(userId, false) as Member;
                if (!((user != null) && user.IsOpenBalance))
                {
                    ShowMsg("本次充值已失败,该用户的预付款还没有开通", false);
                }
                else
                {
                    decimal           num4  = num + user.Balance;
                    BalanceDetailInfo info2 = new BalanceDetailInfo();
                    info2.UserId    = userId;
                    info2.UserName  = user.Username;
                    info2.TradeDate = DateTime.Now;
                    info2.TradeType = TradeTypes.BackgroundAddmoney;
                    info2.Income    = new decimal?(num);
                    info2.Balance   = num4;
                    info2.Remark    = Globals.HtmlEncode(txtRemark.Text.Trim());
                    BalanceDetailInfo target  = info2;
                    ValidationResults results = Hishop.Components.Validation.Validation.Validate <BalanceDetailInfo>(target, new string[] { "ValBalanceDetail" });
                    string            msg     = string.Empty;
                    if (!results.IsValid)
                    {
                        foreach (ValidationResult result in (IEnumerable <ValidationResult>)results)
                        {
                            msg = msg + Formatter.FormatErrorMessage(result.Message);
                        }
                        ShowMsg(msg, false);
                    }
                    else if (UnderlingHelper.AddUnderlingBalanceDetail(target))
                    {
                        txtReCharge.Text = "";
                        ReBind(false);
                    }
                }
            }
        }
        private void BtnRefund_Click(object sender, EventArgs e)
        {
            OrderInfo orderInfo = SubsiteSalesHelper.GetOrderInfo(orderId);

            if (!orderInfo.CheckAction(OrderActions.SELLER_REJECT_REFUND))
            {
                ShowMsg("未付款或不在进行中的订单没有退款操作", false);
            }
            else
            {
                int     length = 0;
                decimal result = 0M;
                if (orderInfo.OrderStatus == OrderStatus.SellerAlreadySent)
                {
                    if (txtRefundTotal.Text.Trim().IndexOf(".") > 0)
                    {
                        length = txtRefundTotal.Text.Trim().Substring(txtRefundTotal.Text.Trim().IndexOf(".") + 1).Length;
                    }
                    if (!(decimal.TryParse(txtRefundTotal.Text.Trim(), out result) && (length <= 2)))
                    {
                        ShowMsg("退款金额只能是数值,且不能超过2位小数", false);
                        return;
                    }
                    if ((result <= 0M) || (result > orderInfo.GetTotal()))
                    {
                        ShowMsg("退款金额必须大于0,小于等于实收款", false);
                        return;
                    }
                }
                if (txtRefundRemark.Text.Length > 200)
                {
                    ShowMsg("退款说明限制在200个字符以内", false);
                }
                else
                {
                    decimal money;
                    Member  user = Users.GetUser(orderInfo.UserId) as Member;
                    if (orderInfo.OrderStatus == OrderStatus.SellerAlreadySent)
                    {
                        money = result;
                    }
                    else if ((orderInfo.GroupBuyId > 0) && (orderInfo.GroupBuyStatus != GroupBuyStatus.Failed))
                    {
                        money = ((decimal)lblTotalPrice.Money) - orderInfo.NeedPrice;
                    }
                    else
                    {
                        money = (decimal)lblTotalPrice.Money;
                    }
                    BalanceDetailInfo balanceDetails = new BalanceDetailInfo();
                    balanceDetails.UserId    = orderInfo.UserId;
                    balanceDetails.UserName  = orderInfo.Username;
                    balanceDetails.TradeDate = DateTime.Now;
                    balanceDetails.TradeType = TradeTypes.RefundOrder;
                    balanceDetails.Income    = new decimal?(money);
                    balanceDetails.Balance   = user.Balance + money;
                    balanceDetails.Remark    = "订单退款到预付款";
                    if (rdolist.SelectedValue == "2")
                    {
                        if (!user.IsOpenBalance)
                        {
                            ShowMsg("本次退款已失败,该用户的预付款还没有开通", false);
                        }
                        else if (UnderlingHelper.AddUnderlingBalanceDetail(balanceDetails))
                        {
                            orderInfo.RefundAmount = money;
                            orderInfo.RefundRemark = Globals.HtmlEncode(txtRefundRemark.Text.Trim());
                            orderInfo.FinishDate   = DateTime.Now;
                            orderInfo.RefundStatus = RefundStatus.Refund;
                            if (SubsiteSalesHelper.RefundOrder(orderInfo))
                            {
                                Messenger.OrderRefund(user, orderInfo.OrderId, money);
                                orderInfo.OnRefund();
                                Page.Response.Redirect(Globals.ApplicationPath + string.Format("/Shopadmin/sales/RefundOrderDetails.aspx?OrderId={0}", orderInfo.OrderId));
                            }
                            else
                            {
                                ShowMsg("退款失败", false);
                            }
                        }
                    }
                    else
                    {
                        orderInfo.RefundAmount = money;
                        orderInfo.RefundRemark = Globals.HtmlEncode(txtRefundRemark.Text.Trim());
                        orderInfo.FinishDate   = DateTime.Now;
                        orderInfo.RefundStatus = RefundStatus.Below;
                        if (SubsiteSalesHelper.RefundOrder(orderInfo))
                        {
                            Messenger.OrderRefund(user, orderInfo.OrderId, money);
                            orderInfo.OnRefund();
                            Page.Response.Redirect(Globals.ApplicationPath + string.Format("/Shopadmin/sales/RefundOrderDetails.aspx?OrderId={0}", orderInfo.OrderId));
                        }
                        else
                        {
                            ShowMsg("退款失败", false);
                        }
                    }
                }
            }
        }