예제 #1
0
        protected void BindVoucherList()
        {
            if (string.IsNullOrEmpty(this.voucherName) &&
                string.IsNullOrEmpty(this.voucherOrder) &&
                !this.voucherstatus.HasValue &&
                !this.VoucherId.HasValue)
            {
                return;
            }
            DbQueryResult vouchersList = VoucherHelper.GetVouchersList(new VoucherItemInfoQuery
            {
                VoucherName   = this.voucherName,
                OrderId       = this.voucherOrder,
                VoucherId     = this.VoucherId,
                VoucherStatus = this.voucherstatus,
                PageIndex     = this.pager.PageIndex,
                PageSize      = this.pager.PageSize,
                SortBy        = "GenerateTime",
                SortOrder     = SortAction.Desc
            });

            this.pager.TotalRecords     = vouchersList.TotalRecords;
            this.grdVouchers.DataSource = vouchersList.Data;
            this.grdVouchers.DataBind();
        }
예제 #2
0
        private void ReceiveVouchers(System.Web.HttpContext context)
        {
            string text = "";

            if (context.Request["voucherid"] != null)
            {
                text = context.Request["voucherid"].ToString();
            }
            Member member = HiContext.Current.User as Member;

            if (member == null)
            {
                this.message = "你还未登陆,请登陆";
                return;
            }
            int voucherid = 0;

            if (!int.TryParse(text, out voucherid))
            {
                this.message = "该链接无效";
                return;
            }

            VoucherInfo voucherInfo = VoucherHelper.GetVoucher(voucherid);

            if (voucherInfo == null || voucherInfo.SendType != 3 || voucherInfo.StartTime.Date > DateTime.Now.Date || voucherInfo.ClosingTime < DateTime.Now.Date)
            {
                this.message = "该链接无效";
                return;
            }

            int count = VoucherHelper.GetCountVoucherItem(voucherid, member.UserId);

            if (count == 0)
            {
                string claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                claimCode = Sign(claimCode, "UTF-8").Substring(8, 16);
                string          password        = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                DateTime        deadline        = DateTime.Now.AddDays(voucherInfo.Validity);
                VoucherItemInfo voucherItemInfo = new VoucherItemInfo(voucherid, claimCode, password, new int?(member.UserId), member.Username, member.Email, System.DateTime.Now, deadline);

                IList <VoucherItemInfo> voucherItemList = new List <VoucherItemInfo>();
                voucherItemList.Add(voucherItemInfo);
                if (VoucherHelper.SendClaimCodes(voucherItemList))
                {
                    this.message = "你已成功领取该优惠券";
                }

                else
                {
                    this.message = "操作失败";
                }
            }
            else
            {
                this.message = "您已经领过该优惠券";
            }
        }
예제 #3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!int.TryParse(this.Page.Request.QueryString["voucherId"], out this.voucherId))
            {
                base.GotoResourceNotFound();
                return;
            }
            this.btnAddVouchers.Click += new System.EventHandler(this.btnAddVouchers_Click);

            //如果是编辑现金券
            if ((!this.Page.IsPostBack))
            {
                if (this.voucherId > 0)
                {
                    VoucherInfo voucher = VoucherHelper.GetVoucher(this.voucherId);
                    if (voucher == null)
                    {
                        base.GotoResourceNotFound();
                        return;
                    }
                    if (voucher.ClosingTime.CompareTo(System.DateTime.Now) < 0)
                    {
                        this.ShowMsg("该现金券已经结束!", false);
                        return;
                    }
                    Globals.EntityCoding(voucher, false);
                    //this.lblEditCouponId.Text = coupon.CouponId.ToString();
                    this.btnAddVouchers.Text = "修改";
                    this.txtVoucherName.Text = voucher.Name;
                    this.txtValidity.Text    = voucher.Validity.ToString();
                    if (voucher.Amount.HasValue)
                    {
                        this.txtAmount.Text = string.Format("{0:F2}", voucher.Amount);
                    }
                    this.txtDiscountValue.Text          = voucher.DiscountValue.ToString("F2");
                    this.calendarEndDate.SelectedDate   = new System.DateTime?(voucher.ClosingTime);
                    this.calendarStartDate.SelectedDate = new System.DateTime?(voucher.StartTime);

                    switch (voucher.SendType)
                    {
                    case 0: rdoManually.Checked = true; break;

                    case 1: rdoOverMoney.Checked = true; this.txtOverMoney.Text = voucher.SendTypeItem; break;

                    case 2: rdoRegist.Checked = true; break;

                    case 3: rdoLq.Checked = true; break;
                    }
                }

                else
                {
                    rdoManually.Checked = true;
                }
            }
        }
