/// <summary> /// 新增员工 /// </summary> /// <param name="data"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public long InsertStaff(Staff data, long nOpStaffId, string strOpStaffName, out string strErrText) { long nStaffId = 0; try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (StaffDAO dao = new StaffDAO()) { nStaffId = dao.InsertStaff(data, nOpStaffId, strOpStaffName, out strErrText); if (nStaffId <= 0) return 0; } transScope.Complete(); } return nStaffId; } catch (Exception e) { strErrText = e.Message; return 0; } }
/// <summary> /// 新增员工 /// </summary> /// <param name="data"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public long InsertStaff(Staff data, long nOpStaffId, string strOpStaffName, out string strErrText) { //创建存储过程参数 SqlParameter[] Params = { MakeParam(ID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Output, (object)data.Id), MakeParam(FAMILYNAME_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.FamilyName), MakeParam(NAME_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Name), MakeParam(SEX_PARAM, SqlDbType.NChar, 1, ParameterDirection.Input, (object)data.Sex), MakeParam(ORGANID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.OrganId), MakeParam(POSITIONID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.PositionId), MakeParam(OFFICETEL_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.OfficeTel), MakeParam(TELEXT_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.TelExt), MakeParam(FAX_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Fax), MakeParam(MOBILETEL1_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.MobileTel1), MakeParam(MOBILETEL2_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.MobileTel2), MakeParam(MOBILETEL3_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.MobileTel3), MakeParam(EMAIL_PARAM, SqlDbType.NVarChar, 255, ParameterDirection.Input, (object)data.EMail), MakeParam(QQ_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.QQ), MakeParam(ISORGANMANAGER_PARAM, SqlDbType.Bit, 1, ParameterDirection.Input, (object)data.IsOrganManager), MakeParam(ISORGANLEADER_PARAM, SqlDbType.Bit, 1, ParameterDirection.Input, (object)data.IsOrganLeader), MakeParam(BOSSSTAFFID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.BossStaffId), MakeParam(OPSTAFFID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)nOpStaffId), MakeParam(OPSTAFFNAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)strOpStaffName), }; SqlParameterCollection outParams; if (Execute("InsertStaff", Params, out outParams, out strErrText) < 0) { return 0; } else { return (long)outParams[ID_PARAM].Value; } }
/// <summary> /// 修改员工 /// </summary> /// <param name="data"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public bool UpdateStaff(Staff data, long nOpStaffId, string strOpStaffName, out string strErrText) { try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (StaffDAO dao = new StaffDAO()) { if (!dao.UpdateStaff(data, nOpStaffId, strOpStaffName, out strErrText)) return false; } transScope.Complete(); } return true; } catch (Exception e) { strErrText = e.Message; return false; } }
public ActionResult NewStaff(StaffViewModel model) { if (ModelState.IsValid) { //创建数据 Staff data = new Staff(); data.FamilyName = model.FamilyName; data.Name = model.Name ?? string.Empty; data.Sex = model.Sex; data.OrganId = model.OrganId; data.PositionId = model.PositionId; data.OfficeTel = model.OfficeTel ?? string.Empty; data.TelExt = model.TelExt ?? string.Empty; data.Fax = model.Fax ?? string.Empty; data.MobileTel1 = model.MobileTel1; data.MobileTel2 = model.MobileTel2 ?? string.Empty; data.MobileTel3 = model.MobileTel3 ?? string.Empty; data.EMail = model.EMail ?? string.Empty; data.QQ = model.QQ ?? string.Empty; data.IsOrganManager = model.IsOrganManager; data.IsOrganLeader = model.IsOrganLeader; data.BossStaffId = model.BossStaffId; //保存数据 string strErrText; StaffSystem staff = new StaffSystem(); if (staff.InsertStaff(data, LoginAccountId, LoginStaffName, out strErrText) > 0) { return Json(string.Empty); } else { return Json(strErrText); } } return View(model); }