public void agregarCoche(Coches coche, int vecesRepetido) { /*Es necesario esto para poder guardar luego los nuevos coches que se vallan agregando a una formacion ya existente*/ Formaciones_X_Coches fc = new Formaciones_X_Coches(); fc.Coches = coche; fc.VecesRepetido = vecesRepetido; fc.Id_Formacion = this.Id; Formaciones_X_Coches.Add(fc); for (int i = 0; i < vecesRepetido; i++) _listaCoches.Add(coche); }
private void GuardarNuevoCoche() { string errorMsj = ""; if (!Util.EsAlfaNumerico(txtModelo.Text)) errorMsj += "Modelo: Incompleto ó Incorrecto.\n"; if(rndEsLocomotoraSi.Checked) { if(cbxTipoConsumo.SelectedItem == "") errorMsj += "Tipo Consumo: Incompleto ó Incorrecto.\n"; if(!Util.EsNumerico(txtConsumoMov.Text)) errorMsj += "Consumo en movimiento: Incompleto ó Incorrecto.\n"; if (!Util.EsNumerico(txtConsumoParado.Text)) errorMsj += "Consumo parado: Incompleto ó Incorrecto.\n"; } if (!Util.EsNumerico(txtCantidadAsientos.Text)) errorMsj += "Cantidad Asientos: Incompleto ó Incorrecto.\n"; if (!Util.EsNumerico(txtMaxLegal.Text)) errorMsj += "Capacidad Máxima Legal: Incompleto ó Incorrecto.\n"; if (!Util.EsNumerico(txtMaxReal.Text)) errorMsj += "Capacidad Máxima Real: Incompleto ó Incorrecto.\n"; if (String.IsNullOrEmpty(errorMsj)) { try { Coches nuevoCoche = new Coches(); nuevoCoche.Modelo = txtModelo.Text; if (rndEsLocomotoraSi.Checked) { nuevoCoche.EsLocomotora = 1; nuevoCoche.ConsumoMovimiento = Convert.ToInt32(txtConsumoMov.Text); nuevoCoche.ConsumoParado = Convert.ToInt32(txtConsumoParado.Text); if (cbxTipoConsumo.SelectedItem == "Eléctrico") nuevoCoche.TipoConsumo = (int)TipoConsumo.Electrico; else nuevoCoche.TipoConsumo = (int)TipoConsumo.Disel; } else { nuevoCoche.EsLocomotora = 0; nuevoCoche.ConsumoMovimiento = 0; nuevoCoche.TipoConsumo = 0; nuevoCoche.ConsumoParado = 0; } nuevoCoche.CantidadAsientos = Convert.ToInt32(txtCantidadAsientos.Text); nuevoCoche.MaximoLegalPasajeros = Convert.ToInt32(txtMaxLegal.Text); nuevoCoche.CapacidadMaximaPasajeros = Convert.ToInt32(txtMaxReal.Text); context.Coches.Add(nuevoCoche); context.SaveChanges(); //lbxCochesBorrar.Items.Add(nuevoCoche); //lbxCochesModificar.Items.Add(nuevoCoche); LimpiarTabNuevoCoche(); cargarCochesEnListas(); MessageBox.Show("Coche Guardado."); } catch (Exception exc) { MessageBox.Show("No se Guardo el Coche \n\n" + exc.ToString()); } } else { MessageBox.Show(errorMsj); } }