Customer Window Actions

Introduction

What is the sequence of events that takes place when you find a customer? There are two things that can happen when the user retrieves the customer information.

  1. The user gives an ID
  2. The customer does not know what their ID is

In either case, the user should first check the customers last name. If the id is given, the user clicks on the "Find Info" button to retrieve the users information. In either case, the user asks for the customer's last name and zip code. At this point if the customer information is incorrect, or if the customer doesn't know their id, the user can use the "Find by Name" button to retrieve all customers that share the same last name and zip code as the current customer. A list of all customers with these properties is presented in the summary box. This is done without the customers knowledge.

Next the user checks the first name. If the customers id is unknown at this point this is compared with the customers in the summary box. If there is a unique match, double click on the matching customer and the information for the customer appears in the appropriate boxes. Continue to check information until it is correct or cannot be matched. If it cannot be matched create a new customer.

Some Details

Finding the customer with a given id or all customers whose Last Name and Zip Code match given values is a job for a Query. Query's often are formulated in Structured Query Language (SQL). The search for a customer with a given Id is fairly simple. You want all the information in the Customer table for the customer with the given id. This query is roughly given by:

SELECT * FROM Customers WHERE customerID = idProvidedByProgram

The words in all caps are SQL key words and other words identify the database table and conditions required for this query. The star (*) after SELECT indicates you want all fields for one or more records from the table following the FROM. If there is no WHERE condition, this retrieves the whole table. If there is a WHERE condition, this selects just those records satisfying the condition.

In C++ you formulate a query as a String with the constant part given as constant string and the variable concatenated at the end. In this example the customer id is found in the TEditBox CustomerId. The query you will create is given as:

String query = "SELECT * FROM Customer WHERE customerID = " +CustomerId->Text;

The other request (for all customers that share the same last name and zip code) is more complicated. The information is again retrieved from one table, "Customers", but this time two conditions must be satisfied. A rough version of this query is:

SELECT * FROM Customers WHERE (lastName = the last name supplied) AND (postatCode = zipcode supplied)

Again in our program this should be:

String query = "SELECT * FROM Customers WHERE (lastName = "  + LastName->Text +
			") AND ( postalCode = "  + ZipCode->Text + ")" ;

As you will see when you look at the implementation of this code, Borlands database handlers don't like this bit of SQL, so you will use it in combination with some standard c++ techniques .