Beispiel #1
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (dgvCars.SelectedRows.Count == 0)
            {
                return;
            }

            var car = (ICar)dgvCars.SelectedRows[0].Tag;

            if (car == null)
            {
                return;
            }

            if (MessageBox.Show(string.Format("Do you want to delete the car {0}?", car.name), "Remove", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    PersistenceCar.getInstance().Delete(car);
                    dgvCars.Rows.Remove(dgvCars.SelectedRows[0]);
                }
                catch (MyException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Beispiel #2
0
        private void CarForm_Load(object sender, EventArgs e)
        {
            var cars = PersistenceCar.getInstance().GetAll().OrderBy(x => x.name);

            foreach (var car in cars)
            {
                InsertGrid(car);
            }
        }
        private void cboCar_DropDown(object sender, EventArgs e)
        {
            var partialName = cboCar.Text;

            cboCar.Items.Clear();
            var cars = PersistenceCar.getInstance().GetByName(cboCar.Text);

            foreach (var car in cars)
            {
                Functions.AddCombobox(ref cboCar, car.Id, car);
            }
        }
Beispiel #4
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (isValid())
         {
             var car = new Car(txtName.Text);
             PersistenceCar.getInstance().Insert(car);
             InsertGrid(car);
             ClearForm();
         }
     }
     catch (MyException ex)
     {
         MessageBox.Show(ex.Message);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }