Пример #1
0
        private void buttonADD_Click(object sender, EventArgs e)
        {
            FormAddChangeCar formAdd = new FormAddChangeCar();

            formAdd.ShowDialog();
            if (formAdd.DialogResult == DialogResult.OK)
            {
                CreateNewItem(formAdd.BrandName, formAdd.ModelName, formAdd.ModelColor, formAdd.Price);
                dataViewModels.Add(new DataViewModel {
                    Id = ++i, Brand = formAdd.BrandName, Model = formAdd.ModelName, Color = formAdd.ModelColor, Price = formAdd.Price, Sold = false
                });                                                                                                                                                                       //
                RerefreshGridAndData();
            }
        }
Пример #2
0
        private void Search_Click(object sender, EventArgs e)
        {
            FormAddChangeCar formAdd = new FormAddChangeCar(true);

            formAdd.ShowDialog();
            if (formAdd.DialogResult == DialogResult.OK)
            {
                Car findCar = FindCarItem(formAdd.BrandName, formAdd.ModelName, formAdd.ModelColor);
                if (findCar == null)
                {
                    MessageBox.Show(@"Car not found");
                }
                else
                {
                    var rowId = dataViewModels.FirstOrDefault(item =>
                                                              item.Brand == findCar.Model.Brand.Name && item.Model == findCar.Model.Name &&
                                                              item.Color == findCar.Model.Color).Id;
                    dataGridView1.Rows[rowId - 1].Selected = true;
                }
            }
        }
Пример #3
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");
            }
        }