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
|
/////////////////////////////////////////////////////////////////////////
// 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 SummaryByQuarter.
/// </summary>
public class SummaryByQuarter
{
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 Orders.ShippedDate, Orders.OrderID, "+
"[Order Subtotals].Subtotal, Format([ShippedDate],'yyyy') AS [Year] "+
"FROM Orders INNER JOIN [Order Subtotals] ON Orders.OrderID = [Order Subtotals].OrderID " +
"WHERE (((Orders.ShippedDate) Is Not Null))";
public SummaryByQuarter(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 GetSummaryByQuarter()
{
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\\SummaryByQuarter.xml";
pdf.BindXML(xmlFile, null);
Section section = pdf.Sections["section1"];
int quarter;
int[] orders = new int[3];
float[] sales = new float[3];
int year;
Table table;
for(quarter=1;quarter<=4;quarter++)
{
table = NewTable(pdf,quarter);
for(year=1996;year<=1998;year++)
{
this.oleDbSelectCommand1.CommandText = "SELECT COUNT(*),SUM([Order Subtotals].Subtotal) FROM (" +
queryString + ") WHERE Year(Orders.ShippedDate)='"+ year.ToString() +
"' AND DatePart('q',Orders.ShippedDate)=" + quarter.ToString() + ";";
resultReader = this.oleDbSelectCommand1.ExecuteReader();
resultReader.Read();
orders[year-1996] = resultReader.IsDBNull(0)?0:Convert.ToInt32(resultReader.GetValue(0));
sales[year-1996] = resultReader.IsDBNull(1)?0:(float)Convert.ToDouble(resultReader.GetValue(1));
resultReader.Close();
}
for(year=1996;year<=1998;year++)
{
if(orders[year-1996] != 0)
AddSummaryRow(pdf,table,year.ToString(),orders[year-1996].ToString(),
sales[year-1996].ToString("c",locale),1);
}
}
this.oleDbConnection.Close();
return pdf;
}
private Aspose.Pdf.Generator.Table NewTable(Aspose.Pdf.Generator.Pdf pdf, int quarter)
{
Section section = pdf.Sections[0];
Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(section, "Quarter: " + quarter.ToString());
text1.Margin.Top = 20;
text1.Segments[0].TextInfo.FontName = "Times-Bold";
text1.Segments[0].TextInfo.FontSize = 14;
section.Paragraphs.Add(text1);
Graph g1 = new Graph(section,480,10);
section.Paragraphs.Add(g1);
g1.Margin.Top = 20;
float[] linePosArr = new float[]{0,5,480,5};
Line l1 = new Line(g1,linePosArr);
g1.Shapes.Add(l1);
l1.GraphInfo.LineWidth = 2;
l1.GraphInfo.Color = new Aspose.Pdf.Generator.Color(204);
Table table = new Table();
section.Paragraphs.Add(table);
table.ColumnWidths = "120 120 120";
table.DefaultCellTextInfo.FontSize = 10;
table.DefaultCellPadding.Top = table.DefaultCellPadding.Bottom = 4;
Graph g2 = new Graph(section);
section.Paragraphs.Add(g2);
g2.Margin.Top = 20;
Line l2 = new Line(g1,linePosArr);
g2.Shapes.Add(l2);
l2.GraphInfo.LineWidth = 2;
l2.GraphInfo.Color = new Aspose.Pdf.Generator.Color(204);
AddSummaryRow(pdf,table,"Year","Orders Shipped","Sales",0);
return table;
}
private void AddSummaryRow(Aspose.Pdf.Generator.Pdf pdf, Aspose.Pdf.Generator.Table table, string s1, string s2, string s3, int type)
{
Row row1 = table.Rows.Add();
Cell cell1 = row1.Cells.Add(s1);
if(type == 0 || type == 2)
((Aspose.Pdf.Generator.Text)cell1.Paragraphs[0]).Segments[0].TextInfo.FontName = "Times-Bold";
((Aspose.Pdf.Generator.Text)cell1.Paragraphs[0]).TextInfo.Alignment = AlignmentType.Center;
Cell cell2 = row1.Cells.Add(s2);
if(type == 0)
((Aspose.Pdf.Generator.Text)cell2.Paragraphs[0]).Segments[0].TextInfo.FontName = "Times-Bold";
((Aspose.Pdf.Generator.Text)cell2.Paragraphs[0]).TextInfo.Alignment = AlignmentType.Center;
Cell cell3 = row1.Cells.Add(s3);
if(type == 0)
((Aspose.Pdf.Generator.Text)cell3.Paragraphs[0]).Segments[0].TextInfo.FontName = "Times-Bold";
((Aspose.Pdf.Generator.Text)cell3.Paragraphs[0]).TextInfo.Alignment = AlignmentType.Center;
}
}
}
|