Beispiel #1
0
        private DataTable BindData()
        {
            try {
                Report    report;
                GetReport getData;
                DataTable data = new DataTable();
                bool      flagOperacionesInusuales = false;

                if (cnbvOptions.Visible)
                {
                    otherOptions.Visible = false;
                }
                else if (otherOptions.Visible)
                {
                    cnbvOptions.Visible = false;
                }
                String reportTypeValue   = reportsType.SelectedValue;
                String cnbvOptionsValue  = cnbvOptions.SelectedValue;
                String otherOptionsValue = otherOptions.SelectedValue;

                lblReport.Text = reportsType.SelectedItem.Text;

                //if (reportTypeValue == "cnbv")
                //{
                //    if (cnbvOptions.SelectedItem.Value == "operacionesInusuales") flagOperacionesInusuales = true;
                //}

                //lblReport.Text += " - " + cnbvOptions.SelectedItem.Text;

                //This code implements Strategy and factory Pattern
                report  = GetObject(reportTypeValue, cnbvOptionsValue, otherOptionsValue);
                getData = new GetReport(report);

                DateTime initialDate = txtDe != null && txtDe.Text != String.Empty ? DateTime.ParseExact(txtDe.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now;
                DateTime finalDate   = txtHasta != null && txtHasta.Text != String.Empty ? DateTime.ParseExact(txtHasta.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now;

                data = getData.GetData(initialDate, finalDate);
                Session["gvData"] = data;

                //if (flagOperacionesInusuales)
                //{
                //    gvReport.Columns[0].Visible = true;
                //}
                //else
                //{
                //    gvReport.Columns[0].Visible = false;
                //}

                if (reportTypeValue == "pld" && (otherOptions.SelectedItem.Value == "personaFisica" || otherOptions.SelectedItem.Value == "personaMoral"))
                {
                    gvReport.DataSource = FilterPLD(data, rblPLD.SelectedItem.Value);
                }
                else
                {
                    gvReport.DataSource = data;
                }

                gvReport.DataBind();
                if (data.Rows.Count > 0)
                {
                    btnDownloadFile.Visible = true;
                }
                else
                {
                }

                return(data);
            } catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        protected void btnDownloadFile_Click(object sender, EventArgs e)
        {
            try
            {
                String    reportsValue      = reportsType.SelectedItem.Value;
                String    optionsCNBVValue  = cnbvOptions.SelectedItem != null ? cnbvOptions.SelectedItem.Value : String.Empty;
                String    optionsOtherValue = otherOptions.SelectedItem != null ? otherOptions.SelectedItem.Value : String.Empty;
                Report    report;
                GetReport getData;
                report  = GetObject(reportsValue, optionsCNBVValue, optionsOtherValue);
                getData = new GetReport(report);

                /*
                 * DateTime initialDate = txtDe != null && txtDe.Text != String.Empty ? DateTime.ParseExact(txtDe.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now;
                 * DateTime finalDate = txtHasta != null && txtHasta.Text != String.Empty ? DateTime.ParseExact(txtHasta.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now;
                 *
                 * DataTable data = getData.GetData(initialDate, finalDate);
                 */
                DataTable data = Session["gvData"] as DataTable;

                DataTable aux = data.Clone();// get the same structure
                foreach (DataColumn column in aux.Columns)
                {
                    if (column.DataType == typeof(String))
                    {
                        column.MaxLength = 1000;
                    }
                    column.AllowDBNull = true;
                    column.Unique      = false;
                }

                //if (reportsValue == "cnbv" && cnbvOptions.SelectedItem.Value == "operacionesInusuales") //get only checkboxes checked
                //{
                //    for (int i = 0; i < gvReport.Rows.Count; i++)
                //    {
                //        CheckBox chk = (CheckBox)gvReport.Rows[i].FindControl("chkSelect");
                //        if (chk != null && chk.Checked)
                //        {
                //            aux.Rows.Add(data.Rows[i].ItemArray);
                //        }
                //    }

                //    String fileName = getData.GenerateFile(aux);
                //    DownloadFile(fileName);
                //}
                //else
                //{
                Session["pldTipo"] = rblPLD.SelectedItem != null ? rblPLD.SelectedItem.Text : String.Empty;
                Session["pld"]     = reportsValue == "pld" && otherOptions.SelectedValue != null ? otherOptions.SelectedItem.Text : String.Empty;

                if (reportsValue == "pld" && otherOptions.SelectedItem != null && (otherOptions.SelectedItem.Value == "personaFisica" || otherOptions.SelectedItem.Value == "personaMoral"))
                {
                    String fileName = getData.GenerateFile(FilterPLD(data, rblPLD.SelectedItem.Value));
                    DownloadFile(fileName);
                }
                else
                {
                    String fileName = getData.GenerateFile(data);
                    DownloadFile(fileName);
                }

                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }