How to search to edit and delete

shak

Member
Joined
Apr 10, 2011
Messages
10
Programming Experience
Beginner
This is my code so far. When i add the customer i want it to give the customer a unique identifier, something like a quote reference. So when I go on the edit or delete menu's i can type it in and that customer comes up and then I can edit the field i require etc.

Sorry for the layout of the code I couldn't do the tag thingy. (New to the forums ;) )

Module Module1

Structure QuickCars
<VBFixedString(4)> Public Title As String
<VBFixedString(15)> Public ForeName As String
<VBFixedString(15)> Public Surname As String
<VBFixedString(8)> Public DOB As String
<VBFixedString(11)> Public TelephoneNumber As String
<VBFixedString(30)> Public Email As String
<VBFixedString(10)> Public Address1 As String
<VBFixedString(10)> Public Address2 As String
<VBFixedString(10)> Public City As String
<VBFixedString(7)> Public PostCode As String
<VBFixedString(10)> Public CarManufacturer As String
<VBFixedString(7)> Public Registration As String
<VBFixedString(10)> Public CarModel As String
<VBFixedString(4)> Public Deposit As String
Dim deleted As Boolean
End Structure


'Global variables available to all sub routines
Dim CustomerQuote As QuickCars
Dim CustomerDetails As String
Dim NumberOfRecords As Integer
Dim FileName As String
Dim Index As Integer
Dim Age As String
Dim FirstName As String
Dim reply As Integer
Dim InterestRates As String
Dim loan, period As Single
Dim quote As Decimal


Sub main()
Dim conInfo As ConsoleKeyInfo
Dim strInputString As String = ""
Dim strPassword As String = "a" '"shakcreatedme"
Dim blnLoggedIn As Boolean = False

Do While Not blnLoggedIn 'outer login control loop
strInputString = "" 'be sure to reset the entered string each time
Console.WriteLine("Please enter the password, or type 'exit' to exit:")

Do 'inner character entry loop
conInfo = Console.ReadKey(True)
If conInfo.Key = ConsoleKey.Enter Then
Exit Do
Else
strInputString &= conInfo.KeyChar
Console.Write("*"c)
End If
Loop


If Trim(strInputString.ToString) = "exit" Then 'provide a way to exit
Exit Sub
End If

If Trim(strInputString) = strPassword Then 'does password match variable?
Console.WriteLine(vbCrLf & vbCrLf & "Login Successful" & vbCrLf)
blnLoggedIn = True
Else
Console.Beep()
Console.WriteLine(vbCrLf & "Login Failed. Please try again.")
End If
Loop

'logged in
Console.ReadKey()


Console.ForegroundColor = ConsoleColor.Green

Console.WriteLine("Access gained. This system is strictly for staff use ONLY!")
Console.ReadLine()
FileName = CurDir() & "\QuickCars.dat"
FileOpen(1, FileName, OpenMode.Random, , , Len(CustomerQuote))

Console.Title = "Main Menu"


'Changes the background colour to white

Console.BackgroundColor() = ConsoleColor.White
Console.Clear()

'Changes the font colour to black
Console.ForegroundColor() = ConsoleColor.Black

Do
Console.Clear()


Console.WriteLine()
Console.WriteLine(" Welcome to QuickQuotes")
Console.WriteLine(" ______________________")
Console.WriteLine()
Console.WriteLine()
Console.WriteLine(" Press 1 to Add new Customer:")
Console.WriteLine(" *****************************")
Console.WriteLine()
Console.WriteLine(" Press 2 to Edit existing customer:")
Console.WriteLine(" ***********************************")
Console.WriteLine()
Console.WriteLine(" Press 3 to Delete Customer:")
Console.WriteLine(" ***************************")
Console.WriteLine()
Console.WriteLine(" Press 4 to View all Customers:")
Console.WriteLine(" *********************************")
Console.WriteLine()
Console.WriteLine(" Press 5 to Enter Administration:")
Console.WriteLine(" ********************************")
Console.WriteLine()
Console.WriteLine(" Press 6 to Exit:")
Console.WriteLine(" ****************")
Console.WriteLine()
Console.WriteLine()



