Esempio n. 1
0
        /// <summary>
        /// 更新某个员工信息,员工编号不变。
        /// </summary>
        /// <param name="sstaff">员工类对象.</param>
        /// <returns>通过布尔值提示是否完成.</returns>
        public bool updateStaff(Model.staff sstaff)
        {
            string sqltext               = "update staff set staffName=@staffName,departId=@departId,birthday=@birthday,gender=@gender,hometown=@hometown,idCard=@idCard,phoneNumber=@phoneNumber where staffNum=@staffNum";
            List <SqlParameter> para     = new List <SqlParameter>();
            SqlParameter        sqlpara1 = new SqlParameter("@staffNum", sstaff.StaffNum);
            SqlParameter        sqlpara2 = new SqlParameter("@staffName", sstaff.StaffName);
            SqlParameter        sqlpara3 = new SqlParameter("@departId", sstaff.DepartId);
            SqlParameter        sqlpara4 = new SqlParameter("@birthday", sstaff.Birthday.ToString());
            SqlParameter        sqlpara5 = new SqlParameter("@gender", sstaff.Gender);
            SqlParameter        sqlpara6 = new SqlParameter("@hometown", sstaff.Hometown);
            SqlParameter        sqlpara7 = new SqlParameter("@idCard", sstaff.IdCard);
            SqlParameter        sqlpara8 = new SqlParameter("@phoneNumber", sstaff.PhoneNumber);

            para.Add(sqlpara2);
            para.Add(sqlpara3);
            para.Add(sqlpara4);
            para.Add(sqlpara5);
            para.Add(sqlpara6);
            para.Add(sqlpara7);
            para.Add(sqlpara8);
            para.Add(sqlpara1);
            int i = DBTools.exenonquerySQL(sqltext, para);

            if (i == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获得具有某个员工编号的员工.
        /// </summary>
        /// <param name="nnum">员工编号.</param>
        /// <returns>符合条件的员工类对象泛型集合.</returns>
        public Model.staff getStaffByNum(string nnum)
        {
            Model.staff         staff    = null;
            string              sqltext  = "select * from staff where staffNum=@staffNum";
            List <SqlParameter> para     = new List <SqlParameter>();
            SqlParameter        sqlpara1 = new SqlParameter("@staffNum", nnum);

            para.Add(sqlpara1);
            SqlDataReader sdr = DBTools.exereaderSQL(sqltext, para);

            while (sdr.Read())
            {
                staff             = new Model.staff();
                staff.StaffNum    = sdr["staffNum"].ToString();
                staff.StaffName   = sdr["staffName"].ToString();
                staff.DepartId    = sdr["DepartId"].ToString();
                staff.Department  = new DAL.DepartmentDAO().getDepartById(staff.DepartId);
                staff.Birthday    = DateTime.Parse(sdr["birthday"].ToString());
                staff.Gender      = sdr["gender"].ToString();
                staff.Hometown    = sdr["hometown"].ToString();
                staff.IdCard      = sdr["idCard"].ToString();
                staff.PhoneNumber = sdr["phoneNumber"].ToString();
                staff.EntryTime   = DateTime.Parse(sdr["entryTime"].ToString());
            }
            sdr.Close();
            DBTools.DBClose();
            return(staff);
        }
Esempio n. 3
0
        /// <summary>
        /// 获得所有的员工对象.
        /// </summary>
        /// <returns>员工对象泛型集合.</returns>
        public List <Model.staff> getStaffs()
        {
            List <Model.staff> staff   = new List <Model.staff>();
            string             sqltext = "select * from staff";
            SqlDataReader      sdr     = DBTools.exereaderSQL(sqltext, new List <SqlParameter> ());

            while (sdr.Read())
            {
                Model.staff s = new Model.staff();
                s.StaffNum    = sdr["staffNum"].ToString();
                s.StaffName   = sdr["staffName"].ToString();
                s.DepartId    = sdr["DepartId"].ToString();
                s.Department  = new DAL.DepartmentDAO().getDepartById(s.DepartId);
                s.Birthday    = DateTime.Parse(sdr["birthday"].ToString());
                s.Gender      = sdr["gender"].ToString();
                s.Hometown    = sdr["hometown"].ToString();
                s.IdCard      = sdr["idCard"].ToString();
                s.PhoneNumber = sdr["phoneNumber"].ToString();
                s.EntryTime   = DateTime.Parse(sdr["entryTime"].ToString());
                staff.Add(s);
            }
            sdr.Close();
            DBTools.DBClose();
            return(staff);
        }
Esempio n. 4
0
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "editt")
     {
         Div1.Style["display"] = "inline";
         int xy = Convert.ToInt32(e.CommandArgument);
         Button9.Text      = "确定";
         GridView1.Visible = false;
         if (GridView1.Visible == true)
         {
             Button1.Visible  = true;
             Button4.Visible  = true;
             Button5.Visible  = true;
             ListBox1.Visible = true;
             TextBox5.Visible = true;
         }
         else if (GridView1.Visible == false)
         {
             Button1.Visible  = false;
             Button4.Visible  = false;
             Button5.Visible  = false;
             ListBox1.Visible = false;
             TextBox5.Visible = false;
         }
         TextBox1.Text = GridView1.Rows[xy].Cells[1].Text;
         TextBox2.Text = GridView1.Rows[xy].Cells[2].Text;
         //TextBox3.Text = GridView1.Rows[xy].Cells[3].Text;
         //TextBox4.Text = GridView1.Rows[xy].Cells[4].Text;
         Model.Department de = new Model.Department();
         Model.staff      st = new Model.staff();
         de               = new DAL.DepartmentDAO().getDepartById(GridView1.Rows[xy].Cells[3].Text);
         st               = new DAL.StaffDAO().getStaffByNum(GridView1.Rows[xy].Cells[4].Text);
         TextBox3.Text    = de.DepartName;
         TextBox4.Text    = st.StaffName;
         Image11.Visible  = true;
         Image11.ImageUrl = "~/Image/对号.png";
         Image12.Visible  = true;
         Image12.ImageUrl = "~/Image/对号.png";
         Image1.Visible   = true;
         Image1.ImageUrl  = "~/Image/对号.png";
         Image2.Visible   = true;
         Image2.ImageUrl  = "~/Image/对号.png";
         rl.Refresh3("departId", "departName", "Department", TextBox1.Text, ListBox2);
     }
     if (e.CommandName == "deletee")
     {
         ideas.Style["display"] = "inline";
         int x = Convert.ToInt32(e.CommandArgument);
         Session["e"] = x;
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.staff model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update staff set ");
            strSql.Append("staff_name=@staff_name,");
            strSql.Append("staff_sex=@staff_sex,");
            strSql.Append("staff_identity_card=@staff_identity_card,");
            strSql.Append("staff_phone_number=@staff_phone_number,");
            strSql.Append("staff_age=@staff_age,");
            strSql.Append("staff_hire_date=@staff_hire_date,");
            strSql.Append("staff_belong_dep_id=@staff_belong_dep_id");
            strSql.Append(" where staff_id=@staff_id ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@staff_name",          MySqlDbType.VarChar,   64),
                new MySqlParameter("@staff_sex",           MySqlDbType.VarChar,    2),
                new MySqlParameter("@staff_identity_card", MySqlDbType.VarChar,   18),
                new MySqlParameter("@staff_phone_number",  MySqlDbType.Int32,     16),
                new MySqlParameter("@staff_age",           MySqlDbType.Int32,      4),
                new MySqlParameter("@staff_hire_date",     MySqlDbType.DateTime),
                new MySqlParameter("@staff_belong_dep_id", MySqlDbType.Int32,     32),
                new MySqlParameter("@staff_id",            MySqlDbType.Int32, 32)
            };
            parameters[0].Value = model.staff_name;
            parameters[1].Value = model.staff_sex;
            parameters[2].Value = model.staff_identity_card;
            parameters[3].Value = model.staff_phone_number;
            parameters[4].Value = model.staff_age;
            parameters[5].Value = model.staff_hire_date;
            parameters[6].Value = model.staff_belong_dep_id;
            parameters[7].Value = model.staff_id;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 是否已有相同编号的员工.
        /// </summary>
        /// <returns>如果有,则返回True;没有,则返回False.</returns>
        public bool hasStaffOfNum(string staffnum)
        {
            Model.staff         staff    = new Model.staff();
            string              sqltext  = "select * from staff where staffNum=@staffNum";
            List <SqlParameter> para     = new List <SqlParameter>();
            SqlParameter        sqlpara1 = new SqlParameter("@staffNum", staffnum);

            para.Add(sqlpara1);
            SqlDataReader sdr = DBTools.exereaderSQL(sqltext, para);

            while (sdr.Read())
            {
                sdr.Close();
                DBTools.DBClose();
                return(true);
            }

            return(false);
        }
        protected void Button30_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            Model.staff staff = new Model.staff();
            GridViewRow row   = (GridViewRow)btn.NamingContainer;

            staff.StaffNum = row.Cells[0].Text;
            bool xx = new DAL.StaffDAO().deleteStaffByNum(staff.StaffNum);

            if (xx)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('删除成功!');", true);
                Response.Redirect(Request.Url.ToString());
                rg.Refresh("select * from Staff order by num", "staffNum", GridView1);
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('删除失败!');", true);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.staff DataRowToModel(DataRow row)
 {
     Model.staff model = new Model.staff();
     if (row != null)
     {
         if (row["staff_id"] != null && row["staff_id"].ToString() != "")
         {
             model.staff_id = int.Parse(row["staff_id"].ToString());
         }
         if (row["staff_name"] != null)
         {
             model.staff_name = row["staff_name"].ToString();
         }
         if (row["staff_sex"] != null)
         {
             model.staff_sex = row["staff_sex"].ToString();
         }
         if (row["staff_identity_card"] != null)
         {
             model.staff_identity_card = row["staff_identity_card"].ToString();
         }
         if (row["staff_phone_number"] != null && row["staff_phone_number"].ToString() != "")
         {
             model.staff_phone_number = int.Parse(row["staff_phone_number"].ToString());
         }
         if (row["staff_age"] != null && row["staff_age"].ToString() != "")
         {
             model.staff_age = int.Parse(row["staff_age"].ToString());
         }
         if (row["staff_hire_date"] != null && row["staff_hire_date"].ToString() != "")
         {
             model.staff_hire_date = DateTime.Parse(row["staff_hire_date"].ToString());
         }
         if (row["staff_belong_dep_id"] != null && row["staff_belong_dep_id"].ToString() != "")
         {
             model.staff_belong_dep_id = int.Parse(row["staff_belong_dep_id"].ToString());
         }
     }
     return(model);
 }
Esempio n. 9
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.staff GetModel(int staff_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select staff_id,staff_name,staff_sex,staff_identity_card,staff_phone_number,staff_age,staff_hire_date,staff_belong_dep_id from staff ");
            strSql.Append(" where staff_id=@staff_id ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@staff_id", MySqlDbType.Int32, 32)
            };
            parameters[0].Value = staff_id;

            Model.staff model = new Model.staff();
            DataSet     ds    = DbHelperMySQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 添加一个员工.
        /// </summary>
        /// <param name="sstaff">员工类对象</param>
        /// <returns>通过布尔值提示是否完成.</returns>
        public bool addStaff(Model.staff sstaff)
        {
            string sqltext               = "insert staff(num,staffNum,staffName,departId,birthday,gender,hometown,idCard,phoneNumber,entryTime) values(@num,@staffNum,@staffName,@departId,@birthday,@gender,@hometown,@idCard,@phoneNumber,@entryTime)";
            List <SqlParameter> para     = new List <SqlParameter>();
            SqlParameter        sqlpara  = new SqlParameter("@num", sstaff.Num);
            SqlParameter        sqlpara1 = new SqlParameter("@staffNum", sstaff.StaffNum);
            SqlParameter        sqlpara2 = new SqlParameter("@staffName", sstaff.StaffName);
            SqlParameter        sqlpara3 = new SqlParameter("@departId", sstaff.DepartId);
            SqlParameter        sqlpara4 = new SqlParameter("@birthday", sstaff.Birthday.ToString());
            SqlParameter        sqlpara5 = new SqlParameter("@gender", sstaff.Gender);
            SqlParameter        sqlpara6 = new SqlParameter("@hometown", sstaff.Hometown);
            SqlParameter        sqlpara7 = new SqlParameter("@idCard", sstaff.IdCard);
            SqlParameter        sqlpara8 = new SqlParameter("@phoneNumber", sstaff.PhoneNumber);
            SqlParameter        sqlpara9 = new SqlParameter("@entryTime", sstaff.EntryTime.ToString());

            para.Add(sqlpara);
            para.Add(sqlpara1);
            para.Add(sqlpara2);
            para.Add(sqlpara3);
            para.Add(sqlpara4);
            para.Add(sqlpara5);
            para.Add(sqlpara6);
            para.Add(sqlpara7);
            para.Add(sqlpara8);
            para.Add(sqlpara9);
            int i = DBTools.exenonquerySQL(sqltext, para);

            if (i == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 11
0
 /// <summary>
 /// 更新员工信息。员工编号不能更新。
 /// </summary>
 /// <param name="sstaff">员工类对象.</param>
 /// <returns>通过布尔值判断是否成功.</returns>
 public bool updateStaff(Model.staff sstaff)
 {
     throw new System.NotImplementedException();
 }
        protected void Button9_Click(object sender, EventArgs e)
        {
            switch (Button9.Text)
            {
            case "增加":
            {
                if (Image1.ImageUrl == "~/Image/对号.png" && Image2.ImageUrl == "~/Image/对号.png" && Image3.ImageUrl == "~/Image/对号.png" && Image4.ImageUrl == "~/Image/对号.png" && Image5.ImageUrl == "~/Image/对号.png" && Image6.ImageUrl == "~/Image/对号.png" && Image7.ImageUrl == "~/Image/对号.png" && Image8.ImageUrl == "~/Image/对号.png")
                {
                    Model.staff staff = new Model.staff();
                    DAL.Query   qu    = new DAL.Query();
                    int         n     = qu.query("staff");
                    staff.Num         = (n + 1).ToString();
                    staff.StaffNum    = TextBox1.Text;
                    staff.StaffName   = TextBox2.Text;
                    staff.DepartId    = TextBox3.Text;
                    staff.Birthday    = Convert.ToDateTime(ListBox2.Text + "/" + ListBox3.Text + "/" + ListBox4.Text);
                    staff.Gender      = ListBox7.Text;
                    staff.Hometown    = ListBox5.SelectedItem.Text + TextBox4.Text;
                    staff.IdCard      = TextBox7.Text;
                    staff.PhoneNumber = TextBox8.Text;
                    staff.EntryTime   = DateTime.Now;
                    bool xx = new DAL.StaffDAO().addStaff(staff);
                    if (xx == true)        //添加一个员工
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('添加成功!');", true);
                        Div1.Visible      = false;
                        GridView1.Visible = true;
                        if (GridView1.Visible == true)
                        {
                            Button2.Visible  = true;
                            Button4.Visible  = true;
                            Button3.Visible  = true;
                            ListBox9.Visible = true;
                            TextBox6.Visible = true;
                        }
                        else if (GridView1.Visible == false)
                        {
                            Button2.Visible  = false;
                            Button4.Visible  = false;
                            Button3.Visible  = false;
                            ListBox9.Visible = false;
                            TextBox6.Visible = false;
                        }
                        rg.Refresh("select * from Staff order by num", "staffNum", GridView1);
                    }
                    else
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('添加失败!');", true);
                        Div1.Visible      = false;
                        GridView1.Visible = true;
                        if (GridView1.Visible == true)
                        {
                            Button2.Visible  = true;
                            Button4.Visible  = true;
                            Button3.Visible  = true;
                            ListBox9.Visible = true;
                            TextBox6.Visible = true;
                        }
                        else if (GridView1.Visible == false)
                        {
                            Button2.Visible  = false;
                            Button4.Visible  = false;
                            Button3.Visible  = false;
                            ListBox9.Visible = false;
                            TextBox6.Visible = false;
                        }
                    }
                }
                else
                {
                    Response.Write("<script>window.location.href='#div_kkk'</script>");
                }
            }
            break;

            case "确定":
            {
                Button      btn   = sender as Button;
                Model.staff staff = new Model.staff();
                staff.StaffNum  = TextBox1.Text;
                staff.StaffName = TextBox2.Text;
                staff.DepartId  = TextBox3.Text;
                staff.Birthday  = Convert.ToDateTime(ListBox2.Text + "/" + ListBox3.Text + "/" + ListBox4.Text);
                staff.Gender    = ListBox7.Text;
                //staff.Hometown = ListBox5.SelectedValue + TextBox4.Text;
                staff.IdCard      = TextBox7.Text;
                staff.PhoneNumber = TextBox8.Text;
                bool xx = new DAL.StaffDAO().updateStaff(staff);
                if (xx)
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('修改成功!');", true);
                    Div1.Visible      = false;
                    GridView1.Visible = true;
                    if (GridView1.Visible == true)
                    {
                        Button2.Visible  = true;
                        Button4.Visible  = true;
                        Button3.Visible  = true;
                        ListBox9.Visible = true;
                        TextBox6.Visible = true;
                    }
                    else if (GridView1.Visible == false)
                    {
                        Button2.Visible  = false;
                        Button4.Visible  = false;
                        Button3.Visible  = false;
                        ListBox9.Visible = false;
                        TextBox6.Visible = false;
                    }
                    rg.Refresh("select * from Staff order by num", "staffNum", GridView1);
                }
                else
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('修改失败!');", true);
                }
            }
            break;
            }
        }