Advertisement
Guest User

VB Project

a guest
May 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 11.51 KB | None | 0 0
  1. Public Class Form1
  2.    
  3.     'Dec Arrays
  4.     Dim ArrProductName(4) As String
  5.     Dim ArrProductPrice(4) As Integer
  6.     Dim ArrProductQuntity(4) As Integer
  7.     Dim ArrProductID(4) As Integer
  8.  
  9.     'Declaring a variable to hold a value that will be used to calculate toltal price
  10.     Dim intValues As Integer = 0
  11.  
  12.     'Dec Counters
  13.     Dim intNCounter As Integer = -1
  14.     Dim intPCounter As Integer = -1
  15.     Dim intQCounter As Integer = -1
  16.     Dim intIDCounter As Integer = -1
  17.  
  18.     'Declare variables
  19.     Dim intAmountET As Integer
  20.     Dim intSalesTax As Integer
  21.     Dim intAmountIT As Integer
  22.     Dim intChangeDue As Integer
  23.     Dim intChange As Integer
  24.     Const VAT As Decimal = CDec((14 / 100))
  25.     Dim intChnage As Integer
  26.  
  27.     'Function for Clearing of fields GroupBox 2
  28.     Private Sub ClearControls()
  29.         txtItemN.Clear()
  30.         txtItemP.Clear()
  31.         txtItemQ.Clear()
  32.         txtItemID.Clear()
  33.         txtItemN.Focus()
  34.     End Sub
  35.  
  36.  
  37.  
  38.  
  39.  
  40.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  41.         TabControl1.TabPages(1).Enabled = False
  42.         TabControl1.TabPages(2).Enabled = False
  43.         TabControl1.TabPages(3).Enabled = False
  44.         TabControl1.TabPages(4).Enabled = False
  45.     End Sub
  46.  
  47.     Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
  48.         Dim UserName As String
  49.         Dim Password As String
  50.  
  51.         UserName = CStr(txtUser.Text)
  52.         Password = CStr(txtPass.Text)
  53.  
  54.         If UserName = "E" And Password = "E" Then
  55.             MessageBox.Show("Login Successful")
  56.             TabControl1.SelectedTab = TabPage2
  57.             TabControl1.TabPages(1).Enabled = True
  58.             TabControl1.TabPages(2).Enabled = True
  59.             TabControl1.TabPages(3).Enabled = True
  60.             TabControl1.TabPages(4).Enabled = True
  61.             txtUser.Clear()
  62.             txtPass.Clear()
  63.             GroupBox1.Enabled = False
  64.         Else
  65.             MessageBox.Show("Login Unsuccessful")
  66.             txtUser.Clear()
  67.             txtPass.Clear()
  68.             txtUser.Focus()
  69.             Exit Sub
  70.         End If
  71.     End Sub
  72.  
  73.     Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
  74.         Dim intResponse As Integer
  75.  
  76.         intResponse = MessageBox.Show("Are You Aure You Want To Exit?", "Exit Application", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
  77.  
  78.         If intResponse = DialogResult.Yes Then
  79.             Me.Close()
  80.         End If
  81.     End Sub
  82.  
  83.     Private Sub btnGen_Click(sender As Object, e As EventArgs) Handles btnGen.Click
  84.         Dim Random As New Random
  85.         Dim ID As Integer
  86.  
  87.         ID = Random.Next(1000, 9666 + 123)
  88.  
  89.         txtItemID.Text = ID.ToString()
  90.     End Sub
  91.  
  92.     Private Sub btnClearC_Click(sender As Object, e As EventArgs) Handles btnClearC.Click
  93.         ClearControls()
  94.     End Sub
  95.  
  96.     Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
  97.         'Adding Product Names to ArrProductName
  98.         If IsNumeric(txtItemN.Text) = True Or IsNothing(txtItemN.Text) = True Then
  99.             MessageBox.Show("Please enter a Item Name!", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  100.         Else
  101.             If intNCounter = 4 Then
  102.                 MessageBox.Show("Stock MAXXED", "We are FULL!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  103.                 ClearControls() 'clears fields inside groupbox 2 so it looks nice
  104.                 GroupBox2.Enabled = False 'disables groupbox 2 so no further enteries can be made
  105.             Else
  106.                 intNCounter = intNCounter + 1
  107.                 ArrProductName(intNCounter) = txtItemN.Text
  108.             End If
  109.         End If
  110.  
  111.         'Adding Product Price to ArrProductPrice
  112.         If IsNumeric(txtItemP.Text) = False Or IsNothing(txtItemP.Text) = True Then
  113.             MessageBox.Show("Please enter a Valid Price!", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  114.         Else
  115.             If intPCounter = 4 Then
  116.                 'MessageBox.Show("Stock MAXXED", "We are FULL!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  117.             Else
  118.                 intPCounter = intPCounter + 1
  119.                 ArrProductPrice(intPCounter) = CInt(txtItemP.Text)
  120.             End If
  121.         End If
  122.  
  123.         'Adding Product Quantity to ArrProductQuantity
  124.         If IsNumeric(txtItemQ.Text) = False Or IsNothing(txtItemQ.Text) = True Then
  125.             MessageBox.Show("Please enter a Valid Quantity!", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  126.         Else
  127.             If intQCounter = 4 Then
  128.                 'MessageBox.Show("Stock MAXXED", "We are FULL!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  129.             Else
  130.                 intQCounter = intQCounter + 1
  131.                 ArrProductQuntity(intQCounter) = CInt(txtItemQ.Text)
  132.             End If
  133.         End If
  134.  
  135.         'Adding Product ID to ArrProductID
  136.         If IsNumeric(txtItemID.Text) = False Or IsNothing(txtItemID.Text) = True Then
  137.             MessageBox.Show("Please enter a Valid Product ID!", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  138.         Else
  139.             If intIDCounter = 4 Then
  140.                 'MessageBox.Show("Stock MAXXED", "We are FULL!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  141.             Else
  142.                 intIDCounter = intIDCounter + 1
  143.                 ArrProductID(intIDCounter) = CInt(txtItemID.Text)
  144.             End If
  145.         End If
  146.     End Sub
  147.  
  148.     Private Sub btnViewP_Click(sender As Object, e As EventArgs) Handles btnViewP.Click
  149.         'Add details captured to ListBox = lstProducts
  150.         lstProducts.Items.Clear()
  151.         lstProducts.Items.Add("Product Name: " & vbTab & "Product ID: ")
  152.         lstProducts.Items.Add("---------------------------------------")
  153.  
  154.         For index As Integer = 0 To 4
  155.             lstProducts.Items.Add(ArrProductName(index).ToString() & vbTab & ArrProductID(index).ToString())
  156.         Next
  157.  
  158.     End Sub
  159.  
  160.     Private Sub btnViewAP_Click(sender As Object, e As EventArgs) Handles btnViewAP.Click
  161.         'Add details captured to ListBox = lstAllProducts
  162.         lstAllProducts.Items.Clear()
  163.         lstAllProducts.Items.Add("Product Name: " & vbTab & "Product Price: " & vbTab & "Product Quantity: " & vbTab & "Product ID: ")
  164.         lstAllProducts.Items.Add("--------------------------------------------------------------------------------------------------------------")
  165.  
  166.         For index As Integer = 0 To 4
  167.             lstAllProducts.Items.Add(ArrProductName(index).ToString() & vbTab & vbTab & "R" & ArrProductPrice(index).ToString() & vbTab & vbTab & ArrProductQuntity(index) & vbTab & vbTab & ArrProductID(index))
  168.         Next
  169.     End Sub
  170.  
  171.     Private Sub btnViewP2_Click(sender As Object, e As EventArgs) Handles btnViewP2.Click
  172.         lstProStock.Items.Clear()
  173.         lstProStock.Items.Add("Product Name: " & vbTab & "Product ID: ")
  174.         lstProStock.Items.Add("-----------------------------------------")
  175.  
  176.         For index As Integer = 0 To 4
  177.             lstProStock.Items.Add(vbTab & ArrProductName(index).ToString() & vbTab & ArrProductID(index).ToString())
  178.         Next
  179.  
  180.     End Sub
  181.  
  182.     Private Sub lstProStock_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstProStock.SelectedIndexChanged
  183.         If lstProStock.SelectedIndex = 2 Then
  184.             txtPrice.Text = ArrProductPrice(0).ToString()
  185.         ElseIf lstProStock.SelectedIndex = 3 Then
  186.             txtPrice.Text = ArrProductPrice(1).ToString()
  187.         ElseIf lstProStock.SelectedIndex = 4 Then
  188.             txtPrice.Text = ArrProductPrice(2).ToString()
  189.         ElseIf lstProStock.SelectedIndex = 5 Then
  190.             txtPrice.Text = ArrProductPrice(3).ToString()
  191.         ElseIf lstProStock.SelectedIndex = 6 Then
  192.             txtPrice.Text = ArrProductPrice(4).ToString()
  193.         End If
  194.     End Sub
  195.  
  196.     Private Sub btnAddP_Click(sender As Object, e As EventArgs) Handles btnAddP.Click
  197.         'Adding selected items from lstProStock to lstReciept
  198.  
  199.         If lstProStock.SelectedIndex = 2 Then
  200.             lstReciept.Items.Add(ArrProductName(0).ToString() & vbTab & "R" & ArrProductPrice(0).ToString() & vbTab & ArrProductID(0))
  201.             lstCompleteR.Items.Add(ArrProductName(0).ToString() & vbTab & "R" & ArrProductPrice(0).ToString() & vbTab & ArrProductID(0)) 'Adds selected item to lstCompleteR
  202.             intValues = intValues + CInt(txtPrice.Text) 'this line is going to hold values from the text box being added to lstReciept, also ganna work out total
  203.         ElseIf lstProStock.SelectedIndex = 3 Then
  204.             lstReciept.Items.Add(ArrProductName(1).ToString() & vbTab & "R" & ArrProductPrice(1).ToString() & vbTab & ArrProductID(1))
  205.             lstCompleteR.Items.Add(ArrProductName(1).ToString() & vbTab & "R" & ArrProductPrice(1).ToString() & vbTab & ArrProductID(1)) 'Adds selected item to lstCompleteR
  206.             intValues = intValues + CInt(txtPrice.Text) 'this line is going to hold values from the text box being added to lstReciept, also ganna work out total
  207.         ElseIf lstProStock.SelectedIndex = 4 Then
  208.             lstReciept.Items.Add(ArrProductName(2).ToString() & vbTab & "R" & ArrProductPrice(2).ToString() & vbTab & ArrProductID(2))
  209.             lstCompleteR.Items.Add(ArrProductName(2).ToString() & vbTab & "R" & ArrProductPrice(2).ToString() & vbTab & ArrProductID(2)) 'Adds selected item to lstCompleteR
  210.             intValues = intValues + CInt(txtPrice.Text) 'this line is going to hold values from the text box being added to lstReciept, also ganna work out total
  211.         ElseIf lstProStock.SelectedIndex = 5 Then
  212.             lstReciept.Items.Add(ArrProductName(3).ToString() & vbTab & "R" & ArrProductPrice(3).ToString() & vbTab & ArrProductID(3))
  213.             lstCompleteR.Items.Add(ArrProductName(3).ToString() & vbTab & "R" & ArrProductPrice(3).ToString() & vbTab & ArrProductID(3)) 'Adds selected item to lstCompleteR
  214.             intValues = intValues + CInt(txtPrice.Text) 'this line is going to hold values from the text box being added to lstReciept, also ganna work out total
  215.         ElseIf lstProStock.SelectedIndex = 6 Then
  216.             lstReciept.Items.Add(ArrProductName(4).ToString() & vbTab & "R" & ArrProductPrice(4).ToString() & vbTab & ArrProductID(4))
  217.             lstCompleteR.Items.Add(ArrProductName(4).ToString() & vbTab & "R" & ArrProductPrice(4).ToString() & vbTab & ArrProductID(4)) 'Adds selected item to lstCompleteR
  218.             intValues = intValues + CInt(txtPrice.Text) 'this line is going to hold values from the text box being added to lstReciept, also ganna work out total
  219.         End If
  220.  
  221.     End Sub
  222.  
  223.     Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
  224.         'Calcs
  225.         intAmountET = intValues
  226.         intSalesTax = CInt(CDec(intValues * VAT))
  227.         intAmountIT = intAmountET + intSalesTax
  228.  
  229.  
  230.         'Display
  231.         lblAmountET.Text = intAmountET.ToString("C2")
  232.         lblVAT.Text = intSalesTax.ToString("C2")
  233.         lblAmountIT.Text = intAmountIT.ToString("C2")
  234.  
  235.  
  236.     End Sub
  237.  
  238.     Private Sub btnChange_Click(sender As Object, e As EventArgs) Handles btnChange.Click
  239.         'defensive stuff
  240.         If IsNumeric(txtPayment.Text) = False Or IsNothing(txtPayment.Text) = True Then
  241.             MessageBox.Show("Please Enter A Numeric Value", "Entery Error")
  242.             Exit Sub
  243.         Else
  244.             intChange = CInt(txtPayment.Text)
  245.         End If
  246.  
  247.         intChangeDue = intAmountIT - intChnage
  248.         lblChange.Text = intChangeDue.ToString("C2")
  249.  
  250.     End Sub
  251. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement