Leadtools.Medical.Workstation.DataAccessLayer Requires Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
AddUser Method
See Also  Example
Leadtools.Medical.Workstation.DataAccessLayer Namespace > IWorkstationDataAccessAgent Interface : AddUser Method



adminUser
The administrator user name adding the new user.
adminPassword
The administrator user password adding the new user.
userName
The new user name to add.
password
The new user password to add.
isAdmin
A Boolean value indicating whether the new user is administrator or not.
adminUser
The administrator user name adding the new user.
adminPassword
The administrator user password adding the new user.
userName
The new user name to add.
password
The new user password to add.
isAdmin
A Boolean value indicating whether the new user is administrator or not.
Adds a new user into the database.

Syntax

Visual Basic (Declaration)  
Overridable Function AddUser( _
   ByVal adminUser As String, _
   ByVal adminPassword As SecureString, _
   ByVal userName As String, _
   ByVal password As SecureString, _
   ByVal isAdmin As Boolean _
) As Boolean
Visual Basic (Usage) Copy Code
Dim instance As IWorkstationDataAccessAgent
Dim adminUser As String
Dim adminPassword As SecureString
Dim userName As String
Dim password As SecureString
Dim isAdmin As Boolean
Dim value As Boolean
 
value = instance.AddUser(adminUser, adminPassword, userName, password, isAdmin)
C#  
virtual bool AddUser( 
   string adminUser,
   SecureString adminPassword,
   string userName,
   SecureString password,
   bool isAdmin
)
C++/CLI  
virtual bool AddUser( 
   String^ adminUser,
   SecureString^ adminPassword,
   String^ userName,
   SecureString^ password,
   bool isAdmin
) 

Parameters

adminUser
The administrator user name adding the new user.
adminPassword
The administrator user password adding the new user.
userName
The new user name to add.
password
The new user password to add.
isAdmin
A Boolean value indicating whether the new user is administrator or not.

Return Value

True if the user is added; otherwise it is false.

Example

Visual Basic Copy Code
<Test> _
Public Sub CreateDbUser()
  Dim dataAccessAgent As IWorkstationDataAccessAgent = Nothing
  Try
     'make sure you have configured the application configuration file with a valid
     'SqlCe connection string which have the same connection name 'WorkstationSqlCeConnection'
     dataAccessAgent = DataAccessAgentFactory.Instance.CreateAccessAgent("WorkstationSqlCeConnection")

     If Nothing Is dataAccessAgent Then
       Console.WriteLine("You have not configured a valid database connection.")

       Return
     End If
  Catch exception As Exception
     Console.WriteLine(exception.Message," :You have not configured a valid database connection.")

     Return
  End Try

  Dim administratorUser As String = "Administrator" 'make sure you have an existent administrator this administrator user should be created when you create the database.
  Dim newUserName As String = "NewUser"
  Dim adminPassword As SecureString = New SecureString()
  Dim newUserPassword As SecureString = New SecureString()

  adminPassword.AppendChar("a"c)
  adminPassword.AppendChar("d"c)
  adminPassword.AppendChar("m"c)
  adminPassword.AppendChar("i"c)
  adminPassword.AppendChar("n"c)

  newUserPassword.AppendChar("u"c)
  newUserPassword.AppendChar("s"c)
  newUserPassword.AppendChar("e"c)
  newUserPassword.AppendChar("r"c)

  dataAccessAgent.AddUser(administratorUser, adminPassword, newUserName, newUserPassword, False)

  Console.WriteLine("Is User Authenticated:", newUserName, dataAccessAgent.IsUserValid(newUserName, newUserPassword))
  Console.WriteLine("Is User Administrator:", newUserName, dataAccessAgent.IsAdmin(newUserName))

  dataAccessAgent.SetAdminUser(administratorUser, adminPassword, newUserName, True)

  Console.WriteLine("Is User Administrator:", newUserName, dataAccessAgent.IsAdmin(newUserName))

  dataAccessAgent.SetUserPassword(administratorUser, adminPassword, newUserName, adminPassword)

  Dim users As User() = dataAccessAgent.GetUsers()

  Console.WriteLine("Listing all database users...")

  For Each dbUser As User In users
     Console.WriteLine(dbUser.UserName)
  Next dbUser

  adminPassword.Dispose()
  newUserPassword.Dispose()
End Sub
C# Copy Code
public void CreateDbUser() 

   IWorkstationDataAccessAgent dataAccessAgent = null ; 
 
   try 
   { 
      //make sure you have configured the application configuration file with a valid  
      //SqlCe connection string which have the same connection name 'WorkstationSqlCeConnection' 
      dataAccessAgent = DataAccessAgentFactory.Instance.CreateAccessAgent("WorkstationSqlCeConnection"); 
 
      if (null == dataAccessAgent) 
      { 
         Console.WriteLine("You have not configured a valid database connection."); 
 
         return; 
      } 
   } 
   catch ( Exception exception ) 
   { 
      Console.WriteLine( exception.Message," :You have not configured a valid database connection."); 
 
      return ; 
   } 
 
   string administratorUser = "Administrator";//make sure you have an existent administrator this administrator user should be created when you create the database. 
   string newUserName = "NewUser"; 
   SecureString adminPassword = new SecureString(); 
   SecureString newUserPassword = new SecureString(); 
 
   adminPassword.AppendChar('a'); 
   adminPassword.AppendChar('d'); 
   adminPassword.AppendChar('m'); 
   adminPassword.AppendChar('i'); 
   adminPassword.AppendChar('n'); 
 
   newUserPassword.AppendChar('u'); 
   newUserPassword.AppendChar('s'); 
   newUserPassword.AppendChar('e'); 
   newUserPassword.AppendChar('r'); 
 
   dataAccessAgent.AddUser(administratorUser, adminPassword, newUserName, newUserPassword, false); 
 
   Console.WriteLine("Is User Authenticated:", newUserName, dataAccessAgent.IsUserValid(newUserName, newUserPassword)); 
   Console.WriteLine("Is User Administrator:", newUserName, dataAccessAgent.IsAdmin(newUserName)); 
 
   dataAccessAgent.SetAdminUser(administratorUser, adminPassword, newUserName, true); 
 
   Console.WriteLine("Is User Administrator:", newUserName, dataAccessAgent.IsAdmin(newUserName)); 
 
   dataAccessAgent.SetUserPassword(administratorUser, adminPassword, newUserName, adminPassword); 
 
   User [ ] users = dataAccessAgent.GetUsers(); 
 
   Console.WriteLine("Listing all database users..."); 
 
   foreach (User dbUser in users) 
   { 
      Console.WriteLine(dbUser.UserName); 
   } 
 
   adminPassword.Dispose(); 
   newUserPassword.Dispose(); 
}

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

Leadtools.Medical.Workstation.DataAccessLayer requires a Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features