-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAddEmployee.aspx.cs
118 lines (110 loc) · 4.06 KB
/
AddEmployee.aspx.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL.EOperations;
using MySql.Web;
using DAL.Entities;
using BLL.BOperations;
using MySql.Data.MySqlClient;
using System.Data;
public partial class AddEmployee : System.Web.UI.Page
{
MySqlConnection con = new MySqlConnection("Server=192.3.73.34;Database=uhuospdn_practice;Uid=uhuospdn_sql;Pwd=rlL)~~*NJ7t(;");
EEmployee emp = new EEmployee();
EOperation empHandler = new EOperation();
protected void Page_Load(object sender, EventArgs e)
{
GenerateId();
}
protected void AddEmp_Click(object sender, EventArgs e)
{
try
{
emp.ID = Convert.ToInt32(EID.Text);
emp.FNAME = EFname.Text;
emp.LNAME = ELname.Text;
emp.EMAIL = EEmail.Text;
emp.PASSWORD = EPass.Text;
emp.DOB = Convert.ToDateTime(EDOB.Text).Date;
emp.TELEPHONE = ETel.Text;
emp.MOBILENO = EMoblie.Text;
emp.DOJ = Convert.ToDateTime(EDOJ.Text).Date;
emp.STATUS = EStatus.Text;
emp.GENDER = EGender.Text;
emp.ROLE = int.Parse(empHandler.GetEmployeeRoleId(ERole.Text));
emp.SALARY = decimal.Parse(Esalary.Text);
if (empHandler.AddNewEmployee(emp) > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alertMessage", "alert('Employee Record Inserted!')", true);
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "')</script>");
}
#region ClearInputs
//Loop through all the control present on the web page/form
foreach (Control ctrl in form2.Controls)
{
//check for all the TextBox controls on the page and clear them
if (ctrl.GetType() == typeof(TextBox))
{
((TextBox)(ctrl)).Text = string.Empty;
}
//check for all the Label controls on the page and clear them
else if (ctrl.GetType() == typeof(Label))
{
((Label)(ctrl)).Text = string.Empty;
}
//check for all the DropDownList controls on the page and reset it to the very first item e.g. "-- Select One --"
else if (ctrl.GetType() == typeof(DropDownList))
{
((DropDownList)(ctrl)).SelectedIndex = 0;
}
//check for all the CheckBox controls on the page and unchecked the selection
else if (ctrl.GetType() == typeof(CheckBox))
{
((CheckBox)(ctrl)).Checked = false;
}
//check for all the CheckBoxList controls on the page and unchecked all the selections
else if (ctrl.GetType() == typeof(CheckBoxList))
{
((CheckBoxList)(ctrl)).ClearSelection();
}
//check for all the RadioButton controls on the page and unchecked the selection
else if (ctrl.GetType() == typeof(RadioButton))
{
((RadioButton)(ctrl)).Checked = false;
}
//check for all the RadioButtonList controls on the page and unchecked the selection
else if (ctrl.GetType() == typeof(RadioButtonList))
{
((RadioButtonList)(ctrl)).ClearSelection();
}
}
#endregion
GenerateId();
}
void GenerateId()
{
try
{
con.Open();
MySqlDataAdapter sda = new MySqlDataAdapter("SELECT IFNULL(MAX(E_ID),0)+1 FROM Employee", con);
DataTable dt = new DataTable();
sda.Fill(dt);
EID.Text = dt.Rows[0][0].ToString();
ERole.DataSource = empHandler.GetEmployeeRole();
ERole.DataTextField = "Role_Name";
ERole.DataBind();
con.Close();
}
catch (MySqlException ex)
{
Response.Write("<script>alert('" + ex.Message + "')</script>");
}
}
}