コード例 #1
0
        protected void buttonIssuePDF_Click(object sender, EventArgs e)
        {
            VoucherBatch batch;

            if (Request.QueryString["batchid"] != null)
            {
                batch = Module.GetObject <VoucherBatch>(Convert.ToInt32(Request.QueryString["batchid"]));
            }
            else
            {
                return;
            }

            var doc = new Document(Server.MapPath("/Userfiles/VoucherTemplates/" + ddlTemplates.SelectedValue));

            //var awPrintDoc = new AsposeWordsPrintDocument(doc);

            #region -- Generate docs --

            var table = new DataTable("Voucher");
            table.Columns.Add("VoucherName");
            table.Columns.Add("Agency");
            table.Columns.Add("ApplyFor");
            table.Columns.Add("Cruise");
            table.Columns.Add("Trip");
            table.Columns.Add("Value");
            table.Columns.Add("ValidUntil");
            table.Columns.Add("IssueDate");
            table.Columns.Add("Code");

            //double total = 0;
            for (int ii = 1; ii <= batch.Quantity; ii++)
            {
                DataRow row = table.NewRow();
                row["VoucherName"] = batch.Name;
                if (batch.Agency != null)
                {
                    row["Agency"] = batch.Agency.Name;
                }

                if (batch.NumberOfPerson == 1)
                {
                    row["ApplyFor"] = "Single person";
                }
                else
                {
                    row["ApplyFor"] = "02 PERSONS, 01 sharing cabin";
                }
                row["Cruise"]     = batch.Cruise.Name;
                row["Trip"]       = batch.Trip.Name;
                row["Value"]      = batch.Value;
                row["ValidUntil"] = batch.ValidUntil.ToString("dd/MM/yyyy");
                if (batch.IssueDate.HasValue)
                {
                    row["IssueDate"] = batch.IssueDate.Value.ToString("dd/MM/yyyy");
                }
                row["Code"] = VoucherCodeEncryption.Encrypt(Convert.ToUInt32(batch.Id * 1000 + ii));
                table.Rows.Add(row);
            }

            doc.MailMerge.Execute(table);

            Response.Clear();
            Response.Buffer      = true;
            Response.ContentType = "application/pdf";
            //Response.ContentType = "application/msword";
            Response.AppendHeader("content-disposition",
                                  "attachment; filename=" + string.Format("{0}.pdf", "voucher" + batch.Id));
            //                  "attachment; filename=" + string.Format("{0}.doc", "voucher" + batch.Id));

            var m = new MemoryStream();

            doc.Save(m, SaveFormat.Doc);

            Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();

            m.Close();
            Response.End();

            #endregion

            if (!batch.IssueDate.HasValue)
            {
                batch.IssueDate = DateTime.Today;
                batch.Issued    = true;
                Module.SaveOrUpdate(batch, UserIdentity);
            }
        }
コード例 #2
0
        protected void rptVouchers_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var value = (int)e.Item.DataItem;

            ValueBinder.BindLiteral(e.Item, "litCode", VoucherCodeEncryption.Encrypt(Convert.ToUInt32(value)));
        }