private void BindEmployeeInfo() { _employee = eBll.GetEmployee(_eId); txtCode.Text = _employee.Code; txtName.Text = _employee.EName; txtIcCode.Text = _employee.IdCode; if (_employee.Sex == 0) { rbtnMale.Checked = true; } else { rbtnFemale.Checked = true; } txtCountry.Text = _employee.Country; dtpBirthDay.Value = _employee.BirthDay; if (_employee.Married == 0) { rbtnNotMarried.Checked = true; } else { rbtnMarried.Checked = true; } cbPosition.SelectedValue = _employee.PId; Organization org = oBll.GetOrganizationByEId(_eId); _orgId = org.OId; txtOrgName.Text = org.OName; for (int i = 0; i < cbEducation.Items.Count;i++) { if (cbEducation.Items[i].ToString() == _employee.Education) { cbEducation.SelectedIndex = i; break; } } txtSchool.Text = _employee.School; txtEmail.Text = _employee.Email; txtPhone.Text = _employee.Phone; txtCellPhone.Text = _employee.CellPhone; for (int i = 0; i < cbStatus.Items.Count; i++) { if (cbStatus.Items[i].ToString() == _employee.Status) { cbStatus.SelectedIndex = i; break; } } txtAddress.Text = _employee.Address; }
/// <summary> /// 获取所有员工列表 /// </summary> /// <returns>员工集合</returns> public IList<Employee> GetAllEmployee() { IList<Employee> list = new List<Employee>(); string sql = "select * from TB_Employee order by Code asc"; DataSet ds = AccessHelper.ExecuteDataSet(_connectionString, sql); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { foreach (DataRow row in ds.Tables[0].Rows) { Employee employee = new Employee(); employee.EId = (int)row["EId"]; employee.Code = (string)row["Code"]; employee.EName = (string)row["EName"]; employee.Sex = (int)row["Sex"]; employee.Country = Convert.ToString(row["Country"]); employee.Married = (int)row["Married"]; employee.BirthDay = (DateTime)row["BirthDay"]; employee.IdCode = Convert.ToString(row["IdCode"]); employee.PId = (int)row["PId"]; employee.Education = Convert.ToString(row["Education"]); employee.School = Convert.ToString(row["School"]); employee.Phone = Convert.ToString(row["Phone"]); employee.CellPhone = Convert.ToString(row["CellPhone"]); employee.Address = Convert.ToString(row["Address"]); employee.Email = Convert.ToString(row["Email"]); employee.Status = (string)row["Status"]; employee.SexStr = employee.Sex == 0 ? "男" : "女"; employee.MarriedStr = employee.Married == 0 ? "未婚" : "已婚"; list.Add(employee); } } return list; }
/// <summary> /// 添加员工 /// </summary> /// <param name="employee">员工对象</param> /// <param name="orgId">部门ID</param> /// <returns>ID</returns> public int Insert(Employee employee,int orgId) { return _dal.Insert(employee,orgId); }
/// <summary> /// 修改员工 /// </summary> /// <param name="employee">员工对象</param> /// <param name="orgId">部门ID</param> /// <returns>影响行数</returns> public int Update(Employee employee, int orgId) { return _dal.Update(employee, orgId); }
/// <summary> /// 修改员工 /// </summary> /// <param name="employee">员工对象</param> /// <param name="orgId">部门ID</param> /// <returns>影响行数</returns> public int Update(Employee employee,int orgId) { string sql = "update TB_Employee set EName=@EName,Code=@Code,Sex=@Sex,Country=@Country,Married=@Married,BirthDay=@BirthDay,IdCode=@IdCode,PId=@PId,Education=@Education,School=@School,Phone=@Phone,CellPhone=@CellPhone,Address=@Address,Email=@Email,Status=@Status where EId=@EId"; OleDbParameter[] param = new OleDbParameter[] { new OleDbParameter("@EName",employee.EName), new OleDbParameter("@Code",employee.Code), new OleDbParameter("@Sex",employee.Sex), new OleDbParameter("@Country",employee.Country), new OleDbParameter("@Married",employee.Married), new OleDbParameter("@BirthDay",employee.BirthDay), new OleDbParameter("@IdCode",employee.IdCode), new OleDbParameter("@PId",employee.PId), new OleDbParameter("@Education",employee.Education), new OleDbParameter("@School",employee.School), new OleDbParameter("@Phone",employee.Phone), new OleDbParameter("@CellPhone",employee.CellPhone), new OleDbParameter("@Address",employee.Address), new OleDbParameter("@Email",employee.Email), new OleDbParameter("@Status",employee.Status), new OleDbParameter("@EId",employee.EId) }; int count = AccessHelper.ExecuteNonQuery(_connectionString, sql, param); AccessHelper.ExecuteNonQuery(_connectionString, "delete from TB_EmployeeOrg where EId=" + employee.EId); string sql1 = "insert into TB_EmployeeOrg(EId,OId) values(" + employee.EId + "," + orgId + ")"; AccessHelper.ExecuteNonQuery(_connectionString, sql1, param); return count; }
/// <summary> /// 添加员工 /// </summary> /// <param name="employee">员工对象</param> /// <param name="orgId">部门ID</param> /// <returns>ID</returns> public int Insert(Employee employee,int orgId) { string sql = "insert into TB_Employee(EName,Code,Sex,Country,Married,BirthDay,IdCode,PId,Education,School,Phone,CellPhone,Address,Email,Status) "; sql += "values(@EName,@Code,@Sex,@Country,@Married,@BirthDay,@IdCode,@PId,@Education,@School,@Phone,@CellPhone,@Address,@Email,@Status)"; OleDbParameter[] param = new OleDbParameter[] { new OleDbParameter("@EName",employee.EName), new OleDbParameter("@Code",employee.Code), new OleDbParameter("@Sex",employee.Sex), new OleDbParameter("@Country",employee.Country), new OleDbParameter("@Married",employee.Married), new OleDbParameter("@BirthDay",employee.BirthDay), new OleDbParameter("@IdCode",employee.IdCode), new OleDbParameter("@PId",employee.PId), new OleDbParameter("@Education",employee.Education), new OleDbParameter("@School",employee.School), new OleDbParameter("@Phone",employee.Phone), new OleDbParameter("@CellPhone",employee.CellPhone), new OleDbParameter("@Address",employee.Address), new OleDbParameter("@Email",employee.Email), new OleDbParameter("@Status",employee.Status) }; AccessHelper.ExecuteNonQuery(_connectionString, sql, param); object id = AccessHelper.ExecuteScalar(_connectionString, "select max(EId) from TB_Employee"); int eId=Convert.ToInt32(id); string sql1 = "insert into TB_EmployeeOrg(EId,OId) values(" + eId + "," + orgId + ")"; AccessHelper.ExecuteNonQuery(_connectionString, sql1, param); return Convert.ToInt32(id); }
/// <summary> /// 根据条件获取员工集合 /// </summary> /// <param name="condition">条件集合</param> /// <returns>员工集合</returns> public IList<Employee> GetEmployeeList(Hashtable condition) { IList<Employee> list = new List<Employee>(); string sql = " select * from TB_Employee where 1=1"; if(condition.Count>0){ if (condition.ContainsKey("Code") && condition["Code"].ToString().Length>0) { sql += " and Code like '%"+condition["Code"]+"%' "; } if (condition.ContainsKey("EName") && condition["EName"].ToString().Length>0) { sql += " and EName like '%" + condition["EName"] + "%' "; } } sql+=" order by Code asc"; DataSet ds = AccessHelper.ExecuteDataSet(_connectionString, sql); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { foreach (DataRow row in ds.Tables[0].Rows) { Employee employee = new Employee(); employee.EId = (int)row["EId"]; employee.Code = (string)row["Code"]; employee.EName = (string)row["EName"]; employee.Sex = (int)row["Sex"]; employee.Country = Convert.ToString(row["Country"]); employee.Married = (int)row["Married"]; employee.BirthDay = (DateTime)row["BirthDay"]; employee.IdCode = Convert.ToString(row["IdCode"]); employee.PId = (int)row["PId"]; employee.Education = Convert.ToString(row["Education"]); employee.School = Convert.ToString(row["School"]); employee.Phone = Convert.ToString(row["Phone"]); employee.CellPhone = Convert.ToString(row["CellPhone"]); employee.Address = Convert.ToString(row["Address"]); employee.Email = Convert.ToString(row["Email"]); employee.Status = (string)row["Status"]; employee.SexStr = employee.Sex == 0 ? "男" : "女"; employee.MarriedStr = employee.Married == 0 ? "未婚" : "已婚"; list.Add(employee); } } return list; }
/// <summary> /// 根据编号获取员工对象 /// </summary> /// <param name="code">编号</param> /// <returns>员工对象</returns> public Employee GetEmployee(string code) { Employee employee = null; string sql = "select * from TB_Employee where code='" + code + "'"; DataSet ds = AccessHelper.ExecuteDataSet(_connectionString, sql); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; employee = new Employee(); employee.EId = (int)row["EId"]; employee.Code = (string)row["Code"]; employee.EName = (string)row["EName"]; employee.Sex = (int)row["Sex"]; employee.Country = Convert.ToString(row["Country"]); employee.Married = (int)row["Married"]; employee.BirthDay = (DateTime)row["BirthDay"]; employee.IdCode = Convert.ToString(row["IdCode"]); employee.PId = (int)row["PId"]; employee.Education = Convert.ToString(row["Education"]); employee.School = Convert.ToString(row["School"]); employee.Phone = Convert.ToString(row["Phone"]); employee.CellPhone = Convert.ToString(row["CellPhone"]); employee.Address = Convert.ToString(row["Address"]); employee.Email = Convert.ToString(row["Email"]); employee.Status = (string)row["Status"]; employee.SexStr = employee.Sex == 0 ? "男" : "女"; employee.MarriedStr = employee.Married == 0 ? "未婚" : "已婚"; } return employee; }