-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployeeInfo_Admin.aspx.cs
96 lines (84 loc) · 3.11 KB
/
EmployeeInfo_Admin.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class EmployeeInfo_Admin : System.Web.UI.Page
{
string connString = "Data Source=omisbi3.niunt.niu.edu;Initial Catalog=z1776136;Persist Security Info=True;User ID=z1776136;Password=Bw1243$h11";
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowData();
}
}
protected void ShowData()
{
using (SqlConnection conn = new SqlConnection(connString))
{
try
{
conn.Open();
using (var cmd = new SqlCommand("SELECT [emp_id],d.[dept_id],[dept_name],[emp_fname],[emp_lname],[emp_doj],[emp_address],[salary],[emp_phone] FROM [employee] e,[department] d where e.dept_id=d.dept_id", conn))
{
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
EmpInfo.DataSource = dt;
EmpInfo.DataBind();
}
}
}
catch (Exception E)
{
String s = E.Message;
}
finally
{
if (conn != null)
{
conn.Close();
}
}
}
}
protected void EmpInfo_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
{
EmpInfo.EditIndex = e.NewEditIndex;
ShowData();
}
protected void EmpInfo_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
{
Label id = EmpInfo.Rows[e.RowIndex].FindControl("emp_id") as Label;
Label dept_id = EmpInfo.Rows[e.RowIndex].FindControl("dept_id") as Label;
TextBox dept_name = EmpInfo.Rows[e.RowIndex].FindControl("dept_name1") as TextBox;
TextBox salary = EmpInfo.Rows[e.RowIndex].FindControl("salary1") as TextBox;
con = new SqlConnection(connString);
con.Open();
SqlCommand cmd = new SqlCommand("Update employee set salary=@salary where emp_id=@id", con);
cmd.Parameters.AddWithValue("@salary", Convert.ToDecimal(salary.Text));
cmd.Parameters.AddWithValue("@id", Convert.ToInt32(id.Text));
cmd.ExecuteNonQuery();
con.Close();
con.Open();
SqlCommand cmd1 = new SqlCommand("Update department set dept_name=@name where dept_id=@id", con);
cmd1.Parameters.AddWithValue("@name",dept_name.Text);
cmd1.Parameters.AddWithValue("@id", Convert.ToInt32(dept_id.Text));
cmd1.ExecuteNonQuery();
con.Close();
EmpInfo.EditIndex = -1;
ShowData();
}
protected void EmpInfo_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
{
EmpInfo.EditIndex = -1;
ShowData();
}
}