示例#1
0
        private void Delete_Click(object sender, EventArgs e)
        {
            try
            {
                DataViewModel viewModels = (DataViewModel)dataGridView1.SelectedRows[0]?.DataBoundItem;
                DataViewModel carItem    = dataViewModels.FirstOrDefault(x => x.Id == viewModels.Id);
                carItem.Deleted = true;

                Car findCar = FindCarItem(carItem.Brand, carItem.Model, carItem.Color, carItem.Price);

                if (findCar == null)
                {
                    MessageBox.Show(@"Car not found");
                }
                else
                {
                    findCar.Deleted = true;
                    RerefreshGridAndData();
                }
            }
            catch (Exception)
            {
                MessageBox.Show(@"Please Choose a line");
            }
        }
示例#2
0
        private void Edit_Click(object sender, EventArgs e)
        {
            try
            {
                DataViewModel    viewModels = (DataViewModel)dataGridView1.SelectedRows[0]?.DataBoundItem;
                DataViewModel    carItem    = dataViewModels.FirstOrDefault(x => x.Id == viewModels.Id);
                FormAddChangeCar formAdd    =
                    new FormAddChangeCar(carItem.Brand, carItem.Model, carItem.Color, carItem.Price);
                formAdd.ShowDialog();
                if (formAdd.DialogResult == DialogResult.OK)
                {
                    Car findCar = FindCarItem(carItem.Brand, carItem.Model, carItem.Color, carItem.Price);

                    if (findCar == null)
                    {
                        MessageBox.Show("Car not found");
                    }
                    else
                    {
                        carItem.Brand = formAdd.BrandName;
                        carItem.Model = formAdd.ModelName;
                        carItem.Color = formAdd.ModelColor;
                        carItem.Price = formAdd.Price;

                        findCar.Model.Brand.Name = formAdd.BrandName;
                        findCar.Model.Name       = formAdd.ModelName;
                        findCar.Model.Color      = formAdd.ModelColor;
                        findCar.Price            = carItem.Price;
                        RerefreshGridAndData();
                    }
                }
            }

            catch (Exception)
            {
                MessageBox.Show(@"Please Choose a line");
            }
        }