-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmPOS.cs
244 lines (211 loc) · 7.96 KB
/
frmPOS.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
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_and_inventory_csharp
{
public partial class frmPOS : Form
{
String id;
String price;
SqlConnection cn = new SqlConnection();
SqlCommand cm = new SqlCommand();
SqlDataReader dr;
DBConnection dbcon = new DBConnection();
frmSecurity f;
public frmPOS(frmSecurity frm)
{
InitializeComponent();
lblDate.Text = DateTime.Now.ToLongDateString();
cn = new SqlConnection(dbcon.MyConnection());
this.KeyPreview = true;
f = frm;
}
private void btnNew_Click(object sender, EventArgs e)
{
GetTransNo();
txtSearch.Enabled = true;
txtSearch.Focus();
}
private void button6_Click(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
frmSoldItems frm = new frmSoldItems();
frm.ShowDialog();
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
frmSettle frm = new frmSettle(this);
frm.txtSale.Text = lblDisplayTotal.Text;
frm.ShowDialog();
}
private void button7_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
if (lblTransno.Text == "0000000000000") { return; }
frmLookUp frm = new frmLookUp(this);
frm.LoadRecords();
frm.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
frmDiscount frm = new frmDiscount(this);
frm.lblID.Text = id;
frm.txtPrice.Text = price;
frm.ShowDialog();
}
private void button12_Click(object sender, EventArgs e)
{
}
public void GetTransNo()
{
try
{
string sdate = DateTime.Now.ToString("yyyyMMdd");
string transno;
int count;
cn.Open();
cm = new SqlCommand("select top 1 transno from tblCart where transno like '%" + sdate + "' order by id desc",cn);
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
transno = dr[0].ToString();
count = int.Parse(transno.Substring(8, 4));
lblTransno.Text = sdate + (count + 1).ToString();
} else
{
transno = sdate + "1001";
lblTransno.Text = transno;
}
dr.Close();
cn.Close();
}catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message, "Error GetTransNo", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void txtSearch_Click(object sender, EventArgs e)
{
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
try
{
if (txtSearch.Text == String.Empty) { return; }
else
{
cn.Open();
cm = new SqlCommand("select * from tblproduct where barcode like '" + txtSearch.Text + "' ", cn);
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
frmQty frm = new frmQty(this);
frm.Productdetails(dr["pcode"].ToString(), double.Parse(dr["price"].ToString()), lblTransno.Text);
dr.Close();
cn.Close();
frm.ShowDialog();
}
else
{
dr.Close();
cn.Close();
}
}
}
catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
public void LoadCart()
{
try
{
dataGridView1.Rows.Clear();
Boolean hasrecord = false;
int i = 0;
double total = 0;
double discount = 0;
cn.Open();
cm = new SqlCommand("select c.id, c.pcode, p.pdesc, c.price, c.qty, c.disc, c.total from tblcart as c inner join tblproduct as p on c.pcode = p.pcode where transno like '" + lblTransno.Text + "' and status like 'Pending'",cn);
dr = cm.ExecuteReader();
while (dr.Read())
{
i++;
total += Double.Parse(dr["total"].ToString());
discount += Double.Parse(dr["disc"].ToString());
dataGridView1.Rows.Add(i, dr["id"].ToString(), dr["pcode"].ToString(), dr["pdesc"].ToString(), dr["price"].ToString(), dr["qty"].ToString(), dr["disc"].ToString(), Double.Parse(dr["total"].ToString()).ToString("#,##0.00"));
hasrecord = true;
}
dr.Close();
cn.Close();
lblTotal.Text = total.ToString("#,##0.00");
lblDiscount.Text = discount.ToString("#,##0.00");
GetCartTotal();
if(hasrecord == true) { btnSttle.Enabled = true; btnDiscount.Enabled = true; } else { btnSttle.Enabled = false; btnDiscount.Enabled = false; }
}catch(Exception ex)
{
MessageBox.Show(ex.Message, "Exception Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
cn.Close();
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string colName = dataGridView1.Columns[e.ColumnIndex].Name;
if (colName == "Delete")
{
if(MessageBox.Show("Remove this item?", "Remove item", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
cn.Open();
cm = new SqlCommand("delete from tblcart where id like '" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() +"'", cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("Item has successfully removed", "Removed", MessageBoxButtons.OK, MessageBoxIcon.Information);
LoadCart();
}
}
}
public void GetCartTotal()
{
double discount = Double.Parse(lblDiscount.Text);
double sales = Double.Parse(lblTotal.Text);
double vat = sales * dbcon.GetVal();
double vatable = sales - vat;
lblVat.Text = vat.ToString("#,##0.00");
lblVatable.Text = vatable.ToString("#,##0.00");
lblDisplayTotal.Text = sales.ToString("#,##0.00");
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
int i = dataGridView1.CurrentRow.Index;
id = dataGridView1[1, i].Value.ToString();
price = dataGridView1[4,i].Value.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToString("hh:MM:ss tt");
lblDate1.Text = DateTime.Now.ToLongDateString();
}
private void lblDate_Click(object sender, EventArgs e)
{
}
}
}