private void EditarRegistro() { FrmPlatosItem F = new FrmPlatosItem(); Plato registro = (Plato)this.bs.Current; if (registro == null) { return; } F.registro = FactoryPlatos.ActualizarCosto(registro); F.Modificar(); if (F.DialogResult == DialogResult.OK) { Busqueda(); } }
private void Aceptar_Click(object sender, EventArgs e) { try { platoBindingSource.EndEdit(); registro = (Plato)platoBindingSource.Current; registro.Precio = Basicas.Round(registro.PrecioConIva.GetValueOrDefault(0) / (1 + (registro.TasaIva.GetValueOrDefault(0) / 100))); if (string.IsNullOrEmpty(registro.Codigo)) { throw new Exception("Error codigo no puede estar vacio"); } if (string.IsNullOrEmpty(registro.Grupo)) { throw new Exception("Error el grupo no puede estar vacio"); } if (registro.Codigo.Length > 6) { throw new Exception("Error codigo no puede tener mas de 6 caracteres"); } if (registro.Grupo.Length > 20) { throw new Exception("Error grupo no puede tener mas de 20 caracteres"); } this.DialogResult = DialogResult.OK; if (esNuevo) { if (registro.IdPlato == null) { registro.IdPlato = FactoryContadores.GetMax("IdPlato"); registro.Activo = true; } } foreach (PlatosIngrediente p in registro.PlatosIngredientes) { if (p.IdPlatoIngrediente == null) { p.IdPlatoIngrediente = FactoryContadores.GetMax("IdPlatoIngrediente"); } } foreach (PlatosContorno p in registro.PlatosContornos) { if (p.IdPlatoContorno == null) { p.IdPlatoContorno = FactoryContadores.GetMax("IdPlatoContorno"); } } foreach (PlatosComentario p in registro.PlatosComentarios) { if (p.IdPlatoComentario == null) { p.IdPlatoComentario = FactoryContadores.GetMax("IdPlatoComentario"); } } foreach (PlatosCombo p in registro.PlatosCombos) { if (p.IdPlatoCombo == null) { p.IdPlatoCombo = FactoryContadores.GetMax("IdPlatoCombo"); } } if (esNuevo) { db.Platos.AddObject(registro); } db.SaveChanges(); FactoryPlatos.ActualizarCosto(registro); this.Close(); } catch (Exception ex) { string s = ex.Message; if (ex.InnerException != null) { s = ex.InnerException.Message; } else { MessageBox.Show("Error al guardar los datos:" + s, "Atencion", MessageBoxButtons.OK); } } }