public ResultModel GetOperateList(UserModel user, int menuId,int empId) { ResultModel result = new ResultModel(); DAL.AuthOperateDAL authOperateDAL = new AuthOperateDAL(); try { result = menuDAL.GetOperateMenu(user); if (result.ResultStatus != 0) return result; DataTable dtOperate = result.ReturnValue as DataTable; if(dtOperate==null||dtOperate.Rows.Count<1) { result.ResultStatus = -1; result.Message ="获取失败"; return result; } result = authOperateDAL.GetOperate(user, empId); if (result.ResultStatus != 0) return result; DataTable dtEmpAuth = result.ReturnValue as DataTable; bool hasAuth = false; if (dtEmpAuth != null && dtEmpAuth.Rows.Count > 0) hasAuth = true; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("["); foreach (DataRow dr in dtOperate.Rows) { sb.Append("{"); sb.AppendFormat("\"label\":\"{0}\",\"id\":\"{1}\",\"checked\":{2}", dr["DetailName"].ToString(), "op_" + menuId.ToString() + "_" + dr["StyleDetailId"].ToString(), hasAuth ? dtEmpAuth.AsEnumerable().Any(row => Convert.ToInt32(row["OperateType"]) == Convert.ToInt32(dr["StyleDetailId"])).ToString().ToLower() : "false");//, "style=\"float:left;\"" ,\"html\":\"{3}\" sb.Append("},"); } sb = sb.Remove(sb.Length - 1, 1); sb.Append("]"); result.ResultStatus = 0; result.Message = "获取成功"; result.ReturnValue = sb.ToString(); } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }
public ResultModel Create(UserModel user, int empId, List<Model.AuthOperate> authOperates, List<Model.EmpMenu> empMenus, string exceptItemIds) { ResultModel result = new ResultModel(); DAL.MenuDAL menuDAL = new MenuDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //if (authOperates == null || !authOperates.Any()) //{ // result.ResultStatus = -1; // result.Message = "数据错误"; // return result; //} DAL.AuthOperateDAL authOperateDAL = new AuthOperateDAL(); result = authOperateDAL.InvalidAll(user, empId, exceptItemIds); if (result.ResultStatus != 0) return result; if (authOperates != null || authOperates.Any()) { foreach (Model.AuthOperate authOperate in authOperates) { result = authoperateDAL.Insert(user, authOperate); if (result.ResultStatus != 0) return result; } } if (empMenus != null && empMenus.Any()) { DAL.EmpMenuDAL empMenuDAL = new EmpMenuDAL(); //result = empMenuDAL.InvalidAll(user, empId); //if (result.ResultStatus != 0) // return result; foreach (Model.EmpMenu empMenu in empMenus) { result = empMenuDAL.Insert(user, empMenu); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }