Ejemplo n.º 1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtSerie.Text) && string.IsNullOrEmpty(txtCorrelativo.Text))
                {
                    epVenta.SetError(txtSerie, "verifica el numero de serie - para poder hacer la venta");
                    epVenta.SetError(txtCorrelativo, "verifica el numero de correlativo - para poder hacer la venta");
                }
                else if (string.IsNullOrEmpty(txtCliente.Text) && idCliente == 0)
                {
                    epVenta.SetError(txtCliente, "Campo vacio - buscar por DNI al cliente o agregar nuevo para hacer la venta");
                }
                else if (dgvDetalleventa.Rows.Count == 0)
                {
                    MessageBox.Show("Caja de productos vacio - ingrese al menos un producto para realizar la venta", "Sistema veterinaria", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    epVenta.SetError(btnBuscarArticulo, "Buscar articulo a vender");
                }
                else
                {
                    if (_isNew)
                    {
                        int ultimo_id = NVenta.Insertar(
                            cboComprobante.SelectedIndex, cboComprobante.Text, txtSerie.Text.Trim(), txtCorrelativo.Text.Trim(),
                            idCliente, txtRazonSocial.Text.Trim(), txtRuc.Text.Trim(),
                            Convert.ToDecimal(txtSubTotal.Text.Trim()), Convert.ToDecimal(txtIGV.Text.Trim()), Convert.ToDecimal(txtTotal.Text.Trim()), idUsuario
                            );
                        int numFilas = dgvDetalleventa.Rows.Count;
                        for (int i = 0; i < numFilas; i++)
                        {
                            int     idventa   = ultimo_id;
                            int     iddia     = Convert.ToInt32(dgvDetalleventa.Rows[i].Cells[7].Value.ToString());
                            int     cantidad  = Convert.ToInt32(dgvDetalleventa.Rows[i].Cells[2].Value.ToString());
                            decimal precio    = Convert.ToDecimal(dgvDetalleventa.Rows[i].Cells[3].Value.ToString());
                            decimal descuento = Convert.ToDecimal(dgvDetalleventa.Rows[i].Cells[4].Value.ToString());

                            bool rpta = NDetalleVenta.Insertar(
                                idventa, iddia, cantidad, precio, descuento
                                );
                        }
                        IdVenta = ultimo_id;
                        if (cboComprobante.Text == "Factura")
                        {
                            bool rpta = NFactura.insertarFactura(txtSerie.Text.Trim(), txtCorrelativo.Text.Trim(), IdVenta);
                        }
                        else
                        {
                            bool rpta = NBoleta.insertarBoleta(txtSerie.Text.Trim(), txtCorrelativo.Text.Trim(), IdVenta);
                        }

                        mensajeYes("Venta registrado correctamente");
                        LimpiarVenta();
                        objNV.ListarDataGridViewVenta(frmListVenta.MyFormListVenta.dgvVenta);
                        string codigo = NBoleta.GenerarCodigoBoleta();
                        txtSerie.Text       = "0001";
                        txtCorrelativo.Text = codigo;
                        btnFacturar.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error ....!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Ejemplo n.º 2
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string rpta           = "";
                int    cantidad       = 0;
                float  precioUnitario = 0;
                if (this.txtEmpleado.Text == string.Empty && this.txtCliente.Text == string.Empty)
                {
                    MensajeError("Falta ingresar Algunos Datos, seran Remarcados");
                    errorIcono.SetError(this.txtEmpleado, "Ingrese Nombre del Empleado");
                    errorIcono.SetError(this.txtCliente, "Ingrese Nombre del Cliente");
                }
                else
                {
                    if (this.IsNuevo)
                    {
                        rpta = NVenta.Insertar(Convert.ToDateTime(txtFecha.Text), Convert.ToSingle(txtTotal.Text), Convert.ToInt32(txtCliente.Value), Convert.ToInt32(txtEmpleado.Value));
                        for (int i = 0; i < dataDetalle.RowCount; i++)
                        {
                            cantidad       = Convert.ToInt32(dataDetalle.Rows[i].Cells["Cantidad"].Value);
                            precioUnitario = Convert.ToSingle(dataDetalle.Rows[i].Cells["Precio_Unitario"].Value);
                            NDetalleVenta.Insertar(cantidad, precioUnitario, Convert.ToInt32(dataDetalle.Rows[i].Cells["id"].Value));
                        }
                    }
                    else
                    {
                        rpta = NVenta.Editar(Convert.ToInt32(txtIdVenta.Text), Convert.ToDateTime(txtFecha.Text), Convert.ToSingle(txtTotal.Text), Convert.ToInt32(txtCliente.Value), Convert.ToInt32(txtEmpleado.Value));
                        NDetalleVenta.Eliminar(Convert.ToInt32(this.txtIdVenta.Text));
                        for (int i = 0; i < dataDetalle.RowCount; i++)
                        {
                            cantidad       = Convert.ToInt32(dataDetalle.Rows[i].Cells["Cantidad"].Value);
                            precioUnitario = Convert.ToSingle(dataDetalle.Rows[i].Cells["Precio_Unitario"].Value);
                            NDetalleVenta.Editar(cantidad, precioUnitario, Convert.ToInt32(this.txtIdVenta.Text), Convert.ToInt32(dataDetalle.Rows[i].Cells["id"].Value));
                        }
                    }

                    if (rpta.Equals("OK"))
                    {
                        if (this.IsNuevo)
                        {
                            this.MensajeOk("Se inserto Correctamente El Registro");
                        }
                        else
                        {
                            this.MensajeOk("Se Actualizo Correctamente El Registro");
                        }
                    }
                    else
                    {
                        this.MensajeError(rpta);
                    }
                    this.IsNuevo  = false;
                    this.IsEditar = false;
                    this.Limpiar();
                    this.usar = false;
                    this.pRegistro.Visible = false;
                    this.pListas.Visible   = true;
                    this.Mostrar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }