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 InsertCar(InventoryRecord car)
    {
        var d = new InventoryDal();

        d.OpenConnection(ConnString);
        d.InsertAuto(car.Id, car.Color, car.Make, car.PetName);
        d.CloseConnection();
    }
    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();
    }
    private void RefreshGrid()
    {
        var dal = new InventoryDal();

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

        dal.CloseConnection();
        carsGridView.DataSource = carsDataTable;
        carsGridView.DataBind();
    }
    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();
    }
    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();
            }
        }
    }
        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();
        }
Beispiel #8
0
        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();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The AutoLot Console UI *****\n");

            // Берем строку подключения из конфигурации.
            string cnStr =
                ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString;
            bool userDone = false;

            InventoryDal inventoryDal = new InventoryDal();

            inventoryDal.OpenConnection(cnStr);

            #region Get user input
            try
            {
                ShowInstructions();
                do
                {
                    Console.Write("\nPlease enter your command: ");
                    string userCommand = Console.ReadLine();
                    Console.WriteLine();
                    if (userCommand != null)
                    {
                        switch (userCommand.ToUpper())
                        {
                        case "I":
                            InsertNewCar(inventoryDal);
                            break;

                        case "U":
                            UpdateCarPetName(inventoryDal);
                            break;

                        case "D":
                            DeleteCar(inventoryDal);
                            break;

                        case "L":
                            // ListInventory(invDAL);
                            ListInventoryViaList(inventoryDal);
                            break;

                        case "S":
                            ShowInstructions();
                            break;

                        case "P":
                            LookUpPetName(inventoryDal);
                            break;

                        case "Q":
                            userDone = true;
                            break;

                        default:
                            Console.WriteLine("Bad data!  Try again");
                            break;
                        }
                    }
                }while (!userDone);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                inventoryDal.CloseConnection();
            }
            #endregion
        }
Beispiel #10
0
        private static void Main(string[] args)
        {
            Console.WriteLine("***** The AutoLot Console UI *****\n");

            var connectionString = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ToString();
            var userDone         = false;

            var inventoryDal = new InventoryDal();

            inventoryDal.OpenConnection(connectionString);

            try
            {
                ShowInstructions();
                do
                {
                    Console.Write("\nPlease enter your command: ");

                    var userCommand = Console.ReadLine();
                    Console.WriteLine();

                    switch (userCommand?.ToUpper() ?? "")
                    {
                    case "I":
                        InsertNewCar(inventoryDal);
                        break;

                    case "U":
                        UpdateCarPetName(inventoryDal);
                        break;

                    case "D":
                        DeleteCar(inventoryDal);
                        break;

                    case "L":
                        ListInventory(inventoryDal);
                        break;

                    case "S":
                        ShowInstructions();
                        break;

                    case "P":
                        LookUpPetName(inventoryDal);
                        break;

                    case "Q":
                        userDone = true;
                        break;

                    default:
                        Console.WriteLine("Bad data! Try again");
                        break;
                    }
                } while (!userDone);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                inventoryDal.CloseConnection();
            }
        }