// Bind Reports Data #region [Bind Reports Data] public DataSet BL_BindReports(EWA_CommonReports objEWA) { try { DataSet ds = new DataSet(); DL_CommonReports objDL = new DL_CommonReports(); ds = objDL.DL_BindReports(objEWA); return(ds); } catch (Exception exp) { throw exp; } }
// Bind Reports Data #region [Bind Reports Data] public DataSet DL_BindReports(EWA_CommonReports objEWA) { DataSet ds = new DataSet(); try { prmList = new string[4]; prmList[0] = "@ViewName"; prmList[1] = objEWA.ViewName; prmList[2] = "@OrgId"; prmList[3] = Convert.ToString(objEWA.OrgId); ds = ObjHelper.FillControl(prmList, "SP_GetReportData"); return(ds); } catch (Exception ex) { throw ex; } }
//Get Report #region [Get Report] private void GetReport() { try { switch (Request.QueryString["ReportName"].ToString()) { case "rptHandicapEmpList": { EWA_CommonReports objEWA = new EWA_CommonReports(); BL_CommonReports objBL = new BL_CommonReports(); objEWA.ViewName = "vwEmpHandicapList"; objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); ReportData = objBL.BL_BindReports(objEWA); if (ReportData.Tables[0].Rows.Count == 0) { msgBox.ShowMessage("No Records Found!", "Information", UserControls.MessageBox.MessageStyle.Information); } else { HttpContext.Current.Session.Remove("ReportData"); HttpContext.Current.Session.Add("ReportData", ReportData); //Response.Redirect("~/Forms/Reports/ReportViewer.aspx?ReportName=rptHandicapEmpList"); string url = "ReportViewer.aspx?ReportName=rptHandicapEmpList"; ScriptManager.RegisterStartupScript(this, this.GetType(), "reportScript", "ReportOpen('" + url + "');", true); } break; } case "rptHandicapStudList": { EWA_CommonReports objEWA = new EWA_CommonReports(); BL_CommonReports objBL = new BL_CommonReports(); objEWA.ViewName = "vwHandicapStudList"; objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); ReportData = objBL.BL_BindReports(objEWA); if (ReportData.Tables[0].Rows.Count == 0) { msgBox.ShowMessage("No Records Found!", "Information", UserControls.MessageBox.MessageStyle.Information); } else { HttpContext.Current.Session.Remove("ReportData"); HttpContext.Current.Session.Add("ReportData", ReportData); //Response.Redirect("~/Forms/Reports/ReportViewer.aspx?ReportName=rptHandicapEmpList"); string url = "ReportViewer.aspx?ReportName=rptHandicapStudList"; ScriptManager.RegisterStartupScript(this, this.GetType(), "reportScript", "ReportOpen('" + url + "');", true); } break; } case "rptSportsStudList": { EWA_CommonReports objEWA = new EWA_CommonReports(); BL_CommonReports objBL = new BL_CommonReports(); objEWA.ViewName = "vwSportsStudList"; objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); ReportData = objBL.BL_BindReports(objEWA); if (ReportData.Tables[0].Rows.Count == 0) { msgBox.ShowMessage("No Records Found!", "Information", UserControls.MessageBox.MessageStyle.Information); } else { HttpContext.Current.Session.Remove("ReportData"); HttpContext.Current.Session.Add("ReportData", ReportData); //Response.Redirect("~/Forms/Reports/ReportViewer.aspx?ReportName=rptHandicapEmpList"); string url = "ReportViewer.aspx?ReportName=rptSportsStudList"; ScriptManager.RegisterStartupScript(this, this.GetType(), "reportScript", "ReportOpen('" + url + "');", true); } break; } case "rptGovernmentSchemes": { EWA_CommonReports objEWA = new EWA_CommonReports(); BL_CommonReports objBL = new BL_CommonReports(); objEWA.ViewName = "vwGovernmentSchemes"; objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); ReportData = objBL.BL_BindReports(objEWA); if (ReportData.Tables[0].Rows.Count == 0) { msgBox.ShowMessage("No Records Found!", "Information", UserControls.MessageBox.MessageStyle.Information); } else { HttpContext.Current.Session.Remove("ReportData"); HttpContext.Current.Session.Add("ReportData", ReportData); //Response.Redirect("~/Forms/Reports/ReportViewer.aspx?ReportName=rptHandicapEmpList"); string url = "ReportViewer.aspx?ReportName=rptGovernmentSchemes"; ScriptManager.RegisterStartupScript(this, this.GetType(), "reportScript", "ReportOpen('" + url + "');", true); } break; } default: break; } } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
private void GetReportData() { DataSet dsMaster = new DataSet(); EWA_CommonReports objEWA = new EWA_CommonReports(); BL_CommonReports objBL = new BL_CommonReports(); string RecSelFormula = string.Empty; objEWA.ViewName = "vwReportHeader"; objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); dsMaster = objBL.BL_BindReportsHeader(objEWA); if (Request.QueryString["ReportName"] != null) { string RptName = string.Empty; RptName = Request.QueryString["ReportName"].ToString(); switch (RptName) { case "rptHandicapEmpList": { ReportObj = new CMS.Forms.Reports.crHandicapEmpList(); dataset = new DataSet(); dataset = (DataSet)HttpContext.Current.Session["ReportData"]; ReportObj.SetDataSource(dataset.Tables[0]); ReportObj.Subreports["crReportHeader.rpt"].SetDataSource(dsMaster); ReportObj.Subreports["crReportHeader.rpt"].RecordSelectionFormula = "{vwReportHeader.OrganizationId}=" + HttpContext.Current.Session["OrgId"].ToString(); break; } case "rptHandicapStudList": { ReportObj = new CMS.Forms.Reports.crHandicapStudList(); dataset = new DataSet(); dataset = (DataSet)HttpContext.Current.Session["ReportData"]; ReportObj.SetDataSource(dataset.Tables[0]); ReportObj.Subreports["crReportHeader.rpt"].SetDataSource(dsMaster); ReportObj.Subreports["crReportHeader.rpt"].RecordSelectionFormula = "{vwReportHeader.OrganizationId}=" + HttpContext.Current.Session["OrgId"].ToString(); break; } case "rptSportsStudList": { ReportObj = new CMS.Forms.Reports.crSportsStudList(); dataset = new DataSet(); dataset = (DataSet)HttpContext.Current.Session["ReportData"]; ReportObj.SetDataSource(dataset.Tables[0]); ReportObj.Subreports["crReportHeader.rpt"].SetDataSource(dsMaster); ReportObj.Subreports["crReportHeader.rpt"].RecordSelectionFormula = "{vwReportHeader.OrganizationId}=" + HttpContext.Current.Session["OrgId"].ToString(); break; } case "rptGovernmentSchemes": { ReportObj = new CMS.Forms.Reports.crGovernmentScheme(); dataset = new DataSet(); dataset = (DataSet)HttpContext.Current.Session["ReportData"]; ReportObj.SetDataSource(dataset.Tables[0]); ReportObj.Subreports["crReportHeader.rpt"].SetDataSource(dsMaster); ReportObj.Subreports["crReportHeader.rpt"].RecordSelectionFormula = "{vwReportHeader.OrganizationId}=" + HttpContext.Current.Session["OrgId"].ToString(); break; } case "crStudentList": { ReportObj = new CMS.Forms.Reports.crStudentList(); dataset = new DataSet(); dataset = (DataSet)HttpContext.Current.Session["ReportData"]; ReportObj.SetDataSource(dataset.Tables[0]); ReportObj.Subreports["crReportHeader.rpt"].SetDataSource(dsMaster); ReportObj.Subreports["crReportHeader.rpt"].RecordSelectionFormula = "{vwReportHeader.OrganizationId}=" + HttpContext.Current.Session["OrgId"].ToString(); break; } case "crStudentAdmissionList": { ReportObj = new CMS.Forms.Reports.crStudentAdmissionList(); dataset = new DataSet(); dataset = (DataSet)HttpContext.Current.Session["ReportData"]; ReportObj.SetDataSource(dataset.Tables[0]); ReportObj.Subreports["crReportHeader.rpt"].SetDataSource(dsMaster); ReportObj.Subreports["crReportHeader.rpt"].RecordSelectionFormula = "{vwReportHeader.OrganizationId}=" + HttpContext.Current.Session["OrgId"].ToString(); break; } case "crPurchaseOrder": { ReportObj = new CMS.Forms.Reports.crPurchaseOrder(); dataset = new DataSet(); dataset = (DataSet)HttpContext.Current.Session["ReportData"]; ReportObj.SetDataSource(dataset.Tables[0]); ReportObj.Subreports["crReportHeader.rpt"].SetDataSource(dsMaster); ReportObj.Subreports["crReportHeader.rpt"].RecordSelectionFormula = "{vwReportHeader.OrganizationId}=" + HttpContext.Current.Session["OrgId"].ToString(); break; } default: break; } if (null != ReportObj) { crTableLogOnInfo = new TableLogOnInfo(); crConnectionInfo = new ConnectionInfo(); //Crystal Report Properties // CrystalDecisions.CrystalReports.Engine.Table crTable; crConnectionInfo.ServerName = DBServerName; crConnectionInfo.DatabaseName = Database; crConnectionInfo.UserID = DBUserId; crConnectionInfo.Password = DBPassword; crDatabase = ReportObj.Database; crTables = crDatabase.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table crTable1 in crTables) { crTableLogOnInfo = crTable1.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; crTable1.ApplyLogOnInfo(crTableLogOnInfo); } //'Set the sections collection with report sections crSections = ReportObj.ReportDefinition.Sections; //'Loop through each section and find all the report objects //'Loop through all the report objects to find all subreport objects, then set the //'logoninfo to the subreport foreach (Section crSection in crSections) { crReportObjects = crSection.ReportObjects; foreach (ReportObject crReportObject in crReportObjects) { if (crReportObject.Kind == ReportObjectKind.SubreportObject) { //'If you find a subreport, typecast the reportobject to a subreport object crSubreportObject = (SubreportObject)crReportObject; //'Open the subreport subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName); crDatabase = subRepDoc.Database; crTables = crDatabase.Tables; //'Loop through each table and set the connection info //'Pass the connection info to the logoninfo object then apply the //'logoninfo to the subreport foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables) { crConnectionInfo.ServerName = DBServerName; crConnectionInfo.DatabaseName = Database; crConnectionInfo.UserID = DBUserId; crConnectionInfo.Password = DBPassword; crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; crTable.ApplyLogOnInfo(crTableLogOnInfo); crTable.Location = crTable.Name; } } } } CrystalReportViewer1.SeparatePages = true; CrystalReportViewer1.Width = 780; CrystalReportViewer1.Height = 600; //ReportObj.DataDefinition.FormulaFields["CollegeName"].Text = "'" + CommonConstants.CollegeName + "'"; //ReportObj.DataDefinition.FormulaFields["CollegeAddress"].Text = "'" + CommonConstants.CollgeAddress + "'"; if (RecSelFormula != string.Empty) { ReportObj.RecordSelectionFormula = RecSelFormula; } CrystalReportViewer1.RefreshReport(); CrystalReportViewer1.ReportSource = ReportObj; CrystalReportViewer1.RefreshReport(); //ReportObj.PrintToPrinter(1, false, 0, 0); Session["ReportFormat"] = "PDF"; if (Session["ReportFormat"] != null) { if (Session["ReportFormat"].ToString() == "PDF") { System.IO.MemoryStream oStream; oStream = (System.IO.MemoryStream) ReportObj.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/pdf"; Response.BinaryWrite(oStream.ToArray()); Response.End(); } } } } }