예제 #4
0
        private void BindVouchers()
        {
            DbQueryResult newVouchers = VoucherHelper.GetNewVouchers(new Pagination
            {
                PageSize  = this.pager.PageSize,
                PageIndex = this.pager.PageIndex
            });

            this.grdVouchers.DataSource = newVouchers.Data;
            this.grdVouchers.DataBind();
            this.pager.TotalRecords = newVouchers.TotalRecords;
        }
예제 #5
0
        public decimal ValidateVoidVoucher(string ticketNumber, int userNo, ref int?nResult)
        {
            decimal dAmount = 0;

            try
            {
                // is tis printed ticket
                if (VoucherHelper.IsTISPrintedTicketPrefix(ticketNumber))
                {
                    // if the tis printed ticket available in local db
                    bool isTISTicketAvailable = VoucherHelper.IsTISPrintedTicket(ticketNumber);
                    if (!isTISTicketAvailable)
                    {
                        // wait worst case 10 secs to get the response from TIS
                        int    count   = 10;
                        string message = "Waiting for receiving data from TIS...";
                        WPFExtensions.ShowAsyncDialog(null, message, null, 1, count,
                                                      (o) =>
                        {
                            IAsyncProgress2 o2 = o as IAsyncProgress2;

                            // failure case - hit the tis communication interface and get the ticket
                            try
                            {
                                o2.UpdateStatusProgress(5, message);
                                VoucherHelper.SendTISRedeemTicketQuery(ticketNumber, userNo);
                                o2.UpdateStatusProgress(10, message);
                            }
                            catch (Exception ex)
                            {
                                ExceptionManager.Publish(ex);
                            }
                        });
                    }
                }

                // Success/failure case - ok proceed with voiding
                foreach (var obj in this.ValidateVoidVoucher(ticketNumber, ref nResult))
                {
                    dAmount = Convert.ToDecimal(obj.iAmount) / 100;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
            }

            return(dAmount);
        }
예제 #6
0
        private void grdVouchers_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
        {
            int voucherId = (int)this.grdVouchers.DataKeys[e.RowIndex].Value;

            if (VoucherHelper.GetVoucherItemAmount(voucherId) > 0)
            {
                this.ShowMsg("现金券已经发送给用户,无法删除", true);

                return;
            }
            if (VoucherHelper.DeleteVoucher(voucherId))
            {
                this.BindVouchers();
                this.ShowMsg("成功删除了选定现金券", true);
                return;
            }
            this.ShowMsg("删除现金券失败", false);
        }
예제 #7
0
        /// <summary>
        /// 注册赠送现金券
        /// </summary>
        /// <param name="members"></param>
        protected void RegistSendVoucher(IList <Member> members)
        {
            IList <VoucherInfo> voucherList = VoucherHelper.GetVoucherBySendType(2);

            IList <VoucherItemInfo> list = new System.Collections.Generic.List <VoucherItemInfo>();

            string claimCode = string.Empty;
            string password  = string.Empty;

            if (voucherList.Count > 0)
            {
                foreach (Member member in members)
                {
                    foreach (VoucherInfo voucher in voucherList)
                    {
                        VoucherItemInfo item = new VoucherItemInfo();
                        if (VoucherHelper.GetCountVoucherItem(voucher.VoucherId, member.UserId) > 0)
                        {
                            continue;
                        }
                        else
                        {
                            claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                            claimCode = Sign(claimCode, "UTF-8").Substring(8, 16);
                            password  = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                            item      = new VoucherItemInfo(voucher.VoucherId, claimCode, password, new int?(member.UserId), member.Username, member.Email, System.DateTime.Now, DateTime.Now.AddDays(voucher.Validity));
                            list.Add(item);
                        }
                    }
                }
            }

            if (list.Count > 0)
            {
                try
                {
                    VoucherHelper.SendClaimCodes(list);
                }

                catch
                {
                }
            }
        }
예제 #8
0
        private void btnSend_Click(object sender, System.EventArgs e)
        {
            VoucherInfo     voucherInfo = VoucherHelper.GetVoucher(voucherId);
            DateTime        deadline    = DateTime.Now.AddDays(voucherInfo.Validity);
            VoucherItemInfo item        = new VoucherItemInfo();

            System.Collections.Generic.IList <VoucherItemInfo> list  = new System.Collections.Generic.List <VoucherItemInfo>();
            System.Collections.Generic.IList <Member>          list2 = new System.Collections.Generic.List <Member>();
            if (this.rdoName.Checked)
            {
                if (!string.IsNullOrEmpty(this.txtMemberNames.Text.Trim()))
                {
                    System.Collections.Generic.IList <string> list3 = new System.Collections.Generic.List <string>();
                    string   text  = this.txtMemberNames.Text.Trim().Replace("\r\n", "\n");
                    string[] array = text.Replace("\n", "*").Split(new char[]
                    {
                        '*'
                    });
                    for (int i = 0; i < array.Length; i++)
                    {
                        list3.Add(array[i]);
                    }
                    list2 = PromoteHelper.GetMemdersByNames(list3);
                }
                string claimCode = string.Empty;
                string password  = string.Empty;
                foreach (Member current in list2)
                {
                    claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                    claimCode = Sign(claimCode, "UTF-8").Substring(8, 16);
                    password  = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                    item      = new VoucherItemInfo(this.voucherId, claimCode, password, new int?(current.UserId), current.Username, current.Email, System.DateTime.Now, deadline);
                    list.Add(item);
                }
                if (list.Count <= 0)
                {
                    this.ShowMsg("你输入的会员名中没有一个正确的,请输入正确的会员名", false);
                    return;
                }
                VoucherHelper.SendClaimCodes(list);
                this.txtMemberNames.Text = string.Empty;
                this.ShowMsg(string.Format("此次发送操作已成功,现金券发送数量:{0}", list.Count), true);
            }
            if (this.rdoRank.Checked)
            {
                StringBuilder strcondition = new StringBuilder();
                strcondition.Append("1=1");
                if (this.rankList.SelectedValue > 0)
                {
                    strcondition.AppendFormat(" and GradeId={0} ", this.rankList.SelectedValue);
                }

                if (this.registerFromDate.SelectedDate.HasValue && this.registerToDate.SelectedDate.HasValue)
                {
                    strcondition.AppendFormat(" and CreateDate>='{0}' and CreateDate<='{1}' ", this.registerFromDate.SelectedDate.Value, this.registerToDate.SelectedDate.Value);
                }

                if (this.ddlReggion.GetSelectedRegionId().HasValue)
                {
                    strcondition.AppendFormat(" and TopRegionId={0} ", this.ddlReggion.GetSelectedRegionId().Value);
                }


                list2 = PromoteHelper.GetMembersByCondition(strcondition.ToString());
                string claimCode2 = string.Empty;
                string password2  = string.Empty;
                foreach (Member current2 in list2)
                {
                    claimCode2 = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                    claimCode2 = Sign(claimCode2, "UTF-8").Substring(8, 16);
                    password2  = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                    item       = new VoucherItemInfo(this.voucherId, claimCode2, password2, new int?(current2.UserId), current2.Username, current2.Email, System.DateTime.Now, deadline);
                    list.Add(item);
                }
                if (list.Count <= 0)
                {
                    this.ShowMsg("您选择的条件下面没有符合条件的会员", false);
                    return;
                }
                VoucherHelper.SendClaimCodes(list);
                this.txtMemberNames.Text = string.Empty;
                this.ShowMsg(string.Format("此次发送操作已成功,现金券发送数量:{0}", list.Count), true);
            }
        }
예제 #9
0
        private void OrderSendVoucher(IList <OrderInfo> orderList)
        {
            IList <VoucherInfo> voucherList = VoucherHelper.GetVoucherBySendType(1);

            IList <VoucherItemInfo> list = new System.Collections.Generic.List <VoucherItemInfo>();

            string claimCode = string.Empty;
            string password  = string.Empty;

            if (voucherList.Count > 0)
            {
                foreach (OrderInfo orderInfo in orderList)
                {
                    foreach (VoucherInfo voucher in voucherList)
                    {
                        VoucherItemInfo item = new VoucherItemInfo();
                        ///不存在拆单
                        if (String.IsNullOrEmpty(orderInfo.SourceOrderId))
                        {
                            if (VoucherHelper.GetCountVoucherItem(voucher.VoucherId, orderInfo.OrderId) > 0)
                            {
                                continue;
                            }
                            else
                            {
                                if (orderInfo.Amount >= Convert.ToDecimal(voucher.SendTypeItem))
                                {
                                    claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                                    claimCode = Sign(claimCode, "UTF-8").Substring(8, 16);
                                    password  = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                                    item      = new VoucherItemInfo(orderInfo.OrderId, voucher.VoucherId, claimCode, password, new int?(orderInfo.UserId), orderInfo.Username, orderInfo.EmailAddress, System.DateTime.Now, DateTime.Now.AddDays(voucher.Validity));
                                    list.Add(item);
                                }
                            }
                        }
                        //拆单
                        else
                        {
                            if (VoucherHelper.GetCountVoucherItem(voucher.VoucherId, orderInfo.SourceOrderId) > 0)
                            {
                                continue;
                            }
                            else
                            {
                                decimal sourceAmount = OrderHelper.GetOrderAmount(orderInfo.SourceOrderId);
                                if (sourceAmount >= Convert.ToDecimal(voucher.SendTypeItem))
                                {
                                    claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                                    claimCode = Sign(claimCode, "UTF-8").Substring(8, 16);
                                    password  = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                                    item      = new VoucherItemInfo(orderInfo.SourceOrderId, voucher.VoucherId, claimCode, password, new int?(orderInfo.UserId), orderInfo.Username, orderInfo.EmailAddress, System.DateTime.Now, DateTime.Now.AddDays(voucher.Validity));
                                    list.Add(item);
                                }
                            }
                        }
                    }
                }
            }

            if (list.Count > 0)
            {
                try
                {
                    VoucherHelper.SendClaimCodes(list);
                }

                catch
                {
                }
            }
        }
예제 #10
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int    InstallationNumber = 0;
                int    ValidationLength   = 0;
                string _Barcode           = this.ucValueCalc.txtDisplay.Text.Trim();
                System.Windows.Forms.DialogResult _diagResult;
                btnVerify.IsEnabled = false;
                if (isScannerFired) //check done not to fire the verify event twice while verifying a ticket using scanner
                {
                    isScannerFired = false;
                    return;
                }
                if ((sender is System.Windows.Controls.TextBox))
                {
                    isScannerFired = true;
                }
                else
                {
                    isScannerFired = false;
                }


                if (this.ucValueCalc.txtDisplay.Text.Trim().Length > 0)
                {
                    //8-digit ticket validation.
                    //Slot ticket cannot be redeemed via cashdesk.
                    if (this.ucValueCalc.txtDisplay.Text.Trim().Length != 18)
                    {
                        LinqDataAccessDataContext            linqDBExchange     = new LinqDataAccessDataContext(CommonDataAccess.ExchangeConnectionString);
                        IEnumerable <InstallationFromTicket> InstallationTicket = linqDBExchange.GetInstallationNumber(_Barcode);
                        if (InstallationTicket != null)
                        {
                            foreach (var item in InstallationTicket)
                            {
                                InstallationNumber = item.installation_no.Value;
                                _Barcode           = item.strbarcode;
                            }
                            DataTable InstallationDetails = (new CommonDataAccess()).GetInstallationDetails(0, InstallationNumber, false, false);
                            if (InstallationDetails.Rows.Count > 0)
                            {
                                int.TryParse(InstallationDetails.Rows[0]["Validation_length"].ToString(), out ValidationLength);
                                if (ValidationLength != _Barcode.Length)
                                {
                                    MessageBox.ShowBox("MessageID403", BMC_Icon.Error);
                                    return;
                                }
                            }
                        }
                    }

                    TicketsHelper objTicketsHelper = new TicketsHelper();

                    int?    nResult        = -1;
                    decimal dAmount        = 0;
                    int     iTransactionNo = 0;
                    int     iSequenceNo    = 0;

                    //foreach (var obj in objTicketsHelper.ValidateVoidVoucher(this.ucValueCalc.txtDisplay.Text.Trim(), ref nResult))
                    //{
                    //    dAmount = Convert.ToDecimal(obj.iAmount)/100;
                    //}
                    dAmount = objTicketsHelper.ValidateVoidVoucher(_Barcode, Security.SecurityHelper.CurrentUser.User_No, ref nResult);

                    switch (nResult)
                    {
                    case 0:
                    {
                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                        {
                            //Message: Are you sure you want to Void the Voucher?
                            _diagResult = MessageBox.ShowBox("MessageID512", BMC_Icon.Question, BMC_Button.YesNo, this.ucValueCalc.txtDisplay.Text.Trim(), Convert.ToString(dAmount));
                            if (_diagResult == System.Windows.Forms.DialogResult.No)
                            {
                                return;
                            }
                        }
                        else
                        {
                            _diagResult = System.Windows.Forms.DialogResult.Yes;
                        }
                        if (_diagResult == System.Windows.Forms.DialogResult.Yes)
                        {
                            string barcode = this.ucValueCalc.txtDisplay.Text.Trim();

                            foreach (var obj in objTicketsHelper.UpdateVoidVoucher(barcode,
                                                                                   System.Environment.MachineName,
                                                                                   Security.SecurityHelper.CurrentUser.User_No,
                                                                                   txtNotes.Text))
                            {
                                iTransactionNo = (int)obj.iTransactionNo;
                                iSequenceNo    = obj.TE_ID;
                            }

                            // TIS Printed Tickets
                            if (VoucherHelper.IsTISPrintedTicket(barcode))
                            {
                                VoucherHelper.SendTISVoidTicket(barcode, Security.SecurityHelper.CurrentUser.User_No);
                            }

                            //Message: "Voucher Voided Successfully."
                            MessageBox.ShowBox("MessageID513", BMC_Icon.Information);
                            //Receipt
                            BMC.Business.CashDeskOperator.Reports objReports = new BMC.Business.CashDeskOperator.Reports();
                            string sCode = BMC.Transport.Settings.SiteCode;
                            using (CReportViewer objReportViewer = new CReportViewer())
                            {
                                objReportViewer.PrintVoidVoucherReceipt(System.Environment.MachineName, this.ucValueCalc.txtDisplay.Text.Trim(),
                                                                        dAmount, iTransactionNo, sCode, iSequenceNo);
                                //objReportViewer.ShowDialog();
                            }

                            Audit(this.ucValueCalc.txtDisplay.Text.Trim(), dAmount, "Voucher Voided Successfully");
                            lblVoidAmountValue.Visibility = Visibility.Visible;
                            lblVoidAmount.Visibility      = Visibility.Visible;
                            lblVoidAmountValue.Text       = string.Empty;
                            lblVoidAmountValue.Text       = dAmount.ToString("0.00");
                        }
                        break;
                    }


                    case 1:
                    {
                        //Voucher Not Found
                        //Message: "Voucher is not available in System"
                        MessageBox.ShowBox("MessageID514", BMC_Icon.Error);
                        Audit(this.ucValueCalc.txtDisplay.Text.Trim(), dAmount, "Voucher Not Found");
                        lblVoidAmount.Visibility      = Visibility.Hidden;
                        lblVoidAmountValue.Visibility = Visibility.Hidden;
                        //Audit
                        break;
                    }

                    case 2:
                    {
                        // Invalid for Slots, only CashDesk is allowed.
                        //Message: "Void is applicable only for Cash Desk Vouchers"
                        MessageBox.ShowBox("MessageID515", BMC_Icon.Error);
                        Audit(this.ucValueCalc.txtDisplay.Text.Trim(), dAmount, "Void is applicable only for Cash Desk Vouchers");
                        //Audit
                        lblVoidAmount.Visibility      = Visibility.Hidden;
                        lblVoidAmountValue.Visibility = Visibility.Hidden;
                        break;
                    }

                    case 3:
                    {
                        //PAID Status
                        // Message: "Voucher has already been redeemed."
                        MessageBox.ShowBox("MessageID516", BMC_Icon.Error);
                        Audit(this.ucValueCalc.txtDisplay.Text.Trim(), dAmount, "Voucher has already been redeemed");
                        lblVoidAmount.Visibility      = Visibility.Hidden;
                        lblVoidAmountValue.Visibility = Visibility.Hidden;
                        //Audit
                        break;
                    }

                    case 4:
                    {
                        //Already Voided
                        // Message: "Voucher has already been Voided."
                        MessageBox.ShowBox("MessageID517", BMC_Icon.Error);
                        Audit(this.ucValueCalc.txtDisplay.Text.Trim(), dAmount, "Voucher has already been Voided");
                        lblVoidAmount.Visibility      = Visibility.Hidden;
                        lblVoidAmountValue.Visibility = Visibility.Hidden;
                        //Audit
                        break;
                    }

                    case 5:
                    {
                        //Expired Date
                        // Message: "Voucher has expired."
                        MessageBox.ShowBox("MessageID518", BMC_Icon.Error);
                        Audit(this.ucValueCalc.txtDisplay.Text.Trim(), dAmount, "Voucher has expired");
                        lblVoidAmount.Visibility      = Visibility.Hidden;
                        lblVoidAmountValue.Visibility = Visibility.Hidden;
                        //Audit
                        break;
                    }
                    }
                }
                else
                {
                    //Message: "Please enter or scan a valid Voucher Number
                    MessageBox.ShowBox("MessageID519", BMC_Icon.Warning);
                    this.ucValueCalc.txtDisplay.Focus();
                }

                ClearAll();
            }
            catch (Exception ex)
            {
                MessageBox.ShowBox("MessageID520", BMC_Icon.Error);
                BMC.Common.ExceptionManagement.ExceptionManager.Publish(ex);
                ClearAll();
            }
            finally
            {
                btnVerify.IsEnabled = true;
            }
        }
