private void btnGuardar_Click(object sender, EventArgs e)
        {
            int ultimoid = 0;

            if (string.IsNullOrEmpty(txtNumIngreso.Text))
            {
                txtNumIngreso.Focus();
                epIngreso.SetError(txtNumIngreso, "Campo obligatorio - ingrese el numero de comprobante");
            }
            else if (dgvIngresoArticulo.Rows.Count == 0)
            {
                epIngreso.SetError(btnBuscarArticulo, "Agregue al menos un articulo para registrar");
            }
            else
            {
                if (_isNew)
                {
                    ultimoid = NIngresoArticulo.Insertar(
                        cboComprobante.Text,
                        txtNumIngreso.Text.Trim(),
                        txtImpuesto.Text.Trim(),
                        Convert.ToInt32(cboProveedor.SelectedValue),
                        IdUsuario
                        );
                    int numFilas = dgvIngresoArticulo.Rows.Count;
                    for (int i = 0; i < numFilas; i++)
                    {
                        int     id_ingreso        = ultimoid;
                        int     id_articulo       = Convert.ToInt32(dgvIngresoArticulo.Rows[i].Cells[8].Value.ToString());
                        decimal precio_compra     = Convert.ToDecimal(dgvIngresoArticulo.Rows[i].Cells[2].Value.ToString());
                        decimal precio_venta      = Convert.ToDecimal(dgvIngresoArticulo.Rows[i].Cells[3].Value.ToString());
                        int     stock_inicial     = Convert.ToInt32(dgvIngresoArticulo.Rows[i].Cells[4].Value.ToString());
                        int     stock_actual      = Convert.ToInt32(dgvIngresoArticulo.Rows[i].Cells[4].Value.ToString());
                        string  fecha_produccion  = Convert.ToString(dgvIngresoArticulo.Rows[i].Cells[5].Value.ToString());
                        string  fecha_vencimiento = Convert.ToString(dgvIngresoArticulo.Rows[i].Cells[6].Value.ToString());

                        bool rpta = NDetalleIngresoArticulo.Insertar(
                            id_ingreso, id_articulo, precio_compra, precio_venta, stock_inicial, stock_actual, Convert.ToDateTime(fecha_produccion), Convert.ToDateTime(fecha_vencimiento)
                            );

                        if (!rpta)
                        {
                            MessageBox.Show("Error al registrar detalle");
                        }
                    }
                    mensajeYes("Ingreso insertado correctamente a la base de datos");
                    LimpiarIngreso();
                    objNIA.ListarDataGridViewIngresoArticulos(frmListIngresoArticulos.MyFormListIngreso.dgvIngresoArt);
                    string codigo = NIngresoArticulo.GenerarCodigoIngreso();
                    txtNumIngreso.Text = codigo;
                }
            }
        }
Exemplo n.º 2
0
 private void MostrarIngreso()
 {
     objNIA.ListarDataGridViewIngresoArticulos(dgvIngresoArt);
 }