-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportForm.cs
127 lines (98 loc) · 5.24 KB
/
ReportForm.cs
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
using CrystalDecisions.CrystalReports.Engine;
using MetroFramework;
using MetroFramework.Forms;
using Microsoft.Reporting.WinForms;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoginForm
{
public partial class ReportForm : MetroForm
{
private MySqlConnection connection;
string ConnectionString = ConfigurationManager.AppSettings["connection"];
public ReportForm()
{
InitializeComponent();
}
private void ReportForm_Load_1(object sender, EventArgs e)
{
this.crystalReportViewer1.RefreshReport();
}
private void btn_search_Click(object sender, EventArgs e)
{
ReportDocument myReport = new ReportDocument();
DataSet myData = new DataSet();
MySqlConnection conn = new MySqlConnection();
MySqlCommand cmd = new MySqlCommand();
MySqlDataAdapter myAdapter = new MySqlDataAdapter();
conn.ConnectionString = ConfigurationManager.AppSettings["connection"];
// conn.ConnectionString = "Server=192.168.0.24;Database=inventory_items;Uid=tina;Pwd=!ojt2015;";
try
{
DataTable dt = new DataTable();
dt.TableName = "inventory_info";
cmd.CommandText = "SELECT inventory_info.item_date, inventory_info.item_name, inventory_info.item_serial, inventory_info.bid, inventory_info.quantity, inventory_info.unit, inventory_info.`status`, inventory_info.item_description, transaction.price, inventory_info.iid FROM category_info Inner Join inventory_info ON category_info.cid = inventory_info.cid Inner Join transaction ON inventory_info.iid = transaction.iid Where inventory_info.cid= '" + mtxtx_cid.Tag + "' And date(trans_date) >='" + date_from.Value.ToString("yyyy-MM-dd") + "' And date(trans_date) <= '" + date_to.Value.ToString("yyyy-MM-dd") + "'";
cmd.Connection = conn;
myAdapter.SelectCommand = cmd;
myAdapter.Fill(dt);
myData.Tables.Add(dt);
string reportPath = @"C:\Users\OJT\Desktop\InventorySystem\LoginForm\CrystalReport1.rpt";
myReport.Load(reportPath);
myReport.SetDataSource(myData);
crystalReportViewer1.ReportSource = myReport;
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MetroMessageBox.Show(this, ex.Message, "Report could not be created", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void mtxt_cat_Click(object sender, EventArgs e)
{
connection = new MySqlConnection(ConnectionString);
CategoryName catname = new CategoryName();
if(catname.ShowDialog(this) == DialogResult.OK)
{
mtxt_cat.Text = catname.cat_grid.Rows[catname.row].Cells[1].Value.ToString();
mtxtx_cid.Tag = catname.cat_grid.Rows[catname.row].Cells[0].Value.ToString();
}
}
private void btn_all_Click(object sender, EventArgs e)
{
ReportDocument myReport = new ReportDocument();
DataSet myData = new DataSet();
MySqlConnection conn = new MySqlConnection();
MySqlCommand cmd = new MySqlCommand();
MySqlDataAdapter myAdapter = new MySqlDataAdapter();
conn.ConnectionString = ConfigurationManager.AppSettings["connection"];
//conn.ConnectionString = "Server=192.168.0.24;Database=inventory_items;Uid=tina;Pwd=!ojt2015;";
try
{
DataTable dt = new DataTable();
dt.TableName = "inventory_info";
cmd.CommandText = "SELECT inventory_info.item_date, inventory_info.item_name, inventory_info.item_serial, inventory_info.bid, inventory_info.quantity, inventory_info.unit, inventory_info.`status`, inventory_info.item_description, transaction.price, inventory_info.iid FROM category_info Inner Join inventory_info ON category_info.cid = inventory_info.cid Inner Join transaction ON inventory_info.iid = transaction.iid Where date(trans_date) >='" + date_from.Value.ToString("yyyy-MM-dd") + "' And date(trans_date) <= '" + date_to.Value.ToString("yyyy-MM-dd") + "'";
cmd.Connection = conn;
myAdapter.SelectCommand = cmd;
myAdapter.Fill(dt);
myData.Tables.Add(dt);
string reportPath = @"C:\Users\OJT\Desktop\InventorySystem\LoginForm\CrystalReport1.rpt";
myReport.Load(reportPath);
myReport.SetDataSource(myData);
crystalReportViewer1.ReportSource = myReport;
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MetroMessageBox.Show(this, ex.Message, "Report could not be created", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}