-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmSalesReport.cs
369 lines (331 loc) · 17 KB
/
frmSalesReport.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SalesPurchase
{
public partial class frmSalesReport : Form
{
public frmSalesReport()
{
InitializeComponent();
}
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
string sParticularValue = "";
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYITEMNAME";
sParticularValue = "ALL";
}
private void button1_Click(object sender, EventArgs e)
{
try
{
GlobalClass.gsReportType = "SALES REPORT";
string sFromDate, sToDate;
sFromDate =Convert.ToDateTime(dtPckrFrmDate.Value).ToString("yyyy-MM-dd");
sToDate =Convert.ToDateTime(dtPckrToDate.Value).ToString("yyyy-MM-dd");
if (GlobalClass.gsSalesReportType == null)
{
MessageBox.Show("Please select a report option to generate", "Reports", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
return;
}
if (GlobalClass.gsSalesReportType == "REPORTBYBILLNO")
{
if (txtInvoiceNo.Text != "" && txtToInvoiceNo.Text == "")
{
MessageBox.Show("Please enter To Invoice Value", "Reports", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
txtToInvoiceNo.Focus();
return;
}
else if (txtInvoiceNo.Text == "" && txtToInvoiceNo.Text != "")
{
MessageBox.Show("Please enter From Invoice Value", "Reports", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
txtInvoiceNo.Focus();
return;
}
else if (txtInvoiceNo.Text != "" && txtToInvoiceNo.Text != "")
{
GlobalClass.gsSalesReportType = "REPORTBYINVRANGE";
}
}
//else
//{
// GlobalClass.gsSalesReportType = "REPORTBYBILLNO";
//}
GenerateSalesReport(GlobalClass.gsReportType, GlobalClass.gsSalesReportType, sFromDate, sToDate);
}
catch (Exception ex)
{
GlobalClass.WriteLog(ex.Message.ToString());
MessageBox.Show(ex.Message.ToString(), "Reports", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
}
public void GenerateSalesReport(string sReportType,string sSalesRptType, string sFromDate, string sToDate, string sOptionalValue = "Default")
{
try
{
Cursor.Current = Cursors.WaitCursor;
//dgDisplaySalesReport.DataSource = null;
cmd = new SqlCommand();
ds = new DataSet();
cmd.Connection = GlobalClass.gCon;
cmd.CommandText = "SP_Reports";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ReportName", SqlDbType.VarChar, GlobalClass.gsReportType.Length).Value = GlobalClass.gsReportType.Trim();
cmd.Parameters.Add("@ReportFilterOption", SqlDbType.VarChar, sSalesRptType.Length).Value = sSalesRptType.Trim();
cmd.Parameters.Add("@ParticularValue", SqlDbType.VarChar, sParticularValue.Length).Value = sParticularValue.Trim();
cmd.Parameters.Add("@FromDate", SqlDbType.VarChar, sFromDate.Length).Value = sFromDate.Trim();
cmd.Parameters.Add("@ToDate", SqlDbType.VarChar, sToDate.Length).Value = sToDate.Trim();
//Added by Kashif on 16-May-2015 for Invoice from and To Reports
cmd.Parameters.Add("@secondval", SqlDbType.VarChar, txtToInvoiceNo.Text.Length).Value = txtToInvoiceNo.Text;
//till here
ds.Load(cmd.ExecuteReader(), LoadOption.OverwriteChanges, "Result");
//dgDisplaySalesReport.DataSource = ds.Tables["Result"];
//ds = new DataSet();
//lblTotalRecords.Text = dgDisplaySalesReport.Rows.Count.ToString();
if (ds.Tables["Result"].Rows.Count == 0)
{
MessageBox.Show("No Records found for report", "Reports", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
CrystalReportViewerSales.ReportSource = null;
Cursor.Current = Cursors.Default;
return;
}
switch (sSalesRptType)
{
case "REPORTBYBILLNO":
SalesPurchase.Reports.ReportByInvoiceNo rptReportByInvoiceNo = new SalesPurchase.Reports.ReportByInvoiceNo();
rptReportByInvoiceNo.SetDataSource(ds.Tables["Result"]);
rptReportByInvoiceNo.SetParameterValue("fromdate",sFromDate);
rptReportByInvoiceNo.SetParameterValue("todate",sToDate);
CrystalReportViewerSales.ReportSource = rptReportByInvoiceNo;
break;
case "REPORTBYINVRANGE":
SalesPurchase.Reports.ReportByInvoiceNo rptReportByInvoiceNoRange = new SalesPurchase.Reports.ReportByInvoiceNo();
rptReportByInvoiceNoRange.SetDataSource(ds.Tables["Result"]);
rptReportByInvoiceNoRange.SetParameterValue("fromdate", sFromDate);
rptReportByInvoiceNoRange.SetParameterValue("todate", sToDate);
CrystalReportViewerSales.ReportSource = rptReportByInvoiceNoRange;
break;
case "REPORTBYITEMNAME":
SalesPurchase.Reports.ReportByItemName rptReportByItemName = new SalesPurchase.Reports.ReportByItemName();
rptReportByItemName.SetDataSource(ds.Tables["Result"]);
rptReportByItemName.SetParameterValue("fromdate", sFromDate);
rptReportByItemName.SetParameterValue("todate", sToDate);
CrystalReportViewerSales.ReportSource = rptReportByItemName;
break;
case "REPORTBYSALESMAN":
SalesPurchase.Reports.SalesManWiseReport rptSalesManWiseReport = new SalesPurchase.Reports.SalesManWiseReport();
rptSalesManWiseReport.SetDataSource(ds.Tables["Result"]);
rptSalesManWiseReport.SetParameterValue("fromdate", sFromDate);
rptSalesManWiseReport.SetParameterValue("todate", sToDate);
CrystalReportViewerSales.ReportSource = rptSalesManWiseReport;
break;
case "DEADSTOCKREP":
SalesPurchase.Reports.DeadStockReport rptDeadStock = new SalesPurchase.Reports.DeadStockReport();
rptDeadStock.SetDataSource(ds.Tables["Result"]);
rptDeadStock.SetParameterValue("fromdate", sFromDate);
rptDeadStock.SetParameterValue("todate",sToDate);
CrystalReportViewerSales.ReportSource = rptDeadStock;
break;
case "REPORTBYITEMGROUP":
SalesPurchase.Reports.rptByItemGroupName rptReportByGrpName = new SalesPurchase.Reports.rptByItemGroupName();
rptReportByGrpName.SetDataSource(ds.Tables["Result"]);
CrystalReportViewerSales.ReportSource = rptReportByGrpName;
break;
}
}
catch (Exception ex)
{
GlobalClass.WriteLog("Error in GenerateSalesReport:" + ex.Message.ToString());
MessageBox.Show(ex.Message.ToString(), "Reports", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
finally
{
Cursor.Current = Cursors.Default;
}
}
private void rbtnBillDate_Click(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYBILLDATE";
}
private void rbtnBillNo_Click(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYBILLNO";
}
private void rbtnItemCode_Click(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYBITEMCODE";
}
private void rbtnItemGroup_Click(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYITEMGROUP";
}
private void rbtnSalesMan_Click(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYSALESMAN";
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYBILLDATE";
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYBILLNO";
sParticularValue = "ALL";
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYSALESMAN";
sParticularValue = "ALL";
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYITEMGROUP";
sParticularValue = "ALL";
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
}
private void frmSalesReport_Load(object sender, EventArgs e)
{
try
{
string sFlag;
sFlag = "FETCHEMPNAME";
GlobalClass.cmd = new SqlCommand();
GlobalClass.cmd.Connection = GlobalClass.gCon;
GlobalClass.cmd.CommandText = "SP_FetchMenuDetails";
GlobalClass.cmd.CommandType = CommandType.StoredProcedure;
GlobalClass.cmd.Parameters.Add("@Flag", SqlDbType.VarChar, sFlag.Length).Value = sFlag.Trim();
ds = new DataSet();
ds.Load(GlobalClass.cmd.ExecuteReader(), LoadOption.OverwriteChanges, "Result");
for (int i = 0; i < ds.Tables["Result"].Rows.Count; i++)
{
cmbSalesBy.Items.Add(ds.Tables["Result"].Rows[i]["Employeename"].ToString().Trim());
//cmbDeliveredBy.Items.Add(ds.Tables["Result"].Rows[i]["Employeename"].ToString().Trim());
}
ds = new DataSet();
GlobalClass.cmd = new SqlCommand();
GlobalClass.cmd.CommandText = "SP_FetchItemCategory";
GlobalClass.cmd.Connection = GlobalClass.gCon;
GlobalClass.cmd.CommandType = CommandType.StoredProcedure;
ds.Load(GlobalClass.cmd.ExecuteReader(), LoadOption.OverwriteChanges, "ItemCategory");
for (int i = 0; i < ds.Tables["Itemcategory"].Rows.Count; i++)
{
if (ds.Tables["Itemcategory"].Rows[i]["Type"].ToString().ToUpper() == "MAINGROUP")
cmbItemGroup.Items.Add(ds.Tables["itemcategory"].Rows[i]["itemcategory"].ToString());
//if (ds.Tables["Itemcategory"].Rows[i]["Type"].ToString().ToUpper() == "ITEMTYPE")
// cmbItemType.Items.Add(ds.Tables["Itemcategory"].Rows[i]["itemcategory"].ToString());
//if (ds.Tables["Itemcategory"].Rows[i]["Type"].ToString().ToUpper() == "MAINGROUP")
// cmbGroup.Items.Add(ds.Tables["Itemcategory"].Rows[i]["itemcategory"].ToString());
}
GlobalClass.WriteLog("Before Fetching Menu details in Invoice");
sFlag = "LOAD";
GlobalClass.cmd = new SqlCommand();
GlobalClass.cmd.Connection = GlobalClass.gCon;
GlobalClass.cmd.CommandText = "SP_FetchMenuDetails";
GlobalClass.cmd.CommandType = CommandType.StoredProcedure;
GlobalClass.cmd.Parameters.Add("@Flag", SqlDbType.VarChar, sFlag.Length).Value = sFlag.Trim();
ds = new DataSet();
ds.Load(GlobalClass.cmd.ExecuteReader(), LoadOption.OverwriteChanges, "Result");
for (int i = 0; i < ds.Tables["Result"].Rows.Count; i++)
cmbItemCode.Items.Add(ds.Tables["Result"].Rows[i]["ItemName"].ToString());
cmbItemGroup.SelectedIndex = -1;
cmbSalesBy.SelectedIndex = -1;
cmbItemCode.SelectedIndex = -1;
cmbItemCode.Items.Add("ALL");
}
catch (Exception ex)
{
GlobalClass.WriteLog("Error in frmSalesReport_Load:"+ex.Message.ToString());
MessageBox.Show(ex.Message.ToString(), "Reports", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
}
private void button1_Click_1(object sender, EventArgs e)
{
ClearForm();
}
private void rbtnCustomer_CheckedChanged(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "DEADSTOCKREP";
}
public void ClearForm()
{
//dgDisplaySalesReport.DataSource = null;
CrystalReportViewerSales.ReportSource = null;
txtInvoiceNo.Text = "";
txtToInvoiceNo.Text = "";
cmbItemCode.SelectedIndex = -1;
cmbItemGroup.SelectedIndex = -1;
cmbSalesBy.SelectedIndex = -1;
}
private void cmbItemCode_SelectedIndexChanged(object sender, EventArgs e)
{
sParticularValue = cmbItemCode.Text;
}
private void cmbSalesBy_SelectedIndexChanged(object sender, EventArgs e)
{
sParticularValue = cmbSalesBy.Text;
GlobalClass.gsSalesReportType = "REPORTBYSALESMAN";
}
private void cmbItemGroup_SelectedIndexChanged(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTBYITEMGROUP";
sParticularValue = cmbItemGroup.Text;
}
private void cmbDeliveredBy_SelectedIndexChanged(object sender, EventArgs e)
{
GlobalClass.gsSalesReportType = "REPORTDELIVEREDBY";
//sParticularValue = cmbDeliveredBy.Text;
}
private void radioButton1_CheckedChanged_1(object sender, EventArgs e)
{
sParticularValue = "ALL";
GlobalClass.gsSalesReportType = "REPORTDELIVEREDBY";
}
private void txtInvoiceNo_Leave(object sender, EventArgs e)
{
if (txtInvoiceNo.Text.Trim() != "")
sParticularValue = txtInvoiceNo.Text;
else
sParticularValue = "ALL";
}
private void btnPrint_Click(object sender, EventArgs e)
{
printDocumentSalesReport.Print();
}
private void printDocumentSalesReport_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
try
{
//PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle(new Point(0, 0), this.Size));
//this.InvokePaint(dgDisplaySalesReport, myPaintArgs);
//printPreviewDialogSalesReprt.Document = printDocumentSalesReport;
//printPreviewDialogSalesReprt.ShowDialog();
//Bitmap bm = new Bitmap(this.dgDisplaySalesReport.Width, this.dgDisplaySalesReport.Height);
//dgDisplaySalesReport.DrawToBitmap(bm, new Rectangle(0, 0, this.dgDisplaySalesReport.Width, this.dgDisplaySalesReport.Height));
//e.Graphics.DrawImage(bm,10, 10);
//printPreviewDialogSalesReprt.Document = printDocumentSalesReport;
//printPreviewDialogSalesReprt.ShowDialog();
}
catch (Exception ex)
{
}
}
private void txtInvoiceNo_TextChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
}
}