-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pricefrm.cs
183 lines (172 loc) · 5.79 KB
/
Pricefrm.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
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 Pricefrm : Form
{
public Pricefrm()
{
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 Pricefrm_Load(object sender, EventArgs e)
{
strsql = "SELECT * FROM Prices";
con = new SqlConnection(strCon);
con.Open();
da = new SqlDataAdapter(strsql, con);
da.Fill(ds, "Prices");
txtID.DataBindings.Add(new Binding("Text", ds, "Prices.UsedServicesID"));
TXTservname.DataBindings.Add(new Binding("Text", ds, "Prices.UsedServicesName"));
txtprice.DataBindings.Add(new Binding("Text", ds, "Prices.UsedServicesPrice"));
con.Close();
txtID.ReadOnly = true;
}
private void btnInsert_Click(object sender, EventArgs e)
{
try
{
newRow = ds.Tables["Prices"].NewRow();
int ID;
int price;
ID = Convert.ToInt32(txtID.Text);
price = Convert.ToInt32(txtprice.Text);
SqlCommand cmd;
string qry;
qry = "INSERT INTO Prices(UsedServicesID,UsedServicesName,UsedServicesPrice)VALUES('" + ID + "','" + TXTservname.Text + "','" + price + "')";
con.Open();
cmd = new SqlCommand(qry, con);
cmd.ExecuteNonQuery();
da.Fill(ds, "Prices");
this.BindingContext[ds, "Prices"].Position = this.BindingContext[ds, "Prices"].Count;
con.Close();
txtID.ReadOnly = true;
MessageBox.Show("Successfully Done!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btndel_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand();
string qry;
con.Open();
int ID;
ID = Convert.ToInt32(txtID.Text);
qry = "DELETE FROM Prices WHERE UsedServicesID=" + ID;
cmd.CommandText = qry;
cmd.Connection = con;
cmd.ExecuteNonQuery();
ds.Clear();
da.Fill(ds, "Prices");
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show("Successfully Done!");
}
private void BtnEdit_Click(object sender, EventArgs e)
{
try
{
int ID;
int price;
ID = Convert.ToInt32(txtID.Text);
price = Convert.ToInt32(txtprice.Text);
SqlCommand cmd = new SqlCommand();
string qry;
qry = "UPDATE Prices SET UsedServicesName='" + TXTservname.Text + "',UsedServicesPrice='" + price + "'WHERE UsedServicesID='" + ID + "'";
con.Open();
cmd.CommandText = qry;
cmd.Connection = con;
cmd.ExecuteNonQuery();
da.Fill(ds, "Prices");
con.Close();
MessageBox.Show("SuccessfullyDone");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnprev_Click(object sender, EventArgs e)
{
if (this.BindingContext[ds, "Prices"].Position == 0)
{
MessageBox.Show("First Record!!!");
}
else
{
this.BindingContext[ds, "Prices"].Position -= 1;
}
}
private void btnFirst_Click(object sender, EventArgs e)
{
this.BindingContext[ds, "Prices"].Position = 0;
MessageBox.Show("First Record!!!");
}
private void btnnext_Click(object sender, EventArgs e)
{
try
{
if (this.BindingContext[ds, "Prices"].Position == this.BindingContext[ds, "Prices"].Count)
{
MessageBox.Show("Last Record!!!");
}
else
{
this.BindingContext[ds, "Prices"].Position += 1;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnLast_Click(object sender, EventArgs e)
{
this.BindingContext[ds, "Prices"].Position = this.BindingContext[ds, "Prices"].Count;
MessageBox.Show("Last Record!!!");
}
private void btnNew_Click(object sender, EventArgs e)
{
try
{
int id;
id = Convert.ToInt32(this.BindingContext[ds, "Prices"].Count);
id += 1;
txtID.Text = id.ToString();
txtprice.Text = "";
TXTservname.Text = "";
txtID.ReadOnly = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
Form objpricesearch = new PricesFrmSrch();
objpricesearch.Show();
}
}
}