Console.Write("Enter the option you'd like:")
reply = Console.ReadLine
Console.WriteLine()
Console.WriteLine()
Console.WriteLine()
Console.WriteLine()
Console.WriteLine()
Console.WriteLine()

Select Case reply
' A case construct that allows the user to navigate around the menu structure above
Case Is = 1
AddCustomer()
Case Is = 2
EditCustomer()
Case Is = 3
DeleteCustomer()
Case Is = 4
DisplayAll()
Case Is = 5
Administration()
End Select
Loop While reply <> 6
End Sub

Sub AddCustomer()
'Variable part of calculate function

Console.Clear()
Console.Title = "Add New Customer"
'If reply = 1 Then
NumberOfRecords = LOF(1) / Len(CustomerQuote)

'Input boxes pop up for the used to enter information
CustomerQuote.Title = InputBox(" Title:")
CustomerQuote.ForeName = InputBox(" Fore name:")
CustomerQuote.Surname = InputBox(" Surname:")
CustomerQuote.DOB = InputBox(" Date of Birth (DD/MM/YY) :")
CustomerQuote.TelephoneNumber = InputBox("Contact Number :")
CustomerQuote.Email = InputBox("Email Address:")
CustomerQuote.Address1 = InputBox("House number and streename:")
CustomerQuote.Address2 = InputBox("Area:")
CustomerQuote.City = InputBox("City:")
CustomerQuote.PostCode = InputBox("Postcode:")

MsgBox("Please enter your car details:")

CustomerQuote.CarManufacturer = InputBox("Enter the car manufacturer")
CustomerQuote.CarModel = InputBox("Enter the model:")
CustomerQuote.Registration = InputBox("Enter the registration:")
CustomerQuote.Deposit = InputBox("Enter the deposit amount:")



'Part of the calculate function
GetLoanDetails()
Quote = calculateQuote(loan, period, InterestRates)

Console.WriteLine("This will be your monthly payment : " & Quote)

Console.ReadLine()
'End If
CustomerQuote.deleted = False
FilePut(1, CustomerQuote, NumberOfRecords + 1)
Console.ReadLine()
End Sub


Sub GetLoanDetails()
Dim months As Integer
Console.WriteLine("Enter the loan amount you require:")
loan = Console.ReadLine
'this is where we should display the table of different payment amounts depending on
'the term selected and interest rate...
Console.WriteLine(vbCrLf & "Payment Schedules:" & vbCrLf)
Console.WriteLine("Interest Rate:" & ControlChars.Tab & "|" & ControlChars.Tab & "8%" & ControlChars.Tab & "|" & ControlChars.Tab & "10%" & ControlChars.Tab & "|")
Console.WriteLine(ControlChars.Tab & "----------------------------------------------")
For months = 12 To 36 Step 6
Console.Write(months & " Month Term:" & ControlChars.Tab & "|" & calculateQuote(loan, months, 8) & ControlChars.Tab)
If calculateQuote(loan, months, 8).ToString.Length < 7 Then Console.Write(ControlChars.Tab)
Console.Write("|" & calculateQuote(loan, months, 10) & ControlChars.Tab)
If calculateQuote(loan, months, 10).ToString.Length < 7 Then Console.Write(ControlChars.Tab)
Console.Write("|" & vbCrLf)
Next

Console.WriteLine(vbCrLf & vbCrLf)
Console.WriteLine("Do you require the loan for 12,18,24,30 or 36 months? : ")
period = Console.ReadLine
Console.WriteLine("Which interest percentage rate would you like? 8 or 10?")
InterestRates = Console.ReadLine
End Sub


' This function will calculate the quote.
Function calculateQuote(ByVal loan, ByVal period, ByVal interest) As Double

interest /= 100

