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



userName
The user name to check.
userName
The user name to check.
Checks if user is an administrator.

Syntax

Visual Basic (Declaration)  
Overridable Function IsAdmin( _
   ByVal userName As String _
) As Boolean
Visual Basic (Usage) Copy Code
Dim instance As IWorkstationDataAccessAgent
Dim userName As String
Dim value As Boolean
 
value = instance.IsAdmin(userName)
C#  
virtual bool IsAdmin( 
   string userName
)
C++/CLI  
virtual bool IsAdmin( 
   String^ userName
) 

Parameters

userName
The user name to check.

Return Value

True if the user is administrator; 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