public void Guardar(Presentaciones presentacion) { DbContext db = new DbContext(); try { db.ContextOptions.ProxyCreationEnabled = _proxy; if (presentacion.IdPresentacion <= 0) db.Presentaciones.AddObject(presentacion); else { Presentaciones pe = db.Presentaciones.SingleOrDefault(s => s.IdPresentacion == presentacion.IdPresentacion); if (pe != null) { pe.IdNegocio = presentacion.IdNegocio; pe.IdUnidadMedida = presentacion.IdUnidadMedida; pe.Descripcion = presentacion.Descripcion; pe.Cantidad = presentacion.Cantidad; pe.Costo = presentacion.Costo; } } db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.InnerException.Message); } finally { db.Dispose(); } }
private void LimpiarControles() { try { _presentacion = null; cmbNegocioRegistro.SelectedIndex = BusinessVariables.ComboBox.Index; txtPresentacionRegistro.Text = string.Empty; cmbMedidaRegistro.SelectedIndex = BusinessVariables.ComboBox.Index; txtCantidad.Text = string.Empty; txtCosto.Text = string.Empty; } catch (Exception ex) { throw new Exception(ex.Message); } }
private void btnGuardar_Click(object sender, EventArgs e) { try { if (!ValidaCaptura()) return; if (_presentacion == null) _presentacion = new Presentaciones(); _presentacion.IdNegocio = (int)cmbNegocioRegistro.SelectedValue; _presentacion.IdUnidadMedida = (int)cmbMedidaRegistro.SelectedValue; _presentacion.Descripcion = txtPresentacionRegistro.Text.Trim(); _presentacion.Cantidad = Convert.ToDecimal(txtCantidad.Text.Trim()); _presentacion.Costo = Convert.ToDecimal(txtCosto.Text.Trim()); _nPresentaciones.Guardar(_presentacion); LimpiarControles(); Mensajes.AlmacenExito(Text); CargaInicial(); } catch (Exception ex) { Mensajes.Error(ex.Message, Text); } }