예제 #1
0
        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();
        }
예제 #2
0
        static void Main(string[] args)
        {
            InventoryDAL 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.GetCarById(list.OrderBy(x => x.Color)
                                     .Select(x => x.CarId)
                                     .First());

            Console.WriteLine("**** First by color*****");
            Console.WriteLine("CarId\tMake\tColor\tPet Name");
            Console.WriteLine($"{car.CarId}\t{car.Make}\t{car.Color}\t{car.PetName}");

            try
            {
                dal.DeleteeAuto(dal.GetCarById(5));
                Console.WriteLine("Car deleted!");
            }catch (Exception ex)
            {
                Console.WriteLine($"An exception occured: {ex.Message}");
            }

            dal.InsertAuto(new Car {
                Make = "Pilot", Color = "Blue", PetName = "TowMonster"
            });

            list = dal.GetAllInventory();

            var newCar = list.First(x => x.PetName.Trim(' ') == "TowMonster");

            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.DeleteeAuto(newCar);

            var petName = dal.GetCarById(newCar.CarId);

            Console.WriteLine("**** New car *****");
            Console.WriteLine($"Car pet name is {petName}!");
            Console.WriteLine("Press space for continue...");

            MoveCustomer(dal);
            DoBulkCopy();
            Console.ReadLine();
        }
예제 #3
0
        static void Main(string[] args)
        {
            InventoryDAL dal  = new InventoryDAL();
            var          list = dal.GetAllInventory();

            WriteLine("***** Get All Inventory *****");
            DisplayCars(list);
            WriteLine();
            Car car = dal.GetCar(list.OrderBy(x => x.Color).Select(x => x.CarId).First()); // ..OrderBy is a Linq thing

            WriteLine("*** First Car By Color***");
            WriteLine($"{car.CarId}\t{car.Make}\t{car.Color}\t{car.PetName}");

            try
            {
                dal.DeleteCar(5);
                WriteLine("Car 5 deleted.");
            }
            catch (Exception ex)
            {
                WriteLine($"An exception occurred: {ex.Message}");
            }

            dal.InsertAuto(new Car {
                Color = "Blue", Make = "Pilot", PetName = "TowMonster"
            });
            list = dal.GetAllInventory();
            Car newCar = list.First(x => x.PetName == "TowMonster");

            WriteLine("*** New Car ***");
            WriteLine("CarId\tMake\tColor\tPetName");
            WriteLine($"{newCar.CarId}\t{newCar.Make}\t{newCar.Color}\t{newCar.PetName}");
            dal.DeleteCar(newCar.CarId);
            string petName = dal.LookupPetName(car.CarId);

            WriteLine("*** New Car ***");
            WriteLine($"Car pet name: {petName}");
            WriteLine();

            WriteLine("\n***** All Cars Currently in DB *****");
            list = dal.GetAllInventory();
            DisplayCars(list);

            // WriteLine("\n*** Move Customer Example Using Transactions ***");
            // MoveCustomer();

            // DoBulkCopy example
            DoBulkCopy();

            WriteLine("\n\nPress <Enter> to Continue. . .");
            ReadLine();
        }
        static void Main(string[] args)
        {
            InventoryDAL dal  = new InventoryDAL();
            var          list = dal.GetAllInventory();

            WriteLine(" ***************** All Cars ***************** ");
            WriteLine("CarId\tMake\tColor\tPet Name");

            foreach (var item in list)
            {
                WriteLine($"{item.CarId}\t{item.Make}\t{item.Color}\t{item.PetName}\n");
            }
            var car = dal.GetCar(list.OrderBy(x => x.Color).Select(x => x.CarId).First());

            WriteLine(" ***************** First Car By Color *************** ");
            WriteLine("CarId\tMake\tColor\tPet Name");
            WriteLine($"{car.CarId}\t{car.Make}\t{car.Color}\t{car.PetName}");

            try
            {
                dal.DeleteCar(5);
                WriteLine("Car Deleted.");
            }

            catch (Exception ex)
            {
                WriteLine($"An exception occured: {ex.Message}");
            }

            dal.InsertAuto(new Car {
                Color   = "Blue", Make = "Pilot",
                PetName = "TowMonster"
            });
            list = dal.GetAllInventory();

            var newCar = list.First(x => x.PetName == "TowMonster");

            WriteLine(" ***************** New Car ********************* ");
            WriteLine("CarId\tMake\tColor\tPet Name");
            WriteLine($"{newCar.CarId}\t{newCar.Make}\t{newCar.Color}\t{newCar.PetName}");
            dal.DeleteCar(newCar.CarId);

            /*
             * following lines is for store procedure ignore
             * var petName = dal.LookUpPetName(car.CarId);
             * WriteLine(" ***************** New Car ******************** ");
             * WriteLine($"Car pet name: {petName}");
             */
            Write("Press enter to continue...");
            ReadLine();
        }
