Ejemplo n.º 1
0
        protected void bGenerar_Click(object sender, EventArgs e)
        {
            try
            {
                count        = 0;
                fechaInicial = tbFechaInicial.Text;
                fechaFinal   = tbFechaFinal.Text;
                if (!String.IsNullOrEmpty(fechaInicial) && !String.IsNullOrEmpty(fechaFinal))
                {
                    if ((Convert.ToInt32(fechaInicial.Replace(@"/", "")) < Convert.ToInt32(fechaFinal.Replace(@"/", ""))) || (fechaInicial == fechaFinal))
                    {
                        //fecha = calentario.SelectedDate.ToShortDateString();
                        fecha = fechaInicial;
                        //sucursal = ddlSucursal.SelectedValue;
                        //fechanom = calendario2.SelectedDate.ToShortDateString();
                        fechanom      = fechaFinal;
                        fechacreacion = System.DateTime.Now.ToString("yyyyMMddHHmm");


                        dir = System.AppDomain.CurrentDomain.BaseDirectory + @"reportes\docs\" + fechacreacion;
                        // fecha = Convert.ToString(DateTime.Now.Day) + "/" + Convert.ToString(DateTime.Now.Month) + "/" + Convert.ToString(DateTime.Now.Year);
                        // fecha = calentario.SelectedDate.ToShortDateString();
                        fecha = fechaInicial.Replace(@"/", "");
                        // sucursal = ddlSucursal.SelectedValue;
                        DB.Conectar();
                        DB.CrearComando(@"set dateformat ymd SELECT  count(Dat_General.idComprobante)
                                      FROM
                                        Dat_Archivos INNER JOIN
                                        Dat_General ON Dat_Archivos.IDEFAC = Dat_General.idComprobante INNER JOIN
                                        Cat_Emisor ON Dat_General.id_Emisor = Cat_Emisor.IDEEMI INNER JOIN
                                        Cat_Receptor ON Dat_General.id_Receptor = Cat_Receptor.IDEREC INNER JOIN
					                    Cat_Catalogo1_C ON Dat_General.codDoc = Cat_Catalogo1_C.codigo AND Cat_Catalogo1_C.tipo = 'Comprobante'
                                     WHERE
                                        Dat_General.fecha>=@fechaIni AND Dat_General.fecha<=@fechaFin and Dat_General.codDoc = '07'");
                        DB.AsignarParametroCadena("@fechaIni", fecha);
                        DB.AsignarParametroCadena("@fechaFin", fechanom + " 23:59:58");
                        DbDataReader DR = DB.EjecutarConsulta();
                        if (DR.Read())
                        {
                            count = Convert.ToInt32(DR[0]);
                        }
                        DB.Desconectar();
                        if (count > 0)
                        {
                            RepSucursal reporteSuc = new RepSucursal(dir, fecha, fechanom, "07", false, false, "", "");
                            if (reporteSuc.getError() != null)
                            {
                                Response.Redirect(@"docs\" + fechacreacion + ".xls");
                            }
                            else
                            {
                                Label2.Text = reporteSuc.getError();
                            }
                        }
                        else
                        {
                            Label2.Text = "No se han elaborado retenciones durante estas fechas";
                        }
                    }
                    else
                    {
                        Label2.Text = "Selecciona fecha inical y fecha final";
                    }
                }
                else
                {
                    Label2.Text = "Tienes que seleccionar ambas fechas.";
                }
            }
            catch (Exception ea) { Label2.Text = ea.Message; }
        }
Ejemplo n.º 2
0
        protected void bGenerar_Click(object sender, EventArgs e)
        {
            string estab      = "";
            string ptoEmision = "";

            string where = "";
            try
            {
                count = 0;
                if (!ddlReporte.SelectedValue.Equals("0"))
                {
                    if (!cFechaInicial.SelectedDate.ToString("yyyyMMdd").Equals("00010101") &&
                        !cFechaFinal.SelectedDate.ToString("yyyyMMdd").Equals("00010101")
                        )
                    {
                        if (cFechaInicial.SelectedDate <= cFechaFinal.SelectedDate)
                        {
                            fecha = cFechaInicial.SelectedDate.ToString("yyyyMMdd");
                            //sucursal = ddlSucursal.SelectedValue;
                            fechanom      = cFechaFinal.SelectedDate.ToString("yyyyMMdd");
                            fechacreacion = System.DateTime.Now.ToString("yyyyMMddHHmm");


                            dir = System.AppDomain.CurrentDomain.BaseDirectory + @"reportes\docs\" + fechacreacion;
                            // fecha = Convert.ToString(DateTime.Now.Day) + "/" + Convert.ToString(DateTime.Now.Month) + "/" + Convert.ToString(DateTime.Now.Year);
                            //fecha = calentario.SelectedDate.ToShortDateString();
                            // sucursal = ddlSucursal.SelectedValue;
                            where += " CONVERT(VARCHAR,GENERAL.FECHA,112) >= " + cFechaInicial.SelectedDate.ToString("yyyyMMdd") +
                                     " AND CONVERT(VARCHAR,GENERAL.FECHA,112) <=" + cFechaFinal.SelectedDate.ToString("yyyyMMdd") + " AND ";

                            if (ddlSucursal.SelectedValue != "0")
                            {
                                where += " GENERAL.estab='" + ddlSucursal.SelectedValue + "' AND ";
                            }
                            if (ddlPtoEmi.SelectedValue != "0")
                            {
                                where += " GENERAL.ptoemi='" + ddlPtoEmi.SelectedValue + "' AND ";
                            }
                            if (ddlEstado.SelectedValue != "0")
                            {
                                where += " (GENERAL.tipo +GENERAL.estado) =  '" + ddlEstado.SelectedValue + "' AND ";
                            }
                            if (ddlTipDoc.SelectedValue != "0")
                            {
                                where += " GENERAL.codDoc='" + ddlTipDoc.SelectedValue + "' AND ";
                            }

                            where = where.Substring(0, where.Length - 5);

                            if (ddlReporte.SelectedValue.Equals("General"))
                            {
                                DB.Conectar();
                                DB.CrearComando(@"SELECT  count(General.idComprobante)
                                            FROM            GENERAL INNER JOIN
                                                RECEPTOR ON GENERAL.id_Receptor = RECEPTOR.IDEREC
                                            WHERE " + where);

                                DbDataReader DR = DB.EjecutarConsulta();
                                if (DR.Read())
                                {
                                    count = Convert.ToInt32(DR[0]);
                                }
                                DB.Desconectar();
                                if (count > 0)
                                {
                                    RepSucursal reporteSuc = new RepSucursal(dir, fechanom, where, ddlReporte.SelectedValue);

                                    if (reporteSuc.getError() != null)
                                    {
                                        Response.Redirect(@"docs\" + fechacreacion + ddlReporte.SelectedValue + ".xls", false);
                                    }
                                    else
                                    {
                                        Label2.Text = reporteSuc.getError();
                                    }
                                }
                                else
                                {
                                    Label2.Text = "No hay registros de acuerdo a los criterios de busqueda";
                                }
                            }
                            else if (ddlReporte.SelectedValue.Equals("Retenciones"))
                            {
                                DB.Conectar();
                                DB.CrearComando(@"SELECT  count(General.idComprobante)
                                              FROM            RECEPTOR INNER JOIN
                                                GENERAL ON RECEPTOR.IDEREC = GENERAL.id_Receptor INNER JOIN
                                                TotalConImpuestos ON GENERAL.idComprobante = TotalConImpuestos.id_Comprobante
                                            WHERE " + where);

                                DbDataReader DR = DB.EjecutarConsulta();
                                if (DR.Read())
                                {
                                    count = Convert.ToInt32(DR[0]);
                                }
                                DB.Desconectar();
                                if (count > 0)
                                {
                                    RepSucursal reporteSuc = new RepSucursal(dir, fechanom, where, ddlReporte.SelectedValue);
                                    if (reporteSuc.getError() != null)
                                    {
                                        Response.Redirect(@"docs\" + fechacreacion + ddlReporte.SelectedValue + ".xls", false);
                                    }
                                    else
                                    {
                                        Label2.Text = reporteSuc.getError();
                                    }
                                }
                                else
                                {
                                    Label2.Text = "No hay registros de acuerdo a los criterios de busqueda";
                                }
                            }
                            else if (ddlReporte.SelectedValue.Equals("NA"))
                            {
                                DB.Conectar();
                                DB.CrearComando(@"SELECT  COUNT(General.idComprobante)
                                      FROM
                                        GENERAL
                                     WHERE " + where);

                                DbDataReader DR = DB.EjecutarConsulta();
                                if (DR.Read())
                                {
                                    count = Convert.ToInt32(DR[0]);
                                }
                                DB.Desconectar();
                                if (count > 0)
                                {
                                    RepSucursal reporteSuc = new RepSucursal(dir, fechanom, where, ddlReporte.SelectedValue);
                                    if (reporteSuc.getError() != null)
                                    {
                                        Response.Redirect(@"docs\" + fechacreacion + ddlReporte.SelectedValue + ".xls", false);
                                    }
                                    else
                                    {
                                        Label2.Text = reporteSuc.getError();
                                    }
                                }
                                else
                                {
                                    Label2.Text = "No hay registros de acuerdo a los criterios de busqueda";
                                }
                            }
                            else if (ddlReporte.SelectedValue.Equals("Email"))
                            {
                                DB.Conectar();
                                DB.CrearComando(@"SELECT  COUNT(GENERAL.idComprobante)
                                              FROM   emailEnvio inner join
			                                       general on GENERAL.idComprobante = emailEnvio.id_general INNER JOIN
			                                       RECEPTOR ON RECEPTOR.IDEREC = GENERAL.id_Receptor
                                             WHERE " + where);
                                DbDataReader DR = DB.EjecutarConsulta();
                                if (DR.Read())
                                {
                                    count = Convert.ToInt32(DR[0]);
                                }
                                DB.Desconectar();
                                if (count > 0)
                                {
                                    RepSucursal reporteSuc = new RepSucursal(dir, fechanom, where, ddlReporte.SelectedValue);
                                    if (reporteSuc.getError() != null)
                                    {
                                        Response.Redirect(@"docs\" + fechacreacion + ddlReporte.SelectedValue + ".xls", false);
                                    }
                                    else
                                    {
                                        Label2.Text = reporteSuc.getError();
                                    }
                                }
                                else
                                {
                                    Label2.Text = "No hay registros de acuerdo a los criterios de busqueda";
                                }
                            }
                        }
                        else
                        {
                            Label2.Text = "Selecciona fecha inical y fecha final";
                        }
                    }
                    else
                    {
                        Label2.Text = "Tienes que seleccionar ambas fechas.";
                    }
                }
                else
                {
                    Label2.Text = "Tienes que seleccionar un tipo de Reporte";
                }
            }
            catch (Exception ea) { Label2.Text = ea.Message; }
        }