-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployee Interface.cs
228 lines (197 loc) · 8.16 KB
/
Employee Interface.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
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;
using System.IO;
namespace Dashboard
{
public partial class Employee_Interface : Form
{
string pwd = Class1.GetRandomPassword(20);
string wanted_path;
public static SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Aspen.mdf;Integrated Security=True;Connect Timeout=30;");
public Employee_Interface()
{
InitializeComponent();
}
string Gender;
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void btnView_Click(object sender, EventArgs e)
{
AllEmployeeDetails a = new AllEmployeeDetails();
a.ShowDialog();
}
private void Employee_Interface_Load(object sender, EventArgs e)
{
cc();
cb();
cd();
}
private void cc()
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Employee";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
cmbId.Items.Add(dr["EmpId"].ToString());
}
con.Close();
}
private void cmbId_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Employee where EmpId= '" + cmbId.SelectedItem.ToString()+"'";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
txtEmpId.Text = dr["EmpId"].ToString();
txtLastN.Text= dr["LastName"].ToString();
txtFirstN.Text = dr["FirstName"].ToString();
txtAddress.Text = dr["Address"].ToString();
dateTimePickerDOB.Text = dr["DOB"].ToString();
if (dr["Sex"].ToString() == "M")
radMale.Checked = true;
else
radFemale.Checked = true;
txtPhoneN.Text = dr["PhoneNumber"].ToString();
cmbPosition.Text = dr["Position_name"].ToString();
cmbdept.Text = dr["Dept_Name"].ToString();
txtAge.Text = dr["Age"].ToString();
dateTimePickerHired.Text = dr["HiredDate"].ToString();
}
con.Close();
}
private void dateTimePickerDOB_ValueChanged(object sender, EventArgs e)
{
DateTime from = dateTimePickerDOB.Value;
DateTime to = DateTime.Now;
TimeSpan TSpan = to - from;
double days = TSpan.TotalDays;
txtAge.Text = (days / 365).ToString("0");
}
private void btnSave_Click(object sender, EventArgs e)
{
if (radMale.Checked)
Gender = "M";
else if (radFemale.Checked)
Gender = "F";
string img_path;
File.Copy(openFileDialog1.FileName, wanted_path + "\\EmpImage\\" + pwd + " .jpg");
img_path = "EmpImage\\" + pwd + " .jpg";
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Employee values('"+txtEmpId.Text+ "','" + txtLastN.Text + "','" + txtFirstN.Text + "','" + txtAddress.Text + "','" + dateTimePickerDOB.Text + "','" + Gender + "','" + txtPhoneN.Text + "','" + cmbPosition.Text + "','" + cmbdept.Text + "','" + txtAge.Text + "','" + dateTimePickerHired.Text + "','"+ img_path.ToString()+"')";
cmd.ExecuteNonQuery();
con.Close();
cc();
MessageBox.Show("New record is Saved");
}
private void radMale_CheckedChanged(object sender, EventArgs e)
{
}
private void radFemale_CheckedChanged(object sender, EventArgs e)
{
}
private void btnClear_Click(object sender, EventArgs e)
{
txtEmpId.Text = txtLastN.Text = txtFirstN.Text = txtAddress.Text = txtPhoneN.Text= cmbdept.Text = txtAge.Text =" ";
radFemale.Checked = radMale.Checked = false;
cmbPosition.Text = cmbId.Text= "";
pictureBox2.Image = null;
}
private void cmbPosition_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void cb()
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Employee";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
cmbPosition.Items.Add(dr["Position_name"].ToString());
}
con.Close();
}
private void cd()
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Employee";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
cmbdept.Items.Add(dr["Dept_Name"].ToString());
}
con.Close();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update Employee set LastName='" + txtLastN.Text + "',FirstName='" + txtFirstN.Text + "',Address='" + txtAddress.Text + "',PhoneNumber='" + txtPhoneN.Text + "',Position_name='" + cmbPosition.Text + "',Dept_Name='" + cmbdept.Text + "',HiredDate='" + dateTimePickerHired.Text + "' where EmpId ='"+txtEmpId.Text +"'";
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record is updated successfully");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "delete from Employee where LastName='" + txtLastN.Text + "'";
cmd.ExecuteNonQuery();
con.Close();
cc();
MessageBox.Show("Record is deleted successfully");
}
private void btnLoadImage_Click(object sender, EventArgs e)
{
wanted_path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
DialogResult result = openFileDialog1.ShowDialog();
openFileDialog1.Filter= "JPG Files(*.jpg)|*.jpg|PNG Files(*.png)|*.png|All Files(*.*)|*.*";
if(result==DialogResult.OK)
{
pictureBox2.ImageLocation = openFileDialog1.FileName;
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
}
}