001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.Linq;
004.
using
System.Web;
005.
using
System.Web.UI;
006.
using
System.Web.UI.WebControls;
007.
using
System.Data.SqlClient;
008.
using
System.Data;
009.
using
System.Configuration;
010.
011.
namespace
Dentist
012.
{
013.
public
partial
class
Staff : System.Web.UI.Page
014.
{
015.
SqlConnection con =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"Dentist_Pool"
].ConnectionString);
016.
017.
SqlDataAdapter da =
null
;
018.
DataTable dt =
null
;
019.
020.
protected
void
Page_Load(
object
sender, EventArgs e)
021.
{
022.
}
023.
024.
protected
void
btnStaffsubmit_Click(
object
sender, EventArgs e)
025.
{
026.
IsStaffdate(txtStaffid.Text);
027.
}
028.
protected
void
IsStaffdate(
string
staffid)
029.
{
030.
con.Open();
031.
032.
String sqlSelect =
"select StaffId from Staffdate where StaffId = @staffid"
;
033.
SqlCommand com =
new
SqlCommand(sqlSelect, con);
034.
035.
com.Parameters.AddWithValue(
"@staffid"
, txtStaffid.Text);
036.
037.
using
(IDataReader reader = com.ExecuteReader())
038.
{
039.
while
(reader.Read())
040.
{
041.
Session[
"sessionStaffId"
] = reader.GetInt32(0);
042.
break
;
043.
}
044.
reader.Close();
045.
con.Close();
046.
047.
con.Open();
048.
String sqlSelect2 =
"select StaffdateId, StaffLeaveStart, StaffLeaveFinish, StaffTimeStart, StaffTimeFinish, StaffLeaveNote from Staffdate where StaffId = '"
+ Session[
"sessionStaffId"
] +
"'"
;
049.
da =
new
SqlDataAdapter(sqlSelect2, con);
050.
con.Close();
051.
052.
}
053.
054.
055.
056.
////SqlCommand com = new SqlCommand();
057.
////com.Parameters.AddWithValue("@staffid", txtStaffid.Text);
058.
059.
060.
061.
062.
BindData();
063.
}
064.
065.
void
BindData()
066.
{
067.
dt =
new
DataTable();
068.
da.Fill(dt);
069.
grdStaffdate.DataSource = dt;
070.
grdStaffdate.DataBind();
071.
072.
dt =
null
;
073.
con.Close();
074.
}
075.
076.
void
Page_Unload()
077.
{
078.
con.Close();
079.
con =
null
;
080.
}
081.
082.
protected
void
modEditCommand(
object
sender, GridViewEditEventArgs e)
083.
{
084.
Label lblStaffLeaveStart = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"lbllblStaffLeaveStartt"
)
as
Label;
085.
Label lblStaffLeaveFinish = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"lblStaffLeaveFinish"
)
as
Label;
086.
Label lblStaffTimeStart = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"lblStaffTimeStart"
)
as
Label;
087.
Label lblStaffTimeFinish = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"lblStaffTimeFinish"
)
as
Label;
088.
Label lblStaffLeaveNote = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"lblStaffLeaveNote"
)
as
Label;
089.
090.
grdStaffdate.EditIndex = e.NewEditIndex;
091.
grdStaffdate.ShowFooter =
false
;
092.
BindData();
093.
094.
TextBox txtEditLeaveStart = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"txtEditLeaveStart"
)
as
TextBox;
095.
TextBox txtEditLeaveFinish = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"txtEditLeaveFinish"
)
as
TextBox;
096.
DropDownList ddlEditTimeStart = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"ddlEditTimeStart"
)
as
DropDownList;
097.
DropDownList ddlEditTimeFinish = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"ddlEditTimeFinish"
)
as
DropDownList;
098.
TextBox txtEditLeaveNote = (sender
as
GridView).Rows[e.NewEditIndex].FindControl(
"txtEditLeaveNote"
)
as
TextBox;
099.
100.
txtEditLeaveStart.Text = lblStaffLeaveStart.Text;
101.
txtEditLeaveFinish.Text = lblStaffLeaveFinish.Text;
102.
ddlEditTimeStart.Text = lblStaffTimeStart.Text;
103.
ddlEditTimeStart.Text = lblStaffTimeFinish.Text;
104.
txtEditLeaveNote.Text = lblStaffLeaveNote.Text;
105.
}
106.
protected
void
modCancelCommand(
object
sender, GridViewCancelEditEventArgs e)
107.
{
108.
grdStaffdate.EditIndex = -1;
109.
grdStaffdate.ShowFooter =
false
;
110.
BindData();
111.
}
112.
protected
void
modDeleteCommand(
object
sender, GridViewDeleteEventArgs e)
113.
{
114.
con.Open();
115.
String sqlDelete =
"delete from Staffdate where StaffdateId = '"
+ grdStaffdate.DataKeys[e.RowIndex].Value +
"'"
;
116.
SqlCommand com =
new
SqlCommand(sqlDelete, con);
117.
com.ExecuteNonQuery();
118.
con.Close();
119.
120.
grdStaffdate.EditIndex = -1;
121.
BindData();
122.
}
123.
protected
void
modUpdateCommand(
object
sender, GridViewUpdateEventArgs e)
124.
{
125.
TextBox txtEditLeaveStart = (TextBox)grdStaffdate.Rows[e.RowIndex].FindControl(
"txtEditLeaveStart"
);
126.
TextBox txtEditLeaveFinish = (TextBox)grdStaffdate.Rows[e.RowIndex].FindControl(
"txtEditLeaveFinish"
);
127.
DropDownList ddlEditTimeStart = (DropDownList)grdStaffdate.Rows[e.RowIndex].FindControl(
"ddlEditTimeStart"
);
128.
DropDownList ddlEditTimeFinish = (DropDownList)grdStaffdate.Rows[e.RowIndex].FindControl(
"ddlEditTimeFinish"
);
129.
TextBox txtEditLeaveNote = (TextBox)grdStaffdate.Rows[e.RowIndex].FindControl(
"txtEditLeaveNote"
);
130.
131.
con.Open();
132.
String sqlUpdate =
"update Staffdate set StaffLeaveStart = '"
+ txtEditLeaveStart.Text +
"'"
+
" , StaffLeaveFinish = '"
+ txtEditLeaveFinish.Text +
"'"
+
" , StaffTimeStart = '"
+ ddlEditTimeStart.Text +
"'"
133.
+
" , StaffTimeFinish ='"
+ ddlEditTimeFinish.Text +
"'"
+
" , StaffLeaveNote = '"
+ txtEditLeaveNote.Text +
"'"
+
" where StaffId = '"
+ grdStaffdate.DataKeys[e.RowIndex].Value +
"'"
;
134.
SqlCommand com =
new
SqlCommand(sqlUpdate, con);
135.
com.ExecuteNonQuery();
136.
con.Close();
137.
138.
grdStaffdate.EditIndex = -1;
139.
grdStaffdate.ShowFooter =
true
;
140.
BindData();
141.
}
142.
protected
void
modRowCommand(
object
sender, GridViewCommandEventArgs e)
143.
{
144.
if
(e.CommandName ==
"Add"
)
145.
{
146.
TextBox txtAddLeaveStart = (TextBox)grdStaffdate.FooterRow.FindControl(
"txtAddLeaveStart"
);
147.
TextBox txtAddLeaveFinish = (TextBox)grdStaffdate.FooterRow.FindControl(
"txtAddLeaveFinish"
);
148.
DropDownList ddlAddTimeStart = (DropDownList)grdStaffdate.FooterRow.FindControl(
"ddlAddTimeStart"
);
149.
DropDownList ddlAddTimeFinish = (DropDownList)grdStaffdate.FooterRow.FindControl(
"ddlAddTimeFinish"
);
150.
TextBox txtAddLeaveNote = (TextBox)grdStaffdate.FooterRow.FindControl(
"txtAddLeaveNote"
);
151.
152.
con.Open();
153.
String sqlInsert =
"insert into Staffdate (StaffLeaveStart, StaffLeaveFinish, StaffTimeStart, StaffTimeFinish, StaffLeaveNote)"
+
154.
"values ('"
+ txtAddLeaveStart.Text +
"','"
+ txtAddLeaveFinish.Text +
"','"
+ ddlAddTimeStart.Text +
"','"
+ ddlAddTimeFinish.Text +
"', '"
+ txtAddLeaveNote.Text +
"')"
;
155.
SqlCommand com =
new
SqlCommand(sqlInsert,con);
156.
com.ExecuteNonQuery();
157.
con.Close();
158.
159.
BindData();
160.
}
161.
}
162.
163.
164.
protected
void
btnStaffcancel_Click(
object
sender, EventArgs e)
165.
{
166.
txtStaffid.Text =
""
;
167.
}
168.
169.
protected
void
btnStaffAdd_Click(
object
sender, EventArgs e)
170.
{
171.
Response.Redirect(
"~/Clinic/StaffAdd.aspx"
);
172.
}
173.
}
174.
}