static void Main() { WriteLine("***** Simple Transaction Example *****"); ForegroundColor = ConsoleColor.Yellow; bool throwEx = true; Write("Do you want to throw an exception (Y or N): "); var userAnswer = ReadLine(); if (userAnswer?.ToLower() == "n") { throwEx = false; } var dal = new InventoryDAL(); string connectString = @"Data Source=(local);Integrated Security=SSPI;Initial Catalog=AutoLot"; dal.OpenConnection(connectString); dal.ProcessCreditRisk(throwEx, 6); WriteLine($"Check CreditRisk table for results (ThrowEx: <{throwEx}>)"); ResetColor(); }
static void Main(string[] args) { InventoryDAL Dal = new InventoryDAL(); ShowAllCars(Dal); Console.WriteLine("1- добавить машину\n2-удалить машину"); int result = Convert.ToInt32(Console.ReadLine()); switch (result) { case (1): { InsertNewCar(); break; } case (2): { DelCar(Dal); break; } } Dal.Update(1, "GolfStream"); Console.ReadLine(); }
private static void LookUpPetName(InventoryDAL invDAL) { Console.WriteLine("Enter ID of Car to look up"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("Petname of {0} is {1}", id, invDAL.LookUpPetName(id).TrimEnd()); }
static void Main(string[] args) { Console.WriteLine("*********Simple transcation example **********"); bool throwEx = true; string userAnswer = string.Empty; Console.WriteLine("Do you want to throw an exception (Y or N):"); userAnswer = Console.ReadLine(); if (userAnswer.ToUpper() == "N") { throwEx = false; } InventoryDAL dal = new InventoryDAL(); string cnStr = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString; dal.OpenConnection(cnStr); dal.ProcessCreditRisk(throwEx, 333); Console.WriteLine("Check CreditRisk table for result."); Console.ReadLine(); }
/// <summary> /// 查询Pet Name /// </summary> /// <param name="dal"></param> static void LookUpPetName(InventoryDAL dal) { Console.WriteLine("请输入要查找的CarID:"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("PetName of {0} is {1}", id, dal.LookUpPetName(id).TrimEnd()); }
private static void InsertNewCar(InventoryDAL invDAL) { // Сначала получить пользовательские данные 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(); // Теперь передать информацию библиотеке доступа к данным NewCar car = new NewCar { CarID = newCarID, Color = newCarColor, Make = newCarMake, PetName = newCarPetName }; invDAL.InsertAuto(car); }
private static void ListInventory(InventoryDAL invDAL) { // Get the list of inventory. DataTable dt = invDAL.GetAllInventoryAsDataTable(); DisplayTable(dt); }
private static void ListInventoryViaList(InventoryDAL inventoryDal) { var carList = inventoryDal.GetAllInventoryAsList(); WriteLine("CarId:\tMake:\tColor:\tPetName:"); carList.ForEach((c => WriteLine($"{c.CarId}\t{c.Make}\t{c.Color}\t{c.PetName}"))); }
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. NewCar c = new NewCar { CarID = newCarID, Color = newCarColor, Make = newCarMake, PetName = newCarPetName }; invDAL.InsertAuto(c); }
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 a List<T> to contain the records. List <InventoryRecord> records = new List <InventoryRecord>(); // Copy the 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()); }
private static void LookUpPetName(InventoryDAL inventoryDal) { Write("Enter car id: "); var carId = int.Parse(ReadLine() ?? "0"); WriteLine($"Petname of {carId} is {inventoryDal.LookUpPetName(carId).TrimEnd()}."); }
private static void LookUpPetName(InventoryDAL invDAL) { Write("Enter ID of Car to look up:"); int id = int.Parse(ReadLine() ?? "0"); WriteLine($"PetName of {id} is {invDAL.LookUpPetName(id).TrimEnd()}."); }
public static void DoBulkCopy() { Console.WriteLine(" ************** Do Bulk Copy ************** "); var cars = new List <Car> { new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar1" }, new Car() { Color = "Red", Make = "Volvo", PetName = "MyCar2" }, new Car() { Color = "White", Make = "VW", PetName = "MyCar3" }, new Car() { Color = "Yellow", Make = "Toyota", PetName = "MyCar4" } }; ProcessBulkImport.ExecuteBulkImport(cars, "Inventory"); InventoryDAL dal = new InventoryDAL(); var list = dal.GetAllInventory(); Console.WriteLine(" ************** All Cars ************** "); Console.WriteLine("CarId\tMake\tColor\tPet Name"); foreach (var itm in list) { Console.WriteLine($"{itm.Id}\t{itm.Make}\t{itm.Color}\t{itm.PetName}"); } Console.WriteLine(); }
static void Main(string[] args) { Console.WriteLine("***** Simple Transaction Example *****\n"); // A simple way to allow the transaction to succeed or not. bool throwEx = true; string userAnswer = string.Empty; Console.Write("Do you want to throw an exception (Y or N): "); userAnswer = Console.ReadLine(); if (userAnswer.ToLower() == "n") { throwEx = false; } InventoryDAL dal = new InventoryDAL(); dal.OpenConnection(@"Data Source=(localdb)\v11.0;Initial Catalog=AutoLot;Integrated Security=True"); // Process customer 333. dal.ProcessCreditRisk(throwEx, 333); Console.WriteLine("Check CreditRisk table for results"); Console.ReadLine(); }
public InventoryRecord[] GetInventory() { InventoryDAL d = new InventoryDAL(); d.OpenConnection(ConnString); DataTable table = d.GetAllInventoryAsDataTable(); d.CloseConnection(); List <InventoryRecord> records = new List <InventoryRecord>(); DataTableReader reader = table.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); } return((InventoryRecord[])records.ToArray()); }
static void Main(string[] args) { InventoryDAL dal = new InventoryDAL(); var list = dal.GetAllInventory(); // list all cars in the inventory Console.WriteLine((new string('*', 15)) + " All Cars " + (new string('*', 15))); Console.WriteLine("CarId\tMake\tColor\tPet Name"); foreach (var itm in list) { Console.WriteLine($"{itm.CarId}\t{itm.Make}\t{itm.Color}\t{itm.PetName}"); } Console.WriteLine(); // list the first car in order of color var car = dal.GetCar(list.OrderBy(x => x.Color).Select(x => x.CarId).First()); Console.WriteLine((new string('*', 15)) + " First Car By Color " + (new string('*', 15))); Console.WriteLine("CarId\tMake\tColor\tPet Name"); Console.WriteLine($"{car.CarId}\t{car.Make}\t{car.Color}\t{car.PetName}"); Console.WriteLine(); // try/catch logic to delete a car in inventory try { dal.DeleteCar(5); Console.WriteLine("Car deleted"); } catch (Exception ex) { Console.WriteLine($"An exception occurred: {ex.Message}"); } Console.WriteLine(); // insert a new car object into the inventory dal.InsertAuto(new Car { Color = "Blue", Make = "Pilot", PetName = "TowMonster" }); list = dal.GetAllInventory(); var newCar = list.First(x => x.PetName == "TowMonster"); Console.WriteLine((new string('*', 15)) + " New Car " + (new string('*', 15))); Console.WriteLine("CarId\tMake\tColor\tPet Name"); Console.WriteLine($"{newCar.CarId}\t{newCar.Make}\t{newCar.Color}\t{newCar.PetName}"); dal.DeleteCar(newCar.CarId); Console.WriteLine(); // list the inventory again Console.WriteLine((new string('*', 15)) + " All Cars After an Insertion & a Deletion " + (new string('*', 15))); Console.WriteLine("CarId\tMake\tColor\tPet Name"); foreach (var itm in list) { Console.WriteLine($"{itm.CarId}\t{itm.Make}\t{itm.Color}\t{itm.PetName}"); } Console.WriteLine(); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); }
private static void LookUpPetName(InventoryDAL invDAL) { // Get ID of car to look up Console.Write("Enter ID of the Car to look up: "); int id = int.Parse(Console.ReadLine() ?? "0"); Console.WriteLine($"Petname of {id} is {invDAL.LookUpPetName(id).TrimEnd()}."); }
private static void LookUpPetName(InventoryDAL invDAL) { // Получение идентификатора автомобиля. Console.Write("Введите ID автомобиля: "); int id = int.Parse(Console.ReadLine()); Console.WriteLine("Имя {0} - {1}.", id, invDAL.LookUpPetName(id)); }
/// <summary> /// List credit risks via a datatable /// </summary> /// <param name="dataAccessLayer"></param> private static void ListCreditRisks(InventoryDAL dataAccessLayer) { // Get the list of credit risks using a view DataTable dataTable = dataAccessLayer.GetDataTable("CreditRisks"); // Pass DataTable to helper function to display. DisplayTable(dataTable); }
/// <summary> /// List inventory using datatable /// </summary> /// <param name="dataAccessLayer"></param> private static void ListInventory(InventoryDAL dataAccessLayer) { // Get the list of inventory. DataTable inventoryDataTable = dataAccessLayer.GetAllInventoryAsDataTable(); // Pass DataTable to helper function to display. DisplayTable(inventoryDataTable); }
/// <summary> /// List customer orders via a datatable /// </summary> /// <param name="dataAccessLayer"></param> private static void ListCustomersOrders(InventoryDAL dataAccessLayer) { // Get the list of customers orders using a view DataTable customerOrdersDataTable = dataAccessLayer.GetDataTable("CustomerOrders"); // Pass DataTable to helper function to display. DisplayTable(customerOrdersDataTable); }
private static void LookUpPetName(InventoryDAL invDal) { //Get id of the car to look up.. Write("Enter ID of car to look up: "); int id = int.Parse(ReadLine() ?? "0"); Write($"Petname of {id} is {invDal.LookUpPetName(id).TrimEnd()}."); }
/// <summary> /// Prompt the user for a CarId, and do a lookup of the name /// </summary> /// <param name="inventoryDAL"></param> private static void LookUpName(InventoryDAL inventoryDAL) { // Get ID of car to look up. Write("Enter ID of Car to look up: "); int carId = int.Parse(ReadLine() ?? "0"); WriteLine($"Car Name of CarId {carId} is {inventoryDAL.LookUpName(carId).TrimEnd()}."); }
public void InsertCar(InventoryRecord car) { InventoryDAL d = new InventoryDAL(); d.OpenConnection(ConnString); d.InsertAuto(car.ID, car.Color, car.Make, car.PetName); d.CloseConnection(); }
private static void Listlnventory(InventoryDAL invDAL) { // Вывод автомобилей в наличии. DataTable dt = invDAL.GetAllInventoryAsDataTable(); // Передача DataTable вспомогательной функции для вывода. DisplayTable(dt); }
private static void DelCar(InventoryDAL Dal) { Console.WriteLine("Введите айди машина для удаления"); int DeleteId = int.Parse(Console.ReadLine()); Dal.DeleteCar(DeleteId); ShowAllCars(Dal); }
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(); }
static void ListInventory(InventoryDAL invDAL) { // получить список автомобилей на складе DataTable dt = invDAL.GetAllInventoryAsDataTable(); // передать DataTable вспомогательной функции для отображения DisplayTable(dt); }
private static void ListInventory(InventoryDAL invDAL) { // Get the list of inventory. DataTable dt = invDAL.GetAllInventoryAsDataTable(); // Pass DataTable to helper function to display. DisplayTable(dt); }
private static void LookUpPetName(InventoryDAL invDAL) { // Получить идентификатор автомобиля для поиска дружественного имени Console.Write("Enter ID of car to look up: "); int id = int.Parse(Console.ReadLine()); Console.WriteLine("PetName of {0} is {1}", id, invDAL.LookUpPetName(id).TrimEnd()); }