--============================================================================================================= -- Application Name: -- Proposal System -- -- Code Description: -- This is where the PSUser class is created and added to the ProposalSystemLibrary namespace. The -- PSUser class is used throughout the Proposal System application. -- =--============================================================================================================ using System; namespace ProposalSystemLibrary { /// /// Summary description for PSUser. /// public class PSUser { public enum UserRoleEnum { ReadOnly, CanMakeChanges, ApproveUnapprove } public PSUser() { // // TODO: Add constructor logic here // } public bool IsUserValid(string strUsername, string strPassword) { bool boolReturn = false; ProposalSystemEncryption.Encryption oEncrypt = new ProposalSystemEncryption.Encryption(); strPassword = oEncrypt.Encrypt(strPassword); PSUserData oUser = new PSUserData(); System.Int64 iValue = oUser.IsValidUser(strUsername.Trim(), strPassword.Trim()); if(iValue >= 1) { boolReturn = true; } return boolReturn; } public System.Data.DataSet GetAllUsers() { System.Data.DataSet ds = new System.Data.DataSet(); PSUserData oList = new PSUserData(); ds = oList.GetAllUsers(); return ds; } public System.Int64 GetUserID(string strUsername) { System.Int64 iReturn = -99; PSUserData oUser = new PSUserData(); iReturn = oUser.GetUserId(strUsername.Trim()); return iReturn; } public PSUser.UserRoleEnum GetRole(System.Int64 intUserId) { PSUserData oUser = new PSUserData(); System.Int64 iRole = 0; System.Data.DataSet ds = oUser.GetUserRole(intUserId); if(ds.Tables[0].Rows.Count >= 1) { if(ds.Tables[0].Columns["UDESCRIPTION"] != null) { System.Data.DataRow oRow; oRow = ds.Tables[0].Rows[0]; switch(oRow["UDESCRIPTION"].ToString()) { case "CAN MAKE CHANGES": iRole = 1; break; case "APPROVE / UNAPPROVE": iRole = 2; break; default: iRole = 0; break; } } else { iRole = 0; } } return(PSUser.UserRoleEnum)iRole; } public bool UserAccountLocked(System.Int64 intuserId) { bool boolReturn = false; PSUserData oUser = new PSUserData(); System.Int64 iBadLogins = oUser.GetUserBadLogins(intuserId); if(iBadLogins >= 3) boolReturn = true; return boolReturn; } public PSUser.RecordDetail GetUserAccount(System.Int64 intUserId) { PSUser.RecordDetail oUserAccount = new PSUser.RecordDetail(); PSUserData oUser = new PSUserData(); System.Data.DataSet ds = new System.Data.DataSet(); ds = oUser.GetUser(intUserId); if(ds.Tables[0].Rows.Count >= 1) { System.Data.DataRow oRow = ds.Tables[0].Rows[0]; oUserAccount.UserID = intUserId; oUserAccount.Username = oRow["USERNAME"].ToString(); oUserAccount.Role = GetRole(intUserId); oUserAccount.EmailAddress = oRow["EMAIL"].ToString(); ProposalSystemEncryption.Encryption oDecrypt = new ProposalSystemEncryption.Encryption(); oUserAccount.Password = oDecrypt.Decrypt(oRow["PASSWORD"].ToString()); if(oRow["THRESHOLD_AMOUNT"] != System.DBNull.Value) oUserAccount.ThresholdAmount = Convert.ToDouble(oRow["THRESHOLD_AMOUNT"]); else oUserAccount.ThresholdAmount = 0; if(oRow["SUPERIOR_USER_ID"] != System.DBNull.Value) oUserAccount.SuperiorUserId = Convert.ToInt64(oRow["SUPERIOR_USER_ID"]); else oUserAccount.SuperiorUserId = 0; oUserAccount.UsernameEncrypted = oRow["USERNAME_ENCRYPTED"].ToString(); } return oUserAccount; } public class RecordDetail { public RecordDetail() { // // TODO: Add constructor logic here // } public string Username; public string Password; public System.Int64 RoleID; public PSUser.UserRoleEnum Role; public System.Int64 UserID; public bool ChangePassword; public double ThresholdAmount; public System.Int64 SuperiorUserId; public string EmailAddress; public string UsernameEncrypted; } } }