PMUser.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:3k
- using System;
- using System.Data;
- using System.Configuration;
- using qminoa.DA;
- namespace qminoa.BLL.PM
- {
- public class PMUser
- {
- public const string UserRoleNone = "0";
- public const string UserRoleAdministrator = "1";
- public const string UserRoleProjectManager = "2";
- public const string UserRoleConsultant = "3";
- public const string UserRoleAdminPMgr = UserRoleAdministrator + "," + UserRoleProjectManager;
- public const string UserRolePMgrConsultant = UserRoleProjectManager + "," + UserRoleConsultant;
- private string _role = UserRoleNone;
- private string _roleName;
- private string _userName;
- private int _userID;
- public PMUser()
- {
- }
- public PMUser(int UserID)
- {
- _userID = UserID;
- _role = GetRoleByUser(UserID);
- }
- public string Role
- {
- get { return _role; }
- set { _role = value; }
- }
- public int UserID
- {
- get { return _userID; }
- set { _userID = value; }
- }
- public string RoleName
- {
- get { return _roleName; }
- set { _roleName = value; }
- }
- public string UserName
- {
- get { return _userName; }
- set { _userName = value; }
- }
- public static UsersCollection GetAllUsers(int userID)
- {
- return GetUsers(userID, PMUser.UserRoleAdministrator);
- }
- public static UsersCollection GetUsers(int userID, string role)
- {
- DataSet ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["ConnectionString"],
- "PM_ListAllUsers", userID, Convert.ToInt32(role));
- UsersCollection users = new UsersCollection();
- // Separate Data into a collection of Users.
- foreach(DataRow r in ds.Tables[0].Rows)
- {
- PMUser usr = new PMUser();
- usr.UserName = r["UserName"].ToString();
- usr.Role = r["RoleID"].ToString();
- usr.RoleName = r["RoleName"].ToString();
- usr.UserID = Convert.ToInt32(r["UserID"]);
- users.Add(usr);
- }
- return users;
- }
- public static UsersCollection GetUsers(int userID, string role,int depID)
- {
- DataSet ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["ConnectionString"],
- "PM_ListUsers", userID, Convert.ToInt32(role),depID);
- UsersCollection users = new UsersCollection();
- foreach(DataRow r in ds.Tables[0].Rows)
- {
- PMUser usr = new PMUser();
- usr.UserName = r["UserName"].ToString();
- usr.Role = r["RoleID"].ToString();
- usr.RoleName = r["RoleName"].ToString();
- usr.UserID = Convert.ToInt32(r["UserID"]);
- users.Add(usr);
- }
- return users;
- }
-
- public static UsersCollection ListManagers()
- {
-
- DataSet ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["ConnectionString"],
- CommandType.StoredProcedure, "PM_ListManagers");
- UsersCollection managersArray = new UsersCollection();
- foreach(DataRow r in ds.Tables[0].Rows)
- {
- PMUser usr = new PMUser();
- usr.UserName = r["UserName"].ToString();
- usr.Role = r["RoleID"].ToString();
- usr.UserID = Convert.ToInt32(r["UserID"]);
- managersArray.Add(usr);
- }
- return managersArray;
- }
- public static void UpdateUserRole(int userID,int userRole)
- {
- SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["ConnectionString"],
- "PM_UpdateUserRole",userID,userRole);
- }
- public static string GetRoleByUser(int userID)
- {
- DataSet ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["ConnectionString"],
- "PM_GetRoleByUser",userID);
- return ds.Tables[0].Rows[0][0].ToString();
- }
- }
- }