예제 #11
0
        protected override void AttachChildControls()
        {
            this.vVoucherImage = (VVoucherImage)this.FindControl("vVoucherImage");

            string nowKeyCode = "";

            if (!string.IsNullOrEmpty(this.Page.Request.QueryString["k"]))
            {
                nowKeyCode = this.Page.Request.QueryString["k"];
            }
            else
            {
                if (this.vVoucherImage != null)
                {
                    vVoucherImage.Visible = false;
                }
            }
            string k = "8c0f9f7b58864063bd83cffeb9624915";
            int    voucherItemsCount = 0;

            if (nowKeyCode != k)
            {
                if (this.vVoucherImage != null)
                {
                    vVoucherImage.Visible = false;
                }
            }
            else
            {
                Member member = HiContext.Current.User as Member;

                voucherItemsCount = VoucherHelper.GetVoucherItemsCount(member.UserId, nowKeyCode);

                if (voucherItemsCount == 0)
                {
                    //通过发送方式获取优惠券列表(3为自助领劵)
                    IList <VoucherInfo> voucherList = VoucherHelper.GetVoucherBySendType(3);

                    //1.看是否登录,就是判断有没有userId,获取openId;2.往Ecshop_VoucherItems插入记录
                    VoucherItemInfo         item = new VoucherItemInfo();
                    IList <VoucherItemInfo> list = new List <VoucherItemInfo>();

                    string   claimCode = string.Empty;
                    string   password  = string.Empty;
                    DateTime deadline;

                    foreach (VoucherInfo current in voucherList)
                    {
                        deadline  = DateTime.Today.AddDays(current.Validity);
                        claimCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                        claimCode = Sign(claimCode, "UTF-8").Substring(8, 16);
                        password  = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);
                        item      = new VoucherItemInfo(current.VoucherId, claimCode, password, new int?(member.UserId), member.Username, member.Email, System.DateTime.Now, deadline, nowKeyCode);
                        list.Add(item);
                    }

                    VoucherHelper.BulkAddVoucherItems(list);
                }

                voucherItemsCount = VoucherHelper.GetVoucherItemsCount(member.UserId, nowKeyCode);
            }

            if (voucherItemsCount > 0)
            {
                //显示页面
                if (this.vVoucherImage != null)
                {
                    //可见
                    vVoucherImage.Visible = true;
                }
            }
            else
            {
                //否则隐藏
                if (this.vVoucherImage != null)
                {
                    vVoucherImage.Visible = false;
                }
            }

            //string.Format("此次发送操作已成功,现金券发送数量:{0}", list.Count);
            PageTitle.AddSiteNameTitle("发送优惠券");
        }
