I need help like the title says. The program needs to work the same it currently is. The program is a simple database program and i need to know how to make the second form have the same functionality as the first one. ill supply the code from the first form below as a reference.
Thanks for any support
Thanks for any support
Code:
Imports System.IO
'COXY'
'2013'
'ITSS Sac'
Public Structure Stock ''This is an indicator of the type of each data''
Public make As String
Public model As String
Public price As String
Public location As String
Public stock As Integer
Public reorder As Integer
Public memo As String
Public warrenty As String
End Structure
Public Class Form1
Dim data As New List(Of Stock)
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''load input
End Sub
Private Sub lstStock_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstStock.SelectedIndexChanged
Dim tempStock As Stock = data.Item(lstStock.SelectedIndex) ''This section represents the stock list and how the text in each of the labels are diplayed in the labels as they appeared in the list''
lblMake.Text = tempStock.make
lblModel.Text = tempStock.model
lblPrice.Text = tempStock.price
lblLocation.Text = tempStock.location
lblStock.Text = tempStock.stock
lblReorder.Text = tempStock.reorder
lblmemo.Text = tempStock.memo
lblwarrenty.text = tempStock.warrenty
If tempStock.stock < tempStock.reorder Then ''This code determines that if the stock number is lower than the reorder number a reorder label is displayed''
lblRed.Visible = True
Else
lblRed.Visible = False
End If
End Sub
Private Sub txtPrice_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPrice.KeyPress
If e.KeyChar <> ControlChars.Back Then
e.Handled = Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = ".")
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim tempStock As Stock ''This states that when the add button is clicked the text in the textboxes are saved to the list as data''
If txtMake.Text <> "" And txtModel.Text <> "" And txtPrice.Text <> "" And txtLocation.Text <> "" And txtStock.Text <> "" And txtReorder.Text <> "" Then
tempStock.make = txtMake.Text
tempStock.model = txtModel.Text
tempStock.price = txtPrice.Text
tempStock.location = txtLocation.Text
tempStock.stock = txtStock.Text
tempStock.reorder = txtReorder.Text
tempStock.memo = txtMemo.Text
tempStock.warrenty = txtwarrenty.text
data.Add(tempStock)
lstStock.Items.Add(tempStock.make)
Else
MsgBox("Input required in each field")
End If
End Sub
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
OpenFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*" ''This states that when the load button is clicked a show dialog appears with two possible filters of text files or all files to load from a location''
OpenFileDialog1.ShowDialog()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*" ''This states that when the save butto is clicked a show dialog appears with two posible filters of text files or all files to save at a location''
SaveFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Try
Dim sr As StreamReader = New StreamReader(OpenFileDialog1.FileName) ''This indicates that when opening a database with the load button, once the file is selected the text in the file is read and put in the appropriate fields and list''
Dim count As Integer = Integer.Parse(sr.ReadLine())
data.Clear()
lstStock.Items.Clear()
For i = 0 To count
Dim tempStock As Stock
tempStock.make = sr.ReadLine()
tempStock.model = sr.ReadLine()
tempStock.price = sr.ReadLine()
tempStock.location = sr.ReadLine()
tempStock.stock = Integer.Parse(sr.ReadLine())
tempStock.reorder = Integer.Parse(sr.ReadLine())
tempStock.memo = sr.ReadLine()
tempStock.warrenty = sr.ReadLine()
data.Add(tempStock)
lstStock.Items.Add(tempStock.make)
Next
sr.Close()
Catch Ex As Exception
Console.WriteLine("The file could not be read:") ''This code is an error trap for if there is an attempt to read an invalid or corrupted file''
Console.WriteLine(Ex.Message)
End Try
End Sub
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Dim filetosaveas As String = SaveFileDialog1.FileName
Dim save As New System.IO.StreamWriter(filetosaveas) ''This code indicates that when a database is saved with the save button a text file is created with the appropriate title and the data is written as lines of text in the file for future reading''
save.WriteLine(data.Count)
For i = 0 To (data.Count - 1)
Dim tempStock As Stock = data.Item(i)
save.WriteLine(tempStock.make)
save.WriteLine(tempStock.model)
save.WriteLine(tempStock.price)
save.WriteLine(tempStock.location)
save.WriteLine(tempStock.stock)
save.WriteLine(tempStock.reorder)
save.WriteLine(tempStock.memo)
save.WriteLine(tempStock.warrenty)
Next
save.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lstStock.Items.Clear() ''This refers to when the clear button is clicked which will make all fields empty and remove all data stored in the list''
data.Clear()
lblMake.Text = ""
lblModel.Text = ""
lblPrice.Text = ""
lblLocation.Text = ""
lblStock.Text = ""
lblReorder.Text = ""
lblmemo.Text = ""
lblwarrenty.Text = ""
lblwarrenty.Text = ""
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Dim currentdate As Date ''This indicates that when the form is closed a text file will be created with the current date month and year for a title and all the data will be saved in the text files as written lines''
Dim saveString As String
currentdate = Date.Now
saveString = "Stock_" + currentdate.Day.ToString() + "." + currentdate.Month.ToString() + "." + currentdate.Year.ToString() + ".txt"
Dim save As New System.IO.StreamWriter(saveString)
save.WriteLine(data.Count)
For i = 0 To (data.Count - 1)
Dim tempStock As Stock = data.Item(i)
save.WriteLine(tempStock.make)
save.WriteLine(tempStock.model)
save.WriteLine(tempStock.price)
save.WriteLine(tempStock.location)
save.WriteLine(tempStock.stock)
save.WriteLine(tempStock.reorder)
save.WriteLine(tempStock.memo)
save.WriteLine(tempStock.warrenty)
Next
save.Close()
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Search.Show()
End Sub
Private Sub lblmem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Quit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Quit.Click
End ''This indicates that when the close button is clicked, the program will end and be terminated''
End Sub
Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
txtMake.Clear()
txtModel.Clear()
txtLocation.Clear()
txtPrice.Clear()
txtReorder.Clear()
txtStock.Clear()
txtMemo.Clear()
txtwarrenty.Clear()
End Sub
Private Sub Horizontal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Horizontal.Click
Form3.Show()
Me.Hide()
End Sub
End Class