Example #1
0
 //txtIdProducto - Evento TextChanged - Busca un producto en la base de datos he incerta las coincidencias.
 private void txtIdProducto_TextChanged(object sender, EventArgs e)
 {
     //Si se ingresó un cóodigo de producto se sigue con el flujo.
     if (!String.IsNullOrEmpty(txtIdProducto.Text))
     {
         lblDescripcion.Text = NFacturas.BuscarProducto(Convert.ToInt32(txtIdProducto.Text), "Descripcion");
         txtPrecio.Text      = NFacturas.BuscarProducto(Convert.ToInt32(txtIdProducto.Text), "Precio");
         this.Impuesto       = NFacturas.BuscarProducto(Convert.ToInt32(txtIdProducto.Text), "Impuesto");
         if (lblDescripcion.Text == "No Encontrado")
         {
             //Si no se encunetran datos se termina el flujo.
             lblDescripcion.Text  = "";
             txtPrecio.Text       = "";
             this.lblImporte.Text = "";
         }
         else
         {
             //Asigna formato al textbox precio.
             txtPrecio.Text = String.Format("{0:#,##0.00}", Double.Parse(txtPrecio.Text));
         }
         if (!String.IsNullOrEmpty(txtPrecio.Text) && !String.IsNullOrEmpty(txtCantidad.Text))
         {
             //Si hay un precio y una cantidad calcula el importe.
             decimal Importe = Convert.ToDecimal(txtCantidad.Text) * Convert.ToDecimal(txtPrecio.Text);
             lblImporte.Text = String.Format("{0:#,##0.00}", Double.Parse(Convert.ToString(Importe)));
         }
     }
     else //Sino se ingresó codigo se borran los datos.
     {
         lblDescripcion.Text = "";
         txtPrecio.Text      = "";
         lblImporte.Text     = "";
     }
 }
        public FrmFacturacion(FrmInicio FormInicio)
        {
            InitializeComponent();
            IdUsuario = FormInicio.IdUsuario;

            //Inserta las condiciones de pago.
            this.cbxCondicionPago.DataSource    = NFacturas.ObtenerCondicionPago();
            this.cbxCondicionPago.ValueMember   = "ID_CONDICION";
            this.cbxCondicionPago.DisplayMember = "NOMBRE";
            this.cbxCondicionPago.SelectedIndex = 1;

            //Verifica que se obtenga un número de factura.
            int NumFact = 0;

            int.TryParse(NFacturas.ObtenerNumFactura(), out NumFact);
            if (NumFact == 0)
            {
                new Configuracion().Mensaje("Número de factura no encontrado en la base de datos" +
                                            "Procedimiento Almacenado: Facturas.ObtenerNumFactura", "Error", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                this.Dispose();
            }
            else
            {
                //Establece el valor si es obtenido.
                lblFactura.Text = String.Format(Convert.ToString(NumFact + 1), "000000");
            }
        }
        //btnBuscarCliente - Evento Click - Muestra el form para buscar cliente e incerta las coincidencias.
        private void btnBuscarCliente_Click(object sender, EventArgs e)
        {
            FrmBuscarCliente FormBuscarCliente = new FrmBuscarCliente(this);

            FormBuscarCliente.ShowDialog();
            FormBuscarCliente.Dispose();
            this.txtIdCliente.Text   = this.IdCliente;
            this.lblRazonSocial.Text = this.RazonSocial;

            //Si se encuentran resultados rellena las direcciones de entrega.
            if (!String.IsNullOrEmpty(txtIdCliente.Text))
            {
                cbxDireccionEntrega.DataSource    = NFacturas.CargarDireccionesEntrega(Convert.ToInt32(txtIdCliente.Text));
                cbxDireccionEntrega.ValueMember   = "Encabezado";
                cbxDireccionEntrega.DisplayMember = "Valores";
            }
        }
Example #4
0
        //btnAnular - Evento Click - Cambia el estado de la factura a ANULADA.
        private void btnAnular_Click(object sender, EventArgs e)
        {
            if (this.dgvFacturas.Rows.Count > 0)
            {
                //Mensaje de confirmación.
                DialogResult Confirmacion = MessageBox.Show(String.Format(@"¿Está seguro de anular la factura número {0}?, 
 después de haberla anulado no podrá revertir los cambios realizados", this.ObtenerFila().Cells["N° FACTURA"].
                                                                          Value), String.Format(Configuracion.Titulo, "Anular Factura"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (Confirmacion == DialogResult.Yes)
                {
                    string Respuesta = NFacturas.Anular(Convert.ToInt32(this.ObtenerFila().Cells["N° FACTURA"].Value));

                    if (Respuesta == "OK")
                    {
                        //Establece mensaje de eliminación el el "lblMensajes".
                        Mensaje(String.Format("El factura {0} ha sido ANULADA satisfactoriamente.",
                                              Convert.ToString(this.ObtenerFila().Cells["N° FACTURA"].Value)));

                        //Mensaje al usuario de cción satisfactoria.
                        new Configuracion().Mensaje(String.Format("La factura {0} ha sido ANULADA exitosamente.",
                                                                  this.ObtenerFila().Cells["N° FACTURA"].Value), "Factura Anulada", MessageBoxButtons.OK,
                                                    MessageBoxIcon.Information);

                        //Refresca la vista.
                        this.Refrescar();
                    }
                    else
                    {
                        //Envía mensaje con error.
                        new Configuracion().Mensaje(Respuesta, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                //Envía mensaje con error.
                new Configuracion().Mensaje("Debe seleccionar una factura para poder anularla.", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 //txtIdCliente - Evento TextChanged - Establece los datos del cliente que coincida con el código.
 private void txtIdCliente_TextChanged(object sender, EventArgs e)
 {
     //Verifica que se hayan ingresado datos en el textbox.
     if (!String.IsNullOrEmpty(txtIdCliente.Text))
     {
         lblRazonSocial.Text = NFacturas.BuscarCliente(Convert.ToInt32(txtIdCliente.Text));
         if (!(lblRazonSocial.Text == "Código de cliente no registrado.") || !String.IsNullOrEmpty(lblRazonSocial.Text))
         {
             //Si se obtiene un cliente se cargan las direcciones de entrega.
             cbxDireccionEntrega.DataSource    = NFacturas.CargarDireccionesEntrega(Convert.ToInt32(txtIdCliente.Text));
             cbxDireccionEntrega.ValueMember   = "Encabezado";
             cbxDireccionEntrega.DisplayMember = "Valores";
         }
     }
     else
     {
         //Elimina los datos si no se encuentran clientes.
         lblRazonSocial.Text            = "";
         cbxDireccionEntrega.DataSource = null;
     }
 }
Example #6
0
 //txtBuscar - Evento TextChanged - Muestra los datos que coincidan con la búsqueda en el "dgvFacturas".
 private void txtBuscar_TextChanged(object sender, EventArgs e)
 {
     if (this.txtBuscar.Text == String.Empty || this.cbxTipoBusqueda.Text == "")
     {
         Configuracion.NumeroPagina = 1;
         this.Mostrar();
         this.panelPaginacion.Show();
     }
     else
     {
         try
         {
             this.dgvFacturas.DataSource = NFacturas.Buscar(this.txtBuscar.Text, this.cbxTipoBusqueda.Text);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, String.Format(Configuracion.Titulo, "Error"),
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         this.panelPaginacion.Hide();
     }
 }
        //btnEmitir - Evento Click - Emite el comprobante de factura y registra la venta en la base de datos.
        private void btnEmitir_Click(object sender, EventArgs e)
        {
            string Respuesta = "";

            //Revisión de datos obligatorios
            if (String.IsNullOrWhiteSpace(txtIdCliente.Text))
            {
                new Configuracion().Mensaje("Debe ingresar un cliente para la factura.", "Dato Inválido",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.errorProvider.SetError(txtIdCliente, "Ingrese un cliente.");
            }
            else if (dgvProductos.RowCount == 0)
            {
                new Configuracion().Mensaje("Debe ingresar algún producto para facturar.", "Dato Inválido",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                //Envía los datos para que sean ingresados en la base de datos.
                Respuesta = NFacturas.Facturar(Convert.ToInt32(txtIdCliente.Text), new Numalet().Convertir(lblTotal.Text, true),
                                               Convert.ToDecimal(lblTotal.Text), Convert.ToDecimal(this.lblSubTotal.Text), Convert.ToDecimal(this.lblExento.Text),
                                               this.lblNombreImpuesto1.Text.Replace(this.lblNombreImpuesto1.Text.Substring(this.lblNombreImpuesto1
                                                                                                                           .Text.Length - 6), ""), Convert.ToDecimal(this.lblBaseImpuesto1.Text), Convert.ToDecimal(this.lblImpuesto1.Text),
                                               this.lblNombreImpuesto2.Text.Replace(this.lblNombreImpuesto2.Text.Substring(this.lblNombreImpuesto2
                                                                                                                           .Text.Length - 6), ""), Convert.ToDecimal(this.lblBaseImpuesto2.Text), Convert.ToDecimal(this.lblImpuesto2.Text),
                                               Convert.ToInt32(this.cbxCondicionPago.SelectedValue), cbxDireccionEntrega.Text, IdUsuario);

                //Obtiene el número de la factura nuevamente por seguridad
                int NumFactura = Convert.ToInt32(NFacturas.ObtenerNumFactura());
                if (Respuesta == "OK")
                {
                    //Ingresa cada uno de los productos cargados en el dgv
                    for (int Fila = 0; Fila < dgvProductos.Rows.Count; Fila++)
                    {
                        string Codigo   = Convert.ToString(dgvProductos.Rows[Fila].Cells["ColumnCodigo"].Value);
                        string Cantidad = Convert.ToString(dgvProductos.Rows[Fila].Cells["ColumnCantidad"].Value);
                        string Precio   = Convert.ToString(dgvProductos.Rows[Fila].Cells["ColumnPrecio"].Value);
                        string Importe  = Convert.ToString(dgvProductos.Rows[Fila].Cells["ColumnImporte"].Value);
                        string Impuesto = Convert.ToString(dgvProductos.Rows[Fila].Cells["ColumnImpuesto"].Value);
                        Respuesta = NFacturas.FacturarProductos(NumFactura, Convert.ToInt32(Codigo), Convert.ToDecimal(Cantidad),
                                                                Convert.ToDecimal(Precio), Convert.ToDecimal(Importe), Impuesto.Replace(Impuesto.Substring(Impuesto.Length - 5), ""));
                    }
                    if (Respuesta == "OK")
                    {
                        FrmImpresiones FormImpresiones = new FrmImpresiones(this);
                        FormImpresiones.NumFactura = NumFactura - 1;
                        FormImpresiones.ShowDialog();

                        //Envía formulario de operación exitosa y descarga el form.
                        new Configuracion().Mensaje(String.Format("La factura {0} ha sido generada exitosamente.",
                                                                  Convert.ToString(NumFactura)), "Factura Generada", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Dispose();
                    }
                    else
                    {
                        //Si ocurre un error muestra mensaje al usuario con la respuesta recibida.
                        new Configuracion().Mensaje(Respuesta, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    //Si ocurre un error muestra mensaje al usuario con la respuesta recibida.
                    new Configuracion().Mensaje(Respuesta, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            //Refresca las facturas en el control
            ctrlFacturas.Refrescar();
        }
Example #8
0
 //Método Mostrar - Muestra los registros actuales en el "dgvProveedores" y establece la cantidad de páginas.
 public void Mostrar()
 {
     this.dgvFacturas.DataSource   = NFacturas.Mostrar(Configuracion.RegistrosPorPagina, Configuracion.NumeroPagina);
     Configuracion.CantidadPaginas = NFacturas.Tamaño(Configuracion.RegistrosPorPagina);
     this.lblPaginacion.Text       = String.Format("Página {0} de {1}.", Configuracion.NumeroPagina, Configuracion.CantidadPaginas);
 }