-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiscountFrm.cs
184 lines (170 loc) · 5.67 KB
/
DiscountFrm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Reception
{
public partial class DiscountFrm : Form
{
public DiscountFrm()
{
InitializeComponent();
}
DataSet ds = new DataSet();
string strsql;
string strCon = "Data Source=.;Initial Catalog=ProjectREC;Integrated Security=True";
SqlDataAdapter da;
SqlConnection con;
DataRow newRow;
private void DiscountFrm_Load(object sender, EventArgs e)
{
try
{
TXTID.ReadOnly = true;
strsql = "SELECT * FROM Discounts";
con = new SqlConnection(strCon);
con.Open();
da = new SqlDataAdapter(strsql, con);
da.Fill(ds, "Discounts");
txtdesc.DataBindings.Add(new Binding("Text", ds, "Discounts.Discript"));
TXTID.DataBindings.Add(new Binding("Text", ds, "Discounts.DiscountID"));
txtdisamnt.DataBindings.Add(new Binding("Text", ds, "Discounts.Amount"));
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnNew_Click(object sender, EventArgs e)
{
int id;
id = Convert.ToInt32(this.BindingContext[ds, "Discounts"].Count);
id += 1;
txtdesc.Text = "";
txtdisamnt.Text = "";
TXTID.Text = id.ToString();
TXTID.ReadOnly = false;
}
private void btnInsert_Click(object sender, EventArgs e)
{
try
{
con = new SqlConnection(strCon);
newRow = ds.Tables["Discounts"].NewRow();
int id;
int amount;
id = Convert.ToInt32(TXTID.Text);
amount = Convert.ToInt32(txtdisamnt.Text);
SqlCommand cmd;
string qry;
qry = "INSERT INTO Discounts(DiscountID,Amount,Discript)VALUES('" + id + "','" + amount + "','" + txtdesc.Text + "')";
con.Open();
cmd = new SqlCommand(qry, con);
cmd.ExecuteNonQuery();
da.Fill(ds, "Discounts");
con.Close();
MessageBox.Show("Successfully Done!");
TXTID.ReadOnly = true;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btndel_Click(object sender, EventArgs e)
{
try
{
con = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand();
string qry;
con.Open();
int ID;
ID = Convert.ToInt32(TXTID.Text);
qry = "DELETE FROM Discounts WHERE DiscountID=" + ID;
cmd.CommandText = qry;
cmd.Connection = con;
cmd.ExecuteNonQuery();
ds.Clear();
da.Fill(ds, "Discounts");
con.Close();
MessageBox.Show("Successfully Done!");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnFirst_Click(object sender, EventArgs e)
{
this.BindingContext[ds, "Discounts"].Position = 0;
}
private void btnprev_Click(object sender, EventArgs e)
{
if (this.BindingContext[ds, "Discounts"].Position == 0)
{
MessageBox.Show("Last Record!!!");
}
else
{
this.BindingContext[ds, "Discounts"].Position -= 1;
}
}
private void btnnext_Click(object sender, EventArgs e)
{
if (this.BindingContext[ds, "Discounts"].Position == this.BindingContext[ds, "Discounts"].Count)
{
MessageBox.Show("Last Record!!!");
}
else
{
this.BindingContext[ds, "Discounts"].Position += 1;
}
}
private void btnLast_Click(object sender, EventArgs e)
{
this.BindingContext[ds, "Discounts"].Position = this.BindingContext[ds, "Discounts"].Count;
}
private void BtnEdit_Click(object sender, EventArgs e)
{
try
{
con = new SqlConnection(strCon);
SqlCommand cmd;
string qry;
int a;
int b;
string c;
c = Convert.ToString(txtdesc.Text);
a = Convert.ToInt32(TXTID.Text);
b = Convert.ToInt32(txtdisamnt.Text);
qry = "UPDATE Discounts SET Amount='" + b + "',Discript='" + c + "' WHERE DiscountID='" + a + "'";
con.Open();
cmd = new SqlCommand(qry, con);
cmd.ExecuteNonQuery();
da.Fill(ds, "Discounts");
con.Close();
MessageBox.Show("SuccessfullyDone");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void BtnClose_Click(object sender, EventArgs e)
{
Close();
}
private void btnsearch_Click(object sender, EventArgs e)
{
Form objdissearch = new DisFrmSrch();
objdissearch.Show();
}
}
}