001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.ComponentModel;
004.
using
System.Data;
005.
using
System.Drawing;
006.
using
System.Linq;
007.
using
System.Text;
008.
using
System.Threading.Tasks;
009.
using
System.Windows.Forms;
010.
using
System.Data.OleDb;
011.
using
CrystalDecisions.CrystalReports.Engine;
012.
using
CrystalDecisions.Shared;
013.
014.
015.
namespace
ProjectV2._0
016.
{
017.
public
partial
class
testreport : Form
018.
{
019.
public
testreport()
020.
{
021.
InitializeComponent();
022.
}
023.
private
ManageSystemDBDataSet dsEx =
new
ManageSystemDBDataSet();
024.
private
string
StrConn =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=managesystemdb.accdb;Persist Security Info=True;"
;
025.
private
OleDbConnection Connection;
026.
private
DataSet DataSt;
027.
private
OleDbCommand command;
028.
private
OleDbDataAdapter DataAdapter;
029.
private
DataTable dataTable;
030.
private
string
Sql =
""
;
031.
032.
private
void
ConnectionDatabase()
033.
{
034.
Connection =
new
OleDbConnection();
035.
if
(Connection.State == ConnectionState.Open)
036.
{
037.
Connection.Close();
038.
}
039.
else
040.
{
041.
Connection.ConnectionString = StrConn;
042.
Connection.Open();
043.
}
044.
}
045.
046.
047.
private
void
testreport_Load(
object
sender, EventArgs e)
048.
{
049.
ConnectionDatabase();
050.
}
051.
052.
private
void
button2_Click(
object
sender, EventArgs e)
053.
{
054.
try
055.
{
056.
if
(dsEx.Asset.Rows.Count > 0)
057.
{
058.
dsEx.Asset.Rows.Clear();
059.
}
060.
for
(
int
i = 0; i <= dataGridView1.Rows.Count - 1; i++)
061.
{
062.
DataGridViewRow dr =
null
;
063.
dr = dataGridView1.Rows[i];
064.
dsEx.Asset.Rows.Add(dr.Cells[0].Value, dr.Cells[1].Value, dr.Cells[2].Value, dr.Cells[3].Value, dr.Cells[4].Value, dr.Cells[5].Value, dr.Cells[6].Value, dr.Cells[7].Value, dr.Cells[8].Value);
065.
}
066.
reportasset crv =
new
reportasset();
067.
crv.SetDataSource(dsEx);
068.
freportasset form =
new
freportasset();
069.
form.report001.ReportSource = crv;
070.
form.report001.Refresh();
071.
072.
form.ShowDialog();
073.
}
074.
catch
075.
{
076.
}
077.
078.
}
079.
080.
private
void
button1_Click(
object
sender, EventArgs e)
081.
{
082.
Sql =
"select * from asset"
;
083.
084.
command =
new
OleDbCommand(Sql, Connection);
085.
086.
OleDbDataReader DataReader = command.ExecuteReader();
087.
if
(DataReader.HasRows)
088.
{
089.
dataTable =
new
DataTable();
090.
dataTable.Load(DataReader);
091.
dataGridView1.DataSource = dataTable;
092.
DataReader.Close();
093.
}
094.
else
095.
{
096.
dataTable =
new
DataTable();
097.
dataTable.Load(DataReader);
098.
dataGridView1.DataSource = dataTable;
099.
DataReader.Close();
100.
}
101.
102.
}
103.
}
104.
}