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

📄 5职工信息管理.aspx.cs

📁 本系统时物资管理系统
💻 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 _6职工 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);
       
        string sql = "select 职工编号 from 职工信息表";
        SqlCommand myComm = new SqlCommand(sql, myConn);
        myConn.Open();
        SqlDataReader myReader = myComm.ExecuteReader();
        if (!IsPostBack)
        {
             
            this.DropDownList1.Items.Add("");
            while (myReader.Read())
            {
                this.DropDownList1.Items.Add(myReader.GetValue(0).ToString());
            }
        }
            myReader.Close();
        
        
            
            sql = "select 姓名 from 职工信息表";
            myComm = new SqlCommand(sql, myConn);
            myReader = myComm.ExecuteReader();
            if (!IsPostBack)
            {
                this.DropDownList2.Items.Add("");
                while (myReader.Read())
               {
                this.DropDownList2.Items.Add(myReader.GetValue(0).ToString());
               }
           }
            myReader.Close();

        
        if (!IsPostBack)
        {
            this.DropDownList3.Items.Add("");
            this.DropDownList3.Items.Add("男");
            this.DropDownList3.Items.Add("女");
        }
        
        
        sql = "select 部门名称 from 部门信息表";
        myComm = new SqlCommand(sql, myConn);
        myReader = myComm.ExecuteReader();
        if(!IsPostBack)
        {
            this.DropDownList4.Items.Add("");
            while (myReader.Read())
            {
                this.DropDownList4.Items.Add(myReader.GetValue(0).ToString());
            }
        }
        myReader.Close();
        
        myConn.Close();

    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        this.Response.Redirect("3物资信息管理.aspx");
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);
        if (this.TextBox2.Text != "")
        {
            string zhigongbianhao=""; 
            string msql = "select 职工编号 from 职工信息表 where 职工编号='" + this.TextBox2.Text+"'";
            SqlCommand myCom = new SqlCommand(msql, myConn);
            myConn.Open();
            SqlDataReader myReader = myCom.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Columns.Add("职工编号", typeof(string));
            if (myReader.Read())
            {
                    DataRow dr = dt.NewRow();
                    dr[0] = myReader.GetValue(0).ToString();
                    zhigongbianhao = Convert.ToString(dr[0]);
                    
            }
            
            myReader.Close();
            if (this.TextBox2.Text!=zhigongbianhao)
            {
                if (this.TextBox3.Text != "" && this.DropDownList3.Text != "" && this.DropDownList4.Text != "" && this.TextBox4.Text != "" )
                {
                    string birthday = Convert.ToString(this.TextBox4.Text);
                    string sql = "insert into 职工信息表(职工编号,姓名,性别,部门名称,出生日期)values('" + this.TextBox2.Text + "','" +
                    this.TextBox3.Text + "','" + this.DropDownList3.Text + "','" + this.DropDownList4.Text + "','" + birthday + "')";
                    //"insert into 职工信息表(职工编号,姓名,性别,部门名称,出生日期)values('" + this.TextBox2.Text + "','" +
                    //this.TextBox3.Text + "','" + this.DropDownList3 + "','" + this.DropDownList4.Text +"','"+this.TextBox4.Text +  "')";
                    SqlCommand myComm = new SqlCommand(sql, myConn);
                    this.DropDownList1.Items.Add(this.TextBox2.Text);
                    this.DropDownList2.Items.Add(this.TextBox3.Text);

                 
                    myComm.ExecuteNonQuery();
               ;
                    //this.Response.Write("<scrip language=javascrip>alter('添加成功!')</script>");
                    this.Response.Write("<script language=javascript>alert('添加成功!')</script>");
                    this.TextBox2.Text = "";
                    this.TextBox3.Text = "";
                    this.TextBox4.Text = "";
                    
                    this.DropDownList3.Text = "";
                    
                    this.DropDownList4.Text = "";
                }
                else
                {
                    this.Response.Write("<script language=javascript>alert('输入信息不完整!')</script>");
                }
                }
                else
                this.Response.Write("<script language=javascript>alert('该职工编号已存在!')</script>");
            myConn.Close();
            }
     else
        {
            this.Response.Write("<script language=javascript>alert('输入信息不完整!')</script>");
        }
    }
   
    protected void Button4_Click(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);
        string sql;
        if (this.DropDownList1.Text != ""|| this.DropDownList2.Text != "")
        {

            if (this.DropDownList1.Text != "")
            {
                sql = "delete from 职工信息表 where 职工编号='" + this.DropDownList1.Text + "'";
            }
            else
                sql = "delete from 职工信息表 where 姓名 ='" + this.DropDownList2.Text + "'";
            SqlCommand myComm = new SqlCommand(sql, myConn);
            myConn.Open();
            myComm.ExecuteNonQuery();
            myConn.Close();
            //this.Response.Write("<scrip language=javascrip>alter('!')</script>");
            this.TextBox2.Text = "";
            this.TextBox3.Text = "";
            this.TextBox4.Text = "";

            this.DropDownList3.Text = "";

            this.DropDownList4.Text = "";
            Response.Write("<script>alert('删除成功!')</script>");
        }
        else 
        {
           Response.Write("<script>alert('请输入搜索项!')</script>");
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);
        string sql;
        myConn.Open();
        if (this.DropDownList1.Text != "" || this.DropDownList2.Text != "")
        {
            string zhigongbianhao="";
            if (this.DropDownList1.Text != "")
            {
                sql = "select 职工编号 from 职工信息表 where 职工编号='" + this.DropDownList1.Text + "'";
                SqlCommand myCom = new SqlCommand(sql, myConn);
                SqlDataReader myReader1 = myCom.ExecuteReader();
                DataTable d = new DataTable();
                d.Columns.Add("职工编号", typeof(string));
                if (myReader1.Read())
                {
                    DataRow dr = d.NewRow();
                    dr[0] = myReader1.GetValue(0).ToString();
                    zhigongbianhao = Convert.ToString(dr[0]);

                }

                myReader1.Close();
                if (this.DropDownList1.Text != zhigongbianhao)
                    this.Response.Write("<script language=javascript>alert('数据库中无此项记录!')</script>");
                sql = "select 职工编号,姓名,性别,部门名称,出生日期 from 职工信息表 where 职工编号 ='" + this.DropDownList1.Text + "'";
            }
            else
                sql = "select 职工编号,姓名,性别,部门名称,出生日期 from 职工信息表 where 姓名 ='" + this.DropDownList2.Text + "'";
            SqlCommand myComm = new SqlCommand(sql, myConn);
           
            SqlDataReader myReader = myComm.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Columns.Add("职工编号", typeof(string));
            dt.Columns.Add("姓名", typeof(string));
            dt.Columns.Add("性别", typeof(string));
            dt.Columns.Add("部门名称", typeof(string));
            dt.Columns.Add("出生日期", typeof(string));
            
                while (myReader.Read())
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = myReader.GetValue(0).ToString();
                    dr[1] = myReader.GetValue(1).ToString();
                    dr[2] = myReader.GetValue(2).ToString();
                    dr[3] = myReader.GetValue(3).ToString();
                    dr[4] = myReader.GetValue(4).ToString();
                    dt.Rows.Add(dr);
                }
                myReader.Close();
                this.GridView2.DataSource = new DataView(dt);
                this.GridView2.DataBind();
           
            myConn.Close();
        }
        else
        {
            Response.Write("<script>alert('请输入搜索项')</script>");
        }
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";

        SqlConnection myConn = new SqlConnection(myConnStr);
        if (this.TextBox2.Text != "")
        {
            string sql = "update 职工信息表 set 职工编号='" + this.TextBox2.Text + "'";
            if (this.DropDownList1.Text != "")
            {
                if (this.TextBox3.Text != "")
                    sql = sql + ", 姓名='" + this.TextBox3.Text + "'";
                if (this.DropDownList3.Text != "")
                    sql = sql + ", 性别='" + this.DropDownList3.Text + "'";
                if (this.DropDownList4.Text != "")
                    sql = sql + ", 部门名称='" + this.DropDownList4.Text + "'";
                if (this.TextBox4.Text != "")
                {
                    string  birthday = Convert.ToString(this.TextBox4.Text);
                    sql = sql + ", 出生日期='" +birthday  + "'";
                }
                sql += "where 职工编号='" + this.DropDownList1.Text + "'";
            }
            else
            {
                if (this.TextBox3.Text != "")
                    sql = sql + ", 姓名='" + this.TextBox3.Text + "'";
                if (this.DropDownList3.Text != "")
                    sql = sql + ", 性别='" + this.DropDownList3.Text + "'";
                if (this.DropDownList4.Text != "")
                    sql = sql + ", 部门名称='" + this.DropDownList4.Text + "'";
                if (this.TextBox4.Text != "")
                    sql = sql + ", 出生日期='" + this.TextBox3.Text + "'";
                sql += "where 姓名='" + this.DropDownList2.Text + "'";
            }

            SqlCommand myComm = new SqlCommand(sql, myConn);
            myConn.Open();
            myComm.ExecuteNonQuery();
            myConn.Close();
            //this.Response.Write("<script language=javascript>alert('修改成功!')</script>");
            Response.Write("<script>alert('修改成功!')</script>");
        }
        else
        {
            Response.Write("<script>alert('修改时,必须输入职工编号!如不清楚,可在搜索中填入姓名,点击核对,进行查询。')</script>");
        }
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        this.Response.Redirect("6部门信息管理.aspx");
    }
   
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        this.Response.Redirect("库存信息管理.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Response.Redirect("1首页.aspx");
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        this.Response.Redirect("3物资信息管理.aspx");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -