Beispiel #1
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();
            }
        }