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; } } }
private void frmIngresoArticulos_Load(object sender, EventArgs e) { string codigo = NIngresoArticulo.GenerarCodigoIngreso(); txtNumIngreso.Text = codigo; dgvIngresoArticulo.Columns[0].HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter; dgvIngresoArticulo.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter; dgvIngresoArticulo.Columns[3].HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter; dgvIngresoArticulo.Columns[4].HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter; dgvIngresoArticulo.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvIngresoArticulo.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvIngresoArticulo.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvIngresoArticulo.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; }
private void dgvIngresoArt_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex != -1) { DataTable tabla = new DataTable(); if (dgvIngresoArt.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Equals("VER")) { int idingreso = Convert.ToInt32(dgvIngresoArt.Rows[e.RowIndex].Cells[8].Value); tabla = NIngresoArticulo.BuscarCodigo(idingreso); //MessageBox.Show(idingreso.ToString()); new frmIngresoArticulos().Show(); int numFilas = tabla.Rows.Count; if (numFilas > 0) { frmIngresoArticulos.MyformIngresoArt.cboProveedor.SelectedValue = tabla.Rows[0]["idproveedor"].ToString(); frmIngresoArticulos.MyformIngresoArt.cboComprobante.Text = tabla.Rows[0]["comprobante"].ToString(); frmIngresoArticulos.MyformIngresoArt.txtNumIngreso.Text = tabla.Rows[0]["numingreso"].ToString(); frmIngresoArticulos.MyformIngresoArt.txtImpuesto.Text = tabla.Rows[0]["impuesto"].ToString(); frmIngresoArticulos.MyformIngresoArt.txtTotal.Text = dgvIngresoArt.Rows[e.RowIndex].Cells[5].Value.ToString(); frmIngresoArticulos.MyformIngresoArt._isNew = false; for (int i = 0; i < numFilas; i++) { string articulo = tabla.Rows[i]["articulo"].ToString(); string p_venta = tabla.Rows[i]["precioventa"].ToString(); string p_compra = tabla.Rows[i]["preciocompra"].ToString(); string cantidad = tabla.Rows[i]["stockactual"].ToString(); DateTime f_produccion = Convert.ToDateTime(tabla.Rows[i]["fechaproduccion"].ToString()); DateTime f_venc = Convert.ToDateTime(tabla.Rows[i]["fechavencimiento"].ToString()); frmIngresoArticulos.MyformIngresoArt.dgvIngresoArticulo.Rows.Add( i + 1, articulo, p_venta, p_compra, cantidad, f_produccion.ToString("dd/MM/yyyy"), f_venc.ToString("dd/MM/yyyy") ); } frmIngresoArticulos.MyformIngresoArt.habilitar(true); //frmIngresoArticulos.MyformIngresoArt.txtNumIngreso.ReadOnly = true; //frmIngresoArticulos.MyformIngresoArt.txtImpuesto.ReadOnly = true; //frmIngresoArticulos.MyformIngresoArt.dgvIngresoArticulo.Enabled = false; //frmIngresoArticulos.MyformIngresoArt.btnGuardar.Enabled = false; } } if (dgvIngresoArt.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Equals("ANULAR")) { try { int estado = 0; int idingreso = Convert.ToInt32(dgvIngresoArt.Rows[e.RowIndex].Cells[8].Value); DialogResult rspta = MessageBox.Show("Desea anular este ingreso", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (DialogResult.Yes == rspta) { //var empleado = new Clases.Empleado(id_personal); bool rpta2 = NIngresoArticulo.ActualizarEstado( estado, idingreso ); MessageBox.Show("Ingreso anulado correctamente", "Sistema veterinaria", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvIngresoArt.Rows.Clear(); MostrarIngreso(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error ...!!", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } } }