asp.net|word| access to the Imports System
Imports System.Data
Imports System.Configuration
Public Class Ttuser
'****************************************************************************
'
' Ttuser Class
'
' The Ttuser class represents a time Tracker user, including their unique
' UserID and UserName. Custom role information retrieved from the database
' is also stored in the Ttuser class.
'
'****************************************************************************
Public Const userrolenone as String = "0"
Public Const userroleadministrator as String = "1"
Public Const Userroleprojectmanager as String = "2"
Public Const userroleconsultant as String = "3"
Public Const userroleadminpmgr as String = Userroleadministrator + "," + Userroleprojectmanager
Public Const userrolepmgrconsultant as String = Userroleprojectmanager + "," + userroleconsultant
Private _displayname as String = String.Empty
Private _FirstName as String = String.Empty
Private _lastname as String = String.Empty
Private _password as String = String.Empty
Private _role as String = Userrolenone
Private _rolename as String
Private _userid as Integer
Private _username as String
Public Sub New ()
End Sub ' New
Public Sub New (ByVal UserName as String)
_username = UserName
End Sub ' New
Public Sub New (ByVal UserID as Integer, ByVal UserName As String, ByVal Name As String, ByVal role as String)
_userid = UserID
_username = UserName
_displayname = Name
_role = Role
End Sub ' New
Public Property DisplayName () as String
Get
Return _displayname
End Get
Set (ByVal Value as String)
_displayname = Value
End Set
End Property
Public Property FirstName () as String
Get
Return _FirstName
End Get
Set (ByVal Value as String)
_FirstName = Value
End Set
End Property
Public Property LastName () as String
Get
Return _lastname
End Get
Set (ByVal Value as String)
_lastname = Value
End Set
End Property
Public Property Name () as String
Get
Return _displayname
End Get
Set (ByVal Value as String)
_displayname = Value
End Set
End Property
Public Property Password () as String
Get
Return _password
End Get
Set (ByVal Value as String)
_password = Value
End Set
End Property
Public property Role () as String
Get
Return _role
End Get
Set (ByVal Value as String)
_role = Value
End Set
End Property
Public Property rolename () as String
Get
Return _rolename
End Get
Set (ByVal Value as String)
_rolename = Value
End Set
End Property
Public Property UserID () as Integer
Get
Return _userid
End Get
Set (ByVal Value as Integer)
_userid = Value
End Set
End Property
Public Property UserName () as String
Get
Return _username
End Get
Set (ByVal Value as String)
_username = Value
End Set
End Property
'*********************************************************************
'
' GetAllUsers Static method
' Retrieves a list of all users.
'
'*********************************************************************
Public Shared Function getallusers (ByVal UserID as Integer) as Userscollection
Return Getusers (UserID, Ttuser. Userroleadministrator)
End Function ' GetAllUsers
'*********************************************************************
'
' Getusers Static method
' Retrieves a list of users based on the specified UserID and role.
' The list returned is restricted by role. For instance, the users with
The role of the Administrator can be all users, while the users with the
' Role of the consultant can only themselves.
'
'*********************************************************************
Public Shared Function getusers (ByVal UserID as Integer, ByVal role as String) as Userscollection
Dim firstName as String = String.Empty
Dim lastName as String = String.Empty
Dim ds as DataSet = SqlHelper.ExecuteDataset (ConfigurationSettings.AppSettings (global.cfgkeyconnstring), "TT_ Listusers ", UserID, Convert.ToInt32 (role))
Dim users as New userscollection
' Separate Data into a collection of Users.
Dim R as DataRow
For each R in DS. Tables (0). Rows
Dim usr as New ttuser
Usr. UserName = R ("UserName"). ToString ()
Usr. Role = R ("Roleid"). ToString ()
Usr. RoleName = R ("RoleName"). ToString ()
Usr. UserID = Convert.ToInt32 (R ("UserID"))
Usr. Name = GetDisplayName (usr. UserName, FirstName, LastName)
Usr. FirstName = FirstName
Usr. LastName = LastName
Users. Add (USR)
Next R
return users
End Function ' Getusers
'*********************************************************************
'
' GetDisplayName static method
' Gets the user ' 's ' the ' specified Ttuser account source, which is
' Set in Web.confg.
'
'*********************************************************************
Public Shared Function GetDisplayName (ByVal userName As String, ByRef firstName As String, ByRef lastName As String) as St Ring
Dim displayName as String = String.Empty
Dim dbname as String = String.Empty
' The Directoryhelper class would attempt to get the user ' s
' And last name from the specified account source.
Directoryhelper.finduser (UserName, FirstName, LastName)
' If the ' and ' last name could is retrieved, return the ttusername.
If firstname.length > 0 Or lastname.length > 0 Then
DisplayName = FirstName + "" + lastName
Else
dbname = Getdisplaynamefromdb (userName)
If not dbname is String.Empty Then
DisplayName = dbname
Else
DisplayName = UserName
End If
End If
Return DisplayName
End Function ' GetDisplayName
Public Shared Function Getdisplaynamefromdb (ByVal userName As String) as String
Dim displayName as String = String.Empty
DisplayName = CStr (Sqlhelper.executescalar (ConfigurationSettings.AppSettings (global.cfgkeyconnstring), "TT_ Getuserdisplayname ", UserName))
Return DisplayName
End Function
'*********************************************************************
'
' Listmanagers Static method
' Retrieves a list of users with the role of Project Manager.
'
'*********************************************************************
Public Shared Function listmanagers () as Userscollection
Dim firstName as String = String.Empty
Dim lastName as String = String.Empty
Dim ds as DataSet = SqlHelper.ExecuteDataset (ConfigurationSettings.AppSettings (global.cfgkeyconnstring), CommandType.StoredProcedure, "Tt_listmanagers")
Dim Managersarray as New userscollection
' Separate Data into a list of collections.
Dim R as DataRow
For each R in DS. Tables (0). Rows
Dim usr as New ttuser
Usr. UserName = R ("UserName"). ToString ()
Usr. Role = R ("Roleid"). ToString ()
Usr. UserID = Convert.ToInt32 (R ("UserID"))
Usr. Name = GetDisplayName (usr. UserName, FirstName, LastName)
Usr. FirstName = FirstName
Usr. LastName = LastName
Managersarray.add (USR)
Next R
Return Managersarray
End Function ' Listmanagers
'*********************************************************************
'
' Remove static method
' Removes a user from database
'
'*********************************************************************
Public Shared Sub Remove (ByVal UserID as Integer)
Sqlhelper.executenonquery (ConfigurationSettings.AppSettings (global.cfgkeyconnstring), "TT_DeleteUser", UserID)
End Sub ' Remove
'*********************************************************************
'
' Load method
' Retrieve user information from the ' Data access layer
' Returns True if user information is loaded successfully, false otherwise.
'
'*********************************************************************
Public Function Load () as Boolean
' Get the ' user ' s information from the database
Dim ds as DataSet = SqlHelper.ExecuteDataset (ConfigurationSettings.AppSettings (global.cfgkeyconnstring), "TT_ Getuserbyusername ", _username)
If ds. Tables (0). Rows.Count < 1 Then
Return False
End If
Dim dr as DataRow = ds. Tables (0). Rows (0)
_userid = Convert.ToInt32 (DR ("UserID"))
_username = DR ("UserName"). ToString ()
_role = DR ("Roleid"). ToString ()
_password = IIf (dr ("password") is DBNull.Value, "", Dr ("password")
_displayname = GetDisplayName (_username, _FirstName, _lastname)
Return True
End Function ' Load
'*********************************************************************
'
' Save method
' ADD or update user information in the ' database depending on the Tt_userid.
' Returns True if saved successfully, false otherwise.
'
'*********************************************************************
Public Overloads Function Save () as Boolean
Dim Isuserfound as Boolean = False
Dim Isuseractivemanager as Boolean = True
Return Save (False, Isuserfound, Isuseractivemanager)
End Function ' Save
'*********************************************************************
'
' Save method
' ADD or update user information in the ' database depending on the Ttuserid.
' Returns True if saved successfully, false otherwise.
'
'*********************************************************************
Public Overloads Function Save (ByVal checkusername As Boolean, ByRef isuserfound As Boolean, ByRef Isuseractivemanager as Boolean) as Boolean
' Determines whether object needs update or to be inserted.
If _userid = 0 Then
Return Insert (Checkusername, Isuserfound)
Else
If _userid > 0 Then
Return Update (Isuseractivemanager)
Else
_userid = 0
Return False
End If
End If
End Function ' Save
Private Function Insert (ByVal checkusername As Boolean, ByRef Isuserfound as Boolean) as Boolean
Dim firstName as String = String.Empty
Dim lastName as String = String.Empty
Isuserfound = False
If configurationsettings.appsettings (Global.cfgkeyuseracctsource) <> "None" Then
' Check to ' if ' the ' user ' was in the NT SAM or Active Directory before inserting them
' Into the time Tracker database. If A or last name is returned, the user exists and
' can be inserted to the time Tracker database.
If Checkusername Then
Ttuser. GetDisplayName (_username, FirstName, LastName)
Isuserfound = firstName <> string.empty Or lastName <> String.Empty
End If
Else
Checkusername = False
Isuserfound = True
End If
If Checkusername and Isuserfound Or not checkusername Then
_userid = Convert.ToInt32 (Sqlhelper.executescalar (ConfigurationSettings.AppSettings (Global.CfgKeyConnString), "TT _adduser ", _username, _password, _displayname, Convert.ToInt32 (_role)))
Isuserfound = True
End If
return _userid > 0
End Function ' Insert
Private Function Update (ByRef Isuseractivemanger As Boolean) as Boolean
' If new user ' is a consultant, check if user are a active manager of one or more project. If so, no update is applied
If _role = userroleconsultant Then
If Convert.ToInt32 (sqlhelper.executescalar configurationsettings.appsettings (global.cfgkeyconnstring), TT_ Getmanagerprojectcount ", _userid)) > 0 Then
Isuseractivemanger = True
Return False
Else
Isuseractivemanger = False
End If
End If
return 0 < Convert.ToInt32 (sqlhelper.executescalar configurationsettings.appsettings (global.cfgkeyconnstring), "Tt_updateuser", _userid, _username, _password, _displayname, Convert.ToInt32 (_role))
End Function ' Update
'*********************************************************************
'
' Usersdb.login () method
'
' The Login method validates a Email/password pair against credentials
' Stored in the users database. If The Email/password pair is valid,
' The method returns user ' s name.
'
' Other relevant sources:
' + userlogin Stored Procedure
'
'*********************************************************************
Public Function Login (ByVal Email As String, ByVal password as String) as String
Dim UserName as String
UserName = CStr (Sqlhelper.executescalar (ConfigurationSettings.AppSettings (global.cfgkeyconnstring), "TT_UserLogin ", email, password)
If not UserName are Or userName is "" Then
Return UserName
Else
Return String.Empty
End If
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.