private void Create() { var item = new Coupon(); item.Title = GetString("title"); var expiry = GetString("expire_date"); item.SellerId = GetInt("sellerid"); item.Expiry = expiry != "-1" ? GetTime("expire_date") : DateTime.Now.AddDays(1); item.ImgUrl = GetString("thumbnail"); item.Extcredit = GetInt("score"); item.FullMoney = GetInt("total"); item.DiscountMoney = GetInt("discount"); item.Enabled = 1; item.GoodsIds = Utility.GetListint(GetString("goods_selected")); item.Description = GetString("content"); var text = GetString("text"); item.Summary = text.Length > 20 ? text.Substring(0, 20) : text; //item.Summary = item.Description.Length > 20 ? item.Description.Substring(0, 20) : item.Description; CouponHelper.CreateCoupon(item); }
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 = CouponHelper.GetCoupon(couponId); string empty = string.Empty; CouponActionStatus couponActionStatus = CouponHelper.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 = CouponHelper.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(); } }
private void btnAddCoupons_Click(object sender, System.EventArgs e) { string text = string.Empty; decimal?amount; decimal discountValue; int needPoint; if (!this.ValidateValues(out amount, out discountValue, out needPoint)) { 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; } CouponInfo couponInfo = new CouponInfo(); 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; } } } string empty = string.Empty; CouponActionStatus couponActionStatus = CouponHelper.CreateCoupon(couponInfo, 0, out empty); if (couponActionStatus == CouponActionStatus.UnknowError) { this.ShowMsg("未知错误", false); } else { if (couponActionStatus == CouponActionStatus.DuplicateName) { this.ShowMsg("已经存在相同的优惠券名称", false); return; } if (couponActionStatus == CouponActionStatus.CreateClaimCodeError) { this.ShowMsg("生成优惠券号码错误", false); return; } this.ShowMsg("添加优惠券成功", true); this.RestCoupon(); return; } }
private void btnAddCoupons_Click(object sender, System.EventArgs e) { string msg = string.Empty; decimal?nullable; decimal num; int num2; 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(); if (CustomConfigHelper.Instance.IsSanzuo || (CustomConfigHelper.Instance.AutoShipping && CustomConfigHelper.Instance.AnonymousOrder)) { target.Name = this.txtCouponName.Text; target.ClosingTime = this.calendarEndDate.SelectedDate.Value; target.StartTime = this.calendarStartDate.SelectedDate.Value; if (this.DDLservice.SelectedValue != "未选择") { target.SenderId = Convert.ToInt32(this.DDLservice.SelectedValue); } else { target.SenderId = 0; } if (this.DDLcategory.SelectedValue != "未选择") { target.CategoryId = Convert.ToInt32(this.DDLcategory.SelectedValue); } else { target.CategoryId = 0; } target.Amount = nullable; target.DiscountValue = num; target.NeedPoint = num2; } else { 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 = Validation.Validate <CouponInfo>(target, new string[] { "ValCoupon" }); if (!results.IsValid) { using (System.Collections.Generic.IEnumerator <ValidationResult> enumerator = ((System.Collections.Generic.IEnumerable <ValidationResult>)results).GetEnumerator()) { if (enumerator.MoveNext()) { ValidationResult result = enumerator.Current; msg += Formatter.FormatErrorMessage(result.Message); this.ShowMsg(msg, false); return; } } } string lotNumber = string.Empty; //创建优惠券 CouponActionStatus status = CouponHelper.CreateCoupon(target, 0, out lotNumber); //创建微信卡包优惠券 //读取配置信息 if (false) //是否同时将生成的优惠券创建到到微信卡券内 { Hidistro.Membership.Context.SiteSettings masterSettings = Hidistro.Membership.Context.SettingsManager.GetMasterSettings(false); //CouponInfo coupon1 = CouponHelper.GetCoupon(couponId); WXCouponInfo wxCoupon = new WXCouponInfo(); wxCoupon.card.card_type = "GENERAL_COUPON"; wxCoupon.card.general_coupon.base_info.code_type = "CODE_TYPE_TEXT"; //wxCoupon.logo_url = Globals.DomainName + masterSettings.DistributorLogoPic; wxCoupon.card.general_coupon.base_info.logo_url = "http://yihui.ewaywin.com/Storage/data/DistributorLogoPic/20151125173959_6308.jpg"; wxCoupon.card.general_coupon.base_info.brand_name = masterSettings.SiteName; wxCoupon.card.general_coupon.base_info.title = "满" + target.Amount.ToString() + "减" + target.DiscountValue.ToString("0.00"); wxCoupon.card.general_coupon.base_info.sub_title = this.txtCouponName.Text; wxCoupon.card.general_coupon.base_info.color = "Color100"; wxCoupon.card.general_coupon.base_info.notice = "购买商品时使用"; wxCoupon.card.general_coupon.base_info.description = target.Description; wxCoupon.card.general_coupon.base_info.sku.quantity = 200; wxCoupon.card.general_coupon.base_info.date_info.type = "DATE_TYPE_FIX_TIME_RANGE"; wxCoupon.card.general_coupon.base_info.date_info.begin_timestamp = DateTimeToUnixTimestamp(target.StartTime); wxCoupon.card.general_coupon.base_info.date_info.end_timestamp = DateTimeToUnixTimestamp(target.ClosingTime); wxCoupon.card.general_coupon.base_info.use_custom_code = false; wxCoupon.card.general_coupon.default_detail = target.Name; string json = Newtonsoft.Json.JsonConvert.SerializeObject(wxCoupon, Newtonsoft.Json.Formatting.Indented); string access_token = Access_token.GetAccess_token(); //string access_token = "12j5h9jB21EEtpBkJKCtG3K10pZFXKAjDuM_CXJmvea6TdU_0YGCEaumhkClH0Wd3sq12901e6hqoA9VvTxemCSNUxtSoCwXSHrZ1Elb_v0CSQcAAAXNL"; Hidistro.UI.Web.API.wx.Post("https://api.weixin.qq.com/card/create?access_token=" + access_token, json); } if (status != CouponActionStatus.UnknowError) { CouponActionStatus couponActionStatus = status; if (couponActionStatus != CouponActionStatus.DuplicateName) { if (couponActionStatus != CouponActionStatus.CreateClaimCodeError) { this.ShowMsg("添加优惠券成功", true); this.RestCoupon(); } else { this.ShowMsg("生成优惠券号码错误", false); } } else { this.ShowMsg("已经存在相同的优惠券名称", false); } } else { this.ShowMsg("未知错误", false); } } } } } }
public void ProcessRequest(System.Web.HttpContext context) { context.Response.ContentType = "text/plain"; try { string text = context.Request["name"].ToString().Trim(); string val = context.Request["val"].ToString().Trim(); string val2 = context.Request["condition"].ToString().Trim(); string val3 = context.Request["begin"].ToString().Trim(); string val4 = context.Request["end"].ToString().Trim(); string val5 = context.Request["total"].ToString().Trim(); string value = context.Request["isAllMember"].ToString().Trim(); string text2 = context.Request["memberlvl"].ToString().Trim(); string text3 = context.Request["defualtGroup"].ToString().Trim(); string text4 = context.Request["customGroup"].ToString().Trim(); string val6 = context.Request["maxNum"].ToString().Trim(); string val7 = context.Request["type"].ToString().Trim(); string couponTypes = context.Request["couponType"].ToString().Trim(); decimal num = 0m; decimal num2 = 0m; System.DateTime now = System.DateTime.Now; System.DateTime now2 = System.DateTime.Now; int stockNum = 0; string memberGrades = ""; int maxReceivNum = 1; int num3 = 0; if (string.IsNullOrEmpty(text) || text.Length > 20) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券名称\"}"); } else { string couponName = text; if (!this.bDecimal(val, ref num)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券面值\"}"); } else if (!this.bDecimal(val2, ref num2)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券适用最大满足额\"}"); } else if (!this.bDate(val3, true, ref now)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的生效日期\"}"); } else if (!this.bDate(val4, false, ref now2)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的失效日期\"}"); } else if (!this.bInt(val5, ref stockNum)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券发放量\"}"); } else { bool flag = bool.Parse(value); if (!flag) { if (string.IsNullOrEmpty(text2) && string.IsNullOrEmpty(text3) && string.IsNullOrEmpty(text4)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请选择正确的会员等级\"}"); return; } memberGrades = text2; } if (!this.bInt(val6, ref maxReceivNum)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请选择正确的优惠券最大领取张数\"}"); } else { this.bInt(val7, ref num3); if (num2 < num && num2 != 0m) { context.Response.Write("{\"type\":\"error\",\"data\":\"优惠券面值不能大于满足金额\"}"); } else if (now2 < now) { context.Response.Write("{\"type\":\"error\",\"data\":\"优惠券失效日期不能早于生效日期\"}"); } else { CouponInfo couponInfo = new CouponInfo(); couponInfo.CouponName = couponName; couponInfo.CouponValue = num; couponInfo.ConditionValue = num2; couponInfo.BeginDate = now; couponInfo.EndDate = now2; couponInfo.StockNum = stockNum; couponInfo.IsAllProduct = (num3 == 0); if (flag) { couponInfo.MemberGrades = "0"; couponInfo.DefualtGroup = "0"; couponInfo.CustomGroup = "0"; } else { couponInfo.MemberGrades = memberGrades; couponInfo.DefualtGroup = text3; couponInfo.CustomGroup = text4; } couponInfo.maxReceivNum = maxReceivNum; couponInfo.CouponTypes = couponTypes; CouponActionStatus couponActionStatus = CouponHelper.CreateCoupon(couponInfo); if (couponActionStatus == CouponActionStatus.Success) { couponInfo = CouponHelper.GetCoupon(couponName); if (couponInfo != null) { context.Response.Write("{\"type\":\"success\",\"data\":\"" + couponInfo.CouponId.ToString() + "\"}"); } else { context.Response.Write("{\"type\":\"error\",\"data\":\"写数据库异常\"}"); } } else { context.Response.Write("{\"type\":\"error\",\"data\":\"" + this.GetErrMsg(couponActionStatus.ToString()) + "\"}"); } } } } } } catch (System.Exception ex) { context.Response.Write("{\"type\":\"error\",\"data\":\"" + ex.Message + "\"}"); } }
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 { Name = this.txtCouponName.Text, ClosingTime = this.calendarEndDate.SelectedDate.Value, StartTime = this.calendarStartDate.SelectedDate.Value, Amount = nullable, DiscountValue = num, 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 = CouponHelper.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); } } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { string str = context.Request["name"].ToString(); string val = context.Request["val"].ToString(); string str3 = context.Request["condition"].ToString(); string str4 = context.Request["begin"].ToString(); string str5 = context.Request["end"].ToString(); string str6 = context.Request["total"].ToString(); string str7 = context.Request["isAllMember"].ToString(); string str8 = context.Request["memberlvl"].ToString(); string str9 = context.Request["maxNum"].ToString(); string str10 = context.Request["type"].ToString(); string couponName = ""; decimal i = 0M; decimal num2 = 0M; DateTime now = DateTime.Now; DateTime time2 = DateTime.Now; int num3 = 0; bool flag = false; string str12 = ""; int num4 = 1; int num5 = 0; if (string.IsNullOrEmpty(str) || (str.Length > 20)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券名称\"}"); } else { couponName = str; if (!this.bDecimal(val, ref i)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券面值\"}"); } else if (!this.bDecimal(str3, ref num2)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券适用最大满足额\"}"); } else if (!this.bDate(str4, true, ref now)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的生效日期\"}"); } else if (!this.bDate(str5, false, ref time2)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的失效日期\"}"); } else if (!this.bInt(str6, ref num3)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券发放量\"}"); } else { flag = bool.Parse(str7); if (!flag) { if (string.IsNullOrEmpty(str8)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请选择正确的会员等级\"}"); return; } str12 = str8; } if (!this.bInt(str9, ref num4)) { context.Response.Write("{\"type\":\"error\",\"data\":\"请选择正确的优惠券最大领取张数\"}"); } else { this.bInt(str10, ref num5); if ((num2 < i) && (num2 != 0M)) { context.Response.Write("{\"type\":\"error\",\"data\":\"优惠券面值不能大于满足金额\"}"); } else if (time2 < now) { context.Response.Write("{\"type\":\"error\",\"data\":\"优惠券失效日期不能早于生效日期\"}"); } else { CouponInfo coupon = new CouponInfo { CouponName = couponName, CouponValue = i, ConditionValue = num2, BeginDate = now, EndDate = time2, StockNum = num3, IsAllProduct = (num5 == 0) ? true : false }; if (flag) { coupon.MemberGrades = "0"; } else { coupon.MemberGrades = str12; } coupon.maxReceivNum = num4; CouponActionStatus status = CouponHelper.CreateCoupon(coupon); if (status == CouponActionStatus.Success) { coupon = CouponHelper.GetCoupon(couponName); if (coupon != null) { context.Response.Write("{\"type\":\"success\",\"data\":\"" + coupon.CouponId.ToString() + "\"}"); } else { context.Response.Write("{\"type\":\"error\",\"data\":\"写数据库异常\"}"); } } else { context.Response.Write("{\"type\":\"error\",\"data\":\"" + this.GetErrMsg(status.ToString()) + "\"}"); } } } } } } catch (Exception exception) { context.Response.Write("{\"type\":\"error\",\"data\":\"" + exception.Message + "\"}"); } }
private void btnAddCoupons_Click(object sender, EventArgs e) { decimal num; decimal?nullable; int num2; int num3; string msg = string.Empty; if (ValidateValues(out nullable, out num, out num2, out num3)) { 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 = num; target.NeedPoint = num3; 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 = CouponHelper.CreateCoupon(target, num2, 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 = CouponHelper.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(); } } } } }
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 = CouponHelper.GetCoupon(num2); string lotNumber = string.Empty; CouponActionStatus status = CouponHelper.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 = CouponHelper.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 btnAddCoupons_Click(object sender, System.EventArgs e) { string msg = string.Empty; decimal?nullable; decimal num; int num2; 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 { Name = this.txtCouponName.Text, ClosingTime = this.calendarEndDate.SelectedDate.Value, StartTime = this.calendarStartDate.SelectedDate.Value, Amount = nullable, DiscountValue = num, NeedPoint = num2 }; ValidationResults results = Validation.Validate <CouponInfo>(target, new string[] { "ValCoupon" }); if (!results.IsValid) { using (System.Collections.Generic.IEnumerator <ValidationResult> enumerator = ((System.Collections.Generic.IEnumerable <ValidationResult>)results).GetEnumerator()) { if (enumerator.MoveNext()) { ValidationResult result = enumerator.Current; msg += Formatter.FormatErrorMessage(result.Message); this.ShowMsg(msg, false); return; } } } string lotNumber = string.Empty; CouponActionStatus status = CouponHelper.CreateCoupon(target, 0, out lotNumber); if (status != CouponActionStatus.UnknowError) { CouponActionStatus couponActionStatus = status; if (couponActionStatus != CouponActionStatus.DuplicateName) { if (couponActionStatus != CouponActionStatus.CreateClaimCodeError) { this.ShowMsg("添加优惠券成功", true); this.RestCoupon(); } else { this.ShowMsg("生成优惠券号码错误", false); } } else { this.ShowMsg("已经存在相同的优惠券名称", false); } } else { this.ShowMsg("未知错误", false); } } } } } }
private void btnAddCoupons_Click(object sender, System.EventArgs e) { string text = string.Empty; string arg_0B_0 = string.Empty; decimal?amount; decimal discountValue; int needPoint; int totalq; if (!this.ValidateValues(out amount, out discountValue, out needPoint, out totalq)) { return; } CouponInfo couponInfo = new CouponInfo(); #region 使用方式 int UseType = 0; if (this.rdoAll.Checked) { UseType = int.Parse(this.rdoAll.Value); } else if (this.rdoProduct.Checked) { UseType = int.Parse(this.rdoProduct.Value); } else if (this.rdoProductType.Checked) { UseType = int.Parse(this.rdoProductType.Value); } else if (this.rdoBrand.Checked) { UseType = int.Parse(this.rdoBrand.Value); } else if (this.rdoSupplier.Checked) { UseType = int.Parse(this.rdoSupplier.Value); } #endregion #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); } else if (this.rdorefund.Checked) { SendType = int.Parse(this.rdorefund.Value); } else if (this.rdZC.Checked) { SendType = int.Parse(this.rdZC.Value); } #endregion if (SendType != 4) { if (!this.calendarStartDate.SelectedDate.HasValue) { this.ShowMsg("请选择开始日期!", false); return; } if (!this.calendarEndDate.SelectedDate.HasValue) { this.ShowMsg("请选择结束日期!", false); return; } if (this.calendarStartDate.SelectedDate.Value.Date.CompareTo(this.calendarEndDate.SelectedDate.Value.Date) > 0) { this.ShowMsg("开始日期不能晚于结束日期!", 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; } if (string.IsNullOrEmpty(base.Request.Form["selectProductsinfo"]) && this.rdoProduct.Checked) { this.ShowMsg("请选择商品", false); return; } if (!this.outBeginDate.SelectedDate.HasValue) { this.ShowMsg("请选择发劵开始日期!", false); return; } if (!this.outEndDate.SelectedDate.HasValue) { this.ShowMsg("请选择发劵结束日期!", false); return; } if (this.outBeginDate.SelectedDate.Value.Date.CompareTo(this.outEndDate.SelectedDate.Value.Date) > 0) { this.ShowMsg("发劵开始日期不能晚于发劵结束日期!", false); return; } if (SendType != 4) { if (this.outEndDate.SelectedDate.Value.Date.CompareTo(this.calendarEndDate.SelectedDate.Value.Date) > 0) { this.ShowMsg("发劵结束日期不能晚于使用结束日期!", false); return; } } string strValidity = this.txtValidity.Text; if (!string.IsNullOrWhiteSpace(strValidity)) { if (!Regex.IsMatch(strValidity, @"^[1-9][0-9]*$")) { this.ShowMsg(" 有效期只能是数字,必须大于O!", false); return; } } couponInfo.Name = this.txtCouponName.Text; couponInfo.ClosingTime = (SendType == 4 ? Convert.ToDateTime("1/1/1753 12:00:00") : this.calendarEndDate.SelectedDate.Value.AddDays(1).AddSeconds(-1)); couponInfo.StartTime = (SendType == 4 ? Convert.ToDateTime("1/1/1753 12:00:00") : this.calendarStartDate.SelectedDate.Value); couponInfo.Amount = amount; couponInfo.DiscountValue = discountValue; couponInfo.NeedPoint = needPoint; couponInfo.OutBeginDate = this.outBeginDate.SelectedDate.Value; couponInfo.OutEndDate = this.outEndDate.SelectedDate.Value; couponInfo.TotalQ = totalq; couponInfo.Remark = this.txtRemark.Text; if (!string.IsNullOrEmpty(txtValidity.Text.Trim())) { couponInfo.Validity = int.Parse(this.txtValidity.Text); } if (this.rdoSDisEnable.Checked) { couponInfo.Status = int.Parse(this.rdoSDisEnable.Value); } else { couponInfo.Status = 1; } 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; } } } string empty = string.Empty; int newcouponId = 0; couponInfo.UseType = UseType; couponInfo.SendType = SendType; couponInfo.SendTypeItem = stroverMoney; #region 添加优惠券 if (this.couponId == 0) { CouponActionStatus couponActionStatus = CouponHelper.CreateCoupon(couponInfo, 0, out empty, out newcouponId); if (couponActionStatus == CouponActionStatus.UnknowError) { this.ShowMsg("未知错误", false); } else { //if (couponActionStatus == CouponActionStatus.DuplicateName) //{ // this.ShowMsg("已经存在相同的优惠券名称", false); // return; //} if (couponActionStatus == CouponActionStatus.CreateClaimCodeError) { this.ShowMsg("生成优惠券号码错误", false); return; } #region 插入优惠券子表 switch (UseType) { case 0: break; case 1: string productselectList = base.Request.Form["selectProductsinfo"]; string[] array = productselectList.Split(new char[] { ',' }); for (int i = 0; i < array.Length; i++) { //string text2 = array[i]; //string[] array2 = text2.Split(new char[] { '|' }); CouponsSendTypeItem senditem = new CouponsSendTypeItem(); senditem.CouponId = newcouponId; senditem.BindId = System.Convert.ToInt32(array[i]); senditem.UserId = HiContext.Current.User.UserId; CouponHelper.CreateCouponsSendTypeItem(senditem); } break; case 2: string producttypeList = base.Request.Form["ProductTypelist"]; string[] arrayproducttype = producttypeList.Split(new char[] { ',' }); for (int i = 0; i < arrayproducttype.Length; i++) { CouponsSendTypeItem senditem = new CouponsSendTypeItem(); senditem.CouponId = newcouponId; senditem.BindId = System.Convert.ToInt32(arrayproducttype[i]); senditem.UserId = HiContext.Current.User.UserId; CouponHelper.CreateCouponsSendTypeItem(senditem); } break; case 3: foreach (var item in dcBrand) { CouponsSendTypeItem senditem = new CouponsSendTypeItem(); senditem.CouponId = newcouponId; senditem.BindId = item.Key; senditem.UserId = HiContext.Current.User.UserId; CouponHelper.CreateCouponsSendTypeItem(senditem); } break; case 4: foreach (var item in dcSupplier) { CouponsSendTypeItem senditem = new CouponsSendTypeItem(); senditem.CouponId = newcouponId; senditem.BindId = item.Key; senditem.UserId = HiContext.Current.User.UserId; CouponHelper.CreateCouponsSendTypeItem(senditem); } break; default: break; } #endregion this.ShowMsg("添加优惠券成功", true); this.RestCoupon(); return; } } #endregion #region 编辑优惠券 else { couponInfo.CouponId = this.couponId; CouponActionStatus couponActionStatus = CouponHelper.NewUpdateCoupon(couponInfo); if (couponActionStatus == CouponActionStatus.UnknowError) { this.ShowMsg("未知错误", false); } else { if (couponActionStatus == CouponActionStatus.DuplicateName) { this.ShowMsg("已经存在相同的优惠券名称", false); return; } if (couponActionStatus == CouponActionStatus.CreateClaimCodeError) { this.ShowMsg("生成优惠券号码错误", false); return; } //删除原来的子表信息 CouponHelper.DeleteCouponSendTypeItem(this.couponId); #region 插入优惠券子表 switch (UseType) { case 0: break; case 1: string productselectList = base.Request.Form["selectProductsinfo"]; string[] array = productselectList.Split(new char[] { ',' }); for (int i = 0; i < array.Length; i++) { //string text2 = array[i]; //string[] array2 = text2.Split(new char[] { '|' }); CouponsSendTypeItem senditem = new CouponsSendTypeItem(); senditem.CouponId = this.couponId; senditem.BindId = System.Convert.ToInt32(array[i]); senditem.UserId = HiContext.Current.User.UserId; CouponHelper.CreateCouponsSendTypeItem(senditem); } break; case 2: string producttypeList = base.Request.Form["ProductTypelist"]; string[] arrayproducttype = producttypeList.Split(new char[] { ',' }); for (int i = 0; i < arrayproducttype.Length; i++) { CouponsSendTypeItem senditem = new CouponsSendTypeItem(); senditem.CouponId = this.couponId; senditem.BindId = System.Convert.ToInt32(arrayproducttype[i]); senditem.UserId = HiContext.Current.User.UserId; CouponHelper.CreateCouponsSendTypeItem(senditem); } break; case 3: foreach (var item in dcBrand) { CouponsSendTypeItem senditem = new CouponsSendTypeItem(); senditem.CouponId = this.couponId; senditem.BindId = item.Key; senditem.UserId = HiContext.Current.User.UserId; CouponHelper.CreateCouponsSendTypeItem(senditem); } break; case 4: foreach (var item in dcSupplier) { CouponsSendTypeItem senditem = new CouponsSendTypeItem(); senditem.CouponId = this.couponId; senditem.BindId = item.Key; senditem.UserId = HiContext.Current.User.UserId; CouponHelper.CreateCouponsSendTypeItem(senditem); } break; default: break; } #endregion this.ShowMsg("编辑优惠券成功", true); this.RestCoupon(); return; } } #endregion }