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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/////////////////////////////////////////////////////////////////////////
// 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;
using System.Data;
using System.Data.OleDb;
namespace Aspose.Pdf.Demos
{
/// <summary>
/// Summary description for ProductsByCategory.
/// </summary>
public class ProductsByCategory
{
private OleDbCommand oleDbSelectCommand1;
private OleDbDataAdapter oleDbDataAdapter1;
private OleDbConnection oleDbConnection;
private DataTable dataTable1;
string path;
public ProductsByCategory(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.oleDbDataAdapter1 = new OleDbDataAdapter();
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbSelectCommand1.Connection = this.oleDbConnection;
this.oleDbConnection.Open();
}
public Aspose.Pdf.Generator.Pdf GetProductsByCategory()
{
string queryString ="SELECT Products.ProductName, Products.UnitsInStock FROM Products";
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\\ProductsByCategory.xml";
pdf.BindXML(xmlFile, null);
Section section = pdf.Sections["section1"];
Table table1 = new Aspose.Pdf.Generator.Table(section);
section.Paragraphs.Add(table1);
table1.ColumnWidths = "314 314 314";
table1.Border = new BorderInfo((int)BorderSide.Top, 4, new Aspose.Pdf.Generator.Color(204));
table1.IsRowBroken = false;
table1.DefaultCellPadding.Top = table1.DefaultCellPadding.Bottom = 15;
table1.DefaultCellTextInfo.FontSize = 14;
table1.Margin.Top = 10;
int j;
Row curRow = null;
Cell curCell = null;
Table curSubTab = null;
string[] names = new string[]
{"Catagory: Beverages","Catagory: Condiments","Catagory: Confections",
"Catagory: Dairy Products","Catagory: Grains/Cereals","Catagory: Meat/Poultry",
"Catagory: Produce","Catagory: Seafood"};
for(j=1;j<=8;j++)
{
if(j == 1 || j == 4 || j == 7)
curRow = table1.Rows.Add();
curCell = curRow.Cells.Add();
curSubTab = new Aspose.Pdf.Generator.Table(curCell);
curSubTab.DefaultCellPadding.Top = curSubTab.DefaultCellPadding.Bottom = 3;
curCell.Paragraphs.Add(curSubTab);
curSubTab.ColumnWidths = "214 90";
Row row0 = curSubTab.Rows.Add();
Aspose.Pdf.Generator.TextInfo tf1 = new Aspose.Pdf.Generator.TextInfo();
tf1.FontSize = 16;
tf1.FontName = "Times-Bold";
row0.Cells.Add(names[j-1],tf1);
this.oleDbSelectCommand1.CommandText = queryString +
" WHERE ((Products.Discontinued)=No AND((Products.CategoryID)=" +
j.ToString() + ")) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
curSubTab.ImportDataTable(dataTable1,true,1,0);
curSubTab.Rows[1].Border = new BorderInfo((int)(BorderSide.Top|BorderSide.Bottom),4,
new Aspose.Pdf.Generator.Color(204));
Row lastRow = curSubTab.Rows[curSubTab.Rows.Count-1];
foreach(Cell cCell in lastRow.Cells)
cCell.Padding.Bottom = 20;
lastRow = curSubTab.Rows.Add();
lastRow.Cells.Add("number of products:");
lastRow.Cells.Add(dataTable1.Rows.Count.ToString());
lastRow.Border = new BorderInfo((int)BorderSide.Top, new Aspose.Pdf.Generator.Color(204));
}
curRow.Cells.Add();
this.oleDbDataAdapter1.Dispose();
this.oleDbConnection.Close();
return pdf;
}
}
}
|