예제 #1
0
        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();
        }
예제 #2
0
        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();
        }
예제 #3
0
        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();
        }
예제 #5
0
        /// <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());
        }
예제 #6
0
        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);
        }
예제 #7
0
        private static void ListInventory(InventoryDAL invDAL)
        {
            // Get the list of inventory.
            DataTable dt = invDAL.GetAllInventoryAsDataTable();

            DisplayTable(dt);
        }
예제 #8
0
        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}")));
        }
예제 #9
0
        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);
        }
예제 #10
0
        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());
        }
예제 #11
0
        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()}.");
        }
예제 #12
0
        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()}.");
        }
예제 #13
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 = "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();
        }
예제 #14
0
        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();
        }
예제 #15
0
        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());
        }
예제 #16
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();
        }
예제 #17
0
        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()}.");
        }
예제 #18
0
        private static void LookUpPetName(InventoryDAL invDAL)
        {
            // Получение идентификатора автомобиля.
            Console.Write("Введите ID автомобиля: ");
            int id = int.Parse(Console.ReadLine());

            Console.WriteLine("Имя {0} - {1}.", id, invDAL.LookUpPetName(id));
        }
예제 #19
0
        /// <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);
        }
예제 #20
0
        /// <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);
        }
예제 #21
0
        /// <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);
        }
예제 #22
0
        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()}.");
        }
예제 #23
0
        /// <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()}.");
        }
예제 #24
0
    public void InsertCar(InventoryRecord car)
    {
        InventoryDAL d = new InventoryDAL();

        d.OpenConnection(ConnString);
        d.InsertAuto(car.ID, car.Color, car.Make, car.PetName);
        d.CloseConnection();
    }
예제 #25
0
        private static void Listlnventory(InventoryDAL invDAL)
        {
            // Вывод автомобилей в наличии.
            DataTable dt = invDAL.GetAllInventoryAsDataTable();

            // Передача DataTable вспомогательной функции для вывода.
            DisplayTable(dt);
        }
예제 #26
0
        private static void DelCar(InventoryDAL Dal)
        {
            Console.WriteLine("Введите айди машина для удаления");
            int DeleteId = int.Parse(Console.ReadLine());

            Dal.DeleteCar(DeleteId);
            ShowAllCars(Dal);
        }
예제 #27
0
    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();
    }
예제 #28
0
        static void ListInventory(InventoryDAL invDAL)
        {
            // получить список автомобилей на складе
            DataTable dt = invDAL.GetAllInventoryAsDataTable();

            // передать DataTable вспомогательной функции для отображения
            DisplayTable(dt);
        }
예제 #29
0
        private static void ListInventory(InventoryDAL invDAL)
        {
            // Get the list of inventory.
            DataTable dt = invDAL.GetAllInventoryAsDataTable();

            // Pass DataTable to helper function to display.
            DisplayTable(dt);
        }
예제 #30
0
        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());
        }