none
Not hard code data to vb code instead using oracle table for log in windoe mobile app

    Question

  • Code I am  utilizing  is as follow:

    Public Class InventoryMainMenu
        Private myreader As Symbol.Barcode.Reader = Nothing
        Private myReaderdata As Symbol.Barcode.ReaderData = Nothing
        Private myeventhandler As System.EventHandler = Nothing
        Public AddCycleID, StopProcess, TagEachBox, isSupervisor As Boolean
    
    
        Sub startscan()
            myreader = New Symbol.Barcode.Reader
            myReaderdata = New Symbol.Barcode.ReaderData(Symbol.Barcode.ReaderDataTypes.Text, 500)
            myeventhandler = New System.EventHandler(AddressOf MyReader_ReadNotify)
            AddHandler myreader.ReadNotify, Me.myeventhandler
            myreader.Actions.Enable()
            myreader.Actions.Read(myReaderdata)
        End Sub                                                                             
    
        Private Sub MyReader_ReadNotify(ByVal o As Object, ByVal e As EventArgs)
            Call ValidateBadgeField()
            Call startscan()
            ControlNumberTextBox.Focus()
        End Sub
    
        Private Sub ValidateBadgeField()
            'Dim returnData As String
            ValidateBadge(myReaderdata.Text, MasterLocation, "CycleCount")
    
            If IsValid Then
                Me.UserLabel.Text = UserName
                Me.UserBox.Text = UserName
                StatusBar1.Text = UserName + " is currently logged in."
            End If
            Call CheckSupervisor()
            If Not PICheckBox.Checked Then
                ControlNumberTextBox.Visible = True
            Else
                ControlNumberTextBox.Visible = False
            End If
    
        End Sub
    
    check supoervisor is part of web services
        Private Sub CheckSupervisor()
            'Check a list of badge IDs to determine if the user is allowed to make cycles
            If BadgeID <> "J7A1" AndAlso BadgeID <> "786" AndAlso BadgeID <> "DIP" AndAlso BadgeID <> "0000" Then
                isSupervisor = False
            Else
                isSupervisor = True
                EachBoxCheckBox.Visible = True
            End If
        End Sub
    
    
    
    #Region "Menu Events"
        Private Sub MenuNewControlID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
            If PICheckBox.Checked Then
                MessageBox.Show("PI has been choosen, cannot make new Cycle in PI mode.")
            Else
                Try
                    If Not isSupervisor Then
                        MessageBox.Show("You are not authorized to add cycles.")
                        Exit Sub
                    End If
                    Call NextPICycle("Cycle")
                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try
            End If
        End Sub
    
        Private Sub MenuNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
            StopProcess = False
            Try
                If UserLabel.Text = " " Then 'Check to see if the user has entered a badge before moving on
                    MessageBox.Show("Must scan badge")
                    Exit Sub
                End If
                Try
                    If Val(ControlNumberTextBox.Text) <= 0 Then 'Check to ensure that user has entered a value for control number
                        MessageBox.Show("Must enter Cycle Count ID")
                        Exit Sub
                    End If
                Catch ex As Exception
                    MessageBox.Show("PI number is not numeric. Please enter correct number.")
                End Try
    
                If Not PICheckBox.Checked Then 'If the Physical Inventory check has not been turned on
                    Try
                        Call AddCycle() 'Add/Check cycle number
                    Catch ex As Exception
                        MessageBox.Show(ex.ToString)
                    End Try
                    If StopProcess Then
                        Exit Sub
                    End If
                    InventoryCycle = " "
                Else
                    InventoryCycle = "PI" 'Sets global variable for Physical Inventory so the next screen knows how to set up
                End If
                InventoryControlID = ControlNumberTextBox.Text
                myreader.Dispose() 'Turns off scanner so it can be turned on by the next form
                myReaderdata.Dispose()
                RemoveHandler myreader.ReadNotify, Me.myeventhandler
                ControlNumberTextBox.Text = ""
                UserLabel.Text = ""
                CycleCountMX.Show() 'Main inventory screen
                PICheckBox.Checked = False
                CheckBoxFlagTimer.Enabled = False
                Me.Visible = False
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
        End Sub
    
        Private Sub MenuClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
            myreader.Dispose()
            myReaderdata.Dispose()
            MCFrmMenu.Show()
            UserLabel.Text = ""
            ControlNumberTextBox.Text = ""
            CheckBoxFlagTimer.Enabled = False
            Me.Visible = False
        End Sub
    
    
    #End Region
    
        Private Sub NextPICycle(ByVal PIorCycle As String) 'Option to add a new cycle.  Looks to cycle table and adds one
            Cursor.Current = Cursors.WaitCursor
            ControlNumberTextBox.Text = Val(ws.NextPICycle("GSWMFG", MasterLocation, PIorCycle)) + 1
            Cursor.Current = Cursors.Default
            AddCycleID = True
        End Sub
    
        Private Sub AddCycle()
            Dim returndata As String
            Select Case AddCycleID 'If the user has previous gone to menu, new control #, we will add the cycle when the user clicks next
                Case True 'User wants to create a new cycle
                    Cursor.Current = Cursors.WaitCursor
                    returndata = ws.CycleCountIDUpdate("GSWMFG", MasterLocation, ControlNumberTextBox.Text, "Add")
                    Cursor.Current = Cursors.Default
                    If returndata.Substring(0, 3) <> "Suc" Then
                        MessageBox.Show(returndata)
                        StopProcess = True
                    End If
                Case False 'User has entered a cycle number to use
                    Cursor.Current = Cursors.WaitCursor
                    returndata = ws.CycleCountIDUpdate("GSWMFG", MasterLocation, ControlNumberTextBox.Text, "Check")
                    Cursor.Current = Cursors.Default
                    If returndata.Substring(0, 3) <> "Suc" Then
                        MessageBox.Show(returndata)
                        StopProcess = True
                    End If
            End Select
        End Sub
    
    #Region "Form Events"
    
        Private Sub UserBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles UserBox.KeyDown
            If e.KeyCode = "134" Then
                UserLabel.Text = UserBox.Text
                BadgeID = UserBox.Text
                ControlNumberTextBox.Visible = True
                ControlNumberTextBox.Focus()
                Call CheckSupervisor()
            End If
        End Sub
    
        Private Sub ControlNumberTextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ControlNumberTextBox.KeyDown
            If e.KeyCode = "134" Then
                Dim returndata As String
    
                If UserLabel.Text = " " Then
                    MessageBox.Show("Must scan badge")
                    Exit Sub
                End If
                Select Case AddCycleID
                    Case True
                        Cursor.Current = Cursors.WaitCursor
                        returndata = ws.CycleCountIDUpdate("GSWMFG", MasterLocation, ControlNumberTextBox.Text, "Add")
                        Cursor.Current = Cursors.Default
                    Case False
                        Cursor.Current = Cursors.WaitCursor
                        returndata = ws.CycleCountIDUpdate("GSWMFG", MasterLocation, ControlNumberTextBox.Text, "Check")
                        Cursor.Current = Cursors.Default
                        If returndata.Substring(0, 3) <> "Suc" Then
                            MessageBox.Show(returndata)
                            Exit Sub
                        End If
                End Select
                InventoryControlID = ControlNumberTextBox.Text
                myreader.Dispose()
                myReaderdata.Dispose()
                RemoveHandler myreader.ReadNotify, Me.myeventhandler
                ControlNumberTextBox.Text = ""
                UserLabel.Text = ""
                'CheckBoxFlagTimer.Enabled = False
                CycleCountMX.Show()
                Me.Close()
            End If
        End Sub
    
        Private Sub PICheckBox_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PICheckBox.CheckStateChanged
            Dim returndata As String = ""
            Try
                Cursor.Current = Cursors.WaitCursor
                returndata = ws.CycleCountIDUpdate("GSWMFG", MasterLocation, " ", " ")
                Cursor.Current = Cursors.Default
            Catch ex As Exception
                MessageBox.Show("State Changed WS " + ex.ToString)
            End Try
            Try
                If PICheckBox.Checked = True Then
                    If returndata.Substring(0, 2) = "PI" Then
                        MessageBox.Show(returndata)
                        PICheckBox.Checked = False
                    ElseIf returndata = "Success" Then
                        Call NextPICycle("PI")
                        AddCycleID = True
                        Call AddCycle()
                    ElseIf returndata.StartsWith("Error") Then
                        MessageBox.Show(returndata)
                        PICheckBox.Checked = False
                    Else
                        ControlNumberTextBox.Text = returndata
                        AddCycleID = False
                    End If
                    ControlNumberTextBox.Enabled = False
                Else
                    ControlNumberTextBox.Enabled = True
                End If
            Catch ex As Exception
                MessageBox.Show("State Changed Logic " + returndata + ", " + ex.ToString)
            End Try
        End Sub
    
        Private Sub InventoryMainMenu_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.GotFocus
            Try
                CheckBoxFlagTimer.Enabled = True
                If myreader.Info.IsEnabled = False Then
                    Call startscan()
                End If
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
        End Sub
    
        Private Sub InventoryMainMenu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Call startscan()
            'Call MasLoc()
            ControlNumberTextBox.Visible = False
            StatusBar1.Text = "Waiting for badge scan..."
            If MasterLocation = "GSW" Then
                UserBox.Visible = True
                UserLabel.Visible = False
            End If
        End Sub
    
    #End Region
    
        Private Sub EachBoxCheckBox_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EachBoxCheckBox.CheckStateChanged
            If EachBoxCheckBox.Checked = True Then
                ws.CycleCountBoxFlag("GSWMFG", MasterLocation, ControlNumberTextBox.Text, "S", "Y")
            Else
                ws.CycleCountBoxFlag("GSWMFG", MasterLocation, ControlNumberTextBox.Text, "S", "N")
            End If
        End Sub
    
    #Region "Timer Events"
        Private Sub CheckBoxFlagTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxFlagTimer.Tick
            Try
                If ControlNumberTextBox.TextLength > 0 Then
                    Cursor.Current = Cursors.WaitCursor
                    If ws.CycleCountBoxFlag("GSWMFG", MasterLocation, ControlNumberTextBox.Text, "G", "").ToString = "Y" Then
                        EachBoxCheckBox.Checked = True
                        EachBoxCheckBox.Enabled = True
                    ElseIf ws.CycleCountBoxFlag("GSWMFG", MasterLocation, ControlNumberTextBox.Text, "G", "").ToString = "N" Then
                        EachBoxCheckBox.Checked = False
                        EachBoxCheckBox.Enabled = True
                    Else
                        EachBoxCheckBox.Enabled = False
                        EachBoxCheckBox.Checked = False
                    End If
                    Cursor.Current = Cursors.Default
                End If
            Catch
    
            End Try
        End Sub
    #End Region
    
    End Class

    I  forgot to mentioned in  and attachment   that I have code mentioned below where  I am adding  new  User or Badger  which   I hard code into  following  code   that make too hard and I need to do that  by adding that into  oracle table and tableadapter and structor of the table is  as follow:

    --------------- -------- -----------

    CCN             NOT NULL VARCHAR2(6)

    Mac_Loc         NOT NULL VARCHAR2(3)

    USER_NUMBER (is badge number)     NOT NULL NUMBER(5)  

    DSCA_PACESETTER          VARCHAR2(1)

    AMI_PACESETTER           VARCHAR2(1)

    I have datatable  

            Private Sub CheckSupervisor()
            'Check a list of badge IDs to determine if the user is allowed to make cycles
            If BadgeID <> "J7A1" AndAlso BadgeID <> "786" AndAlso BadgeID <> "DIP" AndAlso BadgeID <> "0000" Then
                isSupervisor = False

    Snapshot of the screen

            


    Vijay


    Sunday, April 9, 2017 1:49 PM

