private void RemoverButton_Click(object sender, EventArgs e) { ComprasBLL Metodos = new ComprasBLL(); decimal importe = Convert.ToDecimal(DetalleDataGridView.CurrentRow.Cells[6].Value); int cantidad = Convert.ToInt32(DetalleDataGridView.CurrentRow.Cells[4].Value); string Id = ProductoComboBox.SelectedValue.ToString(); if (DetalleDataGridView.Rows.Count > 0 && DetalleDataGridView.CurrentRow != null) { Detalle.RemoveAt(DetalleDataGridView.CurrentRow.Index); Metodos.AgregarCantidad(cantidad * (-1), Convert.ToInt32(Id)); TotalTextBox.Text = Convert.ToString(Convert.ToDecimal(TotalTextBox.Text) - importe); CargarGrid(); } }
private void GuardarButton_Click(object sender, EventArgs e) { RepositorioBase <CompraProductos> Metodos = new RepositorioBase <CompraProductos>(); ComprasBLL Metodos2 = new ComprasBLL(); bool paso = false; CompraProductos compra; if (!Validar()) { return; } compra = LlenaClase(); if (IdNumericUpDown.Value == 0) { paso = Metodos.Guardar(compra); foreach (var item in this.Detalle) { Metodos2.AgregarCantidad(item.Cantidad, item.ProductoId); } } else { if (!ExisteEnLaBaseDeDatos()) { MessageBox.Show("No se puede modificar una compra que no existe", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } paso = Metodos2.Modificar(compra); } if (paso) { Limpiar(); MessageBox.Show("Guardado!", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No se pudo guardar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }