-
Notifications
You must be signed in to change notification settings - Fork 0
/
OfficialInfo.cs
332 lines (281 loc) · 12.3 KB
/
OfficialInfo.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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 HRM
{
public partial class OfficialInfo : Form
{
public int stfID = 0;
public OfficialInfo()
{
InitializeComponent();
}
private void OFSaveButton_Click(object sender, EventArgs e)
{
string query = ""; int DepartmentKey = ((KeyValuePair<int, string>)DeptcomboBox.SelectedItem).Key;
String DepartmentValue = ((KeyValuePair<int, string>)DeptcomboBox.SelectedItem).Value;
String DesignationValue = ((KeyValuePair<int, string>)DesigcomboBox.SelectedItem).Value;
String BloodValue = ((KeyValuePair<int, string>)BloodcomboBox.SelectedItem).Value;
String StatusValue = ((KeyValuePair<int, string>)Statuscombo.SelectedItem).Value;
string que = ""; int DesignationKey = ((KeyValuePair<int, string>)DesigcomboBox.SelectedItem).Key;
string qu = ""; int BloodKey = ((KeyValuePair<int, string>)BloodcomboBox.SelectedItem).Key;
string q = ""; int StatusKey = ((KeyValuePair<int, string>)Statuscombo.SelectedItem).Key;
if (StaftextBox.Text == "")
{
query = "SELECT Count(*) AS Count FROM Official_Info";
int rowsCount = DbAccess.NumberOfRecords(query) + 1;
stfID = Convert.ToInt32(DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + rowsCount.ToString());
}
if (StaffNatext.Text.Trim() == "")
{
MessageBox.Show("Please Enter Staff Name");
StaffNatext.Focus();
return;
}
if (DepartmentKey < 1)
{
MessageBox.Show("Please Enter Department");
DeptcomboBox.Focus();
return;
}
if (DesignationKey < 1)
{
MessageBox.Show("Please Enter designation");
DesigcomboBox.Focus();
return;
}
if (EXPText.Text.Trim() == "")
{
MessageBox.Show("Please Enter Experience");
EXPText.Focus();
return;
}
if (BloodKey < 1)
{
MessageBox.Show("Please Enter BloodGroup");
BloodcomboBox.Focus();
return;
}
if (joindateTimePicker.Text.Trim() == "")
{
MessageBox.Show("Please Enter Time");
joindateTimePicker.Focus();
return;
}
if (NationaText.Text.Trim() == "")
{
MessageBox.Show("Please Enter Nationality");
NationaText.Focus();
return;
}
if (StatusKey < 1)
{
MessageBox.Show("Please Enter Status");
Statuscombo.Focus();
return;
}
try
{
if (StaftextBox.Text == "")
{
query = "INSERT INTO Official_Info(StaffID,StaffName,Department,Designation,AgeExp,BloodGroup,JoiningDate,Nationality,Status ) VALUES(" + stfID + ", '" + StaffNatext.Text + "', '" + DepartmentValue + "', '" + DesignationValue + "', " + Convert.ToInt32(EXPText.Text) + ", '" + BloodValue + "' , '" + joindateTimePicker.Value.ToString("yyyy/MM/dd") + "', '" + NationaText.Text + "', '" + StatusValue + "' )";
}
else
{
query = "UPDATE Official_Info SET StaffName = '" + StaffNatext.Text + "' ,Department = '" + DepartmentValue + "', Designation = '" + DesignationValue + "', AgeExp= '" + Convert.ToInt32(EXPText.Text)+ "',BloodGroup = '" + BloodValue + "', JoiningDate = '" + joindateTimePicker.Value.ToString("yyyy/MM/dd") + "',Nationality = '" + NationaText.Text + "',Status = '" + StatusValue + "' WHERE StaffID = " + Convert.ToInt32(StaftextBox.Text);
}
if (DbAccess.ExecuteToDB(query))
{
if(stfID != 0)
{
MessageBox.Show("Saved Successfully!!!");
}
else
{
MessageBox.Show("Updated Successfully!!!");
}
}
else
{
MessageBox.Show("Failed To Save!!!");
}
}
catch (Exception ex)
{
MessageBox.Show("Connection Error!!!");
}
finally
{
Reset();
}
}
private void LoadCombox()
{
Dictionary<int, string> Dept = new Dictionary<int, string>();
Dept.Add(1, "Marchandising");
Dept.Add(2, "Sales");
Dept.Add(3, "Accounts");
Dept.Add(4, "Finance");
Dept.Add(5, "Production");
Dept.Add(6, "Export");
Dept.Add(7, "IT");
DeptcomboBox.DataSource = new BindingSource(Dept, null);
DeptcomboBox.DisplayMember = "Value";
DeptcomboBox.ValueMember = "Key";
deparCombo.DataSource = new BindingSource(Dept, null);
deparCombo.DisplayMember = "Value";
deparCombo.ValueMember = "Key";
int key = ((KeyValuePair<int, string>)DeptcomboBox.SelectedItem).Key;
//string value = ((KeyValuePair)District.SelectedItem).Value;
Dictionary<int, string> desig = new Dictionary<int, string>();
desig.Add(1, "GM");
desig.Add(2, "AGM");
desig.Add(3, "DGM");
desig.Add(4, "Chief Executive Officer");
desig.Add(5, "Chief Financial Officer");
desig.Add(6, "Chief Technology Officer");
desig.Add(7, "Chief Marketing Officer");
DesigcomboBox.DataSource = new BindingSource(desig, null);
DesigcomboBox.DisplayMember = "Value";
DesigcomboBox.ValueMember = "Key";
int ke = ((KeyValuePair<int, string>)DesigcomboBox.SelectedItem).Key;
//string value = ((KeyValuePair)District.SelectedItem).Value;
Dictionary<int, string> blood = new Dictionary<int, string>();
blood.Add(1, "A+");
blood.Add(2, "O+");
blood.Add(3, "AB+");
blood.Add(4, "O-");
blood.Add(5, "A-");
BloodcomboBox.DataSource = new BindingSource(blood, null);
BloodcomboBox.DisplayMember = "Value";
BloodcomboBox.ValueMember = "Key";
int k = ((KeyValuePair<int, string>)BloodcomboBox.SelectedItem).Key;
//string value = ((KeyValuePair)District.SelectedItem).Value;
Dictionary<int, string> Status = new Dictionary<int, string>();
Status.Add(1, "Active");
Status.Add(2, "Inactive");
Statuscombo.DataSource = new BindingSource(Status, null);
Statuscombo.DisplayMember = "Value";
Statuscombo.ValueMember = "Key";
int kw = ((KeyValuePair<int, string>)BloodcomboBox.SelectedItem).Key;
}
private void Reset()
{
StaftextBox.Text = "";
StaffNatext.Text = "";
EXPText.Text = "";
joindateTimePicker.Value = DateTime.Now.Date;
NationaText.Text = "";
DeptcomboBox.SelectedIndex = 0;
DesigcomboBox.SelectedIndex = 0;
BloodcomboBox.SelectedIndex = 0;
Statuscombo.SelectedIndex = 0;
OfficialDataGridView.Rows.Clear();
sdtext.Text = "";
//DeptcomboBox.DataSource = null;
//DeptcomboBox.Items.Clear();
//DesigcomboBox.DataSource = null;
//DesigcomboBox.Items.Clear();
//BloodcomboBox.DataSource = null;
//BloodcomboBox.Items.Clear();
}
private void OFResetBtn_Click(object sender, EventArgs e)
{
Reset();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void OfficialInfo_Load(object sender, EventArgs e)
{
LoadCombox();
}
private void srcBtn_Click(object sender, EventArgs e)
{
OfficialDataGridView.Rows.Clear();
int SL = 1; string s1 = ""; string s2 = ""; string s3 = ""; string s4 = ""; string s5 = ""; string s6 = ""; string s7 = ""; string s8 = ""; string s9 = ""; string s10 = "";
String DeptValue = ((KeyValuePair<int, string>)deparCombo.SelectedItem).Value;
int DeptKey = ((KeyValuePair<int, string>)deparCombo.SelectedItem).Key;
String query = "SELECT * FROM Official_Info WHERE Department = '" + DeptValue + "'";
if (sdtext.Text != "")
{
query = query + " AND StaffID = " + Convert.ToInt32(sdtext.Text);
}
SqlDataReader reader = DbAccess.GetFromDB(query);
if (reader.HasRows)
{
while (reader.Read())
{
s1 = SL.ToString();
s2 = reader["StaffID"].ToString();
s3 = reader["StaffName"].ToString();
s4 = reader["Department"].ToString();
s5 = reader["Designation"].ToString();
s6 = reader["AgeExp"].ToString();
s7 = reader["BloodGroup"].ToString();
s8 = reader["JoiningDate"].ToString();
s9 = reader["Nationality"].ToString();
s10 = reader["Status"].ToString();
OfficialDataGridView.Rows.Add(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);
SL++;
}
}
DbAccess.connnection.Close();
}
private void OFdeletebtn_Click(object sender, EventArgs e)
{
try
{
string query = "";
if (sdtext.Text.Trim() == "")
{
MessageBox.Show("Please Enter Employee ID");
sdtext.Focus();
return;
}
query = "DELETE FROM Official_Info WHERE EmpID = " + StaffID;
if (DbAccess.ExecuteToDB(query))
{
if (stfID != 0)
{
MessageBox.Show("Delete Successfully!!!");
}
else
{
MessageBox.Show("Failed To Delete!!!");
}
}
}
catch (Exception ex)
{
MessageBox.Show("Connection Error!!!");
}
finally
{
Reset();
}
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void OfficialDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
StaftextBox.Text = OfficialDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
StaffNatext.Text = OfficialDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
DeptcomboBox.SelectedIndex = DeptcomboBox.FindStringExact(OfficialDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString());
DesigcomboBox.SelectedIndex = DesigcomboBox.FindStringExact(OfficialDataGridView.Rows[e.RowIndex].Cells[4].Value.ToString());
EXPText.Text = OfficialDataGridView.Rows[e.RowIndex].Cells[5].Value.ToString();
BloodcomboBox.SelectedIndex = BloodcomboBox.FindStringExact(OfficialDataGridView.Rows[e.RowIndex].Cells[6].Value.ToString());
joindateTimePicker.Value = Convert.ToDateTime(OfficialDataGridView.Rows[e.RowIndex].Cells[7].Value.ToString());
NationaText.Text = OfficialDataGridView.Rows[e.RowIndex].Cells[8].Value.ToString();
Statuscombo.SelectedIndex = Statuscombo.FindStringExact(OfficialDataGridView.Rows[e.RowIndex].Cells[9].Value.ToString());
}
}
}