CHAPTER 21 ADO.NET PART I: THE CONNECTED LAYER
•
P: Looks up pet name from carID.
•
Q: Quits the program.
Each possible option is handled by a unique static method within the Program class. The next
snippet shows the complete implementation of Main(). Notice that each method invoked from the
do/while loop (with the exception of the ShowInstructions() method) takes an InventoryDAL object as its
sole parameter.
static void Main(string[] args)
{
Console.WriteLine("***** The AutoLot Console UI *****\n");
// Get connection string from App.config.
string cnStr =
ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString;
bool userDone = false;
string userCommand = "";
// Create our InventoryDAL object.
InventoryDAL invDAL = new InventoryDAL();
invDAL.OpenConnection(cnStr);
// Keep asking for input until user presses the Q key.
try
{
ShowInstructions();
do
{
Console.Write("\nPlease enter your command: ");
userCommand = Console.ReadLine();
Console.WriteLine();
switch (userCommand.ToUpper())
{
case "I":
InsertNewCar(invDAL);
break;
case "U":
UpdateCarPetName(invDAL);
break;
case "D":
DeleteCar(invDAL);
break;
case "L":
ListInventory(invDAL);
break;
case "S":
ShowInstructions();
break;
case "P":
LookUpPetName(invDAL);
break;
case "Q":
848