01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.ComponentModel;
04.
using
System.Data;
05.
using
System.Drawing;
06.
using
System.Linq;
07.
using
System.Text;
08.
using
System.Windows.Forms;
09.
using
System.IO;
10.
using
MySql.Data.MySqlClient;
11.
using
System.Diagnostics;
12.
using
CrystalDecisions.CrystalReports.Engine;
13.
using
Microsoft.VisualBasic;
14.
using
CrystalDecisions.Shared;
15.
using
System.Drawing.Printing;
16.
17.
namespace
student
18.
{
19.
public
partial
class
UserReport : Form
20.
{
21.
ClassConnectDB Connect =
new
ClassConnectDB();
22.
public
UserReport()
23.
{
24.
InitializeComponent();
25.
}
26.
27.
private
void
btnReport_Click(
object
sender, EventArgs e)
28.
{
29.
printDocument1.Print();
30.
31.
}
32.
33.
private
void
printDocument1_PrintPage(
object
sender, System.Drawing.Printing.PrintPageEventArgs e)
34.
{
35.
Connect.ConnectDB();
36.
String strSQL;
37.
DataTable dt =
null
;
38.
strSQL =
"SELECT user_id,user_name,user_address,user_province"
;
39.
strSQL +=
",user_zipcode,user_mail,user_phone FROM user where user_id like '%"
+ txtId.Text +
"%' "
;
40.
MySqlDataAdapter adapter;
41.
MySqlCommand objCmd;
42.
objCmd =
new
MySqlCommand(strSQL, Connect.objConn);
43.
adapter =
new
MySqlDataAdapter(objCmd);
44.
DataSet data =
new
DataSet();
45.
adapter.Fill(data,
"user"
);
46.
dt = data.Tables[0];
47.
adapter =
null
;
48.
49.
Connect.DisConnectDB();
50.
Connect.objConn =
null
;
51.
52.
ReportDocument rpt =
new
ReportDocument();
53.
string
directory = AppDomain.CurrentDomain.BaseDirectory;
54.
rpt.Load(directory +
"..\\..\\UserCrystalReport.rpt"
);
55.
rpt.SetDataSource(dt);
56.
57.
}
58.
}
59.
}