I'm currently building a Windows Form Application using Visual Studio 2015 and the Visual Basic.NET programming language.
On the main form there is a Tab Control and an ActiveX PDf viewer control. The Tab Control has 4 tabs they are labled "Find", "ECO View", "ECO Edit" & "User Admin". ECO = Engineering Change Order
Tab "Find" uses a List Box and a Textbox. This tab is used to search thru a directory and open a component or assembly drawing from a directory location on one of our file servers.
Tab "ECO View" has many labels that display text. The USer can search for an ECO Number and view the information thru all the labels which get its information from a MS SQL database 2012.
Tab ECO Edit has Textboxes, Labels, Comboboxes and buttons. The purpose of the ECO Edit tab is for creating and updating ECO data.
Tab "User Admin" has a Data Grid View, TextBox and button controls. This tab is used to add and remove Admin Users.
The end users of this application are split into two catagories Standard and Admin. The way I have the application coded is that if your not in the admin list you are a standard user. Standard users have only two tabs visible to them, the "Find" & "ECO View" tabs. The other two are invisible. Most end users are only going to use the view portion of the application. The admins are the engineers who maintain all the drawings and ECO's that others view.
Originally I verified users with this code:
Private Sub AdminOnly() Dim this_username As String lblCurUseName.Text = _UserName this_username = _UserName Select Case this_username Case "SteveW", "miked", "harryg", "JimV" lblAccessLvl.Text = "Admin" tcOAP.TabPages.Remove(tpECOedit) tcOAP.TabPages.Remove(tpUserAdmin) tcOAP.TabPages.Add(tpECOedit) tcOAP.TabPages.Add(tpUserAdmin) Exit Sub Case Else lblAccessLvl.Text = "User Only" tcOAP.TabPages.Remove(tpECOedit) tcOAP.TabPages.Remove(tpUserAdmin) tsmiArchive.Enabled = False tsmiFolders.Enabled = False End Select End Sub
But then I realized I would need to recompile the project everytime I add or remove a new user So I created the "User Admin" Tab to add and remove the users. this data is stored in a MS SQL database.
My question is: How do I approach the code in order to pull the admins from the sql database and impliment the code I have above?
Using windows authentication is not an option so I will not discuss using that as an alternative.
Here are the add user button click event code and the remove user button click event code.
Private Sub btnAddUserUA_Click(sender As Object, e As EventArgs) Handles btnAddUserUA.Click Dim Sqlstr As String = "INSERT INTO dbo.tblUserAdmin(UserName, ClockNo) VALUES (@UserName, @ClockNo)" Dim cn As New SqlConnection() cn = DBConnect() cn.Open() Dim cmdInsert As New SqlCommand(Sqlstr, cn) cmdInsert.Parameters.Add("@UserName", Data.SqlDbType.NVarChar).Value = txtUserNameUA.Text() cmdInsert.Parameters.Add("@ClockNo", Data.SqlDbType.NVarChar).Value = txtClockNoUA.Text cmdInsert.ExecuteNonQuery() cn.Close() TblUserAdminBindingSource.DataSource = TblUserAdminTableAdapter.GetData() TblUserAdminBindingSource.ResetBindings(False) txtUserNameUA.Text = Nothing txtClockNoUA.Text = Nothing End Sub Private Sub btnRemUserUA_Click(sender As Object, e As EventArgs) Handles btnRemUserUA.Click Dim cn As New SqlConnection() cn = DBConnect() cn.Open() Dim cmd As New SqlCommand() cmd.Connection = cn cmd.CommandText = "DELETE FROM dbo.tblUserAdmin where Id='" & dgvUA.CurrentRow.Cells(0).Value & "'" cmd.ExecuteNonQuery() cn.Close() dgvUA.Rows.Remove(dgvUA.CurrentRow) End Sub
Any help on this would be greatly appreciated.