public static PriviDepartment GetDepartmentByDepartmentName(int cityId, int companyId, string departmentName, DataBase _db = null) { DataBase db = new DataBase(_db); try { string sql = "{0} FK_CityId in (0,:cityId) and Fk_CompanyId in (0,:companyId) and DValid=1 and DepartmentName=:departmentName"; sql = string.Format(sql, NHibernateUtility.GetMSSQL_SQL_NOLOCK(NHibernateUtility.TableName_PriviDepartment)); List <NHParameter> parameters = new List <NHParameter>(); parameters.Add(new NHParameter("cityId", cityId, NHibernateUtil.Int32)); parameters.Add(new NHParameter("companyId", companyId, NHibernateUtil.Int32)); parameters.Add(new NHParameter("departmentName", departmentName, NHibernateUtil.String)); PriviDepartment obj = db.DB.GetCustomSQLQueryEntity <PriviDepartment>(sql, parameters); //db.DB.GetCustom<PriviDepartment>( //(Expression<Func<PriviDepartment, bool>>)(tbl => (tbl.FK_CityId == 0 || tbl.FK_CityId == cityId) && (tbl.Fk_CompanyId == 0 || tbl.Fk_CompanyId == companyId) && tbl.DValid == 1 && tbl.DepartmentName == departmentName) //); db.Close(); return(obj); } catch (Exception ex) { db.Close(); throw ex; } }
public ActionResult EditUser_SubmitData_Api(string userName, string truename, string departmentId, string roleIds) { string json = ""; int? _departmentId = null; int[] _roleIds = null; if (string.IsNullOrEmpty(userName)) { Response.Write(json.MvcResponseJson(result: 0, message: "请填写用户名")); Response.End(); return(null); } //获取提交数据 UserCenter_LoginUserInfo loginUserInfo = WebUserHelp.GetNowLoginUser(); int cityId = WebUserHelp.GetNowCityId(); int companyId = loginUserInfo.FxtCompanyId; string loginusername = loginUserInfo.UserName; string loginsignname = loginUserInfo.SignName; if (StringHelp.CheckInteger(departmentId) && departmentId != "0") { _departmentId = Convert.ToInt32(departmentId); } _roleIds = roleIds.ConvertToInts(','); //提交数据 string message = ""; bool result = UserInfoManager.SetUserInfo(cityId, companyId, userName, truename, _departmentId, _roleIds, out message); if (!result) { Response.Write(json.MvcResponseJson(result: 0, message: "提交失败:" + message)); Response.End(); return(null); } IList <SYSRole> roleList = SYSRoleManager.GetSYSRoleByRoleIds(_roleIds); StringBuilder roleNameSb = new StringBuilder(""); string departmentName = ""; foreach (SYSRole roleInfo in roleList) { roleNameSb.Append(roleInfo.RoleName).Append(","); } if (Convert.ToInt32(_departmentId) > 0) { PriviDepartment pd = PriviDepartmentManager.GetDepartmentById(Convert.ToInt32(_departmentId)); if (pd != null) { departmentName = pd.DepartmentName; } } json = string.Format("{{\"username\":\"{0}\",\"truename\":\"{1}\",\"departmentname\":\"{2}\",\"rolename\":\"{3}\"}}", userName, truename, departmentName, roleNameSb.ToString()); Response.Write(json.MvcResponseJson(result: 1, message: "")); Response.End(); return(null); }
public ActionResult SetDepartment(string departmentId, string companyName) { UserCenter_LoginUserInfo loginUserInfo = WebUserHelp.GetNowLoginUser(); int result = 1; companyName = companyName.DecodeField(); if (departmentId.CheckInteger())//修改 { List <int> functionCodes = WebUserHelp.GetNowPageFunctionCodes(loginUserInfo.UserName, loginUserInfo.FxtCompanyId, WebCommon.Url_DepartmentInfo_DepartmentManager); PriviDepartment department = PriviDepartmentManager.GetDepartmentById(Convert.ToInt32(departmentId)); if (functionCodes.Contains(SYSCodeManager.FunOperCode_7)) { } else if (functionCodes.Contains(SYSCodeManager.FunOperCode_5))//修改自己 { PriviDepartment nowDep = PriviDepartmentManager.GetDepartmentByUserName(WebUserHelp.GetNowCityId(), loginUserInfo.FxtCompanyId, loginUserInfo.UserName); if (nowDep == null || !nowDep.DepartmentId.ToString().Equals(departmentId)) { return(WebUserHelp.GetActionNotRightPage());//无权限 } } else { return(WebUserHelp.GetActionNotRightPage());//无权限 } if (department != null) { ViewBag.DepartmentName = department.DepartmentName; ViewBag.DepartmentId = departmentId; } else { result = 0; } } else//新增 { if (!WebUserHelp.CheckNowPageFunctionCode(loginUserInfo.UserName, loginUserInfo.FxtCompanyId, WebCommon.Url_DepartmentInfo_DepartmentManager, SYSCodeManager.FunOperCode_4)) { return(WebUserHelp.GetActionNotRightPage());//无权限 } } ViewBag.Result = result; ViewBag.CompanyName = companyName; return(View()); }
/// <summary> /// 修改小组 /// </summary> /// <param name="cityId"></param> /// <param name="companyId"></param> /// <param name="companyId"></param> /// <param name="departmentId"></param> /// <param name="message"></param> /// <param name="_db"></param> /// <returns></returns> public static bool UpdateDepartment(int departmentId, string departmentName, out string message, DataBase _db = null) { message = ""; departmentName = departmentName.TrimBlank(); if (string.IsNullOrEmpty(departmentName)) { message = "请输入小组名"; return(false); } bool result = true; DataBase db = new DataBase(_db); try { PriviDepartment nowPD = GetDepartmentById(departmentId, db); if (nowPD == null || nowPD.DValid == 0) { message = "你所修改的小组不存在或已被删除"; db.Close(); return(false); } PriviDepartment existsPD = GetDepartmentByDepartmentName(nowPD.FK_CityId, nowPD.Fk_CompanyId, departmentName, db); if (existsPD != null && existsPD.DepartmentId != departmentId) { message = "小组名称已存在"; db.Close(); return(false); } nowPD.DepartmentName = departmentName; if (!db.DB.Update(nowPD)) { result = false; message = "修改失败:系统异常"; } } catch (Exception ex) { result = false; message = "系统异常"; } db.Close(); return(result); }
/// <summary> /// 根据ID获取分组信息 /// </summary> /// <param name="departmentId"></param> /// <param name="_db"></param> /// <returns></returns> public static PriviDepartment GetDepartmentById(int departmentId, DataBase _db = null) { DataBase db = new DataBase(_db); try { //db.DB.SessionLock("PriviDepartment", LockMode.None); string sql = string.Format("{0} DepartmentId={1}", NHibernateUtility.GetMSSQL_SQL_NOLOCK(NHibernateUtility.TableName_PriviDepartment), departmentId); PriviDepartment pd = db.DB.GetCustomSQLQueryEntity <PriviDepartment>(sql, null); //.GetCustom<PriviDepartment>( // (Expression<Func<PriviDepartment, bool>>)(tbl => tbl.DepartmentId == departmentId) // ); db.Close(); return(pd); } catch (Exception ex) { db.Close(); throw ex; } }
/// <summary> /// 获取当前用户属于的组信息 /// </summary> /// <param name="cityId"></param> /// <param name="companyId"></param> /// <param name="userName"></param> /// <param name="_db"></param> /// <returns></returns> public static PriviDepartment GetDepartmentByUserName(int cityId, int companyId, string userName, DataBase _db = null) { DataBase db = new DataBase(_db); try { string sql = "{0} Fk_CompanyId=:companyId and FK_CityId=:cityId and DValid=1 and exists (select * from {1} as tb2 with(nolock) where tb2.DepartmentID=_tb.DepartmentID and UserName=:userName)"; sql = string.Format(sql, NHibernateUtility.GetMSSQL_SQL_NOLOCK(NHibernateUtility.TableName_PriviDepartment), NHibernateUtility.TableName_PriviDepartmentUser); List <NHParameter> parameters = new List <NHParameter>(); parameters.Add(new NHParameter("companyId", companyId, NHibernateUtil.Int32)); parameters.Add(new NHParameter("cityId", cityId, NHibernateUtil.Int32)); parameters.Add(new NHParameter("userName", userName, NHibernateUtil.String)); PriviDepartment obj = db.DB.GetCustomSQLQueryEntity <PriviDepartment>(sql, parameters); db.Close(); return(obj); } catch (Exception ex) { db.Close(); throw ex; } }
/// <summary> /// 新增小组 /// </summary> /// <param name="cityId"></param> /// <param name="companyId"></param> /// <param name="departmentName"></param> /// <param name="message"></param> /// <param name="_db"></param> /// <returns></returns> public static PriviDepartment InsertDepartment(int cityId, int companyId, string departmentName, out string message, DataBase _db = null) { message = ""; departmentName = departmentName.TrimBlank(); if (string.IsNullOrEmpty(departmentName)) { message = "请输入小组名"; return(null); } PriviDepartment existsPD = null; DataBase db = new DataBase(_db); try { existsPD = GetDepartmentByDepartmentName(cityId, companyId, departmentName, db); if (existsPD != null) { message = "小组名称已存在"; db.Close(); return(null); } existsPD = new PriviDepartment { DepartmentName = departmentName, Fk_CompanyId = companyId, FxtCompanyId = companyId, FK_CityId = cityId, DValid = 1, FK_DepTypeCode = 5005003 }; if (!db.DB.Create(existsPD)) { existsPD = null; message = "插入失败:系统异常"; } } catch (Exception ex) { existsPD = null; message = "系统异常"; } db.Close(); return(existsPD); }
public ActionResult SetDepartment_SubmitData_Api(string departmentId, string departmentName) { string json = ""; departmentName = departmentName.DecodeField().TrimBlank(); if (string.IsNullOrEmpty(departmentName)) { Response.Write(json.MvcResponseJson(result: 0, message: "请填写组名")); Response.End(); return(null); } string message = ""; bool result = true; UserCenter_LoginUserInfo loginUserInfo = WebUserHelp.GetNowLoginUser(); //如果是修改 if (departmentId.CheckInteger()) { List <int> functionCodes = WebUserHelp.GetNowPageFunctionCodes(loginUserInfo.UserName, loginUserInfo.FxtCompanyId, WebCommon.Url_DepartmentInfo_DepartmentManager); PriviDepartment department = PriviDepartmentManager.GetDepartmentById(Convert.ToInt32(departmentId)); if (functionCodes.Contains(SYSCodeManager.FunOperCode_7))//修改全部 { } else if (functionCodes.Contains(SYSCodeManager.FunOperCode_5))//修改自己 { PriviDepartment nowDep = PriviDepartmentManager.GetDepartmentByUserName(WebUserHelp.GetNowCityId(), loginUserInfo.FxtCompanyId, loginUserInfo.UserName); if (nowDep == null || !nowDep.DepartmentId.ToString().Equals(departmentId)) { Response.Write(json.MvcResponseJson(result: 0, message: "无权限修改此信息")); Response.End(); return(null); } } else//无修改权限 { Response.Write(json.MvcResponseJson(result: 0, message: "无权限修改此信息")); Response.End(); return(null); } result = PriviDepartmentManager.UpdateDepartment(Convert.ToInt32(departmentId), departmentName, out message); } else//新增 { if (!WebUserHelp.CheckNowPageFunctionCode(loginUserInfo.UserName, loginUserInfo.FxtCompanyId, WebCommon.Url_DepartmentInfo_DepartmentManager, SYSCodeManager.FunOperCode_4)) { Response.Write(json.MvcResponseJson(result: 0, message: "无权限新增信息")); Response.End(); return(null); } int cityId = WebUserHelp.GetNowCityId(); int companyId = loginUserInfo.FxtCompanyId; string loginusername = loginUserInfo.UserName; string loginsignname = loginUserInfo.SignName; PriviDepartment department = PriviDepartmentManager.InsertDepartment(cityId, companyId, departmentName, out message); if (department == null) { result = false; } else { json = department.EncodeField <PriviDepartment>().ToJSONjss(); } } //失败 if (!result) { Response.Write(json.MvcResponseJson(result: 0, message: "提交失败:" + message)); Response.End(); return(null); } //成功 Response.Write(json.MvcResponseJson(result: 1, message: "")); Response.End(); return(null); }