protected void Page_Load(object sender, EventArgs e) { if (!int.TryParse(Page.Request.QueryString["couponId"], out couponId)) { base.GotoResourceNotFound(); } else { if (!Page.IsPostBack) { CouponInfo coupon = SubsiteCouponHelper.GetCoupon(couponId); if (coupon == null) { base.GotoResourceNotFound(); } else { Globals.EntityCoding(coupon, false); lblEditCouponId.Text = coupon.CouponId.ToString(); txtCouponName.Text = coupon.Name; if (coupon.Amount.HasValue) { txtAmount.Text = string.Format("{0:F2}", coupon.Amount); } txtDiscountValue.Text = coupon.DiscountValue.ToString("F2"); calendarEndDate.SelectedDate = new DateTime?(coupon.ClosingTime); txtNeedPoint.Text = coupon.NeedPoint.ToString(); } } } }
protected void Page_Load(object sender, System.EventArgs e) { if (!int.TryParse(this.Page.Request.QueryString["couponId"], out this.couponId)) { base.GotoResourceNotFound(); return; } this.btnEditCoupons.Click += new System.EventHandler(this.btnEditCoupons_Click); if (!this.Page.IsPostBack) { CouponInfo coupon = SubsiteCouponHelper.GetCoupon(this.couponId); if (coupon == null) { base.GotoResourceNotFound(); return; } if (coupon.ClosingTime.CompareTo(System.DateTime.Now) < 0) { this.ShowMsg("该优惠券已经结束!", false); return; } Globals.EntityCoding(coupon, false); this.lblEditCouponId.Text = coupon.CouponId.ToString(); this.txtCouponName.Text = coupon.Name; if (coupon.Amount.HasValue) { this.txtAmount.Text = string.Format("{0:F2}", coupon.Amount); } this.txtDiscountValue.Text = coupon.DiscountValue.ToString("F2"); this.calendarEndDate.SelectedDate = new System.DateTime?(coupon.ClosingTime); this.calendarStartDate.SelectedDate = new System.DateTime?(coupon.StartTime); this.txtNeedPoint.Text = coupon.NeedPoint.ToString(); } }
private void btnSend_Click(object sender, EventArgs e) { CouponItemInfo item = new CouponItemInfo(); IList <CouponItemInfo> listCouponItem = new List <CouponItemInfo>(); IList <Member> memdersByNames = new List <Member>(); if (this.rdoName.Checked) { if (!string.IsNullOrEmpty(this.txtMemberNames.Text.Trim())) { IList <string> names = new List <string>(); string[] strArray = this.txtMemberNames.Text.Trim().Replace("\r\n", "\n").Replace("\n", "*").Split(new char[] { '*' }); for (int i = 0; i < strArray.Length; i++) { if (this.IsMembers(strArray[i])) { names.Add(strArray[i]); } } memdersByNames = SubsitePromoteHelper.GetMemdersByNames(names); } string claimCode = string.Empty; foreach (Member member in memdersByNames) { claimCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); item = new CouponItemInfo(this.couponId, claimCode, new int?(member.UserId), member.Username, member.Email, DateTime.Now); listCouponItem.Add(item); } if (listCouponItem.Count <= 0) { this.ShowMsg("你输入的会员名中没有一个正确的,请输入正确的会员名", false); return; } SubsiteCouponHelper.SendClaimCodes(this.couponId, listCouponItem); this.txtMemberNames.Text = string.Empty; this.ShowMsg(string.Format("此次发送操作已成功,优惠券发送数量:{0}", listCouponItem.Count), true); } if (this.rdoRank.Checked) { memdersByNames = SubsitePromoteHelper.GetMembersByRank(this.rankList.SelectedValue); string str3 = string.Empty; foreach (Member member2 in memdersByNames) { str3 = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); item = new CouponItemInfo(this.couponId, str3, new int?(member2.UserId), member2.Username, member2.Email, DateTime.Now); listCouponItem.Add(item); } if (listCouponItem.Count <= 0) { this.ShowMsg("您选择的会员等级下面没有会员", false); } else { SubsiteCouponHelper.SendClaimCodes(this.couponId, listCouponItem); this.txtMemberNames.Text = string.Empty; this.ShowMsg(string.Format("此次发送操作已成功,优惠券发送数量:{0}", listCouponItem.Count), true); } } }
private void btnEditCoupons_Click(object sender, EventArgs e) { decimal num; decimal?nullable; int num2; if (this.ValidateValues(out nullable, out num, out num2)) { if (!this.calendarEndDate.SelectedDate.HasValue) { this.ShowMsg("请选择结束日期!", false); } else if (this.calendarStartDate.SelectedDate.Value.CompareTo(this.calendarEndDate.SelectedDate.Value) >= 0) { this.ShowMsg("开始日期不能晚于结束日期!", false); } else { string msg = string.Empty; CouponInfo target = new CouponInfo(); target.CouponId = this.couponId; target.Name = this.txtCouponName.Text; target.ClosingTime = this.calendarEndDate.SelectedDate.Value; target.StartTime = this.calendarStartDate.SelectedDate.Value; target.Amount = nullable; target.DiscountValue = num; target.NeedPoint = num2; ValidationResults results = Hishop.Components.Validation.Validation.Validate <CouponInfo>(target, new string[] { "ValCoupon" }); if (!results.IsValid) { foreach (ValidationResult result in (IEnumerable <ValidationResult>)results) { msg = msg + Formatter.FormatErrorMessage(result.Message); this.ShowMsg(msg, false); return; } } CouponActionStatus status = SubsiteCouponHelper.UpdateCoupon(target); if (status == CouponActionStatus.Success) { this.RestCoupon(); this.ShowMsg("成功修改了优惠券信息", true); } else if (status == CouponActionStatus.DuplicateName) { this.ShowMsg("修改优惠券信息错误,已经具有此优惠券名称", false); } else { this.ShowMsg("未知错误", false); this.RestCoupon(); } } } }
private void BindCoupons() { Pagination page = new Pagination(); page.PageSize = pageSize; page.PageIndex = pageIndex; DbQueryResult newCoupons = SubsiteCouponHelper.GetNewCoupons(page); grdCoupons.DataSource = newCoupons.Data; grdCoupons.DataBind(); pager.TotalRecords = newCoupons.TotalRecords; }
private void grdCoupons_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e) { int couponId = (int)this.grdCoupons.DataKeys[e.RowIndex].Value; if (SubsiteCouponHelper.DeleteCoupon(couponId)) { this.BindCoupons(); this.ShowMsg("成功删除了选定张优惠券", true); return; } this.ShowMsg("删除优惠券失败", false); }
private void BindCoupons() { DbQueryResult newCoupons = SubsiteCouponHelper.GetNewCoupons(new Pagination { PageSize = this.pageSize, PageIndex = this.pageIndex }); this.grdCoupons.DataSource = newCoupons.Data; this.grdCoupons.DataBind(); this.pager.TotalRecords = newCoupons.TotalRecords; }
private void grdCoupons_RowDeleting(object sender, GridViewDeleteEventArgs e) { int couponId = (int)grdCoupons.DataKeys[e.RowIndex].Value; if (SubsiteCouponHelper.DeleteCoupon(couponId)) { BindCoupons(); ShowMsg("成功删除了选定张优惠券", true); } else { ShowMsg("删除优惠券失败", false); } }
private void btnEditCoupons_Click(object sender, System.EventArgs e) { decimal?amount; decimal discountValue; int needPoint; if (!this.ValidateValues(out amount, out discountValue, out needPoint)) { 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 text = string.Empty; CouponInfo couponInfo = new CouponInfo(); couponInfo.CouponId = this.couponId; couponInfo.Name = this.txtCouponName.Text; couponInfo.ClosingTime = this.calendarEndDate.SelectedDate.Value; couponInfo.StartTime = this.calendarStartDate.SelectedDate.Value; couponInfo.Amount = amount; couponInfo.DiscountValue = discountValue; couponInfo.NeedPoint = needPoint; ValidationResults validationResults = Validation.Validate <CouponInfo>(couponInfo, new string[] { "ValCoupon" }); 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; } } } CouponActionStatus couponActionStatus = SubsiteCouponHelper.UpdateCoupon(couponInfo); if (couponActionStatus == CouponActionStatus.Success) { this.RestCoupon(); this.ShowMsg("成功修改了优惠券信息", true); } else { if (couponActionStatus == CouponActionStatus.DuplicateName) { this.ShowMsg("修改优惠券信息错误,已经具有此优惠券名称", false); return; } this.ShowMsg("未知错误", false); this.RestCoupon(); return; } }
protected void btnExport_Click(object sender, System.EventArgs e) { int num; if (!int.TryParse(this.tbcouponNum.Text, out num)) { this.ShowMsg("导出数量必须为正数", false); return; } if (num <= 0) { this.ShowMsg("导出数量必须为正数", false); return; } int couponId; if (!int.TryParse(this.txtcouponid.Value, out couponId)) { this.ShowMsg("参数错误", false); return; } CouponInfo coupon = SubsiteCouponHelper.GetCoupon(couponId); string empty = string.Empty; CouponActionStatus couponActionStatus = SubsiteCouponHelper.CreateCoupon(coupon, num, out empty); if (couponActionStatus == CouponActionStatus.UnknowError) { this.ShowMsg("未知错误", false); return; } if (couponActionStatus == CouponActionStatus.CreateClaimCodeError) { this.ShowMsg("生成优惠券号码错误", false); return; } if (couponActionStatus == CouponActionStatus.CreateClaimCodeSuccess && !string.IsNullOrEmpty(empty)) { System.Collections.Generic.IList <CouponItemInfo> couponItemInfos = SubsiteCouponHelper.GetCouponItemInfos(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 (CouponItemInfo current in couponItemInfos) { stringBuilder.AppendLine("<tr>"); stringBuilder.AppendLine("<td>" + empty + "</td>"); stringBuilder.AppendLine("<td>" + current.ClaimCode + "</td>"); stringBuilder.AppendLine("<td>" + coupon.DiscountValue + "</td>"); stringBuilder.AppendLine("<td>" + coupon.ClosingTime + "</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=CouponsInfo_" + 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()); this.Page.Response.End(); } }
protected void btnExport_Click(object sender, EventArgs e) { int num; if (!int.TryParse(this.tbcouponNum.Text, out num)) { this.ShowMsg("导出数量必须为正数", false); } else if (num <= 0) { this.ShowMsg("导出数量必须为正数", false); } else { int num2; if (!int.TryParse(this.txtcouponid.Value, out num2)) { this.ShowMsg("参数错误", false); } else { CouponInfo coupon = SubsiteCouponHelper.GetCoupon(num2); string lotNumber = string.Empty; CouponActionStatus status = SubsiteCouponHelper.CreateCoupon(coupon, num, out lotNumber); switch (status) { case CouponActionStatus.UnknowError: this.ShowMsg("未知错误", false); return; case CouponActionStatus.CreateClaimCodeError: this.ShowMsg("生成优惠券号码错误", false); return; } if ((status == CouponActionStatus.CreateClaimCodeSuccess) && !string.IsNullOrEmpty(lotNumber)) { IList <CouponItemInfo> couponItemInfos = SubsiteCouponHelper.GetCouponItemInfos(lotNumber); StringBuilder builder = new StringBuilder(); builder.AppendLine("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\" border=\"1\">"); builder.AppendLine("<tr style=\"font-weight: bold; white-space: nowrap;\">"); builder.AppendLine("<td>优惠券批次号</td>"); builder.AppendLine("<td>优惠券号码</td>"); builder.AppendLine("<td>优惠券金额</td>"); builder.AppendLine("<td>过期时间</td>"); builder.AppendLine("</tr>"); foreach (CouponItemInfo info2 in couponItemInfos) { builder.AppendLine("<tr>"); builder.AppendLine("<td>" + lotNumber + "</td>"); builder.AppendLine("<td>" + info2.ClaimCode + "</td>"); builder.AppendLine("<td>" + coupon.DiscountValue + "</td>"); builder.AppendLine("<td>" + coupon.ClosingTime + "</td>"); builder.AppendLine("</tr>"); } builder.AppendLine("</table>"); this.Page.Response.Clear(); this.Page.Response.Buffer = false; this.Page.Response.Charset = "GB2312"; this.Page.Response.AppendHeader("Content-Disposition", "attachment;filename=CouponsInfo_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); this.Page.Response.ContentEncoding = Encoding.GetEncoding("GB2312"); this.Page.Response.ContentType = "application/ms-excel"; this.Page.EnableViewState = false; this.Page.Response.Write(builder.ToString()); this.Page.Response.End(); } } } }
private void btnSend_Click(object sender, System.EventArgs e) { CouponItemInfo item = new CouponItemInfo(); System.Collections.Generic.IList <CouponItemInfo> list = new System.Collections.Generic.List <CouponItemInfo>(); System.Collections.Generic.IList <Hidistro.Membership.Context.Member> list2 = new System.Collections.Generic.List <Hidistro.Membership.Context.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++) { if (this.IsMembers(array[i])) { list3.Add(array[i]); } } list2 = SubsitePromoteHelper.GetMemdersByNames(list3); } string claimCode = string.Empty; foreach (Hidistro.Membership.Context.Member current in list2) { claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); item = new CouponItemInfo(this.couponId, claimCode, new int?(current.UserId), current.Username, current.Email, System.DateTime.Now); list.Add(item); } if (list.Count <= 0) { this.ShowMsg("你输入的会员名中没有一个正确的,请输入正确的会员名", false); return; } SubsiteCouponHelper.SendClaimCodes(this.couponId, list); this.txtMemberNames.Text = string.Empty; this.ShowMsg(string.Format("此次发送操作已成功,优惠券发送数量:{0}", list.Count), true); } if (this.rdoRank.Checked) { list2 = SubsitePromoteHelper.GetMembersByRank(this.rankList.SelectedValue); string claimCode2 = string.Empty; foreach (Hidistro.Membership.Context.Member current2 in list2) { claimCode2 = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); item = new CouponItemInfo(this.couponId, claimCode2, new int?(current2.UserId), current2.Username, current2.Email, System.DateTime.Now); list.Add(item); } if (list.Count <= 0) { this.ShowMsg("您选择的会员等级下面没有会员", false); return; } SubsiteCouponHelper.SendClaimCodes(this.couponId, list); this.txtMemberNames.Text = string.Empty; this.ShowMsg(string.Format("此次发送操作已成功,优惠券发送数量:{0}", list.Count), true); } }
private void btnAddCoupons_Click(object sender, EventArgs e) { decimal num; decimal?nullable; int num2; string msg = string.Empty; if (this.ValidateValues(out nullable, out num, out num2)) { if (!this.calendarStartDate.SelectedDate.HasValue) { this.ShowMsg("请选择开始日期!", false); } else if (!this.calendarEndDate.SelectedDate.HasValue) { this.ShowMsg("请选择结束日期!", false); } else if (this.calendarStartDate.SelectedDate.Value.CompareTo(this.calendarEndDate.SelectedDate.Value) >= 0) { this.ShowMsg("开始日期不能晚于结束日期!", false); } else { CouponInfo target = new CouponInfo(); target.Name = this.txtCouponName.Text; target.ClosingTime = this.calendarEndDate.SelectedDate.Value; target.StartTime = this.calendarStartDate.SelectedDate.Value; target.Amount = nullable; target.DiscountValue = num; target.NeedPoint = num2; ValidationResults results = Hishop.Components.Validation.Validation.Validate <CouponInfo>(target, new string[] { "ValCoupon" }); if (!results.IsValid) { foreach (ValidationResult result in (IEnumerable <ValidationResult>)results) { msg = msg + Formatter.FormatErrorMessage(result.Message); this.ShowMsg(msg, false); return; } } string lotNumber = string.Empty; CouponActionStatus status = SubsiteCouponHelper.CreateCoupon(target, 0, out lotNumber); if (status != CouponActionStatus.UnknowError) { switch (status) { case CouponActionStatus.DuplicateName: this.ShowMsg("已经存在相同的优惠券名称", false); return; case CouponActionStatus.CreateClaimCodeError: this.ShowMsg("生成优惠券号码错误", false); return; } this.ShowMsg("添加优惠券成功", true); this.RestCoupon(); } else { this.ShowMsg("未知错误", false); } } } }
protected void btnAddCoupons_Click(object sender, EventArgs e) { decimal discount; decimal?nullable; int count; int needPoint; string msg = string.Empty; if (ValidateValues(out nullable, out discount, out count, out needPoint)) { if (!calendarEndDate.SelectedDate.HasValue) { ShowMsg("请选择结束日期!", false); } else { CouponInfo target = new CouponInfo(); target.Name = txtCouponName.Text; target.ClosingTime = calendarEndDate.SelectedDate.Value; target.Amount = nullable; target.DiscountValue = discount; target.NeedPoint = needPoint; ValidationResults results = Hishop.Components.Validation.Validation.Validate <CouponInfo>(target, new string[] { "ValCoupon" }); if (!results.IsValid) { foreach (ValidationResult result in (IEnumerable <ValidationResult>)results) { msg = msg + Formatter.FormatErrorMessage(result.Message); ShowMsg(msg, false); return; } } string lotNumber = string.Empty; CouponActionStatus status = SubsiteCouponHelper.CreateCoupon(target, count, out lotNumber); if (status == CouponActionStatus.UnknowError) { ShowMsg("未知错误", false); } else { CouponActionStatus status2 = status; if (status2 == CouponActionStatus.DuplicateName) { ShowMsg("已经存在相同的优惠券名称", false); } else if (status2 == CouponActionStatus.CreateClaimCodeError) { ShowMsg("生成优惠券号码错误", false); } else { if ((status == CouponActionStatus.CreateClaimCodeSuccess) && !string.IsNullOrEmpty(lotNumber)) { IList <CouponItemInfo> couponItemInfos = SubsiteCouponHelper.GetCouponItemInfos(lotNumber); StringWriter writer = new StringWriter(); writer.WriteLine("优惠券批次号\t优惠券号码\t优惠券金额\t过期时间"); foreach (CouponItemInfo info2 in couponItemInfos) { string str3 = string.Concat(new object[] { lotNumber, "\t", info2.ClaimCode, "\t", target.DiscountValue, "\t", target.ClosingTime }); writer.WriteLine(str3); } writer.Close(); Page.Response.AddHeader("Content-Disposition", "attachment; filename=CouponsInfo_" + DateTime.Now + ".xls"); Page.Response.ContentType = "application/ms-excel"; Page.Response.ContentEncoding = Encoding.GetEncoding("GB2312"); Page.Response.Write(writer); Page.Response.End(); } ShowMsg("添加优惠卷成功", true); RestCoupon(); } } } } }