Пример #1
0
        private void ejecutarReporte_Click(object sender, EventArgs e)
        {
            // AAAA / MM / DD
            string dia = "";
            string mes = "";
            string ano = "";

            string[] preformato;
            cajaReporte.Text = "";

            int    tipoFecha = 0; // 1 = 1 Fecha    2 = 2 Fechas   3 = General
            string fecha1    = "";
            string fecha2    = "";

            if (check1fecha.Checked)
            {
                tipoFecha = 1;
            }
            if (check2fechas.Checked)
            {
                tipoFecha = 2;
            }
            if (checkGeneral.Checked)
            {
                tipoFecha = 3;
            }

            switch (tipoFecha)
            {
            case 1:
                fecha1     = cajafecha1.Text;
                preformato = cajafecha1.Text.Split('/');
                dia        = preformato[0];
                mes        = preformato[1];
                ano        = preformato[2];
                fecha1     = ano + "-" + mes + "-" + dia;
                fecha2     = fecha1;
                break;

            case 2:
                fecha1     = cajafecha21.Text;
                preformato = cajafecha21.Text.Split('/');
                dia        = preformato[0];
                mes        = preformato[1];
                ano        = preformato[2];
                fecha1     = ano + "-" + mes + "-" + dia;

                fecha2     = cajafecha22.Text;
                preformato = cajafecha22.Text.Split('/');
                dia        = preformato[0];
                mes        = preformato[1];
                ano        = preformato[2];
                fecha2     = ano + "-" + mes + "-" + dia;
                break;

            case 3:
                fecha1 = "1900-01-01";
                fecha2 = "2090-12-30";
                break;
            }

            grupoCajaReporte.Visible = true;
            copyClipBoard.Visible    = true;
            button1.Visible          = true; // Boton de grabar


            #region Reporte de Ventas Articulo
            if (rventas.Checked)
            {
                cajaReporte.Text = "Tipo de Reporte: Ventas por Articulo." + Environment.NewLine + Environment.NewLine;

                if (fecha1 == "1900-01-01")
                {
                    cajaReporte.Text += "Reporte General (Todo el Tiempo)." + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    if (fecha1 != fecha2)
                    {
                        cajaReporte.Text += "Reporte entre las Fechas: " + fecha1 + " y " + fecha2 + "." + Environment.NewLine + Environment.NewLine;
                    }
                    else
                    {
                        cajaReporte.Text += "Reporte de la fecha: " + fecha1 + "." + Environment.NewLine + Environment.NewLine;
                    }
                }

                cajaReporte.Text += "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                sql.open();
                List <datosReporte> datos = sql.rep_ventasPorArticulo(fecha1, fecha2);

                if (datos != null)
                {
                    float totalGanancia  = (float)0.0;
                    int   totalArticulos = 0;

                    foreach (datosReporte dat in datos)
                    {
                        float precioTotal = float.Parse(dat.cantidad) * float.Parse(dat.precioArticulo);


                        if (dat.nombreArticulo.Length < 9)
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\t\tCant. " + dat.cantidad + "\t\t" + String.Format("{0:C}", precioTotal) + Environment.NewLine;
                        }
                        else
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\tCant. " + dat.cantidad + "\t\t" + String.Format("{0:C}", precioTotal) + Environment.NewLine;
                        }

                        totalGanancia += precioTotal;

                        totalArticulos += int.Parse(dat.cantidad);
                    }

                    cajaReporte.Text += Environment.NewLine + "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                    cajaReporte.Text += Environment.NewLine + "Total de Articulos Vendidos ----->  " + totalArticulos.ToString() + Environment.NewLine;
                    cajaReporte.Text += Environment.NewLine + "Ganancias Total de Ventas -------> " + String.Format("{0:C}", totalGanancia);
                }
                else
                {
                    cajaReporte.Text = "No existen datos para este reporte.";
                }
                sql.close();
            }
            #endregion

            #region Reporte de Devoluciones (Clientes)
            if (rdevoluciones.Checked)
            {
                cajaReporte.Text = "Tipo de Reporte: Devoluciones de Clientes." + Environment.NewLine + Environment.NewLine;

                if (fecha1 == "1900-01-01")
                {
                    cajaReporte.Text += "Reporte General (Todo el Tiempo)." + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    if (fecha1 != fecha2)
                    {
                        cajaReporte.Text += "Reporte entre las Fechas: " + fecha1 + " y " + fecha2 + "." + Environment.NewLine + Environment.NewLine;
                    }
                    else
                    {
                        cajaReporte.Text += "Reporte de la fecha: " + fecha1 + "." + Environment.NewLine + Environment.NewLine;
                    }
                }

                cajaReporte.Text += "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                sql.open();
                List <datosReporte> datos = sql.rep_ComprasPorProvedor(fecha1, fecha2, "Cliente");

                if (datos != null)
                {
                    float totalGanancia  = (float)0.0;
                    int   totalArticulos = 0;

                    foreach (datosReporte dat in datos)
                    {
                        float precioTotal = float.Parse(dat.cantidad) * float.Parse(dat.precioArticulo);

                        if (dat.nombreArticulo.Length < 9)
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\t\tCant. " + dat.cantidad + "\t\t" + String.Format("{0:C}", precioTotal) + Environment.NewLine;
                        }
                        else
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\tCant. " + dat.cantidad + "\t\t" + String.Format("{0:C}", precioTotal) + Environment.NewLine;
                        }

                        totalGanancia += precioTotal;

                        totalArticulos += int.Parse(dat.cantidad);
                    }

                    cajaReporte.Text += Environment.NewLine + "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                    cajaReporte.Text += Environment.NewLine + "Total de Articulos Devueltos --------->  " + totalArticulos.ToString() + Environment.NewLine;
                    cajaReporte.Text += Environment.NewLine + "Total de Pago de Devoluciones --------> " + String.Format("{0:C}", totalGanancia);
                }
                else
                {
                    cajaReporte.Text = "No existen datos para este reporte.";
                }
                sql.close();
            }
            #endregion

            #region Reporte de Compras (Provedor Especifico)
            if (rcomprasProvedor.Checked)
            {
                cajaReporte.Text = "Tipo de Reporte: Compras a un Provedor (" + comboProvedor.SelectedItem.ToString() + ")" + Environment.NewLine + Environment.NewLine;

                if (fecha1 == "1900-01-01")
                {
                    cajaReporte.Text += "Reporte General (Todo el Tiempo)." + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    if (fecha1 != fecha2)
                    {
                        cajaReporte.Text += "Reporte entre las Fechas: " + fecha1 + " y " + fecha2 + "." + Environment.NewLine + Environment.NewLine;
                    }
                    else
                    {
                        cajaReporte.Text += "Reporte de la fecha: " + fecha1 + "." + Environment.NewLine + Environment.NewLine;
                    }
                }

                cajaReporte.Text += "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                sql.open();
                List <datosReporte> datos = sql.rep_ComprasPorProvedor(fecha1, fecha2, comboProvedor.SelectedItem.ToString());

                if (datos != null)
                {
                    float totalGanancia  = (float)0.0;
                    int   totalArticulos = 0;

                    foreach (datosReporte dat in datos)
                    {
                        float precioTotal = float.Parse(dat.cantidad) * float.Parse(dat.precioArticulo);

                        if (dat.nombreArticulo.Length < 9)
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\t\tCant. " + dat.cantidad + "\t\t" + String.Format("{0:C}", precioTotal) + Environment.NewLine;
                        }
                        else
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\tCant. " + dat.cantidad + "\t\t" + String.Format("{0:C}", precioTotal) + Environment.NewLine;
                        }

                        totalGanancia += precioTotal;

                        totalArticulos += int.Parse(dat.cantidad);
                    }

                    cajaReporte.Text += Environment.NewLine + "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                    cajaReporte.Text += Environment.NewLine + "Total de Articulos Comprados --------->  " + totalArticulos.ToString() + Environment.NewLine;
                    cajaReporte.Text += Environment.NewLine + "Total de Pago por Compras ------------> " + String.Format("{0:C}", totalGanancia);
                }
                else
                {
                    cajaReporte.Text = "No existen datos para este reporte.";
                }
                sql.close();
            }
            #endregion

            #region Reporte de Articulos (Cantidades)
            if (rArticulos.Checked)
            {
                cajaReporte.Text = "Tipo de Reporte: Existencias de Articulos." + Environment.NewLine + Environment.NewLine;

                sql.open();
                List <datosReporte> datos = sql.rep_articulos();

                if (datos != null)
                {
                    float totalGanancia  = (float)0.0;
                    int   totalArticulos = 0;

                    foreach (datosReporte dat in datos)
                    {
                        float precioTotal = float.Parse(dat.cantidad) * float.Parse(dat.precioArticulo);


                        if (dat.nombreArticulo.Length < 9)
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\t\tCant. " + dat.cantidad;
                        }
                        else
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\tCant. " + dat.cantidad;
                        }


                        if (int.Parse(dat.cantidad) <= 0)
                        {
                            cajaReporte.Text += " (Agotado)";
                        }

                        cajaReporte.Text += Environment.NewLine;
                        totalGanancia    += precioTotal;
                        totalArticulos   += int.Parse(dat.cantidad);
                    }
                }
                else
                {
                    cajaReporte.Text = "No existen datos para este reporte.";
                }
                sql.close();
            }
            #endregion

            #region Reporte de Compras (Todos los Provedores)
            if (rprovedoresGen.Checked)
            {
                cajaReporte.Text = "Tipo de Reporte: Compras a Provedores" + Environment.NewLine + Environment.NewLine;

                if (fecha1 == "1900-01-01")
                {
                    cajaReporte.Text += "Reporte General (Todo el Tiempo)." + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    if (fecha1 != fecha2)
                    {
                        cajaReporte.Text += "Reporte entre las Fechas: " + fecha1 + " y " + fecha2 + "." + Environment.NewLine + Environment.NewLine;
                    }
                    else
                    {
                        cajaReporte.Text += "Reporte de la fecha: " + fecha1 + "." + Environment.NewLine + Environment.NewLine;
                    }
                }

                cajaReporte.Text += "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                sql.open();
                List <datosReporte> datos = sql.rep_ComprasPorProvedorGenerales(fecha1, fecha2);

                if (datos != null)
                {
                    float totalGanancia  = (float)0.0;
                    int   totalArticulos = 0;

                    foreach (datosReporte dat in datos)
                    {
                        float precioTotal = float.Parse(dat.cantidad) * float.Parse(dat.precioArticulo);

                        if (dat.nombreArticulo.Length < 9)
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\t\tCant. " + dat.cantidad + "\t\t" + String.Format("{0:C}", precioTotal) + Environment.NewLine;
                        }
                        else
                        {
                            cajaReporte.Text += dat.nombreArticulo + "\tCant. " + dat.cantidad + "\t\t" + String.Format("{0:C}", precioTotal) + Environment.NewLine;
                        }

                        totalGanancia += precioTotal;

                        totalArticulos += int.Parse(dat.cantidad);
                    }

                    cajaReporte.Text += Environment.NewLine + "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                    cajaReporte.Text += Environment.NewLine + "Total de Articulos Comprados --------->  " + totalArticulos.ToString() + Environment.NewLine;
                    cajaReporte.Text += Environment.NewLine + "Total de Pago por Compras ------------> " + String.Format("{0:C}", totalGanancia);
                }
                else
                {
                    cajaReporte.Text = "No existen datos para este reporte.";
                }
                sql.close();
            }
            #endregion

            #region Reporte de Entradas y Salidas
            if (rasistencia.Checked)
            {
                cajaReporte.Text = "Tipo de Reporte: Entradas y Salidas de " + comboUsuarios.SelectedItem.ToString() + Environment.NewLine + Environment.NewLine;

                if (fecha1 == "1900-01-01")
                {
                    cajaReporte.Text += "Reporte General (Todo el Tiempo)." + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    if (fecha1 != fecha2)
                    {
                        cajaReporte.Text += "Reporte entre las Fechas: " + fecha1 + " y " + fecha2 + "." + Environment.NewLine + Environment.NewLine;
                    }
                    else
                    {
                        cajaReporte.Text += "Reporte de la fecha: " + fecha1 + "." + Environment.NewLine + Environment.NewLine;
                    }
                }

                cajaReporte.Text += "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;



                sql.open();
                List <registroEntradasSalidas> datos = sql.rep_entradasysalidas(fecha1, fecha2, comboUsuarios.SelectedItem.ToString());

                if (datos != null)
                {
                    foreach (registroEntradasSalidas dat in datos)
                    {
                        if (dat.tipo == 1)
                        {
                            cajaReporte.Text += "Entrada:\t";
                        }
                        else
                        {
                            cajaReporte.Text += "Salida: \t";
                        }

                        cajaReporte.Text += dat.hora + "  ----- " + dat.fecha + Environment.NewLine;
                    }

                    cajaReporte.Text += Environment.NewLine + "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    cajaReporte.Text = "No existen datos para este reporte.";
                }
            }
            #endregion

            #region Reporte de Facturas
            if (rFacturas.Checked)
            {
                cajaReporte.Text = "Tipo de Reporte: Facturas." + Environment.NewLine + Environment.NewLine;

                if (fecha1 == "1900-01-01")
                {
                    cajaReporte.Text += "Reporte General (Todo el Tiempo)." + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    if (fecha1 != fecha2)
                    {
                        cajaReporte.Text += "Reporte entre las Fechas: " + fecha1 + " y " + fecha2 + "." + Environment.NewLine + Environment.NewLine;
                    }
                    else
                    {
                        cajaReporte.Text += "Reporte de la fecha: " + fecha1 + "." + Environment.NewLine + Environment.NewLine;
                    }
                }

                cajaReporte.Text += "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;

                sql.open();
                List <factura> datos = sql.rep_facturas(fecha1, fecha2);

                if (datos != null)
                {
                    foreach (factura factura in datos)
                    {
                        string [] fechaEstilo = factura.fecha.Split(' ');
                        factura.fecha = fechaEstilo[0];

                        cajaReporte.Text += "Cliente: " + factura.cliente + " [ " + factura.fecha + " ] " + Environment.NewLine + "Importe: " + string.Format("{0:C}", float.Parse(factura.importe)) + Environment.NewLine + Environment.NewLine;
                    }

                    cajaReporte.Text += Environment.NewLine + "----------------------------------------------------------------------------------" + Environment.NewLine + Environment.NewLine;
                }
                else
                {
                    cajaReporte.Text = "No existen datos para este reporte.";
                }
                sql.close();
            }
            #endregion

            reiniciarReporte();
            copyClipBoard.Focus();
            ejecutarReporte.Visible = false;
            sql.close();
        }