-
Notifications
You must be signed in to change notification settings - Fork 8
/
Report.cs
221 lines (159 loc) · 6.27 KB
/
Report.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace pos
{
public partial class Report : UserControl
{
string dblocation = "C:\\db\\pos.mdf";
decimal cash, credit;
int dine, take;
public Report()
{
InitializeComponent();
}
private void Report_Load(object sender, EventArgs e)
{
Loaddata();
}
private string DailyTot(string Qry)
{
SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=" + dblocation + ";Integrated Security = True; Connect Timeout = 30");
string total="";
SqlCommand cmd = new SqlCommand(Qry, con);
try
{
con.Open();
total = cmd.ExecuteScalar().ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
con.Close();
}
return total;
}
public void Loaddata()
{
lblDaily.Text = DailyTot("SELECT isnull(sum(fulltotal),0) FROM Bill WHERE DATEDIFF(day,datetime,GETDATE()) < 1");
lblWeekly.Text = DailyTot("SELECT isnull(sum(fulltotal),0) FROM Bill WHERE DATEDIFF(day,datetime,GETDATE()) < 7 ");
lblMonthly.Text = DailyTot("SELECT isnull(sum(fulltotal),0) FROM Bill WHERE DATEDIFF(day,datetime,GETDATE()) < 30 ");
lblYearly.Text = DailyTot("SELECT isnull(sum(fulltotal),0) FROM Bill WHERE DATEDIFF(day,datetime,GETDATE()) < 365 ");
CreditCashChart();
DineTakeChart();
Top5();
}
private void CreditCashChart()
{
SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=" + dblocation + ";Integrated Security = True; Connect Timeout = 30");
try
{
con.Open();
string Qry = "SELECT sum(fulltotal) FROM Bill WHERE payment_type='Credit' ";
SqlCommand cmd = new SqlCommand(Qry, con);
credit = (decimal)cmd.ExecuteScalar() ;
}
catch (Exception ex)
{
MessageBox.Show( ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
con.Close();
}
try
{
con.Open();
string Qry = "SELECT sum(fulltotal) FROM Bill WHERE payment_type='Cash' ";
SqlCommand cmd = new SqlCommand(Qry, con);
cash = (decimal)cmd.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
con.Close();
}
chart1.Series["s1"].Points.Clear();
chart1.Series["s1"].Label = "#VALX\n#PERCENT{P2}";
chart1.Series["s1"].Points.AddXY("Credit", credit);
chart1.Series["s1"].Points.AddXY("Cash", cash);
}
private void DineTakeChart()
{
SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=" + dblocation + ";Integrated Security = True; Connect Timeout = 30");
try
{
con.Open();
string Qry = "SELECT count(order_type) FROM Bill WHERE order_type='Dine in' ";
SqlCommand cmd = new SqlCommand(Qry, con);
dine = (int)cmd.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show( ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
con.Close();
}
try
{
con.Open();
string Qry = "SELECT count(order_type) FROM Bill WHERE order_type='Take out' ";
SqlCommand cmd = new SqlCommand(Qry, con);
take = (int)cmd.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
con.Close();
}
chart2.Series["s1"].Points.Clear();
chart2.Series["s1"].Label = "#VALX\n#PERCENT{P2}";
chart2.Series["s1"].Points.AddXY("Dine in", dine);
chart2.Series["s1"].Points.AddXY("Take Away", take);
}
private void Top5()
{
SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=" + dblocation + ";Integrated Security = True; Connect Timeout = 30");
try
{
con.Open();
string Qry = "select pname,COUNT(*) As ValueFrequency from BillItems group by pname order by ValueFrequency DESC OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY";
SqlCommand cmd = new SqlCommand(Qry, con);
SqlDataReader dr = cmd.ExecuteReader();
chart3.Series["s1"].Points.Clear();
chart3.Series["s1"].Label = "#VALX\n#PERCENT{P2}";
while (dr.Read())
{
chart3.Series["s1"].Points.AddXY(dr["pname"].ToString(), dr["ValueFrequency"]);
}
dr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
con.Close();
}
}
}
}