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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/////////////////////////////////////////////////////////////////////////
// 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 Catalog.
/// </summary>
public class Catalog
{
private OleDbCommand oleDbSelectCommand1;
private OleDbDataAdapter oleDbDataAdapter1;
private OleDbConnection oleDbConnection;
private DataTable dataTable1;
string path;
NumberFormatInfo format;
public Catalog(string curPath)
{
path = curPath;
format = new NumberFormatInfo();
format.CurrencyPositivePattern = 0;
format.CurrencySymbol = "$";
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.oleDbDataAdapter1 = new OleDbDataAdapter();
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbSelectCommand1.Connection = this.oleDbConnection;
this.oleDbConnection.Open();
}
public Aspose.Pdf.Generator.Pdf GetCatalog()
{
string queryString = "SELECT DISTINCTROW Products.ProductName, Products.ProductID, " +
"Products.QuantityPerUnit, Products.UnitPrice FROM Categories INNER JOIN Products ON " +
"Categories.CategoryID = Products.CategoryID WHERE (((Products.Discontinued)=No) AND " +
"((Categories.CategoryID)=";
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\\Catalog.xml";
pdf.BindXML(xmlFile, null);
Section section = pdf.Sections["section1"];
Paragraph logoPara = section.Paragraphs["Logo"];
Image logoImage = (Image)logoPara;
logoImage.ImageInfo.File = path + "\\Images\\FallCatalog.jpg";
logoImage.ImageScale = 0.77F;
Section section2 = pdf.Sections["section2"];
Paragraph beveragePara = section2.Paragraphs["BeverageTable"];
Table beverageTable = (Table)beveragePara;
Row row1 = beverageTable.Rows[0];
Cell row1Cell2 = row1.Cells[1];
Image beverageImage = (Image)row1Cell2.Paragraphs[0];
beverageImage.ImageInfo.File = path + "\\Images\\Beverage.jpg";
Table beveragesTable1 = (Table)section2.Paragraphs["BeverageTable1"];
this.oleDbSelectCommand1.CommandText = queryString + "1)) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
FillTable(beveragesTable1,dataTable1);
Paragraph condimentsPara = section2.Paragraphs["CondimentsTable"];
Table condimentsTable = (Table)condimentsPara;
Row row1CondimentTable = condimentsTable.Rows[0];
Cell row1Cell2CondimentTable = row1CondimentTable.Cells[1];
Image condimentsImage = (Image)row1Cell2CondimentTable.Paragraphs[0];
condimentsImage.ImageInfo.File = path + "\\Images\\Condiments.jpg";
Table condimentsTable1 = (Table)section2.Paragraphs["CondimentsTable1"];
this.oleDbSelectCommand1.CommandText = queryString + "2)) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
FillTable(condimentsTable1,dataTable1);
Paragraph confectionsPara = section2.Paragraphs["ConfectionsTable"];
Table confectionsTable = (Table)confectionsPara;
Row row1ConfectionsTable = confectionsTable.Rows[0];
Cell row1Cell2ConfectionsTable = row1ConfectionsTable.Cells[1];
Image confectionsImage = (Image)row1Cell2ConfectionsTable.Paragraphs[0];
confectionsImage.ImageInfo.File = path + "\\Images\\Confections.jpg";
Table confectionsTable1 = (Table)section2.Paragraphs["ConfectionsTable1"];
this.oleDbSelectCommand1.CommandText = queryString + "3)) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
FillTable(confectionsTable1,dataTable1);
Paragraph dairyPara = section2.Paragraphs["DairyTable"];
Table dairyTable = (Table)dairyPara;
Row row1DairyTable = dairyTable.Rows[0];
Cell row1Cell2DairyTable = row1DairyTable.Cells[1];
Image diaryImage = (Image)row1Cell2DairyTable.Paragraphs[0];
diaryImage.ImageInfo.File = path + "\\Images\\Dairy.jpg";
Table dairyTable1 = (Table)section2.Paragraphs["DairyTable1"];
this.oleDbSelectCommand1.CommandText = queryString + "4)) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
FillTable(dairyTable1,dataTable1);
Paragraph grainsPara = section2.Paragraphs["GrainsTable"];
Table grainsTable = (Table)grainsPara;
Row row1GrainsTable = grainsTable.Rows[0];
Cell row1Cell2GrainsTable = row1GrainsTable.Cells[1];
Image grainsImage = (Image)row1Cell2GrainsTable.Paragraphs[0];
grainsImage.ImageInfo.File = path + "\\Images\\Grains.jpg";
Table grainsTable1 = (Table)section2.Paragraphs["GrainsTable1"];
this.oleDbSelectCommand1.CommandText = queryString + "5)) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
FillTable(grainsTable1,dataTable1);
Paragraph meatPara = section2.Paragraphs["MeatTable"];
Table meatTable = (Table)meatPara;
Row row1MeatTable = meatTable.Rows[0];
Cell row1Cell2MeatTable = row1MeatTable.Cells[1];
Image meatImage = (Image)row1Cell2MeatTable.Paragraphs[0];
meatImage.ImageInfo.File = path + "\\Images\\Meat.jpg";
Table meatTable1 = (Table)section2.Paragraphs["MeatTable1"];
this.oleDbSelectCommand1.CommandText = "SELECT DISTINCTROW Products.ProductName, Products.ProductID,"+
"Products.QuantityPerUnit, Products.UnitPrice FROM Categories INNER JOIN Products ON "+
"Categories.CategoryID = Products.CategoryID WHERE ( "+
"(Categories.CategoryID)=6) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
FillTable(meatTable1,dataTable1);
Paragraph producePara = section2.Paragraphs["ProduceTable"];
Table produceTable = (Table)producePara;
Row row1ProduceTable = produceTable.Rows[0];
Cell row1Cell2ProduceTable = row1ProduceTable.Cells[1];
Image produceImage = (Image)row1Cell2ProduceTable.Paragraphs[0];
produceImage.ImageInfo.File = path + "\\Images\\Produce.jpg";
Table produceTable1 = (Table)section2.Paragraphs["ProduceTable1"];
this.oleDbSelectCommand1.CommandText = "SELECT DISTINCTROW Products.ProductName, Products.ProductID,"+
"Products.QuantityPerUnit, Products.UnitPrice FROM Categories INNER JOIN Products ON "+
"Categories.CategoryID = Products.CategoryID WHERE ( "+
"(Categories.CategoryID)=7) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
FillTable(produceTable1,dataTable1);
Paragraph seafoodPara = section2.Paragraphs["SeafoodTable"];
Table seafoodTable = (Table)seafoodPara;
Row row1SeafoodTable = seafoodTable.Rows[0];
Cell row1Cell2SeafoodTable = row1SeafoodTable.Cells[1];
Image seafoodImage = (Image)row1Cell2SeafoodTable.Paragraphs[0];
seafoodImage.ImageInfo.File = path + "\\Images\\Seafood.jpg";
Table seafoodTable1 = (Table)section2.Paragraphs["SeafoodTable1"];
this.oleDbSelectCommand1.CommandText = "SELECT DISTINCTROW Products.ProductName, Products.ProductID,"+
"Products.QuantityPerUnit, Products.UnitPrice FROM Categories INNER JOIN Products ON "+
"Categories.CategoryID = Products.CategoryID WHERE ( "+
"(Categories.CategoryID)=8) ORDER BY Products.ProductName;";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
FillTable(seafoodTable1,dataTable1);
this.oleDbDataAdapter1.Dispose();
this.oleDbConnection.Close();
return pdf;
}
private void FillTable(Aspose.Pdf.Generator.Table tab, DataTable dt)
{
tab.DefaultCellTextInfo.FontSize = 10;
tab.ImportDataTable(dt,false,1,0);
foreach(Row curRow in tab.Rows)
{
foreach(Cell curCell in curRow.Cells)
{
curCell.Padding = new MarginInfo();
curCell.Padding.Top = 3;
curCell.Padding.Bottom = 3;
}
if(tab.Rows.IndexOf(curRow) > 0)
{
((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).TextInfo.Alignment = AlignmentType.Right;
((Aspose.Pdf.Generator.Text)curRow.Cells[1].Paragraphs[0]).TextInfo.Alignment = AlignmentType.Center;
double price = Convert.ToDouble(((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).Segments[0].Content);
((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).Segments[0].Content = price.ToString("C", format);
}
((Aspose.Pdf.Generator.Text)curRow.Cells[0].Paragraphs[0]).Segments[0].TextInfo.FontName = "Times-Bold";
}
}
}
}
|