-
Notifications
You must be signed in to change notification settings - Fork 1
/
frmReceipt.cs
95 lines (84 loc) · 4.42 KB
/
frmReceipt.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
using System;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace POS_System
{
public partial class frmReceipt : Form
{
SqlConnection cn = new SqlConnection();
DBConnection dbcon = new DBConnection();
frmPOS frmPOSInstance;
public frmReceipt(frmPOS frm)
{
InitializeComponent();
cn = new SqlConnection(dbcon.MyConnection());
this.frmPOSInstance = frm;
this.KeyPreview = true;
}
private void frmReceipt_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
public void LoadReport(string pcash, string pchange)
{
ReportDataSource rptDataSource;
try
{
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\Reports\Report1.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
DataSet1 dataSet = new DataSet1();
SqlDataAdapter dataAdapter = new SqlDataAdapter();
cn.Open();
string query = $"SELECT c.id, c.transno, c.pcode, c.price, c.qty, c.disc, c.total, c.sdate, c.status, p.pdesc FROM tblCart AS c INNER JOIN tblProduct AS p ON c.pcode = p.pcode WHERE transno LIKE '{frmPOSInstance.lblTransno.Text}';";
dataAdapter.SelectCommand = new SqlCommand(query, cn);
dataAdapter.Fill(dataSet.Tables["dtSold"]);
cn.Close();
// Report Parameters
ReportParameter pAmount = new ReportParameter("pAmount", this.frmPOSInstance.lblAmount.Text);
ReportParameter pGST = new ReportParameter("pGST", this.frmPOSInstance.lblGst.Text);
ReportParameter pDiscount = new ReportParameter("pDiscount", this.frmPOSInstance.lblDiscount.Text);
ReportParameter pTotal = new ReportParameter("pTotal", this.frmPOSInstance.lblTotal.Text);
ReportParameter pCash = new ReportParameter("pCash", pcash);
ReportParameter pChange = new ReportParameter("pChange", pchange);
//ReportParameter pStore = new ReportParameter("pStore", this.store);
ReportParameter pStore = new ReportParameter("pStore", dbcon.getStoreName());
//ReportParameter pAddress = new ReportParameter("pAddress", this.address);
ReportParameter pAddress = new ReportParameter("pAddress", dbcon.getStoreAddress());
ReportParameter pTransaction = new ReportParameter("pTransaction", $"Invoice #: {this.frmPOSInstance.lblTransno.Text}");
ReportParameter pCashier = new ReportParameter("pCashier", this.frmPOSInstance.lblUser.Text);
ReportParameter pGSTNumber = new ReportParameter("pGSTNumber", dbcon.getStoreGSTNo());
// Setting Report Parameter
reportViewer1.LocalReport.SetParameters(pAmount);
reportViewer1.LocalReport.SetParameters(pGST);
reportViewer1.LocalReport.SetParameters(pDiscount);
reportViewer1.LocalReport.SetParameters(pTotal);
reportViewer1.LocalReport.SetParameters(pCash);
reportViewer1.LocalReport.SetParameters(pChange);
reportViewer1.LocalReport.SetParameters(pStore);
reportViewer1.LocalReport.SetParameters(pAddress);
reportViewer1.LocalReport.SetParameters(pTransaction);
reportViewer1.LocalReport.SetParameters(pCashier);
reportViewer1.LocalReport.SetParameters(pGSTNumber);
rptDataSource = new ReportDataSource("DataSet1", dataSet.Tables["dtSold"]);
reportViewer1.LocalReport.DataSources.Add(rptDataSource);
reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
reportViewer1.ZoomMode = ZoomMode.Percent;
reportViewer1.ZoomPercent = 100;
} catch (Exception ex)
{
MessageBox.Show(ex.Message);
} finally
{
cn.Close();
}
}
private void frmReceipt_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode.Equals(Keys.Escape))
{
this.Dispose();
}
}
}
}