コード例 #1
0
    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());
    }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void GetInventoryItemsTest()
        {
            var inventoryDal = new InventoryDal();
            var result       = inventoryDal.GetInventoryItems();

            Assert.AreEqual(23, result.Count);
        }
コード例 #4
0
        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}");
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: HarrowinG/Autolot_ADO_EF
        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();
        }
コード例 #6
0
        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()}.");
        }
コード例 #7
0
        public void GetItemDetailSummary()
        {
            var inventoryDal = new InventoryDal();

            var result = inventoryDal.GetItemHistorySummary(1);

            Assert.AreEqual(0, result.Count);
        }
コード例 #8
0
 public void AddCar(Inventory newCar)
 {
     Cars.Add(newCar);
     using (InventoryDal inventory = (new InventoryDal()))
     {
         inventory.InsertAuto(ModelTransformations.InventoryToCar(newCar));
     }
 }
コード例 #9
0
    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();
    }
コード例 #10
0
    public void InsertCar(InventoryRecord car)
    {
        var d = new InventoryDal();

        d.OpenConnection(ConnString);
        d.InsertAuto(car.Id, car.Color, car.Make, car.PetName);
        d.CloseConnection();
    }
コード例 #11
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
        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());
        }
コード例 #12
0
        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}");
            }
        }
コード例 #13
0
        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);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
        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);
            }
        }
コード例 #15
0
    private void RefreshGrid()
    {
        var dal = new InventoryDal();

        dal.OpenConnection(ConnectionString);
        DataTable carsDataTable = dal.GetAllInventoryAsDataTable();

        dal.CloseConnection();
        carsGridView.DataSource = carsDataTable;
        carsGridView.DataBind();
    }
コード例 #16
0
 public MainWindowViewModel()
 {
     using (InventoryDal cars = (new InventoryDal()))
     {
         var allCars = cars.GetAllInventory();
         foreach (var car in allCars)
         {
             Cars.Add(ModelTransformations.CarToInventory(car));
         }
     }
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
        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);
        }
コード例 #18
0
        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}");
            }
        }
コード例 #19
0
 public void PersistChanges()
 {
     using (InventoryDal inventory = (new InventoryDal()))
     {
         foreach (var car in Cars)
         {
             if (car.IsChanged)
             {
                 inventory.UpdateCar(ModelTransformations.InventoryToCar(car));
             }
         }
     }
 }
コード例 #20
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
        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);
            }
        }
コード例 #21
0
 private void DeleteCar(Inventory car)
 {
     Cars.Remove(car);
     using (InventoryDal inventory = (new InventoryDal()))
     {
         try
         {
             inventory.DeleteCar(car.CarId);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
コード例 #22
0
    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();
    }
コード例 #23
0
        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);
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: HarrowinG/Autolot_ADO_EF
        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();
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: HarrowinG/Autolot_ADO_EF
        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();
        }
コード例 #26
0
    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();
            }
        }
    }
コード例 #27
0
        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);
        }
コード例 #28
0
        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();
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
        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();
        }
コード例 #30
0
        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);
        }