-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmSettle.cs
158 lines (133 loc) · 4.6 KB
/
frmSettle.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
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 frmSettle : Form
{
frmPOS fpos;
SqlConnection cn = new SqlConnection();
SqlCommand cm = new SqlCommand();
DBConnection dbcon = new DBConnection();
SqlDataReader dr;
public frmSettle(frmPOS fp)
{
InitializeComponent();
cn = new SqlConnection(dbcon.MyConnection());
fpos = fp;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void txtCash_TextChanged(object sender, EventArgs e)
{
try
{
double sale = double.Parse(txtSale.Text);
double cash = double.Parse(txtCash.Text);
double change = cash - sale;
txtChange.Text = change.ToString("#,##0.00");
}catch(Exception ex)
{
txtChange.Text = "0.00";
}
}
private void btn7_Click(object sender, EventArgs e)
{
txtCash.Text += btn7.Text;
}
private void btn8_Click(object sender, EventArgs e)
{
txtCash.Text += btn8.Text;
}
private void btn9_Click(object sender, EventArgs e)
{
txtCash.Text += btn9.Text;
}
private void btnc_Click(object sender, EventArgs e)
{
txtCash.Clear();
txtCash.Focus();
}
private void btn4_Click(object sender, EventArgs e)
{
txtCash.Text += btn4.Text;
}
private void btn5_Click(object sender, EventArgs e)
{
txtCash.Text += btn5.Text;
}
private void btn6_Click(object sender, EventArgs e)
{
txtCash.Text += btn6.Text;
}
private void btn0_Click(object sender, EventArgs e)
{
txtCash.Text += btn0.Text;
}
private void btn1_Click(object sender, EventArgs e)
{
txtCash.Text += btn1.Text;
}
private void btn2_Click(object sender, EventArgs e)
{
txtCash.Text += btn2.Text;
}
private void btn3_Click(object sender, EventArgs e)
{
txtCash.Text += btn3.Text;
}
private void btn00_Click(object sender, EventArgs e)
{
txtCash.Text += btn00.Text;
}
private void btnEnter_Click(object sender, EventArgs e)
{
try
{
if((double.Parse(txtChange.Text) < 0) || (txtCash.Text == String.Empty) )
{
MessageBox.Show("Insufficient Amount. Please enter the correcet!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
for (int i = 0; i < fpos.dataGridView1.Rows.Count; i++)
{
cn.Open();
cm = new SqlCommand("update tblproduct set qty = qty - " + int.Parse(fpos.dataGridView1.Rows[i].Cells[5].Value.ToString())+ " where pcode = '"+ fpos.dataGridView1.Rows[i].Cells[2].Value.ToString() + "'", cn);
cm.ExecuteNonQuery();
cn.Close();
cn.Open();
cm = new SqlCommand("USE [POS_DEMO_DB] update tblcart set status = 'Sold' where id like'" + fpos.dataGridView1.Rows[i].Cells[1].Value.ToString() +"'", cn);
cm.ExecuteNonQuery();
cn.Close();
}
frmReceipt frm = new frmReceipt(fpos);
frm.LoadReport(txtCash.Text, txtChange.Text);
frm.ShowDialog();
MessageBox.Show("Payment Successfully Saved!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
//fpos.LoadCart();
this.Dispose();
fpos.dataGridView1.Rows.Clear();
fpos.Refresh();
fpos.dataGridView1.Rows.Clear();
fpos.GetTransNo();
fpos.LoadCart();
}
}catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message,"Error Enter Click");
}
}
}
}