Hi, this is what I have to do...
1. read customer details from Customer file (e.g. record would be "John,Smith,0422123456,Yes")
2. display list of customers in list box
3. add new customer to the list box (via text boxes - "FirstName,Surname,Mobile,VIP")
4. save updated customer list back to Customer file
5. calculate Total cost of each order (form has Product combobox with options Ink and Toner, and a Quantity textbox) (Total cost would be Quantity * Product Price - Discount (5%)
6. write order to Order file (would probably have FirstName,Surname,Mobile,Product,Quantity,TotalCost
Can someone please help me....
1. save the list box (with original customers and new customers) back to file (ALL customers)
2. calculate cost of each order (if my code doesn't look right)
3. write it back to an Order file like so ---> John,Smith,0422123456,Ink(product),1 (quantity),5.50(total)
So far this is what I've got...
1. read customer details from Customer file (e.g. record would be "John,Smith,0422123456,Yes")
2. display list of customers in list box
3. add new customer to the list box (via text boxes - "FirstName,Surname,Mobile,VIP")
4. save updated customer list back to Customer file
5. calculate Total cost of each order (form has Product combobox with options Ink and Toner, and a Quantity textbox) (Total cost would be Quantity * Product Price - Discount (5%)
6. write order to Order file (would probably have FirstName,Surname,Mobile,Product,Quantity,TotalCost
Can someone please help me....
1. save the list box (with original customers and new customers) back to file (ALL customers)
2. calculate cost of each order (if my code doesn't look right)
3. write it back to an Order file like so ---> John,Smith,0422123456,Ink(product),1 (quantity),5.50(total)
So far this is what I've got...
Code:
Public Class frmMain
Dim W As IO.StreamWriter
Private Sub cmdLoad_Click(sender As Object, e As EventArgs) Handles cmdLoad.Click
'Declear file location and string'
Dim CustomerFile As New System.IO.StreamReader("C:\Users\xxxxx.xxxxx\Documents\Customers.txt")
Dim CustomerLine As String
'Read first line of data from file
CustomerLine = CustomerFile.ReadLine
'Continue until file is empty
While CustomerLine Is Nothing = False
'Add line to Orders listbox
lstCustomers.Items.Add(CustomerLine)
'Read next line from file
CustomerLine = CustomerFile.ReadLine
End While
'Close Order File
CustomerFile.Close()
CustomerFile.Dispose()
End Sub
Private Sub cmdSelect_Click(sender As Object, e As EventArgs) Handles cmdSelect.Click
'declare customers selected in to storage.
Dim SelectCustomers As String
'read line of data'
SelectCustomers = lstCustomers.SelectedItem
'split line in to array values and declare new variable'
Dim DataItem() As String = Split(SelectCustomers, ",")
'asign data items to different split data'
txtFirstName.Text = DataItem(0)
txtSurname.Text = DataItem(1)
txtMobile.Text = DataItem(2)
cboDiscount.Text = DataItem(3)
End Sub
Private Sub cmdOrder_Click(sender As Object, e As EventArgs) Handles cmdOrder.Click
'declare variables for storage'
Dim Quantity As Integer
Dim Discount As String
Dim Product As String
Dim Price As Decimal
Dim Cost As Decimal
Dim DiscountAmount As Decimal
Dim TotalCost As Decimal
'determine the text box that is linked to variable'
Product = cboProduct.Text
Quantity = txtQuantity.Text
Discount = cboDiscount.Text
'set amounts for products'
Select Case Product
Case Is = "Ink"
Price = 5.5
Case Is = "Toner"
Price = 8.5
Case Is = "Super Ink"
Price = 15.5
Case Is = "Super Toner"
Price = 18.5
End Select
'calculate cost'
Cost = Price * Quantity
'calculate discount'
If Discount = "Yes" Then
DiscountAmount = Price * 0.05
Else
DiscountAmount = 0
End If
'calculate final cost'
TotalCost = Cost - DiscountAmount
End Sub
Private Sub cmdAdd_Click(sender As Object, e As EventArgs) Handles cmdAdd.Click
Dim UpdateCustomerFile As New System.IO.StreamWriter("C:\Users\xxxxx.xxxxx\Documents\Customers.txt")
Dim UpdateRecord As String
UpdateRecord = txtFirstName.Text + "," + txtSurname.Text + "," + txtMobile.Text + "," + cboDiscount.Text
UpdateCustomerFile.WriteLine(UpdateRecord)
UpdateCustomerFile.Close()
My.Computer.FileSystem.OpenTextFileReader("C:\Users\xxxxx.xxxxxDocuments\Customers.txt")
Dim A() As String = IO.File.ReadAllLines("C:\Users\xxxxx.xxxxx\Documents\Customers.txt")
For Each content As String In A
lstCustomers.Items.Add(content)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'clear text boxes'
txtFirstName.Text = ""
txtSurname.Text = ""
txtMobile.Text = ""
cboDiscount.Text = ""
cboProduct.Text = ""
txtQuantity.Text = ""
End Sub
Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click
Dim I As Integer
W = New IO.StreamWriter("C:\Users\xxxxx.xxxxx\Documents\Customers.txt")
For I = 0 To lstCustomers.Items.Count - 1
W.WriteLine(lstCustomers.Items.Item(I))
Next
W.Close()
End Sub
End Class