Пример #1
0
        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();
                        }
                    }
                }
            }
        }
Пример #2
0
        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();
            }
        }
Пример #3
0
        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();
                    }
                }
            }
        }