예제 #1
0
        private void vehicleGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string errorMessage = String.Empty;

            if (e.RowIndex >= 0)
            {
                Vehicle vehicle = (Vehicle)vehicleGrid.Rows[e.RowIndex].DataBoundItem;

                if (vehicle.Name == null)
                {
                    vehicle.Name = String.Empty;
                }
                if (vehicle.Description == null)
                {
                    vehicle.Description = String.Empty;
                }
                if (vehicle.VIN == null)
                {
                    vehicle.VIN = String.Empty;
                }

                if (vehicle != null)
                {
                    if (String.IsNullOrEmpty(vehicle.Name) && String.IsNullOrEmpty(vehicle.Description) && String.IsNullOrEmpty(vehicle.VIN))
                    {
                        DialogResult answer = MessageBox.Show("This Vehicle is currently empty, would you like to delete it?", "Approve Delete", MessageBoxButtons.YesNoCancel);
                        if (answer == DialogResult.Yes)
                        {
                            Controller.DeleteVehicle(vehicle, out errorMessage);
                            ResetGridView();
                        }
                        else if (answer == DialogResult.No)
                        {
                            Controller.SaveVehicle(vehicle, out errorMessage);
                        }
                    }
                    else
                    {
                        Controller.SaveVehicle(vehicle, out errorMessage);
                    }
                }

                if (!String.IsNullOrEmpty(errorMessage))
                {
                    MessageBox.Show(errorMessage);
                }
            }
        }