⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin_staffmanage.aspx.cs

📁 oa办公系统
💻 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 + -