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 = "您已经领过该优惠券"; } }
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; } } }
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); } }
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(); } }