예제 #5
0
        static void Main(string[] args)
        {
            InventoryDAL dal  = new InventoryDAL();
            var          list = dal.GetAllInventory();

            Console.WriteLine(" ********** All Cars **********1");
            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();
            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 occurred: {ex.Message}");
            }
            dal.InsertAuto(new Car {
                Color = "Blue", Make = "Pilot", PetName = "TowMonster"
            });
            list = dal.GetAllInventory();
            var newCar = list.First(x => x.PetName == "TowMonster");

            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.Id);
            var petName = DllNotFoundException.LookUpPetName(car.CarId);

            Console.WriteLine(" ********** New Car ********** ");
            Console.WriteLine($"Car pet name; {petName}");
            Console.Write("Press enter to continue...");
            Console.ReadLine();
        }
예제 #6
0
파일: UnitTest1.cs 프로젝트: dakazia/apress
        public void ShouldGetInventory()
        {
            var sut  = new InventoryDAL();
            var cars = sut.GetAllInventory();

            Assert.Equal(7, cars.Count);
        }
예제 #7
0
    public InventoryRecord[] GetInventory()
    {
        // First, get the DataTable from the database.
        InventoryDAL d = new InventoryDAL();

        d.OpenConnection(ConnString);
        DataTable dt = d.GetAllInventory();

        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"]).Trim();
            r.Make    = ((string)reader["Make"]).Trim();
            r.PetName = ((string)reader["PetName"]).Trim();
            records.Add(r);
        }
        // Transform List<T> to array of InventoryRecord types.
        return((InventoryRecord[])records.ToArray());
    }
예제 #8
0
        public static void DoBulkCopy()
        {
            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");
            var dal  = new InventoryDAL();
            var list = dal.GetAllInventory();

            Console.WriteLine("CarId\tMake\tColor\tPet Name");
            foreach (var car in list)
            {
                Console.WriteLine($"{car.CarId}\t{car.Make}\t{car.Color}\t{car.PetName}");
            }
        }
예제 #9
0
        // -------------------------------------------------------------------------
        #endregion


        #region Executing Bulk Copies with ADO.NET
        // ------------------------ Executing Bulk Copies with ADO.NET -------------------------
        // In cases where you need to load lots of records into the database, the methods shown so far would be rather
        // inefficient.SQL Server has a feature called bulk copy that is designed specifically for this scenario, and it’s wrapped
        // up in ADO.NET with the SqlBulkCopy class.

        public static void TestBulkCopyWithCustomDataReader()
        {
            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.CarId}\t{itm.Make}\t{itm.Color}\t{itm.PetName}");
            }
            Console.WriteLine();
        }
예제 #10
0
        public static void AutoLotClient()
        {
            var dal  = new InventoryDAL();
            var list = dal.GetAllInventory();

            Console.WriteLine("***** Show All Cars *****\n");
            Console.WriteLine("CarId\tMake\tColor\tPet Name");
            foreach (var car in list)
            {
                Console.WriteLine($"{car.CarId}\t{car.Make}\t{car.Color}\t{car.PetName}");
            }
            Console.WriteLine();

            Console.WriteLine("***** First Car By Color *****\n");
            var firstCarByColor = dal.GetCar(list.OrderBy(c => c.Color).Select(c => c.CarId).First());

            Console.WriteLine("CarId\tMake\tColor\tPet Name");
            Console.WriteLine($"{firstCarByColor.CarId}\t{firstCarByColor.Make}\t" +
                              $"{firstCarByColor.Color}\t{firstCarByColor.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 = "TowMonster"
            });
            list = dal.GetAllInventory();
            var newCar = list.First(c => c.PetName == "TowMonster");

            Console.WriteLine("***** New Car *****\n");
            Console.WriteLine("CarId\tMake\tColor\tPet Name");
            Console.WriteLine($"{newCar.CarId}\t{newCar.Make}\t" +
                              $"{newCar.Color}\t{newCar.PetName}");

            var petName = dal.LookUpPetName(firstCarByColor.CarId);

            Console.WriteLine($"Car pet name (using SP): {petName}");
        }
예제 #11
0
        public static void GetFirstCarByName(InventoryDAL dal)
        {
            List <Car> cars     = dal.GetAllInventory();
            Car        firstCar = dal.GetCar(cars.OrderBy(x => x.PetName).Select(x => x.CarId).First());

            Console.WriteLine("******* First Car By Name *******");
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", firstCar.CarId, firstCar.Make, firstCar.Color, firstCar.PetName);
            Console.WriteLine();
        }
