'Code to save data
Dim csvFile As String = My.Application.Info.DirectoryPath & "\HoseData.csv"
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, True)
'If My.Computer.FileSystem.FileExists(csvFile) Then
'outFile.WriteLine("job number, sales order number, date, requested by, serial number, hose type, hose size, fitting 1, fitting 2, qty, oal, cut off, offset, crimp 1, crimp 2, cleaned, pigged", False)
' End If
outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """" & "," & ComboBox1.Text & "," & TextBox3.Text & "," & ListBox2.Text & "," & ListBox3.Text & "," & TextBox11.Text & "," & TextBox12.Text & "," & NumericUpDown1.TextAlign & "," & TextBox4.Text & "," & TextBox5.Text & "," & TextBox6.Text & "," & TextBox9.Text & "," & TextBox10.Text & "," & ListBox4.Text & "," & ListBox5.Text)
MessageBox.Show("INPUT WAS SAVED")
Dim butt As System.Windows.Forms.Button = DirectCast(sender, System.Windows.Forms.Button)
'butt.Enabled = False
'butt.Visible = False
outFile.Close()
TextBox1.Text = ""
TextBox2.Text = ""
DateTimePicker1.Text = ""
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0 ' The first item has index 0 '
End If
TextBox3.Text = ""
ListBox2.ClearSelected()
ListBox3.ClearSelected()
TextBox11.Text = ""
TextBox12.Text = ""
NumericUpDown1.Value = 0
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
ListBox4.ClearSelected()
ListBox5.ClearSelected()
Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))
'code to load data into datagridview1
Dim TextFieldParser1 As New Microsoft.VisualBasic.FileIO.TextFieldParser("HoseData.csv")
TextFieldParser1.Delimiters = New String() {","}
While Not TextFieldParser1.EndOfData
Dim Row1 As String() = TextFieldParser1.ReadFields()
If DataGridView1.Columns.Count = 0 AndAlso Row1.Count > 0 Then
Dim i As Integer
For i = 0 To Row1.Count - 1
DataGridView1.Columns.Add("Column" & i + 1, "Column" & i + 1)
Next
End If
DataGridView1.Rows.Add(Row1)
End While
Button1.Enabled = False
Dim csvFile As String = My.Application.Info.DirectoryPath & "\HoseData.csv"
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, True)
'If My.Computer.FileSystem.FileExists(csvFile) Then
'outFile.WriteLine("job number, sales order number, date, requested by, serial number, hose type, hose size, fitting 1, fitting 2, qty, oal, cut off, offset, crimp 1, crimp 2, cleaned, pigged", False)
' End If
outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """" & "," & ComboBox1.Text & "," & TextBox3.Text & "," & ListBox2.Text & "," & ListBox3.Text & "," & TextBox11.Text & "," & TextBox12.Text & "," & NumericUpDown1.TextAlign & "," & TextBox4.Text & "," & TextBox5.Text & "," & TextBox6.Text & "," & TextBox9.Text & "," & TextBox10.Text & "," & ListBox4.Text & "," & ListBox5.Text)
MessageBox.Show("INPUT WAS SAVED")
Dim butt As System.Windows.Forms.Button = DirectCast(sender, System.Windows.Forms.Button)
'butt.Enabled = False
'butt.Visible = False
outFile.Close()
TextBox1.Text = ""
TextBox2.Text = ""
DateTimePicker1.Text = ""
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0 ' The first item has index 0 '
End If
TextBox3.Text = ""
ListBox2.ClearSelected()
ListBox3.ClearSelected()
TextBox11.Text = ""
TextBox12.Text = ""
NumericUpDown1.Value = 0
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
ListBox4.ClearSelected()
ListBox5.ClearSelected()
Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))
'code to load data into datagridview1
Dim TextFieldParser1 As New Microsoft.VisualBasic.FileIO.TextFieldParser("HoseData.csv")
TextFieldParser1.Delimiters = New String() {","}
While Not TextFieldParser1.EndOfData
Dim Row1 As String() = TextFieldParser1.ReadFields()
If DataGridView1.Columns.Count = 0 AndAlso Row1.Count > 0 Then
Dim i As Integer
For i = 0 To Row1.Count - 1
DataGridView1.Columns.Add("Column" & i + 1, "Column" & i + 1)
Next
End If
DataGridView1.Rows.Add(Row1)
End While
Button1.Enabled = False