| |
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SalesTotalsForm.aspx.cs" Inherits="Aspose.Pdf.Demos.NorthwindForms.SalesTotalsForm" MasterPageFile="~/tpl/Demo.Master"
Title="Sales Totals by Amount - Aspose.Pdf Demos"%>
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server">
<p class="componentDescriptionTxt">
Click <b>Process</b> to see how example
generates document containing sales totals (by amount) based on Northwind database data
<br/>You can either open the resulting PDF file into your PDF reader
or save directly to your disk.
</p>
<asp:Button ID="btnProcess" runat="server" Text="Process" OnClick="btnProcess_Click" />
</asp:Content>
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Aspose.Pdf.Generator;
namespace Aspose.Pdf.Demos.NorthwindForms
{
public partial class SalesTotalsForm : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnProcess_Click(object sender, EventArgs e)
{
string path = GetResource(string.Empty); // Database is under RESOURCES
Aspose.Pdf.Generator.Pdf pdf;
SalesTotals salesTotals = new SalesTotals(path);
pdf = salesTotals.GetSalesTotals();
pdf.Save("salestotalsbyamount.pdf", SaveType.OpenInAcrobat, Response);
Response.End();
}
}
}
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2011 Aspose Pty Ltd. All rights reserved.
//
// This file is part of Aspose.Pdf. The source code in this file
// is only intended as a supplement to the documentation, and is provided
// "as is", without warranty of any kind, either expressed or implied.
/////////////////////////////////////////////////////////////////////////
using System;
using Aspose.Pdf.Generator;
using System.Globalization;
namespace Aspose.Pdf.Demos
{
/// <summary>
/// Summary description for SalesTotals.
/// </summary>
public class SalesTotals
{
private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
private System.Data.OleDb.OleDbDataReader resultReader;
private System.Data.OleDb.OleDbConnection oleDbConnection;
string path;
System.Globalization.CultureInfo locale = new System.Globalization.CultureInfo("en-US");
private string queryString = "SELECT DISTINCTROW [Order Subtotals].Subtotal,Orders.OrderID, " +
"Customers.CompanyName FROM Customers INNER JOIN (Orders INNER JOIN [Order Subtotals] ON " +
"Orders.OrderID = [Order Subtotals].OrderID) ON Customers.CustomerID = Orders.CustomerID " +
"WHERE (((Orders.ShippedDate) Is Not Null) AND Year(Orders.ShippedDate)=1997 AND " +
"[Order Subtotals].Subtotal>2500 ) ORDER BY [Order Subtotals].Subtotal DESC;";
public SalesTotals(string curPath)
{
path = curPath;
this.oleDbConnection = new System.Data.OleDb.OleDbConnection();
this.oleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path +
"\\Database\\Northwind.mdb";
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1.Connection = this.oleDbConnection;
this.oleDbConnection.Open();
}
public Aspose.Pdf.Generator.Pdf GetSalesTotals()
{
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
pdf.IsTruetypeFontMapCached = false;
// If you have purchased a license,
// Set license like this:
// string licenseFile = MapPath("License") + "\\Aspose.Pdf.lic";
// Aspose.Pdf.License lic = new Aspose.Pdf.License();
// lic.SetLicense(licenseFile);
string xmlFile = path + "\\Xml\\SalesTotals.xml";
pdf.BindXML(xmlFile, null);
Section section = pdf.Sections["section1"];
Aspose.Pdf.Generator.Text dataText = (Aspose.Pdf.Generator.Text)section.Paragraphs["Date"];
Segment segment1 = dataText.Segments[0];
DateTime dateTime = DateTime.Now;
segment1.Content = dateTime.ToString("d",DateTimeFormatInfo.InvariantInfo);
Table table = (Table)section.Paragraphs["table1"];
table.ColumnWidths = "80 70 180 70";
table.DefaultCellTextInfo.FontSize = 10;
table.DefaultCellPadding.Top = table.DefaultCellPadding.Bottom = 5;
this.oleDbSelectCommand1.CommandText = queryString;
resultReader = this.oleDbSelectCommand1.ExecuteReader();
string orderID,companyName;
float salesAmount;
int j = 0;
while(resultReader.Read())
{
salesAmount = (float)Convert.ToDouble(resultReader.GetValue(0));
orderID = Convert.ToString(resultReader.GetValue(1));
companyName = Convert.ToString(resultReader.GetValue(2));
AddRow(pdf,table,salesAmount.ToString("c",locale),orderID,companyName,(j+1).ToString());
j++;
}
this.oleDbConnection.Close();
return pdf;
}
private void AddRow(Aspose.Pdf.Generator.Pdf pdf, Aspose.Pdf.Generator.Table table, string s1, string s2, string s3, string s4)
{
Row row1 = table.Rows.Add();
Cell cell1 = row1.Cells.Add(s1);
((Aspose.Pdf.Generator.Text)cell1.Paragraphs[0]).TextInfo.Alignment = AlignmentType.Center;
Cell cell2 = row1.Cells.Add(s2);
((Aspose.Pdf.Generator.Text)cell2.Paragraphs[0]).TextInfo.Alignment = AlignmentType.Center;
Cell cell3 = row1.Cells.Add(s3);
Cell cell4 = row1.Cells.Add(s4);
((Aspose.Pdf.Generator.Text)cell4.Paragraphs[0]).TextInfo.Alignment = AlignmentType.Right;
}
}
}
|
|
|
|