/// <summary> /// 添加人员信息表 /// </summary> /// <param name="Person">人员信息</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回是否成功添加/修改部门信息表</returns> public bool AddPersonnel(HR_Personnel Person, out string error) { error = null; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; var result = from c in dataContxt.HR_Personnel where c.WorkID == Person.WorkID select c; if (result.Count() == 0) { dataContxt.HR_Personnel.InsertOnSubmit(Person); dataContxt.SubmitChanges(); } else { error = string.Format("人员编码 {0} 的人员已经存在, 不允许重复添加", Person.WorkID); return(false); } return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { if (!CheckDataItem()) { return; } HR_Personnel personnel = CreatePersonnelFromForm(); if (personnel.WorkID != txtPersonnelCode.Text) { MessageDialog.ShowErrorMessage("不可修改人员编码"); return; } if (!m_personnelInfo.UpdatePersonnel(personnel, out m_err)) { MessageDialog.ShowErrorMessage(m_err); return; } else { MessageBox.Show("修改成功!", "提示"); treeView1_AfterSelect(sender, null); } }
/// <summary> /// 根据界面数据生成部门信息对象 /// </summary> /// <returns>返回生成的部门信息对象</returns> private HR_Personnel CreatePersonnelFromForm() { HR_Personnel personnel = new HR_Personnel(); personnel.OnTheJob = ckbOnTheJob.Checked; personnel.Name = txtPersonnelName.Text.Trim(); personnel.IsOperationalUser = ckbUser.Checked; personnel.WorkID = txtPersonnelCode.Text; personnel.Dept = cmbDepot.SelectedValue.ToString(); personnel.WorkPost = (int)cmbWorkPost.SelectedValue; personnel.DeleteFlag = ckbDelete.Checked; personnel.PY = UniversalFunction.GetPYWBCode(txtPersonnelName.Text.Trim(), "PY"); personnel.WB = UniversalFunction.GetPYWBCode(txtPersonnelName.Text.Trim(), "WB"); return(personnel); }
/// <summary> /// 添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { if (!CheckDataItem()) { return; } HR_Personnel personnel = CreatePersonnelFromForm(); if (!m_personnelInfo.AddPersonnel(personnel, out m_err)) { MessageDialog.ShowErrorMessage(m_err); return; } else { MessageBox.Show("添加成功!", "提示"); } treeView1_AfterSelect(sender, null); }
/// <summary> /// 修改人员信息表 /// </summary> /// <param name="Person">人员信息</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回是否成功添加/修改部门信息表</returns> public bool UpdatePersonnel(HR_Personnel Person, out string error) { error = null; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; var Result = from c in dataContxt.HR_Personnel where c.WorkID == Person.WorkID select c; if (Result.Count() == 0) { error = "找不到相关记录,无法进行操作"; return(false); } HR_Personnel updatePerson = Result.Single(); updatePerson.WorkPost = Person.WorkPost; updatePerson.OnTheJob = Person.OnTheJob; updatePerson.Name = Person.Name; updatePerson.IsOperationalUser = Person.IsOperationalUser; updatePerson.Handset = Person.Handset; updatePerson.Remark = Person.Remark; updatePerson.DeleteFlag = Person.DeleteFlag; updatePerson.Dept = Person.Dept; dataContxt.SubmitChanges(); return(true); } catch (Exception ex) { error = ex.Message; return(false); } }