Example #1
0
        static void Main(string[] args) {
            string cnStr = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString;
            //  Console.WriteLine(dp);
            Console.WriteLine(cnStr);


            InventoryDAL invDAL = new InventoryDAL();
            invDAL.OpenConnection(cnStr);
            try {
                DeleteCar(invDAL, 44);
                NewCar c = new NewCar { CarID = 44, Color = "Yellow", Make = "FIAT", PetName = "BÄ…bel" };
                InsertNewCar(invDAL, c);
                UpdateCarPetName(invDAL, 44, "Bombel");

                ListInventoryAsTable(invDAL);
                ListInventoryAsList(invDAL);
                LookupPetName(invDAL, 44);
                DeleteCar(invDAL, 44);
                
            } finally {
                invDAL.CloseConnection();
            }

            Console.ReadLine();
        }
Example #2
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();
 }
Example #3
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();
 }
Example #4
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 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"]);
          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();
    }
    protected void btnFillGrid_Click(object sender, EventArgs e) {
        Trace.Write("AAAAAAAAAAAAA", "Button Clicked");
        InventoryDAL dal = new InventoryDAL();
        dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=AutoLot;Integrated Security=True");
        carsGridView.DataSource = dal.GetAllInventoryAsList();
        carsGridView.DataBind();
        dal.CloseConnection();

    }
        public AutoLotActionManager()
        {
            string connectionStr = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString;
             bool userDone = false;
             string userCommand = "";

             InventoryDAL inventory = new InventoryDAL();
             inventory.OpenConnection(connectionStr);

             try
             {
            ShowInstructions();
            do
            {
               Console.WriteLine("Insert New Instruction:");
               userCommand = Console.ReadLine();
               Console.WriteLine();

               switch(userCommand.ToUpper())
               {
                  case "I":
                     InsertNewCar(inventory);
                     break;
                  case "U":
                     UpdateCarPetName( inventory );
                     break;
                  case "D":
                     DeleteCar( inventory );
                     break;
                  case "L":
                     ListInventory( inventory );
                     break;
                  case "S":
                     ShowInstructions();
                     break;
                  case "P":
                     LookUpPetName( inventory );
                     break;
                  case "Q":
                     userDone = true;
                     break;
                  default:
                     break;
               }
            } while (!userDone);
             }
             catch (Exception ex)
             {
            Console.WriteLine(ex.Message);
             }
             finally
             {
            inventory.CloseConnection();
             }
        }
Example #7
0
    private void RefreshGrid()
    {
        InventoryDAL dal = new InventoryDAL();
        dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;" +
          "Initial Catalog=AutoLot;Integrated Security=True");
        DataTable theCars = dal.GetAllInventoryAsDataTable();
        dal.CloseConnection();

        carsGridView.DataSource = theCars;
        carsGridView.DataBind();
    }
Example #8
0
    protected void btnFillData_Click(object sender, EventArgs e)
    {
        Trace.Write("CodeFileTraceInfo!", "Filling the grid!");

        InventoryDAL dal = new InventoryDAL();
        dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;" +
          "Initial Catalog=AutoLot;Integrated Security=True");
        carsGridView.DataSource = dal.GetAllInventoryAsList();
        carsGridView.DataBind();
        dal.CloseConnection();
    }
Example #9
0
 protected void btnAddCar_Click(object sender, EventArgs e)
 {
     // Update the Inventory table
     // and call RefreshGrid().
     InventoryDAL dal = new InventoryDAL();
     dal.OpenConnection(@"Data Source=(local)\SQLEXPRESS;" +
       "Initial Catalog=AutoLot;Integrated Security=True");
     dal.InsertAuto(int.Parse(txtCarID.Text), txtCarColor.Text,
       txtCarMake.Text, txtCarPetName.Text);
     dal.CloseConnection();
     RefreshGrid();
 }
Example #10
0
 static void Main(string [] args)
 {
     Console.WriteLine("*********The AutoLot Console UI********");
     string conStr = ConfigurationManager.ConnectionStrings ["AutoLotSqlProvider"].ConnectionString;
     bool userDone = false;
     string userCommand = "";
     InventoryDAL dal = new InventoryDAL();
     dal.OpenConnection(conStr);
     try {
         ShowInstructions();
         do {
             Console.WriteLine("Please, enter command:");
             userCommand = Console.ReadLine();
             switch(userCommand.ToUpper()) {
                 case "I":
                     InsertNewCar(dal);
                     break;
                 case "U":
                     UpdateCarPetName(dal);
                     break;
                 case "D":
                     DeleteCar(dal);
                     break;
                 case "L":
                     ListInventory(dal);
                     break;
                 case "S":
                     ShowInstructions();
                     break;
                 case "P":
                     LookUpPetName(dal);
                     break;
                 case "Q":
                     userDone = true;
                     break;
                 default:
                     Console.WriteLine("Bad data! try again");
                     break;
             }
         }
         while (!userDone);
     }
     catch(Exception ex) {
         Console.WriteLine(ex.Message);
     }
     finally {
         dal.CloseConnection();
     }
 }
        public TransactionManagement()
        {
            bool throwEx = true;

             Console.WriteLine("Do you want to throw an exception (Y or N)");
             string userAnswer = Console.ReadLine();

             if (userAnswer.ToLower() == "n")
            throwEx = false;

             InventoryDAL inventory = new InventoryDAL();
             inventory.OpenConnection(@"Data Source=(local)\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=AutoLot");

             inventory.ProcessCreditRisk(throwEx, 333);
        }
        /* This program allows the user to enter the following commands:
            * I: Inserts a new record into the Inventory table.
            * U: Updates an existing record in the Inventory table.
            * D: Deletes an existing record from the Inventory table.
            * L: Displays the current inventory using a data reader.
            * S: Shows these options to the user.
            * P: Looks up pet name from carID.
            * Q: Quits the program. */
        static void Main(string[] args)
        {
            Console.WriteLine("***** The AutoLot Console UI *****\n");

            // Get connection string from App.config
            string cnStr = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString;
            bool userDone = false;
            string userCommand = string.Empty;

            // Create our Inventory DAL object.
            InventoryDAL invDAL = new InventoryDAL();
            invDAL.OpenConnection(cnStr);

            //Keep asking for input until user presses the "Q" key.
            try
            {
                ShowInstructions();
                do
                {
                    Console.Write("\nPlease enter your command: ");
                    userCommand = Console.ReadLine();
                    Console.WriteLine();
                    switch (userCommand.ToUpper())
                    {
                        case "I":
                            InsertNewCar(invDAL);
                            break;
                        case "U":
                            UpdateCarPetName(invDAL);
                            break;
                        case "D":
                            DeleteCar(invDAL);
                            break;
                        case "L":
                            ListInventory(invDAL);
                            break;
                        case "S":
                            ShowInstructions();
                            break;
                        case "P":
                            LookupPetName(invDAL);
                            break;
                        case "Q":
                            userDone = true;
                            break;
                        default:
                            Console.WriteLine("Bad data! Try again");
                            break;
                    }
                } while (!userDone);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                invDAL.CloseConnection();
            }
        }