我正在做一个使用文本文件来点餐和查看餐厅订单的项目。我希望使用计时器自动删除一个小时后保存订单详细信息的文本文件。我其余的代码都可以正常工作,只是自动计时器不起作用。
Public Class frmOrderSummary
Dim strOrderName As String = ""
Private Sub frmSummary_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'calling display order sub
Call DisplayOrder()
timerOrder.Start()
Dim FileToDelete As String
timerOrder.Start()
FileToDelete = (txtOrderNum.Text & ".txt")
If System.IO.File.Exists(FileToDelete) = True And timerOrder.Interval = 400 Then
System.IO.File.Delete(FileToDelete)
MessageBox.Show("File Deleted")
End If
End Sub
Private Sub lstOrders_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstOrders.SelectedIndexChanged
'items selected from listbox will appear in textbox below
strOrderName = lstOrders.Text
txtOrderNum.Text = lstOrders.Text
End Sub
Sub DisplayOrder()
'adding items from OrderNums.txt to listbox
lstOrders.Items.Clear()
If IO.File.Exists("OrderNums.txt") Then
Dim query = From OrderNum In IO.File.ReadAllLines("OrderNums.txt")
Order By OrderNum Ascending
Select OrderNum
For Each OrderNum In query
lstOrders.Items.Add(OrderNum)
Next
End If
End Sub
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
'using textfile to assign stored data to specific textboxes using arrays
If (txtOrderNum.Text & ".txt" <> "") And IO.File.Exists(txtOrderNum.Text & ".txt") Then
Dim query = From line In IO.File.ReadAllLines(txtOrderNum.Text & ".txt")
Dim name = query(0).Split(","c)(0)
Dim surname = query(0).Split(",")(1)
Dim address = query(0).Split(","c)(2)
Dim phonenum = query(0).Split(","c)(3)
Dim method = query(0).Split(","c)(4)
txtName.Text = name
txtSurname.Text = surname
txtAddress.Text = address
txtPhoneNum.Text = phonenum
txtMethod.Text = method
Dim cellvalue(20) As String
Dim OrderID As String
OrderID = txtOrderNum.Text
Dim lines = IO.File.ReadAllLines(OrderID & ".txt")
For index = 1 To lines.Length - 1
Dim cells = lines(index).Split(","c)
dgvOutput.Rows.Add(cells)
Next
End If
End Sub