public InventoryRecord[] GetInventory() { var d = new InventoryDal(); d.OpenConnection(ConnString); var dt = d.GetAllInventoryAsDataTable(); d.CloseConnection(); var records = new List <InventoryRecord>(); var reader = dt.CreateDataReader(); while (reader.Read()) { var r = new InventoryRecord() { Id = (int)reader["CarId"], Color = ((string)reader["Color"]), Make = ((string)reader["Make"]), PetName = ((string)reader["PetName"]) }; records.Add(r); } return(records.ToArray()); }
public void RemoveThatDoesNotExistInMedia() { var item = new InventoryItem { Type = "Movie", Title = "TESTTITLEFORTESTINGREMOVE", Category = "Action", Condition = "New" }; var inventoryDal = new InventoryDal(); inventoryDal.AddInventoryItem(item); var items = inventoryDal.GetInventoryItems(); var itemBefore = items.OrderByDescending(itemSort => itemSort.InventoryId).First(); inventoryDal.RemoveInventoryItem(itemBefore.InventoryId); this.cleanDataBaseWhenDoesNotExistInMedia(itemBefore.MediaId, itemBefore.InventoryId); var itemsAfterDelete = inventoryDal.GetInventoryItems(); Assert.AreEqual("TESTTITLEFORTESTINGREMOVE", itemBefore.Title); Assert.AreEqual(true, itemBefore.InStock); Assert.AreEqual(false, itemBefore.IsRented); Assert.AreNotEqual("TESTTITLEFORTESTINGREMOVE", itemsAfterDelete.OrderByDescending(itemSort => itemSort.InventoryId).First().Title); }
public void GetInventoryItemsTest() { var inventoryDal = new InventoryDal(); var result = inventoryDal.GetInventoryItems(); Assert.AreEqual(23, result.Count); }
public static void DoBulkCopy() { Console.WriteLine("----------Do Bulk Copy-----------"); var cars = new List <Car> { new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar" }, new Car() { Color = "Red", Make = "Volvo", PetName = "MyCar2" } }; ProcessBulkImport.ExecuteBulkImport(cars, "Inventory"); InventoryDal dal = new InventoryDal(); var list = dal.GetAllInventory(); Console.WriteLine("*************All cars***********"); Console.WriteLine("CarId\tMake\tColor\tPetName"); foreach (var car in list) { Console.WriteLine($"{car.Id}\t{car.Make}\t{car.Color}\t{car.PetName}"); } }
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.ExecuteBulkCopy(cars, "Inventory"); var dal = new InventoryDal(); var list = dal.GetAllInventory(); Console.WriteLine("**** All Cars ****"); Console.WriteLine("CarId\tMake\tColor\tPet Name"); foreach (var item in list) { Console.WriteLine($"{item.CarId}\t{item.Make}\t{item.Color}\t{item.PetName}"); } Console.WriteLine(); }
private static void LookUpPetName(InventoryDal inventory) { Console.Write("Enter Id of Car to look up: "); var id = int.Parse(Console.ReadLine() ?? "0"); Console.WriteLine($"PetName of {id} is {inventory.LookUpPetName(id).TrimEnd()}."); }
public void GetItemDetailSummary() { var inventoryDal = new InventoryDal(); var result = inventoryDal.GetItemHistorySummary(1); Assert.AreEqual(0, result.Count); }
public void AddCar(Inventory newCar) { Cars.Add(newCar); using (InventoryDal inventory = (new InventoryDal())) { inventory.InsertAuto(ModelTransformations.InventoryToCar(newCar)); } }
public void InsertCar(int id, string make, string color, string petName) { var d = new InventoryDal(); d.OpenConnection(ConnString); d.InsertAuto(id, color, make, petName); d.CloseConnection(); }
public void InsertCar(InventoryRecord car) { var d = new InventoryDal(); d.OpenConnection(ConnString); d.InsertAuto(car.Id, car.Color, car.Make, car.PetName); d.CloseConnection(); }
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()); }
private static void ListInventoryViaList(InventoryDal inventory) { var record = inventory.GetAllInventoryAsList(); Console.WriteLine("CarId:\tMake:\tColor:\tPetName:"); foreach (var c in record) { Console.WriteLine($"{c.CarId}\t{c.Make}\t{c.Color}\t{c.PetName}"); } }
private static void UpdateCarPetName(InventoryDal inventory) { Console.Write("Enter Car ID: "); var carId = int.Parse(Console.ReadLine() ?? "0"); Console.Write("Enter New Pet Name: "); var newCarPetName = Console.ReadLine(); inventory.UpdateCarPetName(carId, newCarPetName); }
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); } }
private void RefreshGrid() { var dal = new InventoryDal(); dal.OpenConnection(ConnectionString); DataTable carsDataTable = dal.GetAllInventoryAsDataTable(); dal.CloseConnection(); carsGridView.DataSource = carsDataTable; carsGridView.DataBind(); }
public MainWindowViewModel() { using (InventoryDal cars = (new InventoryDal())) { var allCars = cars.GetAllInventory(); foreach (var car in allCars) { Cars.Add(ModelTransformations.CarToInventory(car)); } } }
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); }
public static void GetAll() { InventoryDal dal = new InventoryDal(); var list = dal.GetAllInventory(); Console.WriteLine("*************All cars***********"); Console.WriteLine("CarId\tMake\tColor\tPetName"); foreach (var car in list) { Console.WriteLine($"{car.Id}\t{car.Make}\t{car.Color}\t{car.PetName}"); } }
public void PersistChanges() { using (InventoryDal inventory = (new InventoryDal())) { foreach (var car in Cars) { if (car.IsChanged) { inventory.UpdateCar(ModelTransformations.InventoryToCar(car)); } } } }
private static void DeleteCar(InventoryDal invDal) { Console.Write("Enter ID of Car to delete: "); int id = int.Parse(Console.ReadLine()); try { invDal.DeleteCar(id); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void DeleteCar(Inventory car) { Cars.Remove(car); using (InventoryDal inventory = (new InventoryDal())) { try { inventory.DeleteCar(car.CarId); } catch (Exception) { throw; } } }
protected void addCarButton_Click(object sender, EventArgs e) { // Обновить таблицу Inventory и вызвать RefreshGrid() var dal = new InventoryDal(); dal.OpenConnection(ConnectionString); dal.InsertAuto(new NewCar() { CarId = int.Parse(carIdTextBox.Text), Color = carIdTextBox.Text, Make = makeTextBox.Text, PetName = petNameTextBox.Text }); dal.CloseConnection(); RefreshGrid(); }
public static void MoveCustomer() { Console.WriteLine("Simple Transaction Example.."); bool throwEx = true; Console.Write("Do you want to throw an exception?(Y or N): "); var userAnswer = Console.ReadLine(); if (userAnswer?.ToLower() == "n") { throwEx = false; } var dal = new InventoryDal(); dal.ProcessCreditRisk(throwEx, 1); }
public static void DalTest() { var dal = new InventoryDal(); var list = dal.GetAllInventory(); Console.WriteLine("***** All Cars ******"); Console.WriteLine("CarId\tMake\tColor\tPet Name"); foreach (var item in list) { Console.WriteLine($"{item.CarId}\t{item.Make}\t{item.Color}\t{item.PetName}"); } Console.WriteLine(); var car = dal.GetCar(list.OrderBy(x => x.Color).Select(x => x.CarId).First()); Console.WriteLine("***** First Car by Color ********"); Console.WriteLine("CarId\tMake\tColor\tPet Name"); Console.WriteLine($"{car.CarId}\t{car.Make}\t{car.Color}\t{car.PetName}"); try { dal.DeleteCar(5); Console.WriteLine("Car deleted"); } catch (Exception ex) { Console.WriteLine($"An exception occured: {ex.Message}"); } dal.InsertAuto(new Car { Color = "Blue", Make = "Pilot", PetName = "TownMonster" }); list = dal.GetAllInventory(); var newCar = list.First(x => x.PetName == "TownMonster"); Console.WriteLine("***** New Car ********"); Console.WriteLine("CarId\tMake\tColor\tPet Name"); Console.WriteLine($"{newCar.CarId}\t{newCar.Make}\t{newCar.Color}\t{newCar.PetName}"); dal.DeleteCar(newCar.CarId); var petName = dal.LookUpPetName(car.CarId); Console.WriteLine($"Car pet name: {petName}"); Console.WriteLine("Press Enter to continue..."); Console.ReadLine(); }
public static void MoveCustomer() { Console.WriteLine("****** Simple Transaction Example *********"); bool throwEx = true; Console.Write("Do you want to throw Exception (y or n): ?"); var userAnswer = Console.ReadLine(); if (userAnswer?.ToLower() == "n") { throwEx = false; } var dal = new InventoryDal(); dal.ProcessCreditRisk(throwEx, 1); Console.WriteLine("Check CreditRisk table for result"); Console.ReadLine(); }
protected void fillGridButton_Click(object sender, EventArgs e) { InventoryDal dal = null; try { dal = new InventoryDal(); dal.OpenConnection(AutoLotConnectionString); autoLotGridView.DataSource = dal.GetAllInventoryAsList(); autoLotGridView.DataBind(); Trace.Write("CodeFileTraceInfo!", "Filling the grid!"); // Протоколируем } finally { if (dal != null) { dal.CloseConnection(); } } }
public void AddItemThatExistsInMedia() { var item = new InventoryItem { Type = "Movie", Title = "Superman", Category = "Action", Condition = "New" }; var inventoryDal = new InventoryDal(); inventoryDal.AddInventoryItem(item); var items = inventoryDal.GetInventoryItems(); this.cleanDataBaseWhenAlreadyExistsInMedia(items.OrderByDescending(itemSort => itemSort.InventoryId).First().InventoryId); var itemsAfterDelete = inventoryDal.GetInventoryItems(); Assert.AreEqual("Superman", items.OrderByDescending(itemSort => itemSort.InventoryId).First().Title); Assert.AreNotEqual("Superman", itemsAfterDelete.OrderByDescending(itemSort => itemSort.InventoryId).First().Title); }
private static void Main(string[] args) { Console.WriteLine("**** Simple Transaction Example *****\n"); var throwEx = true; Console.Write("Do you want to throw an exception (Y or N): "); var userAnswer = Console.ReadLine(); if (userAnswer?.ToLower() == "n") { throwEx = false; } var inventory = new InventoryDal(); inventory.OpenConnection(@"Data Source=SEGOTW10393726;Initial Catalog=AutoLot;Integrated Security=SSPI"); inventory.ProcessCreditRisk(throwEx, 7); Console.WriteLine("Check CreditRisk table for results"); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Simple Transaction Example *****\n"); bool throwEx = true; string userAnswer = string.Empty; Console.Write("Do you want to throw an exception (Y or N): "); userAnswer = Console.ReadLine(); if (userAnswer != null && userAnswer.ToLower() == "n") { throwEx = false; } InventoryDal dal = new InventoryDal(); dal.OpenConnection(@"Data Source=Hi-Tech-PC;Initial Catalog=AutoLot;Integrated Security=True;Pooling=False"); dal.ProcessCreditRisk(333, throwEx); Console.WriteLine("Check CreditRisk table for results"); Console.ReadLine(); }
public void AddItemThatDoesNotExistInMedia() { var item = new InventoryItem { Type = "Movie", Title = "TESTTITLEFORTESTING", Category = "Action", Condition = "New" }; var inventoryDal = new InventoryDal(); inventoryDal.AddInventoryItem(item); var items = inventoryDal.GetInventoryItems(); var itemAdded = items.OrderByDescending(itemSort => itemSort.InventoryId).First(); this.cleanDataBaseWhenDoesNotExistInMedia(itemAdded.MediaId, itemAdded.InventoryId); var itemsAfterDelete = inventoryDal.GetInventoryItems(); Assert.AreEqual("TESTTITLEFORTESTING", items.OrderByDescending(itemSort => itemSort.InventoryId).First().Title); Assert.AreNotEqual("TESTTITLEFORTESTING", itemsAfterDelete.OrderByDescending(itemSort => itemSort.InventoryId).First().Title); }