Dim dblMonthlyRate As Double = Double.Parse(interest) / 12
quote = loan * dblMonthlyRate
quote = quote / (1 - Math.Pow((1 + interest / 12), -period))

quote = FormatNumber(quote, 2, , , True)
Return quote
End Function


Sub DisplayAll()
Console.Clear()
Console.Title = " Displaying All Customers"
NumberOfRecords = LOF(1) / Len(CustomerQuote)
For Index = 1 To NumberOfRecords
FileGet(1, CustomerQuote, Index)

If CustomerQuote.deleted = False Then
'displays the following headings
Console.WriteLine()
Console.WriteLine()
Console.WriteLine()
Console.WriteLine(CustomerQuote.Title)
Console.WriteLine(CustomerQuote.ForeName)
Console.WriteLine(CustomerQuote.Surname)
Console.WriteLine(CustomerQuote.DOB)
Console.WriteLine(CustomerQuote.TelephoneNumber)
Console.WriteLine(CustomerQuote.Email)
Console.WriteLine(CustomerQuote.Address1)
Console.WriteLine(CustomerQuote.Address2)
Console.WriteLine(CustomerQuote.City)
Console.WriteLine(CustomerQuote.PostCode)
Console.WriteLine(CustomerQuote.CarManufacturer)
Console.WriteLine(CustomerQuote.CarModel)
Console.WriteLine(CustomerQuote.Registration)
Console.WriteLine(CustomerQuote.Deposit)
Console.ReadLine()
End If
Next
Console.WriteLine("Press any key to return to main menu")
Console.ReadKey()
End Sub

Sub DeleteCustomer()



Console.Clear()
Console.Title = "Delete Customer Details"
Index = Console.ReadLine
NumberOfRecords = LOF(1) / Len(CustomerQuote)
FileGet(1, CustomerQuote, Index)
CustomerQuote.deleted = True ' deleted is true so the record will be deleted off the file
CustomerQuote.Title = ""
CustomerQuote.ForeName = ""
CustomerQuote.Surname = ""
CustomerQuote.DOB = ""
CustomerQuote.TelephoneNumber = ""
CustomerQuote.Email = ""
CustomerQuote.Address1 = ""
CustomerQuote.Address2 = ""
CustomerQuote.City = ""
CustomerQuote.PostCode = ""

FilePut(1, CustomerQuote, Index)
End Sub

Sub EditCustomer()
Console.Clear()
Console.Title = "Edit Existing Customer Details"
'need to prompt for which customer to edit here, then load the appropriate record for editing

Index = Console.ReadLine


NumberOfRecords = LOF(1) / Len(CustomerQuote)
FileGet(1, CustomerQuote, Index)
CustomerQuote.deleted = False 'similar to "delete" but will fetch the record and allow used to modify the record before placing it back
CustomerQuote.Title = ""
CustomerQuote.Title = InputBox("Title:")
CustomerQuote.ForeName = ""
CustomerQuote.ForeName = InputBox(" First name:")
CustomerQuote.Surname = ""
CustomerQuote.Surname = InputBox(" Surname:")
CustomerQuote.DOB = ""
CustomerQuote.DOB = InputBox(" Date of Birth (DD/MM/YY) :")
CustomerQuote.TelephoneNumber = ""
CustomerQuote.TelephoneNumber = InputBox("Contact Number :")
CustomerQuote.Email = ""
CustomerQuote.Email = InputBox("Email Address:")
CustomerQuote.Address1 = ""
CustomerQuote.Address1 = InputBox("Street name")
CustomerQuote.Address2 = ""
CustomerQuote.Address2 = InputBox("Area:")
CustomerQuote.City = ""
CustomerQuote.City = InputBox("City:")
CustomerQuote.PostCode = ""
CustomerQuote.PostCode = InputBox("Postcode:")
FilePut(1, CustomerQuote, Index)
End Sub

Sub Administration()

End Sub

End Module
 
Top Bottom