dcsimg
Results 1 to 4 of 4

Thread: Transfer data to DB once processes are complete

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2019
    Posts
    7

    Transfer data to DB once processes are complete

    Recently, I was working on a datagridview with its own assigned database (which I manually created on the VB and not on MS Access when I clicked "edit columns"). To it, I want to try and add the items necessary once one other page specifcally has been completed. Could somebody please recommend a way to do this? Also, I want exterior pages (other than Payment page, namely from NewUser) to fill in specific rows once the payment process is complete.

    Thanks for the help.

    *Code*
    Code:
    Public Class Payment
    
        Public requiredAmount As Double
        Dim amount, change As Double
    
        ' Public Class GlobalVariables
        'Public Shared success As Boolean = False
        ' End Class
    
        Private Sub Payment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' disable everything except card number and back
            txtCardNumber.Enabled = True
            btnCancel.Enabled = True
            comboBoxType.Enabled = False
            txtCVV.Enabled = False
            txtEmail.Enabled = False
            txtCost.Enabled = False
            txtPaymentInput.Enabled = False
            btnSubmit.Enabled = False
    
            ' auto infil txt
            txtCost.Text = FormatCurrency(PrototypeNewCheckout3.txtGrandTotal.Text) 'assign the required amount to the textbox
    
        End Sub
    
        Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
            Dim success As Boolean
            amount = CDbl(txtPaymentInput.Text)
            txtPaymentInput.Text = FormatCurrency(amount)
            requiredAmount = CDbl(txtCost.Text)
            If amount < requiredAmount Then 'if the customer has not tended enough money
                MsgBox("Please enter a payment that is at least the amount owing.")
                txtPaymentInput.Clear()
                success = False
            ElseIf amount >= requiredAmount Then
                ' proceed with payment, displaying the change due
                change = amount - requiredAmount
                MsgBox("Change owing: " & FormatCurrency(change), MsgBoxStyle.OkOnly, "Payment Complete")
                Me.Close()
                Bookingv2.Close()
                PrototypeNewCheckout3.Close()
                success = True
            End If
    
        End Sub
    
        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            PrototypeNewCheckout3.Show()
            Me.Close()
        End Sub
    
        Private Sub txtCVV_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCVV.KeyPress
            If Char.IsNumber(e.KeyChar) = False Then
                e.Handled = True
            End If
        End Sub
    
        Private Sub txtCVV_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCVV.TextChanged
            If txtCVV.Text <> "" And txtCVV.Text.Length = 4 Then ' if entered and more than 4 text entered
                txtEmail.Enabled = True ' enable
            ElseIf txtCVV.Text.Length > 4 Then ' if more than 4
                MsgBox("Please keep less than 4 numbers.") ' show
            End If
        End Sub
    
        Private Sub txtCardNumber_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCardNumber.KeyPress
            ' code from YT allow only numbers in a textbox VBNET lesson
            If Char.IsNumber(e.KeyChar) = False Then
                e.Handled = True
            End If
        End Sub
    
        Private Sub txtCardNumber_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCardNumber.TextChanged
            If txtCardNumber.Text <> "" Then ' if not nothing
                comboBoxType.Enabled = True ' enable
            End If
        End Sub
    
        Private Sub comboBoxType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comboBoxType.SelectedIndexChanged
            If comboBoxType.Text <> "" Then ' If not nothing
                txtCVV.Enabled = True
            End If
        End Sub
    
        Private Sub txtEmail_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmail.TextChanged
            If txtEmail.Text <> "" Then ' if something
                txtPaymentInput.Enabled = True
            End If
        End Sub
    
        Private Sub txtPaymentInput_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPaymentInput.KeyPress
            If Char.IsNumber(e.KeyChar) = False Then
                e.Handled = True
            End If
        End Sub
    
    
        Private Sub txtPaymentInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPaymentInput.TextChanged
            If txtPaymentInput.Text <> "" Then ' if not nothing
                btnSubmit.Enabled = True
            End If
        End Sub
    
    End Class 
    
    Imports System.Security.Cryptography
    Public Class NewUser2
    
        Private Sub NewUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' turn off everthing except txtNewUser and back btn
            txtNewUser.Enabled = True
            txtNewPass.Enabled = False
            txtFirstName.Enabled = False
            txtSurname.Enabled = False
            txtAddress.Enabled = False
            txtRoomNumber.Enabled = False
            txtAccountNumber.Enabled = False
            btnCreate.Enabled = False
            btnGenerate.Enabled = False
        End Sub
    
        Public Function passwordEncryptSHA(ByVal password As String) As String
            Dim sha As New SHA1CryptoServiceProvider ' declare SHA as new SHA1CryptoServiceProvider
            Dim bytesToHash() As Byte ' and here is a byte variable
    
            bytesToHash = System.Text.Encoding.ASCII.GetBytes(password) ' convert the password into ASCII code
    
            bytesToHash = sha.ComputeHash(bytesToHash) ' begin encryption
    
            Dim encPassword As String = ""
    
            For Each b As Byte In bytesToHash
                encPassword += b.ToString("x2")
            Next
            Return encPassword ' password encrypted
    
        End Function
    
    
        Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
            Me.Close()
            Form1.Show()
        End Sub
    
    
        Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
            Dim password As String
            Dim passwordSHA As String
            Dim FILE_NAME As String = "UserPasswords.txt"
    
            password = txtNewPass.Text ' give password encrypted the value typed in the textbox
    
            Call passwordEncryptSHA(password) ' Call the first password encryption function for SHA1
    
            passwordSHA = passwordEncryptSHA(password) ' give the variable the returned SHA value
    
            'Display both values in the corresponding textboexes
            lblSHA1.Text = passwordSHA
    
            If System.IO.File.Exists(FILE_NAME) = True Then
                Dim objWriter As IO.StreamWriter = IO.File.AppendText("UserPasswords.txt")
    
                objWriter.WriteLine(txtNewUser.Text & "," & lblSHA1.Text)
    
                objWriter.Close()
    
                ' Create user if details match
                MsgBox("Account Created. Please remember your account number created as that will be used when you pick up your items.")
                Me.Close()
                Form1.Show()
            Else
                MsgBox("Error")
                Me.Close()
            End If
    
            If System.IO.File.Exists(FILE_NAME) = True Then
                Dim objWriter As IO.StreamWriter = IO.File.AppendText("UserInformation.txt")
    
                objWriter.WriteLine(txtFirstName.Text & "," & txtSurname.Text & "," & txtAddress.Text & "," & txtRoomNumber.Text & ",") ' write into userinfo txt file 
    
                objWriter.Close()
    
                ' Create user if details match
                Me.Close()
                Form1.Show()
            Else
                MsgBox("Error")
                Me.Close()
            End If
    
        End Sub
    
    
        Private Sub btnHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelp.Click
            UserHelp.Show() ' open userhelp
        End Sub
    
        Private Sub txtRoomNumber_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtRoomNumber.KeyPress
            ' code from YT allow only numbers in a textbox VBNET lesson
            If Char.IsNumber(e.KeyChar) = False Then
                e.Handled = True
            End If
        End Sub
    
    
    
        Private Sub txtNewUser_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNewUser.TextChanged
            If txtNewUser.Text <> "" Then ' if entered
                txtNewPass.Enabled = True ' turn on
            End If
        End Sub
    
        Private Sub txtNewPass_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNewPass.TextChanged
            If txtNewPass.Text <> "" Then ' if entered
                txtFirstName.Enabled = True ' turn on
            End If
        End Sub
    
        Private Sub txtFirstName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFirstName.TextChanged
            If txtFirstName.Text <> "" Then ' if entered
                txtSurname.Enabled = True ' turn on
            End If
        End Sub
    
        Private Sub txtSurname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSurname.TextChanged
            If txtSurname.Text <> "" Then ' if entered
                txtRoomNumber.Enabled = True ' enable
            End If
        End Sub
    
        Private Sub txtAccountNumber_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAccountNumber.TextChanged
            If txtAccountNumber.Text <> "" Then
                btnCreate.Enabled = True
            End If
    
        End Sub
    
    
        Private Sub txtRoomNumber_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRoomNumber.TextChanged
            If txtRoomNumber.Text <> "" And txtRoomNumber.Text.Length > 3 Then ' if entered and more than 3 text entered
                txtAddress.Enabled = True ' enable
            End If
            If txtRoomNumber.Text.Length > 4 Then ' if more than 4
                MsgBox("Please keep less than 4 numbers.")
                txtAddress.Enabled = False ' turn off
            End If
        End Sub
    
        
    
    
        Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
            Dim FILE_NAME As String = "C:\Users\Owner\Documents\useraccountnumber.txt"
    
    
            ' code from Visual Basic Random Number Generator by jejeroyetompson on YT, except number was changed to string instead of integer
            Dim rn As Random ' set rn as random
            Dim number As String ' sets number as string
            rn = New Random
            number = rn.Next(0, 999999) ' create integer or account number between 0 and 999999
            txtAccountNumber.Text = number ' put the random integer into the textbox
            
    
            If System.IO.File.Exists(FILE_NAME) = True Then
                Dim objWriter As IO.StreamWriter = IO.File.AppendText("useraccountnumber.txt")
                objWriter.WriteLine(txtAccountNumber.Text)
                objWriter.Close()
    
            End If
    
    
        End Sub
    
        Private Sub txtAddress_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAddress.TextChanged
            If txtAddress.Text <> "" Then
                btnGenerate.Enabled = True
            End If
        End Sub
    End Class
    Attached Images Attached Images    
    Last edited by Shaggy Hiker; Jul 19th, 2019 at 09:02 AM. Reason: Added CODE tags.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,325

    Re: Transfer data to DB once processes are complete

    When posting code, press either the # or VB button and paste the code between the resulting tags.
    My usual boring signature: Nothing

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,486

    Re: Transfer data to DB once processes are complete

    Are we supposed to just start trawling through that code looking for problems to solve? Please provide a FULL and CLEAR explanation of the actual problem and provide ALL and ONLY the information relevant to that problem.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,266

    Re: Transfer data to DB once processes are complete

    Recently, I was working on a datagridview with its own assigned database (which I manually created on the VB and not on MS Access when I clicked "edit columns"). To it, I want to try and add the items necessary once one other page specifcally has been completed.
    You don't assign a database to a DataGridView, I don't see anything about a DataGridView in the code you posted but maybe I missed it because that quite a bit of code. I also don't know what this means "I manually created on the VB and not on MS Access when I clicked "edit columns".

    Maybe there's a language issue but we definitely need a clearer definition of the situation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width