예제 #12
0
        /// <summary>
        /// 生成可用取票凭证
        /// </summary>
        /// <param name="fillCount">范围为1到1,000,000</param>
        /// <param name="effectiveTime"></param>
        /// <param name="expiredTime"></param>
        /// <returns></returns>
        public int FillNewVoucher(int fillCount, DateTime effectiveTime, DateTime expiredTime)
        {
            string strLog = String.Format("Generate new voucher:{0}, from {1} to {2}"
                                          , fillCount
                                          , TimeHelper.GetTimeStringYyyyMMddHHmmss(effectiveTime)
                                          , TimeHelper.GetTimeStringYyyyMMddHHmmss(expiredTime));

            _log.Info(strLog);

            if ((fillCount < 1) ||
                (fillCount > 1000000))
            {
                throw new ArgumentOutOfRangeException("fillCount");
            }
            if (0 < effectiveTime.CompareTo(expiredTime))
            {
                throw new ArgumentException("expiredTime must larger then effectiveTime");
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            int filledCount = 0;


            try
            {
                VoucherHelper voucherHelper = new VoucherHelper();
                // 为免重复生成双倍随机数
                int doublefillCount = fillCount * 2;
                // 不重复随机数
                List <string> noRepeatRandomNumList = voucherHelper.GetNoRepeatRandomNumList(doublefillCount, Constants.VoucherLength);
                // 已有随机数字典
                Dictionary <string, string> dictExistVoucherCode = new Dictionary <string, string>();
                // 需添加的新随机数列表,与已有随机数不重复
                List <VoucherList> toAddVoucherList = new List <VoucherList>();
                using (MobilePayDBEntities dbContext = new MobilePayDBEntities())
                {
                    // 填充 已有随机数字典
                    foreach (VoucherList eachVoucher in dbContext.VoucherLists.ToList())
                    {
                        string eachExistVoucherCode = eachVoucher.VoucherCode;
                        dictExistVoucherCode.Add(eachExistVoucherCode, eachExistVoucherCode);
                    }

                    // 填充 需添加的新随机数列表
                    int newVoucherCodeCount = 0;
                    foreach (string eachNewVoucherCode in noRepeatRandomNumList)
                    {
                        if (!dictExistVoucherCode.ContainsKey(eachNewVoucherCode))
                        {
                            VoucherList newVoucherList = new VoucherList();
                            newVoucherList.VoucherId     = Guid.NewGuid();
                            newVoucherList.VoucherCode   = eachNewVoucherCode;
                            newVoucherList.EffectiveTime = effectiveTime;
                            newVoucherList.ExpiredTime   = expiredTime;
                            newVoucherList.IsValid       = true;
                            newVoucherList.IsUsed        = false;
                            newVoucherList.IsLocked      = false;

                            toAddVoucherList.Add(newVoucherList);

                            newVoucherCodeCount++;
                            if (fillCount <= newVoucherCodeCount)
                            {
                                break;
                            }
                        }
                    }

                    DateTime dtGenerateTime = DateTime.Now;
                    foreach (VoucherList eachNewVoucher in toAddVoucherList)
                    {
                        eachNewVoucher.GenerateTime = dtGenerateTime;
                        dbContext.VoucherLists.AddObject(eachNewVoucher);
                    }
                    filledCount = dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }

            sw.Stop();
            TimeSpan ts = sw.Elapsed;

            _log.Info(ts.TotalMilliseconds);

            return(filledCount);
        }
예제 #13
0
        protected void btnExport_Click(object sender, System.EventArgs e)
        {
            //默认为复杂密码
            int pwdtype = 1;

            if (!string.IsNullOrEmpty(hiddenPwdtype.Value))
            {
                pwdtype = int.Parse(hiddenPwdtype.Value);
            }

            int num;

            if (!int.TryParse(this.tbvoucherNum.Text, out num))
            {
                this.ShowMsg("导出数量必须为正数", false);
                return;
            }
            if (num <= 0)
            {
                this.ShowMsg("导出数量必须为正数", false);
                return;
            }
            int voucherId;

            if (!int.TryParse(this.txtvoucherid.Value, out voucherId))
            {
                this.ShowMsg("参数错误", false);
                return;
            }
            VoucherInfo         voucher             = VoucherHelper.GetVoucher(voucherId);
            string              empty               = string.Empty;
            VoucherActionStatus voucherActionStatus = VoucherHelper.CreateVoucher(voucher, num, out empty, pwdtype);

            if (voucherActionStatus == VoucherActionStatus.UnknowError)
            {
                this.ShowMsg("未知错误", false);
                return;
            }
            if (voucherActionStatus == VoucherActionStatus.CreateClaimCodeError)
            {
                this.ShowMsg("生成现金券号码错误", false);
                return;
            }
            if (voucherActionStatus == VoucherActionStatus.CreateClaimCodeSuccess && !string.IsNullOrEmpty(empty))
            {
                System.Collections.Generic.IList <VoucherItemInfo> voucherItemInfos = VoucherHelper.GetVoucherItemInfos(empty);
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                stringBuilder.AppendLine("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\" border=\"1\">");
                stringBuilder.AppendLine("<tr style=\"font-weight: bold; white-space: nowrap;\">");
                stringBuilder.AppendLine("<td>现金券号码</td>");
                stringBuilder.AppendLine("<td>现金券密码</td>");
                stringBuilder.AppendLine("<td>现金券金额</td>");
                stringBuilder.AppendLine("<td>过期时间</td>");
                stringBuilder.AppendLine("</tr>");
                foreach (VoucherItemInfo current in voucherItemInfos)
                {
                    stringBuilder.AppendLine("<tr>");
                    stringBuilder.AppendLine("<td>" + current.ClaimCode + "</td>");
                    stringBuilder.AppendLine("<td>" + current.Password + "</td>");
                    stringBuilder.AppendLine("<td>" + voucher.DiscountValue + "</td>");
                    stringBuilder.AppendLine("<td>" + current.Deadline + "</td>");
                    stringBuilder.AppendLine("</tr>");
                }
                stringBuilder.AppendLine("</table>");
                this.Page.Response.Clear();
                this.Page.Response.Buffer  = false;
                this.Page.Response.Charset = "GB2312";
                this.Page.Response.AppendHeader("Content-Disposition", "attachment;filename=VoucherInfo_" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
                this.Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                this.Page.Response.ContentType     = "application/ms-excel";
                this.Page.EnableViewState          = false;
                this.Page.Response.Write(stringBuilder.ToString());
                hiddenPwdtype.Value = "";
                this.Page.Response.End();
            }
        }
예제 #14
0
        /// <summary>
        /// 添加按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddVouchers_Click(object sender, System.EventArgs e)
        {
            string  text     = string.Empty;
            string  arg_0B_0 = string.Empty;
            decimal?amount;
            decimal discountValue;

            if (!this.ValidateValues(out amount, out discountValue))
            {
                return;
            }
            if (!this.calendarStartDate.SelectedDate.HasValue)
            {
                this.ShowMsg("请选择开始日期!", false);
                return;
            }
            if (!this.calendarEndDate.SelectedDate.HasValue)
            {
                this.ShowMsg("请选择结束日期!", false);
                return;
            }
            if (this.calendarStartDate.SelectedDate.Value.CompareTo(this.calendarEndDate.SelectedDate.Value) >= 0)
            {
                this.ShowMsg("开始日期不能晚于结束日期!", false);
                return;
            }

            string strValidity = this.txtValidity.Text;

            if (!Regex.IsMatch(strValidity, @"^[1-9][0-9]*$"))
            {
                this.ShowMsg(" 有效期只能是数字,必须大于等于O!", false);
                return;
            }

            string strOverMoney = txtOverMoney.Text;

            if (this.rdoOverMoney.Checked && !Regex.IsMatch(strOverMoney, @"^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$"))
            {
                this.ShowMsg(" 满足金额必须为正数,且最多只能有两位小数", false);
                return;
            }


            VoucherInfo voucherInfo = new VoucherInfo();

            voucherInfo.Name          = this.txtVoucherName.Text;
            voucherInfo.ClosingTime   = this.calendarEndDate.SelectedDate.Value.AddDays(1).AddSeconds(-1);
            voucherInfo.StartTime     = this.calendarStartDate.SelectedDate.Value;
            voucherInfo.Amount        = amount;
            voucherInfo.DiscountValue = discountValue;

            #region 发送方式
            int    SendType     = 0;
            string stroverMoney = string.Empty;
            if (this.rdoManually.Checked)
            {
                SendType = int.Parse(this.rdoManually.Value);
            }

            else if (this.rdoOverMoney.Checked)
            {
                SendType     = int.Parse(this.rdoOverMoney.Value);
                stroverMoney = txtOverMoney.Text.ToString();
            }

            else if (this.rdoRegist.Checked)
            {
                SendType = int.Parse(this.rdoRegist.Value);
            }

            else if (this.rdoLq.Checked)
            {
                SendType = int.Parse(this.rdoLq.Value);
            }


            #endregion

            voucherInfo.SendType     = SendType;
            voucherInfo.SendTypeItem = stroverMoney;
            voucherInfo.Validity     = int.Parse(this.txtValidity.Text);

            #region 字段限制验证,通过数据注解验证的方式
            ValidationResults validationResults = Validation.Validate <VoucherInfo>(voucherInfo, new string[]
            {
                "Voucher"
            });
            if (!validationResults.IsValid)
            {
                using (System.Collections.Generic.IEnumerator <ValidationResult> enumerator = ((System.Collections.Generic.IEnumerable <ValidationResult>)validationResults).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ValidationResult current = enumerator.Current;
                        text += Formatter.FormatErrorMessage(current.Message);
                        this.ShowMsg(text, false);
                        return;
                    }
                }
            }
            #endregion

            string empty = string.Empty;
            if (this.voucherId == 0)  //创建现金券
            {
                VoucherActionStatus voucherActionStatus = VoucherHelper.CreateVoucher(voucherInfo, 0, out empty, 1);
                if (voucherActionStatus == VoucherActionStatus.UnknowError)
                {
                    this.ShowMsg("未知错误", false);
                }
                else
                {
                    if (voucherActionStatus == VoucherActionStatus.DuplicateName)
                    {
                        this.ShowMsg("已经存在相同的现金券名称", false);
                        return;
                    }
                    if (voucherActionStatus == VoucherActionStatus.CreateClaimCodeError)
                    {
                        this.ShowMsg("生成现金券号码错误", false);
                        return;
                    }
                    this.ShowMsg("添加现金券成功", true);
                    this.RestCoupon();
                    return;
                }
            }

            else  //修改现金券
            {
                voucherInfo.VoucherId = this.voucherId;
                VoucherActionStatus voucherActionStatus = VoucherHelper.UpdateVoucher(voucherInfo);
                if (voucherActionStatus == VoucherActionStatus.Success)
                {
                    this.RestCoupon();
                    this.ShowMsg("成功修改了现金券信息", true);
                }
                else
                {
                    if (voucherActionStatus == VoucherActionStatus.DuplicateName)
                    {
                        this.ShowMsg("修改现金券信息错误,已经具有此现金券名称", false);
                        return;
                    }
                    this.ShowMsg("未知错误", false);
                    this.RestCoupon();
                    return;
                }
            }
        }