Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // Prebuild Existing Vehicle ID list for comparison
                List <string> existingIDList = new List <string>();
                foreach (Vehicle vehicle in database.SelectAllVehicle())
                {
                    existingIDList.Add(vehicle.VehicleID);
                }

                string vehicleID         = textBox1.Text;
                string yearString        = textBox2.Text;
                string make              = textBox3.Text;
                string model             = textBox4.Text;
                string location          = textBox5.Text;
                string mileageCostString = textBox6.Text;

                if (!existingIDList.Contains(vehicleID))
                {
                    if (vehicleID != "" & vehicleID != null &
                        yearString != "" & yearString != null &
                        make != "" & make != null &
                        model != "" & model != null &
                        location != "" & location != null &
                        mileageCostString != "" & mileageCostString != null)
                    {
                        int year        = int.Parse(yearString);
                        int mileageCost = int.Parse(mileageCostString);

                        // Create Record
                        Controller controller = new Controller(database);
                        controller.AddVehicle(vehicleID, year, make, model, location, mileageCost);

                        this.parent.LoadVehiclesDataGrid();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Please enter all vehicle information");
                    }
                }
                else
                {
                    MessageBox.Show("That VehicleID already exists. Please select a new ID.");
                }
            }
            catch
            {
                MessageBox.Show("Invalid Entries - Please enter vehicle information.");
            }
        }
 public void Append_SelectAll_Vehicle_UnitTest()
 {
     Database database = new Database();
     Vehicle vehicle1 = new Vehicle("Truck1", "Milwaukee", 1);
     Vehicle vehicle2 = new Vehicle("Truck2", "Milwaukee", 1);
     database.Append(vehicle1);
     database.Append(vehicle2);
     List<Vehicle> vehicleList = database.SelectAllVehicle();
     Assert.AreSame(vehicleList[0], vehicle1);
     Assert.AreSame(vehicleList[1], vehicle2);
     Assert.AreEqual(vehicleList[0].VehicleID, "Truck1");
 }