private void button1_Click(object sender, EventArgs e) { if (currentAction == SaveAction.Agregar) { var aa = new Models.Vehiculos(); aa.TipoVehiculo = (int)_db.VehiculosTipos.FirstOrDefault(x => x.Descripcion == comboBox1.SelectedItem.ToString())?.Id; aa.Marca = (int)_db.Marcas.FirstOrDefault(x => x.Descripcion == comboBox2.SelectedItem.ToString())?.Id; aa.Modelo = (int)_db.Modelos.FirstOrDefault(x => x.Descripcion == comboBox3.SelectedItem.ToString())?.Id; aa.TipoCombustible = (int)_db.CombustiblesTipos.FirstOrDefault(x => x.Descripcion == comboBox4.SelectedItem.ToString())?.Id; aa.NoChasis = textBox3.Text; aa.NoMotor = textBox2.Text; aa.NoPlaca = textBox1.Text; aa.Deleted = false; aa.Estado = 1; _db.Vehiculos.Add(aa); } else if (currentAction == SaveAction.Editar) { var toUpdate = _db.Vehiculos.FirstOrDefault(x => x.Id == currentType.Id); toUpdate.TipoVehiculo = (int)_db.VehiculosTipos.FirstOrDefault(x => x.Descripcion == comboBox1.Text)?.Id; toUpdate.Marca = (int)_db.Marcas.FirstOrDefault(x => x.Descripcion == comboBox2.Text)?.Id; toUpdate.Modelo = (int)_db.Modelos.FirstOrDefault(x => x.Descripcion == comboBox3.Text)?.Id; toUpdate.TipoCombustible = (int)_db.CombustiblesTipos.FirstOrDefault(x => x.Descripcion == comboBox4.Text)?.Id; toUpdate.NoChasis = textBox3.Text; toUpdate.NoMotor = textBox2.Text; toUpdate.NoPlaca = textBox1.Text; } _db.SaveChanges(); AppData.ViewsRepository.VehiculosView.GetData(); Close(); }
public Inspeccion(Models.Clientes cliente, Models.Vehiculos vehiculo, int tipo) { InitializeComponent(); BackColor = Resources.Colors.Info; panel2.BackColor = BackColor; button1.BackColor = BackColor; button1.ForeColor = Color.White; button2.BackColor = Resources.Colors.Secundary; button2.ForeColor = Color.White; _tipo = tipo; _vehiculo = vehiculo; _cliente = cliente; textBox1.Text = _cliente.Nombre; textBox2.Text = $"{_vehiculo.NoPlaca}"; }
public SingleVehiculo(SaveAction action, int vehiculoId) { currentAction = action; InitializeComponent(); TypeInit(); FillCombos(); var _vehiculo = _db.Vehiculos.FirstOrDefault(x => x.Id == vehiculoId); if (comboBox1.FindStringExact(_vehiculo.VehiculosTipos.Descripcion) == -1) { comboBox1.Items.Add(_vehiculo.VehiculosTipos.Descripcion); } comboBox1.SelectedIndex = comboBox1.FindStringExact(_vehiculo.VehiculosTipos.Descripcion); if (comboBox2.FindStringExact(_vehiculo.Marcas.Descripcion) == -1) { comboBox2.Items.Add(_vehiculo.Marcas.Descripcion); } comboBox2.SelectedIndex = comboBox2.FindStringExact(_vehiculo.Marcas.Descripcion); if (comboBox3.FindStringExact(_vehiculo.Modelos.Descripcion) == -1) { comboBox3.Items.Add(_vehiculo.Modelos.Descripcion); } comboBox3.SelectedIndex = comboBox3.FindStringExact(_vehiculo.Modelos.Descripcion); if (comboBox4.FindStringExact(_vehiculo.CombustiblesTipos.Descripcion) == -1) { comboBox4.Items.Add(_vehiculo.CombustiblesTipos.Descripcion); } comboBox4.SelectedIndex = comboBox4.FindStringExact(_vehiculo.CombustiblesTipos.Descripcion); textBox1.Text = _vehiculo.NoPlaca; textBox2.Text = _vehiculo.NoMotor; textBox3.Text = _vehiculo.NoChasis; currentType = _vehiculo; }
public void SetVehiculo(int id) { currentVehiculo = _db.Vehiculos.FirstOrDefault(x => x.Id == id); textBox2.Text = $"{currentVehiculo.Marcas.Descripcion} {currentVehiculo.Modelos.Descripcion} {currentVehiculo.NoPlaca}"; }