/// <summary> /// Constructor: Sets up a database connection and loads all the Test run information into /// memory for fast and easy access. /// </summary> public RunQueue( ) { // First, setup a connection to the database... dbConnection = new SQLDatabase( ); dbConnection.Connect( ); // First thing we need to do is load all the RunItems... RunItems = RetrieveTestScheduleInformation( ); }
private static void AddUser( ) { string externalAccount = null; bool userAlreadyExists = false; Console.WriteLine( "\nADD USER: "******"\n" ); Console.WriteLine( "To add a user, you must associate the username with an external" ); Console.WriteLine( "account on the local machine or on a domain server. To do this," ); Console.WriteLine( "enter the username as \"DOMAIN\\USERNAME\" or as \"MACHINE\\USERNAME\"\n"); Console.Write( "External Account: " ); // Read in the external user account to use... externalAccount = Console.ReadLine( ); Permissions permissions = new Permissions( ); Console.WriteLine( "\nNow, permissions for this user must be set.\n" ); Console.Write( "Allow to Create Tests [y/n]? " ); permissions.CreateTests = ConvertResponseToBool( Console.ReadLine( ) ); Console.Write( "Allow to Delete Tests [y/n]? " ); permissions.DeleteTests = ConvertResponseToBool( Console.ReadLine( ) ); Console.Write( "Allow to Modify Tests [y/n]? " ); permissions.ModifyTests = ConvertResponseToBool( Console.ReadLine( ) ); Console.Write( "Allow to Create Areas [y/n]? " ); permissions.CreateAreas = ConvertResponseToBool( Console.ReadLine( ) ); Console.Write( "Allow to Delete Areas [y/n]? " ); permissions.DeleteAreas = ConvertResponseToBool( Console.ReadLine( ) ); Console.Write( "Allow to Modify Areas [y/n]? " ); permissions.ModifyAreas = ConvertResponseToBool( Console.ReadLine( ) ); User user = new User( ); user.PermissionSettings = permissions; user.ExternID = externalAccount.ToUpper( ); user.Name = UserName.ToUpper( ); Console.WriteLine( "\n**YOU ENTERED**" ); PrintUserInformation( user ); Console.Write( "\nDoes the above information look correct [y/n]?" ); try { if ( ConvertResponseToBool( Console.ReadLine( ) ) ) { SQLDatabase dbConnection = new SQLDatabase( ); dbConnection.Connect( ); try { dbConnection.GetUserIDFromName( user.Name ); userAlreadyExists = true; } catch ( Exception ) { // this is the SUCCESS case... } if ( userAlreadyExists ) throw new Exception( "User Already Exists!" ); dbConnection.AddUser( user ); dbConnection.Disconnect( ); Console.WriteLine( "\nTHE USER WAS ADDED SUCCESSFULLY" ); } else { Console.WriteLine( "\nPLEASE RUN THE TOOL AGAIN WITH THE PROPER INFORMATION" ); } } catch ( Exception ) { Console.WriteLine( "\nERROR: The user could not be added because the user already exists, or" ); Console.WriteLine( "you do not have access to the sql database." ); } }
private void Page_Load(object sender, System.EventArgs e) { dbConnection = new SQLDatabase( ); // The expanded nodes arraylist tracks the expanded and collapsed nodes // of the tree view. ExpandedNodes = new ArrayList( ); // We must maintain the expanded nodes across the session... if ( Session["ExpandedNodes"] == null ) Session["ExpandedNodes"] = ExpandedNodes; dbConnection.DataSource = "user id=" + DBUserName + ";password="******";Data Source=" + SQLServer + ";Initial Catalog=" + dbConnection.InitialCatalog; // Connect to the database... dbConnection.Connect( dbConnection.DataSource ); // Put user code to initialize the page here UserNameLabel.Text = userName; Permissions userPermissions = dbConnection.RetrieveUser( dbConnection.GetUserIDFromExternalID( userName ) ).PermissionSettings; AddNewTestButton.Enabled = userPermissions.CreateTests; DeleteArea.Enabled = userPermissions.DeleteAreas; AddArea.Enabled = userPermissions.CreateAreas; AreaTestsGrid.Columns[2].Visible = userPermissions.DeleteTests; AreaTestsGrid.Columns[0].Visible = userPermissions.ModifyTests; this.PopulateTreeview( ); }