예제 #12
0
    protected void btnFillData_Click(object sender, EventArgs e)
    {
        Trace.Write("My Category", "Filling the grid!");
        InventoryDAL dal = new InventoryDAL();

        dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;" +
                           "Initial Catalog=AutoLot;Integrated Security=True");
        carsGridView.DataSource = dal.GetAllInventory();
        carsGridView.DataBind();
        dal.CloseConnection();
    }
예제 #13
0
        public static void DisplayInventory(InventoryDAL dal)
        {
            List <Car> cars = dal.GetAllInventory();

            Console.WriteLine("CarId\tMake\tColor\tPet Name");
            foreach (Car car in cars)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}", car.CarId, car.Make, car.Color, car.PetName);
            }
            Console.WriteLine();
        }
    private void RefreshGrid()
    {
        InventoryDAL dal = new InventoryDAL();

        dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=AutoLot;Integrated Security=True");
        DataTable theCars = dal.GetAllInventory();

        dal.CloseConnection();

        carsGridView.DataSource = theCars;
        carsGridView.DataBind();
    }
예제 #15
0
        static void Main(string[] args)
        {
            MoveCustomer();
            DoBulkCopy();
            InventoryDAL dal  = new InventoryDAL();
            var          list = dal.GetAllInventory();

            Console.WriteLine("CarId \t Make \t Color \t Pet Name");
            foreach (var itm in list)
            {
                Console.WriteLine($" {itm.Carld} \t {itm.Make} \t{itm.Color} \t{itm.PetName} ");
            }
            Console.WriteLine();
            //var car = dal.GetCar(list.OrderBy(x => x.Color).Select(x => x.Carld).First());
            //Console.WriteLine(" **************First Car By Color * ************* ");
            //Console.WriteLine("CarId \t Make \t Color \t Pet Name");
            //Console.WriteLine($"{ car.Carld} \t { car.Make} \t { car.Color} \t { car.PetName}");
            //try
            //{
            //    dal.DeleteCar(5);
            //    Console.WriteLine("Car deleted.");
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine($"An exception occurred: {ex.Message}");
            //    // Возникло исключение
            //}
            //dal.InsertAuto(new Car
            //{
            //    Color = "Blue",
            //    Make ="Pilot", PetName = "TowMonster"}) ;
            //list = dal.GetAllInventory();
            //var newCar = list.First(x => x.PetName == "TowMonster");
            //Console.WriteLine(" ************** New Car ************** ");
            //Console.WriteLine("CarId \t Make \t Color \t Pet Name");
            //Console.WriteLine($"{newCar.Carld} \t {newCar.Make} \t {newCar.Color} \t { newCar.PetName}");
            //dal.DeleteCar(newCar.Carld);
            //var petName = dal.LookUpPetName(car.Carld);
            //Console.WriteLine(" ************** New Car ************** ");
            //Console.WriteLine($"Car pet name: {petName}");
            //Console.Write("Press enter to continue...");
            //Console.ReadLine();
        }
예제 #16
0
        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 = "Blue", Make = "Honda", PetName = "MyCar2"
                },
                new Car()
                {
                    Color = "Blue", Make = "Honda", PetName = "MyCar3"
                },
                new Car()
                {
                    Color = "Blue", Make = "Honda", PetName = "MyCar4"
                }
            };

            ProcessBulkImport.ExecuteBulkImport(cars, "Inventory");

            InventoryDAL dal = new InventoryDAL();

            var list = dal.GetAllInventory();

            Console.WriteLine("CarID\tColor\tMake\tPetName");
            foreach (var item in list)
            {
                Console.WriteLine($"{item.CarId}\t{item.Color}\t{item.Make}\t{item.PetName}");
            }

            Console.WriteLine();
        }
예제 #17
0
        public static void DoBulkCopy()
        {
            WriteLine("******* Do Bulk Copy *******");
            var cars = new List <Car>
            {
                new Car()
                {
                    Color = "Blue", Make = "Honda", PetName = "BulkCar1"
                },
                new Car()
                {
                    Color = "Red", Make = "Subaru", PetName = "BulkCar2"
                },
                new Car()
                {
                    Color = "White", Make = "VW", PetName = "BulkCar3"
                },
                new Car()
                {
                    Color = "Yellow", Make = "Toyota", PetName = "BlukCar4"
                }
            };

            ProcessBulkImport.ExecuteBulkImport(cars, "Inventory");
            Console.WriteLine("Bulk copy completed.");
            InventoryDAL dal  = new InventoryDAL();
            var          list = dal.GetAllInventory();

            Console.WriteLine(" ************** Display 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}");
            }
            WriteLine();
        }
예제 #18
0
 public DataTable GetAllInventory(int InventoryID)
 {
     return(inventoryDAL.GetAllInventory(InventoryID));
 }
        private static void ListInventory(InventoryDAL invDAL)
        {
            DataTable dt = invDAL.GetAllInventory();

            DisplayTable(dt);
        }