Esempio n. 1
0
 public CarEdit(car c)
 {
     InitializeComponent();
     enginePowerNumericUpDown.Value = c.power_eng;
     fuelEffNumericUpDown.Value     = Convert.ToDecimal(c.fuel_eff);
     resourseNumericUpDown.Value    = c.resourse;
     weightNumericUpDown.Value      = Convert.ToDecimal(c.car_weight);
     this.Text = "Car #" + c.id;
 }
Esempio n. 2
0
        private void carsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //7.8
            int id = Convert.ToInt32(carsDataGridView.CurrentRow.Cells[0].Value);

            if (e.ColumnIndex == 7)
            {
                //Edit
                if (loggedUser == "Admin")
                {
                    car c = context.cars.Find(id);
                    using (CarEdit frm = new CarEdit(c))
                    {
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            if (dbm.EditCar(id, Convert.ToInt32(frm.enginePowerNumericUpDown.Value), Convert.ToDouble(frm.fuelEffNumericUpDown.Value), Convert.ToInt32(frm.resourseNumericUpDown.Value), Convert.ToDouble(frm.weightNumericUpDown.Value)))
                            {
                                MessageBox.Show("OK", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("Error", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            carsDataGridView.DataSource = context.cars.ToList();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Access Denied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (e.ColumnIndex == 8)
            {
                if (loggedUser == "Admin")
                {
                    //Delete
                    if (dbm.DeleteDriver(id))
                    {
                        MessageBox.Show("Deleted", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    carsDataGridView.DataSource = context.cars.ToList();
                }
                else
                {
                    MessageBox.Show("Access Denied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }