Example #1
0
        public override String CreateFile(DataTable data)
        {
            String fileName     = FileSettings.fileName("PLDMoral");
            String fullFileName = System.Web.HttpContext.Current.Server.MapPath(FileSettings.filePath + fileName);

            FileSettings.CreateCSVFile(data, fullFileName,
                                       HttpContext.Current.Session["pldTipo"] != null && HttpContext.Current.Session["pldTipo"].ToString() != String.Empty ? HttpContext.Current.Session["pldTipo"].ToString() : String.Empty,
                                       HttpContext.Current.Session["pld"] != null && HttpContext.Current.Session["pld"].ToString() != String.Empty ? HttpContext.Current.Session["pld"].ToString() : String.Empty);
            return(fileName);
        }
Example #2
0
        protected void btnExportToExcel_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlTipoReporte.SelectedItem.Value != "0")
                {
                    if (cbFechas.Checked)
                    {
                        if (txtDel.Text != String.Empty && txtHasta.Text != String.Empty) //Bind gridview between dates
                        {
                            DateTime initialDate = DateTime.ParseExact(txtDel.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            DateTime finalDate   = DateTime.ParseExact(txtHasta.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            String   query       = ReportsOperations.GetQueryToExport(ddlTipoReporte.SelectedItem.Value, initialDate, finalDate);
                            if (txtFiltroNombre.Text.Trim() != String.Empty)
                            {
                                String finalQuery = String.Format("AND RazonSocial LIKE '%{0}%'", txtFiltroNombre.Text.Trim());
                                query = String.Format("{0} {1}", query, finalQuery); //concat like condition to where clause
                            }

                            DataTable        aux = new DataTable();
                            DataBaseSettings db  = new DataBaseSettings();
                            aux = db.GetDataTable(query);
                            string fileName = FileSettings.CreateCSVFile(aux, ddlTipoReporte.SelectedItem.Text + " " + DateTime.Now.ToString("yyyy-MM-dd"));
                            this.DownloadFile(fileName);
                        }
                        else
                        {
                            ShowMessage(true, "Favor de ingresar ambas fechas");
                        }
                    }
                    else //Bind gridview without dates
                    {
                        String query = ReportsOperations.GetQueryToExport(ddlTipoReporte.SelectedItem.Value);
                        if (txtFiltroNombre.Text.Trim() != String.Empty)
                        {
                            String finalQuery = String.Format("AND RazonSocial LIKE '%{0}%'", txtFiltroNombre.Text.Trim());
                            query = String.Format("{0} {1}", query, finalQuery); //concat like condition to where clause
                        }

                        DataTable        aux = new DataTable();
                        DataBaseSettings db  = new DataBaseSettings();
                        aux = db.GetDataTable(query);
                        string fileName = FileSettings.CreateCSVFile(aux, ddlTipoReporte.SelectedItem.Text + " " + DateTime.Now.ToString("yyyy-MM-dd"));
                        this.DownloadFile(fileName);
                    }
                }
            } catch (Exception ex)
            {
                throw ex;
            }
        }