All replies

  • There is a lot of code, what specific part of the code is problematic? In the future only present relevant code to the issue at hand, not all code.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, April 9, 2017 2:02 PM
    Moderator
  • Private Sub CheckSupervisor()

            'Check a list of badge IDs to determine if the user is allowed to make cycles

            If BadgeID <> "J7A1" AndAlso BadgeID <> "786" AndAlso BadgeID <> "DIP" AndAlso BadgeID <> "0000" Then

                isSupervisor = False

    Above mentioned code has  hard coded value and I need to use datatable and table adapter   to  recognise the log in  so I dont need to hard code  instead   perform insert to oracle table.


    Vijay

    Sunday, April 9, 2017 2:07 PM
  • Presumably you would just need to query this table using the current BadgeID value.  It isn't clear whether you are simply looking to see if the BadgeID exists in the table or if you need to check the value of another associated field.  Either way the answer is the same - query the user table for the BadgeID and determine if the user is authorized to take the action.

    Now, I do not see where the ValidateBadge() function or IsValid variable are declared, but that method call might be an opportunity to determine not only the validity of the badge number, but also its user level.  The fact that these code members are missing also indicates a design problem with the overall application.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Sunday, April 9, 2017 2:11 PM
    Moderator
  • Also, it doesn't look like you are handling the barcode scanner correctly either, and actually may have induced a memory leak in your application.  Every time you receive a barcode reader event, you are recreating the symbol object instance and attaching a new event handler.  The old handler is never removed which means the old instance can't fall out of scope while the form is still running.

    Your "startscan()" method should only ever be called once and should not contain the last "read" line of code.  All this method should do is make the scanner ready to use - it should not actually use it.  Move the code which actually uses the scanner into some other method, and then call this new method after you receive data.

    To be honest I can't understand what your intent really was other than it looks like you might be putting the scanner into a read loop where it just sits there on all the time until a barcode passes under it - like a handheld scanner with the trigger always pulled.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Sunday, April 9, 2017 2:18 PM
    Moderator
  • Startscan is part of the project previous employee  wrotr  to see if barcode  works once the  scan Badge and Count Control number verify I am  just trying to make that happen is to verify user info for the code mentined  in   : 

    Private Sub CheckSupervisor() has  hard coded info or data  and I am  in process to  remove that code and  need to make it sure I will use database query located in xsd  file  where tatatable and tableadapter but I lost touch from old school code  which will  recognise that. user or badge No.

     is this make sence to you?


    Vijay

    Sunday, April 9, 2017 3:09 PM
  • Startscan is part of the project previous employee  wrotr  to see if barcode  works once the  scan Badge and Count Control number verify I am  just trying to make that happen is to verify user info for the code mentined  in   : 

    Private Sub CheckSupervisor() has  hard coded info or data  and I am  in process to  remove that code and  need to make it sure I will use database query located in xsd  file  where tatatable and tableadapter but I lost touch from old school code  which will  recognise that. user or badge No.

     is this make sence to you?


    Vijay

    Yes I understand you want to replace the hard-coded badge values with the result of a query.  If you don't already have one, create a DataSet from the Oracle database (presumably you have a .Net ADO adapter for Oracle) and add a TableAdapter with a query that looks up the BadgeId for you.

    My point on the scanner related code is that it is incorrect and should be fixed.  It does not work as intended the way it is being used now.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Sunday, April 9, 2017 3:43 PM
    Moderator