public ResultModel Load(UserModel user, int empId) { ResultModel result = new ResultModel(); try { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(" select distinct m.* from dbo.AuthOperate ao left join dbo.Menu m on ao.MenuId = m.MenuId where ao.EmpId =@empId and ao.AuthOperateStatus=@status and m.MenuStatus=@status "); sb.Append(" union select distinct mParent.* from dbo.EmpMenu em left join dbo.Menu m on em.MenuId = m.MenuId left join dbo.Menu mParent on mParent.MenuId = m.ParentId where em.EmpId =@empId and em.RefStatus=@status and ISNULL(mParent.MenuId,0)<>0 and mParent.MenuStatus=@status"); SqlParameter[] paras = new SqlParameter[2]; paras[0] = new SqlParameter("@empId", empId); paras[1] = new SqlParameter("@status", (int)Common.StatusEnum.已生效); DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringUser, sb.ToString(), paras, CommandType.Text); List<Menu> menus = new List<Menu>(); foreach (DataRow dr in dt.Rows) { Menu menu = new Menu(); menu.MenuId = Convert.ToInt32(dr["MenuId"]); if (dr["MenuName"] != DBNull.Value) { menu.MenuName = Convert.ToString(dr["MenuName"]); } if (dr["MenuDesc"] != DBNull.Value) { menu.MenuDesc = Convert.ToString(dr["MenuDesc"]); } if (dr["ParentId"] != DBNull.Value) { menu.ParentId = Convert.ToInt32(dr["ParentId"]); } if (dr["FirstId"] != DBNull.Value) { menu.FirstId = Convert.ToInt32(dr["FirstId"]); } if (dr["Url"] != DBNull.Value) { menu.Url = Convert.ToString(dr["Url"]); } if (dr["MenuStatus"] != DBNull.Value) { menu.MenuStatus = (Common.StatusEnum)Convert.ToInt32(dr["MenuStatus"]); } if (dr["CreatorId"] != DBNull.Value) { menu.CreatorId = Convert.ToInt32(dr["CreatorId"]); } if (dr["CreateTime"] != DBNull.Value) { menu.CreateTime = Convert.ToDateTime(dr["CreateTime"]); } if (dr["LastModifyId"] != DBNull.Value) { menu.LastModifyId = Convert.ToInt32(dr["LastModifyId"]); } if (dr["LastModifyTime"] != DBNull.Value) { menu.LastModifyTime = Convert.ToDateTime(dr["LastModifyTime"]); } menus.Add(menu); } result.AffectCount = dt.Rows.Count; result.Message = "获取列表成功"; result.ResultStatus = 0; result.ReturnValue = menus; } catch (Exception ex) { result.Message = ex.Message; } return result; }
public override IModel CreateModel(SqlDataReader dr) { Menu menu = new Menu(); int indexMenuId = dr.GetOrdinal("MenuId"); menu.MenuId = Convert.ToInt32(dr[indexMenuId]); int indexMenuName = dr.GetOrdinal("MenuName"); if (dr["MenuName"] != DBNull.Value) { menu.MenuName = Convert.ToString(dr[indexMenuName]); } int indexMenuDesc = dr.GetOrdinal("MenuDesc"); if (dr["MenuDesc"] != DBNull.Value) { menu.MenuDesc = Convert.ToString(dr[indexMenuDesc]); } int indexParentId = dr.GetOrdinal("ParentId"); if (dr["ParentId"] != DBNull.Value) { menu.ParentId = Convert.ToInt32(dr[indexParentId]); } int indexFirstId = dr.GetOrdinal("FirstId"); if (dr["FirstId"] != DBNull.Value) { menu.FirstId = Convert.ToInt32(dr[indexFirstId]); } int indexUrl = dr.GetOrdinal("Url"); if (dr["Url"] != DBNull.Value) { menu.Url = Convert.ToString(dr[indexUrl]); } int indexMenuStatus = dr.GetOrdinal("MenuStatus"); if (dr["MenuStatus"] != DBNull.Value) { menu.MenuStatus = (Common.StatusEnum)Convert.ToInt32(dr[indexMenuStatus]); } int indexCreatorId = dr.GetOrdinal("CreatorId"); if (dr["CreatorId"] != DBNull.Value) { menu.CreatorId = Convert.ToInt32(dr[indexCreatorId]); } int indexCreateTime = dr.GetOrdinal("CreateTime"); if (dr["CreateTime"] != DBNull.Value) { menu.CreateTime = Convert.ToDateTime(dr[indexCreateTime]); } int indexLastModifyId = dr.GetOrdinal("LastModifyId"); if (dr["LastModifyId"] != DBNull.Value) { menu.LastModifyId = Convert.ToInt32(dr[indexLastModifyId]); } int indexLastModifyTime = dr.GetOrdinal("LastModifyTime"); if (dr["LastModifyTime"] != DBNull.Value) { menu.LastModifyTime = Convert.ToDateTime(dr[indexLastModifyTime]); } return menu; }