//Export data file as per selected export type protected void GenerateReport_Click(object sender, EventArgs e) { try { lblMessage.Text = ""; ddlSource.Attributes.Add("onchange", "javascript:sourceChanged();"); lblMessage.Text = "Data exported successfully."; if (uploadedTemplatePath != "") { // Creating business layer object with user provided connection string BusinessDB businessDBObj = new BusinessDB(txtConString.Text.Trim()); // Verify connection string successfully connect database if (businessDBObj.IsValidConnection()) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=GroupDocs_GeneratedReport_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "_" + DateTime.Now.Millisecond.ToString() + "." + uploadedTemplateType); Response.Charset = ""; Response.ContentType = "Application/" + uploadedTemplateType; // if data source type is Table if (ddlSource.SelectedItem.Text == "Tables") { businessDBObj.GenerateReport_DBO(ddlTables.SelectedValue, uploadedTemplatePath.Replace("UploadTemplates", "GeneratedReports"), uploadedTemplatePath); Response.WriteFile(businessDBObj.ReportDestinationPath); } // if data source type is Views else if (ddlSource.SelectedItem.Text == "Views") { businessDBObj.GenerateReport_DBO(ddlViews.SelectedValue, uploadedTemplatePath.Replace("UploadTemplates", "GeneratedReports"), uploadedTemplatePath); Response.WriteFile(businessDBObj.ReportDestinationPath); } // if data source type is custom query else { businessDBObj.GenerateReport_Query(txtCustomQuery.Text.Trim(), uploadedTemplatePath.Replace("UploadTemplates", "GeneratedReports"), uploadedTemplatePath); Response.WriteFile(businessDBObj.ReportDestinationPath); } Response.End(); } } else { lblMessage.Text = "Please upload template file."; } } catch (Exception exc) { lblMessage.Text = exc.Message; } }
//Reload/Populate Tables & Views dropdownlist protected void TestConnectionAndLoad_Click(object sender, EventArgs e) { try { ddlSource.Attributes.Add("onchange", "javascript:sourceChanged();"); // Creating business layer object with user provided connection string BusinessDB businessDBObj = new BusinessDB(txtConString.Text.Trim()); // Verify connection string successfully connect database if (businessDBObj.IsValidConnection()) { // populate dataset with tables DataSet dsDBObjects = businessDBObj.getDBObjectNames(DBObjects.Tables); if (dsDBObjects != null) { ddlTables.DataSource = dsDBObjects; ddlTables.DataTextField = "name"; ddlTables.DataValueField = "name"; ddlTables.DataBind(); } // populate dataset with views dsDBObjects = null; dsDBObjects = businessDBObj.getDBObjectNames(DBObjects.Views); if (dsDBObjects != null) { ddlViews.DataSource = dsDBObjects; ddlViews.DataTextField = "name"; ddlViews.DataValueField = "name"; ddlViews.DataBind(); } lblMessage.Text = "Successfully connected to database."; } else { ddlTables.Items.Clear(); ddlViews.Items.Clear(); txtCustomQuery.Text = ""; } } catch (Exception exc) { lblMessage.Text = exc.Message; } }