-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
267 lines (216 loc) · 10.4 KB
/
Form1.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
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 population
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button3_Click(object sender, EventArgs e)
{
try
{
conn.Open();
SqlCommand cm2 = new SqlCommand("delete from papula where ID=@ID", conn);
cm2.Parameters.AddWithValue("ID", comboBox1.Text);
cm2.Parameters.AddWithValue("Name", textBox1.Text);
cm2.Parameters.AddWithValue("F_name", textBox2.Text);
cm2.Parameters.AddWithValue("Cnic", textBox3.Text);
cm2.Parameters.AddWithValue("Gendar", textBox4.Text);
cm2.Parameters.AddWithValue("Marital", textBox5.Text);
cm2.Parameters.AddWithValue("Current_adress", textBox6.Text);
cm2.Parameters.AddWithValue("permenant_adress", textBox7.Text);
cm2.Parameters.AddWithValue("Contact_no", textBox8.Text);
cm2.Parameters.AddWithValue("DOB", textBox9.Text);
cm2.Parameters.AddWithValue("POB", textBox10.Text);
cm2.Parameters.AddWithValue("Mother_tongue", textBox11.Text);
cm2.Parameters.AddWithValue("T_Famly_members", textBox12.Text);
cm2.ExecuteNonQuery();
MessageBox.Show("Data has been Deleted", "Command Succesfull", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
this.comboBox1.Items.Clear();
this.textBox1.Clear();
this.textBox2.Clear();
this.textBox3.Clear();
this.textBox4.Clear();
this.textBox5.Clear();
this.textBox6.Clear();
this.textBox7.Clear();
this.textBox8.Clear();
this.textBox9.Clear();
this.textBox10.Clear();
this.textBox11.Clear();
this.textBox12.Clear();
cm2 = new SqlCommand("select * from papula", conn);
SqlDataReader dr = cm2.ExecuteReader();
while (dr.Read())
{
this.comboBox1.Items.Add(dr["ID"].ToString());
}
conn.Close();
}
catch (Exception)
{
MessageBox.Show("Your Cannot Assigned Same Id Your Records Please give Another id");
}
}
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Integrated security=SSPI;database=population");
private void Form1_Load(object sender, EventArgs e)
{
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("select ID from papula", conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr["Id"].ToString());
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("error" + ex);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
conn.Open();
SqlCommand cm = new SqlCommand("select * from papula where Id='" + this.comboBox1.Text + "'", conn);
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
this.textBox1.Text = dr["Name"].ToString();
this.textBox2.Text = dr["F_name"].ToString();
this.textBox3.Text = dr["Cnic"].ToString();
this.textBox4.Text = dr["Gendar"].ToString();
this.textBox5.Text = dr["Marital"].ToString();
this.textBox6.Text = dr["Current_adress"].ToString();
this.textBox7.Text = dr["permenant_adress"].ToString();
this.textBox8.Text = dr["Contact_no"].ToString();
this.textBox9.Text = dr["DOB"].ToString();
this.textBox10.Text = dr["POB"].ToString();
this.textBox11.Text = dr["Mother_tongue"].ToString();
this.textBox12.Text = dr["T_famly_members"].ToString();
} conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
conn.Open();
SqlCommand cm2 = new SqlCommand("insert into papula(ID,Name,F_name,Cnic,Gendar,Marital,Current_adress,permenant_adress,Contact_no,DOB,POB,Mother_tongue,T_Famly_members) values (@ID,@Name,@F_name,@Cnic,@Gendar,@Marital,@Current_adress,@permenant_adress,@Contact_no,@DOB,@POB,@Mother_tongue,@T_Famly_members)", conn);
cm2.Parameters.AddWithValue("ID", comboBox1.Text);
cm2.Parameters.AddWithValue("Name", textBox1.Text);
cm2.Parameters.AddWithValue("F_name", textBox2.Text);
cm2.Parameters.AddWithValue("Cnic", textBox3.Text);
cm2.Parameters.AddWithValue("Gendar", textBox4.Text);
cm2.Parameters.AddWithValue("Marital", textBox5.Text);
cm2.Parameters.AddWithValue("Current_adress", textBox6.Text);
cm2.Parameters.AddWithValue("permenant_adress", textBox7.Text);
cm2.Parameters.AddWithValue("Contact_no", textBox8.Text);
cm2.Parameters.AddWithValue("DOB", textBox9.Text);
cm2.Parameters.AddWithValue("POB", textBox10.Text);
cm2.Parameters.AddWithValue("Mother_tongue", textBox11.Text);
cm2.Parameters.AddWithValue("T_Famly_members", textBox12.Text);
cm2.ExecuteNonQuery();
MessageBox.Show("Data Has Been Inserted", "Data Inserted", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
this.comboBox1.Items.Clear();
this.textBox1.Clear();
this.textBox2.Clear();
this.textBox3.Clear();
this.textBox4.Clear();
this.textBox5.Clear();
this.textBox6.Clear();
this.textBox7.Clear();
this.textBox8.Clear();
this.textBox9.Clear();
this.textBox10.Clear();
this.textBox11.Clear();
this.textBox12.Clear();
cm2 = new SqlCommand("select * from papula", conn);
SqlDataReader dr = cm2.ExecuteReader();
while (dr.Read())
{
this.comboBox1.Items.Add(dr["ID"].ToString());
}
}
catch (Exception)
{
MessageBox.Show("You Cannot Input Same ID Becouse Its Primary Key", "Alert");
this.comboBox1.Items.Clear();
}
conn.Close();
}
private void button2_Click(object sender, EventArgs e)
{
conn.Open();
SqlCommand cm3 = new SqlCommand("update papula set ID=@ID,Name=@Name,F_name=@F_name,Cnic=@Cnic,Gendar=@Gendar,Marital=@Marital,Current_adress=@Current_adress,permenant_adress=@permenant_adress,Contact_no=@Contact_no,DOB=@DOB,POB=@POB,Mother_tongue=@Mother_tongue,T_famly_members=@T_famly_members where ID = '" + comboBox1.Text + "'", conn);
cm3.Parameters.AddWithValue("ID", comboBox1.Text);
cm3.Parameters.AddWithValue("Name", textBox1.Text);
cm3.Parameters.AddWithValue("F_name", textBox2.Text);
cm3.Parameters.AddWithValue("Cnic", textBox3.Text);
cm3.Parameters.AddWithValue("Gendar", textBox4.Text);
cm3.Parameters.AddWithValue("Marital", textBox5.Text);
cm3.Parameters.AddWithValue("Current_adress", textBox6.Text);
cm3.Parameters.AddWithValue("permenant_adress", textBox7.Text);
cm3.Parameters.AddWithValue("Contact_no", textBox8.Text);
cm3.Parameters.AddWithValue("DOB", textBox9.Text);
cm3.Parameters.AddWithValue("POB", textBox10.Text);
cm3.Parameters.AddWithValue("Mother_tongue", textBox11.Text);
cm3.Parameters.AddWithValue("T_famly_members", textBox12.Text);
cm3.ExecuteNonQuery();
MessageBox.Show("Data has Updated", "Command Succesfull", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
this.comboBox1.Items.Clear();
this.textBox1.Clear();
this.textBox2.Clear();
this.textBox3.Clear();
this.textBox4.Clear();
this.textBox5.Clear();
this.textBox6.Clear();
this.textBox7.Clear();
this.textBox8.Clear();
this.textBox9.Clear();
this.textBox10.Clear();
this.textBox11.Clear();
this.textBox12.Clear();
cm3 = new SqlCommand("select * from papula", conn);
SqlDataReader dr = cm3.ExecuteReader();
while (dr.Read())
{
this.comboBox1.Items.Add(dr["ID"].ToString());
}
conn.Close();
}
private void button5_Click(object sender, EventArgs e)
{
SqlDataAdapter dat = new SqlDataAdapter("select *from papula", conn);
DataTable dt = new DataTable();
dat.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}