public List <entVenta> ListarVenta(String fechadesde, String fechahasta, int idSucursal)
        {
            SqlCommand      cmd   = null;
            List <entVenta> Lista = null;
            SqlDataReader   dr    = null;

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("spListaVenta", cn);
                cmd.Parameters.AddWithValue("@prmfinicio", fechadesde);
                cmd.Parameters.AddWithValue("@prmfin", fechahasta);
                cmd.Parameters.AddWithValue("@prmidsucursal", idSucursal);
                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                dr    = cmd.ExecuteReader();
                Lista = new List <entVenta>();
                while (dr.Read())
                {
                    entVenta v = new entVenta();
                    v.Id_Venta          = Convert.ToInt32(dr["Id_Venta"]);
                    v.Codigo_Venta      = dr["Codigo_Venta"].ToString();
                    v.Estado_Venta      = dr["Estado_Venta"].ToString();
                    v.Correlativo_Venta = dr["Correlativo_Venta"].ToString();
                    v.FechaVenta        = Convert.ToDateTime(dr["FechaVenta"]);
                    v.Igv_Venta         = Convert.ToInt32(dr["Igv_Venta"]);
                    v.Total             = Convert.ToDouble(dr["Total"].ToString());
                    v.Descuento_Venta   = Convert.ToDouble(dr["Descuento_Venta"]);
                    v.Utilidad          = Convert.ToDouble(dr["Utilidad"]);
                    v.Inversion         = Convert.ToDouble(dr["Inversion"]);

                    entTipComprobante tc = new entTipComprobante();
                    tc.Id_TipCom      = Convert.ToInt32(dr["Id_TipCom"]);
                    tc.Nombre_TipCom  = dr["Nombre_TipCom"].ToString();
                    v.tipocomprobante = tc;

                    entTipoPago tp = new entTipoPago();
                    tp.Id_TipPago = Convert.ToInt32(dr["Id_TipPago"]);
                    v.tipopago    = tp;
                    Lista.Add(v);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally { cmd.Connection.Close(); }
            return(Lista);
        }
        public entSerie CargarSerie(int id_Suc, int id_tipcom)
        {
            SqlCommand    cmd = null;
            entSerie      s   = null;
            SqlDataReader dr  = null;

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("spCargarSerie", cn);
                cmd.Parameters.AddWithValue("@prmIdSuc", id_Suc);
                cmd.Parameters.AddWithValue("@prmIdTipcom", id_tipcom);

                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    s              = new entSerie();
                    s.Id_Serie     = Convert.ToInt32(dr["Id_Serie"]);
                    s.Numero_Serie = dr["Numero_Serie"].ToString();
                    entSucursal suc = new entSucursal();
                    suc.Id_Suc = Convert.ToInt32(dr["Id_Sucursal_Serie"]);
                    s.sucursal = suc;
                    entTipComprobante tc = new entTipComprobante();
                    tc.Id_TipCom = Convert.ToInt32(dr["Id_TipCom_Serie"]);
                    s.tipocom    = tc;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally { cmd.Connection.Close(); }
            return(s);
        }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult r = MessageBox.Show("¿Desea guardar esta nota de venta?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (r == DialogResult.Yes)
                {
                    SoloNumCeldaGrid();
                    EscribirNuevoMonto();
                    ActualizarMontosDgv();
                    CargarSerie_correlativo();
                    entVenta v = new entVenta();

                    entCliente c = new entCliente();
                    c.Id_Cliente = LocalBD.Instancia.ReturnIdClienteNV(0, 0);
                    v.cliente    = c;

                    v.usuario = u;

                    entSucursal s = new entSucursal();
                    s.Id_Suc   = LocalBD.Instancia.IdSucursal;
                    v.sucursal = s;

                    entTipComprobante tc = new entTipComprobante();
                    tc.Id_TipCom      = serie.tipocom.Id_TipCom;
                    v.tipocomprobante = tc;

                    entMoneda m = new entMoneda();
                    m.Id_Moneda = Convert.ToInt32(CboMoneda.SelectedValue);
                    v.moneda    = m;

                    entTipoPago tp = new entTipoPago();
                    tp.Id_TipPago = Convert.ToInt32(cboTipoPago.SelectedValue);
                    v.tipopago    = tp;

                    v.Igv_Venta       = 0;
                    v.Descuento_Venta = Convert.ToDouble(txtDescuento.Text);

                    List <entDetalleVenta> Detalle = new List <entDetalleVenta>();
                    foreach (DataGridViewRow row in dgvDetalleNotaVenta.Rows)
                    {
                        entDetalleVenta dt = new entDetalleVenta();
                        dt.Id_Prod_Det  = Convert.ToInt32(row.Cells[0].Value);
                        dt.PrecProd_Det = Convert.ToDouble(row.Cells[3].Value);
                        dt.Cantidad_Det = Convert.ToInt32(row.Cells[2].Value);
                        Detalle.Add(dt);
                    }
                    v.detalleventa = Detalle;
                    v.Desc_Venta   = rtxtDescripcion.Text;
                    CargarSerie_correlativo();
                    int result = negVenta.Intancia.GuardarVenta(v, serie.tipocom.Id_TipCom, serie.Numero_Serie);
                    MessageBox.Show("Nota de venta guardo de manera correcta!", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dgvDetalleNotaVenta.Enabled = false; ControlBotones(true, false, false, false); btnAgregarItem.Enabled = false; btnAnular.Enabled = true;
                    ac.BloquearText(this.gbCliente, false); ac.BloquearText(this.panel1, false);
                    // lblMontoEnletras.Text = "Son: " + ac.enletras(txtTotal.Text).ToLower() + " Soles";
                }
            }
            catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public entVenta LstVentaDetalle(int id_venta)
        {
            SqlCommand             cmd = null;
            IDataReader            idr = null;
            entVenta               v   = null;
            List <entDetalleVenta> det = null;

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("spMostrarCabeceraVenta", cn);
                cmd.Parameters.AddWithValue("@prmid_venta", id_venta);
                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                idr = cmd.ExecuteReader();
                if (idr.Read())
                {
                    v = new entVenta();
                    v.Codigo_Venta      = idr["Codigo_Venta"].ToString();
                    v.Serie_Venta       = Convert.ToInt32(idr["Serie_Venta"].ToString());
                    v.Correlativo_Venta = idr["Correlativo_Venta"].ToString();
                    v.Igv_Venta         = Convert.ToInt32(idr["Igv_Venta"]);
                    v.FechaVenta        = Convert.ToDateTime(idr["FechaVenta"]);
                    v.Estado_Venta      = idr["Estado_Venta"].ToString();
                    v.Descuento_Venta   = Convert.ToDouble(idr["Descuento_Venta"]);
                    v.Desc_Venta        = idr["Desc_Venta"].ToString();

                    entCliente c = new entCliente();
                    c.Nombre_Cliente    = idr["Nombre_Cliente"].ToString();
                    c.NumeroDoc_Cliente = idr["NumeroDoc_Cliente"].ToString();
                    entTipoDocumento td = new entTipoDocumento();
                    td.Nombre_TipDoc = idr["Nombre_TipDoc"].ToString();
                    c.tipodocumento  = td;
                    v.cliente        = c;

                    entSucursal s = new entSucursal();
                    s.Direccion_Suc = idr["Direccion_Suc"].ToString();
                    v.sucursal      = s;

                    entUsuario u = new entUsuario();
                    u.Nombre_Usuario = idr["Nombre_Usuario"].ToString();
                    v.usuario        = u;

                    entTipComprobante tc = new entTipComprobante();
                    tc.Nombre_TipCom  = idr["Nombre_TipCom"].ToString();
                    v.tipocomprobante = tc;

                    entMoneda m = new entMoneda();
                    m.Descripcion_Moneda = idr["Descripcion_Moneda"].ToString();
                    v.moneda             = m;

                    entTipoPago tp = new entTipoPago();
                    tp.Descripcion_TipPago = idr["Descripcion_TipPago"].ToString();
                    v.tipopago             = tp;

                    if (idr.NextResult())
                    {
                        det = new List <entDetalleVenta>();
                        while (idr.Read())
                        {
                            entDetalleVenta d = new entDetalleVenta();
                            d.PrecProd_Det = Convert.ToDouble(idr["PrecProd_Det"]);
                            d.Cantidad_Det = Convert.ToInt32(idr["Cantidad_Det"]);
                            entProducto p = new entProducto();
                            p.Codigo_Prod = idr["Codigo_Prod"].ToString();
                            p.Nombre_Prod = idr["Nombre_Prod"].ToString();
                            p.Precio_Prod = Convert.ToDouble(idr["Precio_Prod"]);
                            d.producto    = p;
                            det.Add(d);
                        }
                        v.detalleventa = det;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally { cmd.Connection.Close(); } return(v);
        }
Exemple #5
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult r = MessageBox.Show("¿Desea Registrar la Venta?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (r == DialogResult.Yes)
                {
                    SoloNumCeldaGrid();
                    EscribirNuevoMonto();
                    ActualizarMontosDgv();
                    entVenta venta = new entVenta();

                    entCliente cliente = new entCliente();
                    cliente.Id_Cliente = LocalBD.Instancia.ReturnIdCliente(0, 0);
                    venta.cliente      = cliente;

                    entUsuario usuario = new entUsuario();
                    usuario       = us;
                    venta.usuario = usuario;

                    entSucursal sucursal = new entSucursal();
                    sucursal.Id_Suc = LocalBD.Instancia.IdSucursal;
                    venta.sucursal  = sucursal;

                    entTipComprobante tipocomprobante = new entTipComprobante();
                    tipocomprobante.Id_TipCom = 1;
                    venta.tipocomprobante     = tipocomprobante;

                    entMoneda moneda = new entMoneda();
                    moneda.Id_Moneda = Convert.ToInt32(CboMoneda.SelectedValue);
                    venta.moneda     = moneda;

                    entTipoPago tipoPago = new entTipoPago();
                    tipoPago.Id_TipPago = Convert.ToInt32(cboTipoPago.SelectedValue);
                    venta.tipopago      = tipoPago;

                    venta.Igv_Venta       = 0;
                    venta.Descuento_Venta = 0.0;

                    List <entDetalleVenta> Detalle = new List <entDetalleVenta>();
                    foreach (DataGridViewRow row in dgvDetalleBoleta.Rows)
                    {
                        entDetalleVenta dt = new entDetalleVenta();
                        dt.Id_Prod_Det  = Convert.ToInt32(row.Cells[0].Value);
                        dt.PrecProd_Det = Convert.ToDouble(row.Cells[3].Value);
                        dt.Cantidad_Det = Convert.ToInt32(row.Cells[2].Value);
                        Detalle.Add(dt);
                    }
                    venta.detalleventa = Detalle;
                    venta.Desc_Venta   = "";
                    Stock();
                    CargarSerie_correlativo();
                    int result = VentaServices.Intancia.GuardarVenta(venta, 1, serie.Numero_Serie);


                    //var stock= negVenta.Equals.Resta
                    MessageBox.Show("Se guardo de manera correcta!", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dgvDetalleBoleta.Enabled = false; ControlBotones(true, false, false, false); btnAgregarItem.Enabled = false; btnAnular.Enabled = true; btnCrearFactura.Enabled = true;
                    ac.BloquearText(this.gbCliente, false); ac.BloquearText(this.panel1, false);
                    lblMontoEnletras.Text = "Son: " + ac.enletras(txtTotal.Text).ToLower() + " Pesos";
                }
            }
            catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }