?? admin_staffmanage.aspx.cs
字號:
?using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Staff_manage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["uname"].ToString() != null && Session["role"].ToString() == "1")
{
btndel.Attributes.Add("onclick", "return confirm('刪除該員工將刪除其所有信息,確定刪除嗎?')");
btnsetpass.Attributes.Add("onclick", "return confirm('密碼重設后為123456,確定重設嗎?')");
if (!IsPostBack)
{
position p = new position();
this.dropdepartment.DataSource = p.band_department();
dropdepartment.DataTextField = "d_name";
dropdepartment.DataValueField = "d_id";
dropdepartment.DataBind();
role rolesp = new role();
this.droprole.DataSource = rolesp.sel_allroles();
this.droprole.DataTextField = "r_name";
this.droprole.DataValueField = "r_value";
this.droprole.DataBind();
band();
}
}
}
catch
{
Response.Redirect("login.aspx");
}
}
private void band()
{
staff s = new staff();
this.Manage_StaffView.DataSource = s.sel_staff();
this.Manage_StaffView.DataBind();
}
protected void dropdepartment_SelectedIndexChanged(object sender, EventArgs e)
{
position p = new position();
int d_id = Convert.ToInt32(dropdepartment.SelectedValue);
this.dropposition.DataSource = p.select_position(d_id);
this.dropposition.DataTextField = "p_name";
this.dropposition.DataValueField = "p_id";
this.dropposition.DataBind();
}
protected void btn_cancel_Click(object sender, EventArgs e)
{
this.updatetable.Visible = false;
}
protected void Manage_StaffView_SelectedIndexChanged(object sender, EventArgs e)
{
this.updatetable.Visible = false;
string s_id = this.Manage_StaffView.SelectedValue.ToString();
ViewState["s_id"] = s_id;
}
//進行更新操作
protected void btn_update_Click(object sender, EventArgs e)
{
ArrayList arr = new ArrayList();
arr.Add(this.tname.Text.Trim().ToString());
arr.Add(this.radio_sex.SelectedValue.ToString());
arr.Add(this.tnation.Text.Trim().ToString());
arr.Add(this.tbirthday.Text.Trim().ToString());
arr.Add(this.tschool.Text.Trim().ToString());
arr.Add(this.tcollage.Text.Trim().ToString());
arr.Add(this.tphone.Text.Trim().ToString());
arr.Add(this.tmobile.Text.Trim().ToString());
arr.Add(this.tmail.Text.Trim().ToString());
arr.Add(this.dropdepartment.SelectedItem.Text.ToString());
position p = new position();
arr.Add(p.Sel_departmentName(this.dropdepartment.SelectedItem.Text.ToString()));
arr.Add(this.dropposition.SelectedItem.Text.ToString());
arr.Add(this.dropposition.SelectedValue.ToString());
arr.Add(this.dropState.SelectedValue.ToString());
arr.Add(this.droprole.SelectedValue.ToString());
arr.Add(ViewState["s_id"].ToString());
staff s = new staff();
s.UpdateStaff(arr);
Response.Write("<script>alert('更新成功!')</script>");
this.updatetable.Visible = false;
ViewState["s_id"] = null;
}
protected void btncancel_Click(object sender, EventArgs e)
{
this.updatetable.Visible = false;
}
//進入編輯界面
protected void btnupdate_Click(object sender, EventArgs e)
{
if (Convert.ToString(ViewState["s_id"])!="")
{
this.updatetable.Visible = true;
staff s = new staff();
SqlDataReader dr = s.sel_staffInfo(Convert.ToInt32(ViewState["s_id"]));
if (dr.Read())
{
this.tname.Text = dr["s_name"].ToString();
this.radio_sex.SelectedItem.Text = dr["s_sex"].ToString();
this.tbirthday.Text = Convert.ToDateTime(dr["s_birthday"].ToString()).ToShortDateString();
this.tnation.Text = dr["s_nation"].ToString();
this.tschool.Text = dr["s_collage"].ToString();
this.tcollage.Text = dr["s_edu"].ToString();
this.tphone.Text = dr["s_phone"].ToString();
this.tmobile.Text = dr["s_mobile"].ToString();
this.tmail.Text = dr["s_email"].ToString();
this.dropdepartment.SelectedItem.Text = dr["s_department"].ToString();
int d_id = Convert.ToInt32(dr["s_departmentid"]);
position p = new position();
this.dropposition.DataSource = p.select_position(d_id);
this.dropposition.DataTextField = "p_name";
this.dropposition.DataValueField = "p_id";
this.dropposition.DataBind();
this.dropposition.SelectedItem.Text = dr["s_position"].ToString();
this.dropState.SelectedValue = dr["s_status"].ToString();
this.droprole.SelectedValue = dr["r_name"].ToString();
this.ttime.Text = Convert.ToDateTime(dr["s_registerDate"].ToString()).ToShortDateString();
}
}
else
{
Response.Write("<script>alert('請選擇要編輯的數據!')</script>");
}
}
protected void Manage_StaffView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.Manage_StaffView.PageIndex = e.NewPageIndex;
band();
}
protected void btndel_Click(object sender, EventArgs e)
{
if (Convert.ToString(ViewState["s_id"]) != "")
{
staff s = new staff();
s.del_StaffAllInfo(ViewState["s_id"].ToString());
band();
Response.Write("<script>alert('刪除成功!')</script>");
updatetable.Visible = false;
ViewState["s_id"] = null;
}
else
{
Response.Write("<script>alert('請選擇要刪除的數據!')</script>");
}
}
protected void btnsetpass_Click(object sender, EventArgs e)
{
if (Convert.ToString(ViewState["s_id"]) != "")
{
staff s = new staff();
string password=FormsAuthentication.HashPasswordForStoringInConfigFile("123456","MD5");
s.set_password(ViewState["s_id"].ToString(), password);
Response.Write("<script>alert('密碼重設成功!')</script>");
updatetable.Visible = false;
ViewState["s_id"] = null;
}
else
{
Response.Write("<script>alert('請選擇要重設密碼的用戶!')</script>");
}
}
protected void btn_search_Click(object sender, EventArgs e)
{
string cword = this.tword.Text.Trim().ToString();
string type = droptype.SelectedItem.Value.ToString();
staff s = new staff();
if(type=="員工編號")
{
try
{
if (cword == "")
{
band();
Response.Write("<script>alert('請輸入員工編號!')</script>");
}
else
{
this.Manage_StaffView.DataSource = s.SelectStaffInfo_id(Convert.ToString(cword));
}
}
catch
{
Response.Write("<script>alert('編號字符串格式輸入錯誤!')</script>");
}
}
else if (type == "姓名")
{
this.Manage_StaffView.DataSource = s.SelectStaffInfo_Name(cword);
}
else if (type == "部門")
{
this.Manage_StaffView.DataSource = s.SelectStaffInfo_Department(cword);
}
this.Manage_StaffView.DataBind();
updatetable.Visible = false;
}
protected void Manage_StaffView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠標經過時,行背景色變
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ECF3E1'");
//鼠標移出時,行背景色變
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -