static void Main(string[] args) { string cnStr = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString; // Console.WriteLine(dp); Console.WriteLine(cnStr); InventoryDAL invDAL = new InventoryDAL(); invDAL.OpenConnection(cnStr); try { DeleteCar(invDAL, 44); NewCar c = new NewCar { CarID = 44, Color = "Yellow", Make = "FIAT", PetName = "Bąbel" }; InsertNewCar(invDAL, c); UpdateCarPetName(invDAL, 44, "Bombel"); ListInventoryAsTable(invDAL); ListInventoryAsList(invDAL); LookupPetName(invDAL, 44); DeleteCar(invDAL, 44); } finally { invDAL.CloseConnection(); } Console.ReadLine(); }
private static void ListInventory(InventoryDAL dal) { foreach (NewCar car in dal.GetAllInventoryAsList()) { Console.WriteLine("CarId: {0}, Make: {1}, Color: {2}, PetName: {3}", car.CarId, car.Make, car.Color, car.PetName); } Console.WriteLine(); }
static void DeleteCar(InventoryDAL invDal, int carID) { try { invDal.DeleteCar(carID); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void InsertNewCar(InventoryDAL invDAL) { // First get the user data. int newCarID; string newCarColor, newCarMake, newCarPetName; Console.Write("Enter Car ID: "); newCarID = int.Parse(Console.ReadLine()); Console.Write("Enter Car Color: "); newCarColor = Console.ReadLine(); Console.Write("Enter Car Make: "); newCarMake = Console.ReadLine(); Console.Write("Enter Pet Name: "); newCarPetName = Console.ReadLine(); // Now pass to data access library. // invDAL.InsertAuto(newCarID, newCarColor, newCarMake, newCarPetName); NewCar c = new NewCar { CarID = newCarID, Color = newCarColor, Make = newCarMake, PetName = newCarPetName }; invDAL.InsertAuto(c); }
public void InsertCar(InventoryRecord car) { InventoryDAL d = new InventoryDAL(); d.OpenConnection(ConnString); d.InsertAuto(car.ID, car.Color, car.Make, car.PetName); d.CloseConnection(); }
public void InsertCar(int id, string make, string color, string petname) { InventoryDAL d = new InventoryDAL(); d.OpenConnection(ConnString); d.InsertAuto(id, color, make, petname); d.CloseConnection(); }
public InventoryRecord[] GetInventory() { // First, get the DataTable from the database. InventoryDAL d = new InventoryDAL(); d.OpenConnection(ConnString); DataTable dt = d.GetAllInventoryAsDataTable(); d.CloseConnection(); // Now make an List<T> to contain the records. List<InventoryRecord> records = new List<InventoryRecord>(); // Copy data table into List<> of custom contracts. DataTableReader reader = dt.CreateDataReader(); while (reader.Read()) { InventoryRecord r = new InventoryRecord(); r.ID = (int)reader["CarID"]; r.Color = ((string)reader["Color"]); r.Make = ((string)reader["Make"]); r.PetName = ((string)reader["PetName"]); records.Add(r); } // Transform List<T> to array of InventoryRecord types. return (InventoryRecord[])records.ToArray(); }
static void ListInventoryAsList(InventoryDAL invDal) { Console.WriteLine("************* ListInventoryAsList *********"); List<NewCar> data = invDal.GetAllInventoryAsList(); foreach (NewCar c in data) { Console.WriteLine("CarID: {0}, Make: {1}, Color: {2}, PetName: {3}", c.CarID, c.Make, c.Color, c.PetName); } }
private static void ListInventoryViaList(InventoryDAL invDAL) { List<NewCar> record = invDAL.GetAllInventoryAsList(); foreach (NewCar c in record) { Console.WriteLine("CarID: {0}, Make: {1}, Color: {2}, PetName: {3}", c.CarID, c.Make, c.Color, c.PetName); } }
protected void btnFillGrid_Click(object sender, EventArgs e) { Trace.Write("AAAAAAAAAAAAA", "Button Clicked"); InventoryDAL dal = new InventoryDAL(); dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=AutoLot;Integrated Security=True"); carsGridView.DataSource = dal.GetAllInventoryAsList(); carsGridView.DataBind(); dal.CloseConnection(); }
private static void LookUpPetName(InventoryDAL dal) { Console.WriteLine("Enter Id car to look up:"); int carId = int.Parse(Console.ReadLine()); string petName = dal.LookUpPetName(carId); if (petName.Length > 0) Console.WriteLine("PetName of {0} is {1}", carId, petName); else Console.WriteLine("PetName of {0} is not exists", carId); }
public AutoLotActionManager() { string connectionStr = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString; bool userDone = false; string userCommand = ""; InventoryDAL inventory = new InventoryDAL(); inventory.OpenConnection(connectionStr); try { ShowInstructions(); do { Console.WriteLine("Insert New Instruction:"); userCommand = Console.ReadLine(); Console.WriteLine(); switch(userCommand.ToUpper()) { case "I": InsertNewCar(inventory); break; case "U": UpdateCarPetName( inventory ); break; case "D": DeleteCar( inventory ); break; case "L": ListInventory( inventory ); break; case "S": ShowInstructions(); break; case "P": LookUpPetName( inventory ); break; case "Q": userDone = true; break; default: break; } } while (!userDone); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { inventory.CloseConnection(); } }
protected void btnFillData_Click(object sender, EventArgs e) { Trace.Write("CodeFileTraceInfo!", "Filling the grid!"); InventoryDAL dal = new InventoryDAL(); dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;" + "Initial Catalog=AutoLot;Integrated Security=True"); carsGridView.DataSource = dal.GetAllInventoryAsList(); carsGridView.DataBind(); dal.CloseConnection(); }
private void RefreshGrid() { InventoryDAL dal = new InventoryDAL(); dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;" + "Initial Catalog=AutoLot;Integrated Security=True"); DataTable theCars = dal.GetAllInventoryAsDataTable(); dal.CloseConnection(); carsGridView.DataSource = theCars; carsGridView.DataBind(); }
private static void DeleteCar(InventoryDAL dal) { Console.WriteLine("Enter CarId to delete"); int CarId = int.Parse(Console.ReadLine()); try { dal.DeleteCar(CarId); } catch(Exception ex) { Console.WriteLine(ex.Message); } }
protected void btnAddCar_Click(object sender, EventArgs e) { // Update the Inventory table // and call RefreshGrid(). InventoryDAL dal = new InventoryDAL(); dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;" + "Initial Catalog=AutoLot;Integrated Security=True"); dal.InsertAuto(int.Parse(txtCarID.Text), txtCarColor.Text, txtCarMake.Text, txtCarPetName.Text); dal.CloseConnection(); RefreshGrid(); }
private static void InsertNewCar(InventoryDAL dal) { string newCarMake, newCarColor, newCarPetName; Console.WriteLine("Enter car Make:"); newCarMake = Console.ReadLine(); Console.WriteLine("Enter car Color:"); newCarColor = Console.ReadLine(); Console.WriteLine("Enter car PetName"); newCarPetName = Console.ReadLine(); dal.InsertAuto(newCarColor, newCarMake, newCarPetName); }
private void DeleteCar(InventoryDAL inventory) { Console.Write("Enter ID of Car to delete:"); int id = int.Parse(Console.ReadLine()); try { inventory.DeleteCar(id); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string [] args) { Console.WriteLine("*********The AutoLot Console UI********"); string conStr = ConfigurationManager.ConnectionStrings ["AutoLotSqlProvider"].ConnectionString; bool userDone = false; string userCommand = ""; InventoryDAL dal = new InventoryDAL(); dal.OpenConnection(conStr); try { ShowInstructions(); do { Console.WriteLine("Please, enter command:"); userCommand = Console.ReadLine(); switch(userCommand.ToUpper()) { case "I": InsertNewCar(dal); break; case "U": UpdateCarPetName(dal); break; case "D": DeleteCar(dal); break; case "L": ListInventory(dal); break; case "S": ShowInstructions(); break; case "P": LookUpPetName(dal); break; case "Q": userDone = true; break; default: Console.WriteLine("Bad data! try again"); break; } } while (!userDone); } catch(Exception ex) { Console.WriteLine(ex.Message); } finally { dal.CloseConnection(); } }
public TransactionManagement() { bool throwEx = true; Console.WriteLine("Do you want to throw an exception (Y or N)"); string userAnswer = Console.ReadLine(); if (userAnswer.ToLower() == "n") throwEx = false; InventoryDAL inventory = new InventoryDAL(); inventory.OpenConnection(@"Data Source=(local)\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=AutoLot"); inventory.ProcessCreditRisk(throwEx, 333); }
private static void DeleteCar(InventoryDAL invDAL) { // Get ID of car to delete. Console.Write("EnterID of Car to delete: "); int id = int.Parse(Console.ReadLine()); // Catch referential integrity violation try { invDAL.DeleteCar(id); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void DeleteCar(InventoryDAL invDAL) { // Get ID of car to delete. Console.Write("Enter ID of Car to delete: "); int id = int.Parse(Console.ReadLine()); // Just in case we have a primary key // violation! try { invDAL.DeleteCar(id); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void InsertNewCar(InventoryDAL invDAL) { //Get user data. int newCarID; string newCarColor, newCarMake, newCarPetName; Console.Write("Enter Car ID: "); newCarID = int.Parse(Console.ReadLine()); Console.Write("Enter Car Color: "); newCarColor = Console.ReadLine(); Console.Write("Enter Car Make: "); newCarMake = Console.ReadLine(); Console.Write("Enter Car Pet Name: "); newCarPetName = Console.ReadLine(); // Insert data into access library invDAL.InsertAuto(newCarID, newCarColor, newCarMake, newCarPetName); }
private void UpdateCarPetName(InventoryDAL inventory) { Console.WriteLine("Enter Car ID:"); int id = int.Parse( Console.ReadLine() ); Console.WriteLine( "Enter A New Pet Name:" ); string petName = Console.ReadLine(); inventory.UpdateCarPetName(id, petName); }
private static void UpdateCarPetName(InventoryDAL dal) { int carId; string newCarPetName; Console.WriteLine("Enter car id:"); carId = int.Parse(Console.ReadLine()); Console.WriteLine("Enter new PetName:"); newCarPetName = Console.ReadLine(); dal.UpdateCarPetName(carId, newCarPetName); }
private static void LookupPetName(InventoryDAL invDAL) { Console.Write("Enter ID of Car to Lookup: "); int id = int.Parse(Console.ReadLine()); Console.WriteLine("Petname of {0} is {1}.", id, invDAL.LookUpPetName(id).TrimEnd()); }
private static void ListInventory(InventoryDAL invDAL) { DataTable dt = invDAL.GetAllInventoryAsTable(); DisplayTable(dt); }
private static void UpdateCarPetName(InventoryDAL invDAL) { int carID; string newCarPetName; Console.Write("Enter Car ID: "); carID = int.Parse(Console.ReadLine()); Console.Write("Enter New Pet Name: "); newCarPetName = Console.ReadLine(); invDAL.UpdateCarPetName(carID, newCarPetName); }
private void InsertNewCar(InventoryDAL inventory) { Console.WriteLine("Enter Car ID:"); int id = int.Parse( Console.ReadLine() ); Console.WriteLine("Enter Car Color:"); string color = Console.ReadLine(); Console.WriteLine("Enter Car Make:"); string make = Console.ReadLine(); Console.WriteLine("Enter Pet Name:"); string petName = Console.ReadLine(); inventory.InsertAuto(id, color, make, petName); }
/* This program allows the user to enter the following commands: * I: Inserts a new record into the Inventory table. * U: Updates an existing record in the Inventory table. * D: Deletes an existing record from the Inventory table. * L: Displays the current inventory using a data reader. * S: Shows these options to the user. * P: Looks up pet name from carID. * Q: Quits the program. */ 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 = string.Empty; // Create our Inventory DAL 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": userDone = true; break; default: Console.WriteLine("Bad data! Try again"); break; } } while (!userDone); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { invDAL.CloseConnection(); } }