/// <summary> /// 添加职位 /// </summary> /// <param name="type">职位信息</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回是否成功添加职位信息</returns> public bool AddPositionType(HR_PositionType type, out string error) { error = null; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; var result = from d in dataContxt.HR_PositionType where d.ID == type.ID select d; if (result.Count() == 0) { dataContxt.HR_PositionType.InsertOnSubmit(type); dataContxt.SubmitChanges(); return(true); } else { error = string.Format(" {0} 职位编号已经存在, 不允许重复添加", type.ID); return(false); } } catch (Exception exce) { error = exce.Message; return(false); } }
/// <summary> /// 修改职位 /// </summary> /// <param name="type">职位信息</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回是否成功</returns> public bool UpdatePositionType(HR_PositionType type, out string error) { error = null; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; var Result = from e in dataContxt.HR_PositionType where e.ID == type.ID select e; if (Result.Count() == 0) { error = "找不到相关记录,无法进行操作"; return(false); } HR_PositionType updateType = Result.Single(); updateType.PositionName = type.PositionName; updateType.Remark = type.Remark; dataContxt.SubmitChanges(); return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
public static Common.Business.HR_PositionType Fetch(HR_PositionType data) { Common.Business.HR_PositionType item = (Common.Business.HR_PositionType)Activator.CreateInstance(typeof(Common.Business.HR_PositionType)); //using (ObjectFactory.BypassPropertyChecks(item)) { item.Client = data.Client; item.PositionType = data.PositionType; item.DText = data.DText; item.Mark = data.Mark; } ObjectFactory.MarkAsChild(item); ObjectFactory.MarkOld(item); return(item); }
/// <summary> /// 提交按钮,添加或修改职位信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPosition_Click(object sender, EventArgs e) { if (txtPositionID.Text == "" || txtPositionID.Text == null) { return; } if (txtPositionID.ReadOnly) { HR_PositionType type = new HR_PositionType(); type.ID = int.Parse(txtPositionID.Text); type.PositionName = txtPositionName.Text; type.Remark = txtPositionRemark.Text; if (!m_personnelInfo.UpdatePositionType(type, out m_strErr)) { MessageDialog.ShowErrorMessage(m_strErr); return; } else { MessageBox.Show("职位修改成功!", "提示"); } } else { HR_PositionType type = new HR_PositionType(); type.ID = int.Parse(txtPositionID.Text); type.PositionName = txtPositionName.Text; type.Remark = txtPositionRemark.Text; if (!m_personnelInfo.AddPositionType(type, out m_strErr)) { MessageDialog.ShowErrorMessage(m_strErr); return; } else { MessageBox.Show("新职位添加成功!", "提示"); } } m_findPositionType = m_personnelInfo.GetPositionType(); dgvShowPosition.DataSource = m_findPositionType; //this.DialogResult = DialogResult.OK; }