Reference some code. I didn't think so much about it. I just kept it for reference. I don't need to take this document back and forth in the future.
Public String username = string. empty;
Public String number = string. empty;
/// <Summary>
/// Crystal Report 1
/// </Summary>
Private void initrept ()
{
Try
{
Datatable dt = new datatable ("pzhtable ");
DT. Columns. Add ("name ");
DT. Columns. Add ("Number ");
DT. Columns. Add ("name1 ");
DT. Columns. Add ("number1 ");
Datarow newrow = DT. newrow ();
Newrow ["name"] = username;
Newrow ["Number"] = number;
Newrow ["name1"] = username;
Newrow ["number1"] = number;
DT. Rows. Add (newrow );
ReportDocument RPTC = new reportdocument ();
String rptfile = application. startuppath + "\ Rept. rpt ";
RPTC. Load (rptfile );
RPTC. database. Tables [0]. setdatasource (DT );
This. crystalreportviewer1.reportsource = RPTC;
Crystalreportviewer1.printreport ();
}
Catch (exception ex)
{
MessageBox. Show (ex. tostring ());
}
}
// Call and pass the value
Rept. frmrept FRM = new Rept. frmrept ();
FRM. Username = username;
FRM. Number = convert. toint32 (lblnumber. Text. Trim (). tostring ();
FRM. showdialog ();
/// <Summary>
/// Crystal Report 2
/// </Summary>
Private void initrept ()
{
Try
{
Datatable dt = new datatable ("zigetable ");
DT. Columns. Add ("name ");
DT. Columns. Add ("zigehao ");
DT. Columns. Add ("name1 ");
DT. Columns. Add ("zigehao1 ");
DT. Columns. Add ("name2 ");
DT. Columns. Add ("zigehao2 ");
String MySQL = "select * From zigetable order by shunxuhao ASC ";
Datatable newdt = new dataaccess (). getdataset (MySQL). Tables [0];
If (newdt! = NULL & newdt. Rows. Count> 0)
{
For (INT I = 0; I <newdt. Rows. Count; I ++)
{
Datarow newrow = DT. newrow ();
If (I <newdt. Rows. Count-1)
{
Newrow ["name"] = newdt. Rows [I] ["clientinfoid"]. tostring ();
Newrow ["zigehao"] = newdt. Rows [I] ["shunxuhao"]. tostring ();
}
If (I <newdt. Rows. Count-1)
{
Newrow ["name1"] = newdt. Rows [I + 1] ["clientinfoid"]. tostring ();
Newrow ["zigehao1"] = newdt. Rows [I + 1] ["shunxuhao"]. tostring ();
}
If (I <newdt. Rows. Count-2)
{
Newrow ["name2"] = newdt. Rows [I + 2] ["clientinfoid"]. tostring ();
Newrow ["zigehao2"] = newdt. Rows [I + 2] ["shunxuhao"]. tostring ();
}
I = I + 2;
DT. Rows. Add (newrow );
}
ReportDocument RPTC = new reportdocument ();
String rptfile = application. startuppath + "\ reptxh. rpt ";
RPTC. Load (rptfile );
RPTC. database. Tables [0]. setdatasource (DT );
This. crystalreportviewer1.reportsource = RPTC;
}
}
Catch (exception ex)
{
MessageBox. Show (ex. tostring ());
}
}