public bool InsertIntoEmployee(MEmployee emp) { StringBuilder sb = new StringBuilder(); sb.Append("insert into tb_employee (name,sex,birthday,learnDegree,post,dept,job,tel,address,email,state,photoPath) values(@EmpName,@Sex,@Birthday,@LearnDegree,@Post,@Department,@Job,@Tel,@Address,@Email,@State,@PhotoPath)"); SqlParameter[] param = { SQLDbHelper.GetParameter("@EmpName",SqlDbType.VarChar,20,"name",emp.Name), SQLDbHelper.GetParameter("@Sex",SqlDbType.VarChar,10,"sex",emp.Sex), SQLDbHelper.GetParameter("@Birthday",SqlDbType.SmallDateTime,"birthday",emp.Birthday), SQLDbHelper.GetParameter("@LearnDegree",SqlDbType.VarChar,50,"learnDegree",emp.LearnDegree), SQLDbHelper.GetParameter("@Post",SqlDbType.VarChar,50,"post",emp.Post), SQLDbHelper.GetParameter("@Department",SqlDbType.VarChar,50,"dept",emp.Dept), SQLDbHelper.GetParameter("@Job",SqlDbType.VarChar,50,"job",emp.Job), SQLDbHelper.GetParameter("@Tel",SqlDbType.VarChar,50,"tel",emp.Tel), SQLDbHelper.GetParameter("@Address",SqlDbType.VarChar,50,"address",emp.Address), SQLDbHelper.GetParameter("@Email",SqlDbType.VarChar,50,"email",emp.Email), SQLDbHelper.GetParameter("@State",SqlDbType.VarChar,50,"state",emp.State), SQLDbHelper.GetParameter("@PhotoPath",SqlDbType.VarChar,50,"photoPath",emp.PhotoPath) }; bool is_succeed = SQLDbHelper.ExecuteSql(sb.ToString(), param); if (is_succeed) { return true; } else { return false; } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { objdept.ID = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value); DataTable dtDept = dept.SelectDepartmentByID(objdept); employee emp = new employee(); MEmployee objemp = new MEmployee(); objemp.Dept = dtDept.Rows[0]["name"].ToString(); DataTable dtEmp = emp.SelectEmployeeByDept(objemp); if (dtEmp.Rows.Count > 0) { string myscript = @"alert('此部门内尚有员工,不能删除!');"; Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", myscript, true); } else { dept.DeleteDepartmentByID(objdept); } GridView1.DataSource = dept.SelectAllDepartment(); GridView1.DataBind(); } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message + "');</script>"); } }
public DataTable SelectEmployeeByID(MEmployee emp) { StringBuilder sb = new StringBuilder(); sb.Append("select * from tb_employee where ID=@ID"); SqlParameter[] param = { SQLDbHelper.GetParameter("@ID",SqlDbType.Int,4,"ID",emp.ID) }; DataTable dt = SQLDbHelper.ExecuteDt(sb.ToString(),param); return dt; }
public DataTable SelectEmployeeByDept(MEmployee emp) { StringBuilder sb = new StringBuilder(); sb.Append("select * from tb_employee where dept=@Dept"); SqlParameter[] param = { SQLDbHelper.GetParameter("@Dept",SqlDbType.VarChar,50,"dept",emp.Dept) }; DataTable dt = SQLDbHelper.ExecuteDt(sb.ToString(), param); return dt; }
public bool DeleteEmployeeByID(MEmployee emp) { StringBuilder sb = new StringBuilder(); sb.Append("delete from tb_employee where ID=@ID"); SqlParameter[] param = { SQLDbHelper.GetParameter("@ID",SqlDbType.Int,4,"ID",emp.ID) }; bool is_succeed = SQLDbHelper.ExecuteSql(sb.ToString(), param); if (is_succeed) { return true; } else { return false; } }
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { string area = Hidden1.Value; employee emp = new employee(); MEmployee objemp = new MEmployee(); objemp.Name = txtName.Text.Trim().ToString(); objemp.Sex = dlSex.Text.ToString(); objemp.Birthday = Convert.ToDateTime(txtBirthday.Text.Trim()); objemp.LearnDegree = txtLearn.Text.Trim().ToString(); objemp.Post = txtPost.Text.Trim().ToString(); objemp.Dept = dlDepartment.Text.ToString(); objemp.Job = dlJob.Text.ToString(); objemp.Tel = txtTel.Text.Trim().ToString(); objemp.Address = area + " " + txtAddress.Text.Trim().ToString(); objemp.Email = txtEmail.Text.Trim().ToString(); objemp.State = dlState.Text.ToString(); objemp.PhotoPath = path; bool bl = emp.InsertIntoEmployee(objemp); if (bl) { this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('员工基础信息添加成功!');</script>"); } else { this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('员工基础信息添加失败!');</script>"); if (IsUploadPhoto) { try { FileInfo file = new FileInfo(Server.MapPath(path)); file.Delete(); } catch { } finally { } } } }
public bool UpdateEmployeeByID(MEmployee emp) { StringBuilder sb = new StringBuilder(); sb.Append("update tb_employee set name=@EmpName,sex=@Sex,birthday=@Birthday,"); sb.Append("learnDegree=@LearnDegree,post=@Post,dept=@Department,job=@Job,tel=@Tel,"); sb.Append("address=@Address,email=@Email,state=@State where ID=@ID"); SqlParameter[] param = { SQLDbHelper.GetParameter("@ID",SqlDbType.Int,4,"ID",emp.ID), SQLDbHelper.GetParameter("@EmpName",SqlDbType.VarChar,20,"name",emp.Name), SQLDbHelper.GetParameter("@Sex",SqlDbType.VarChar,10,"sex",emp.Sex), SQLDbHelper.GetParameter("@Birthday",SqlDbType.SmallDateTime,"birthday",emp.Birthday), SQLDbHelper.GetParameter("@LearnDegree",SqlDbType.VarChar,50,"learnDegree",emp.LearnDegree), SQLDbHelper.GetParameter("@Post",SqlDbType.VarChar,50,"post",emp.Post), SQLDbHelper.GetParameter("@Department",SqlDbType.VarChar,50,"dept",emp.Dept), SQLDbHelper.GetParameter("@Job",SqlDbType.VarChar,50,"job",emp.Job), SQLDbHelper.GetParameter("@Tel",SqlDbType.VarChar,50,"tel",emp.Tel), SQLDbHelper.GetParameter("@Address",SqlDbType.VarChar,50,"address",emp.Address), SQLDbHelper.GetParameter("@Email",SqlDbType.VarChar,50,"email",emp.Email), SQLDbHelper.GetParameter("@State",SqlDbType.VarChar,50,"state",emp.State) }; bool is_succeed = SQLDbHelper.ExecuteSql(sb.ToString(), param); if (is_succeed) { return true; } else { return false; } }
public bool UpdateEmployeeByID(MEmployee emplye) { return emp.UpdateEmployeeByID(emplye); }
public DataTable SelectEmployeeByID(MEmployee emplye) { return emp.SelectEmployeeByID(emplye); }
public bool InsertIntoEmployee(MEmployee emplye) { return emp.InsertIntoEmployee(emplye); }
public bool DeleteEmployeeByID(MEmployee emplye) { return emp.DeleteEmployeeByID(emplye); }