/// <summary> /// 生成报表文件 /// </summary> /// <param name="designView">报表设计数据</param> /// <param name="formatFile">报表格式模板</param> /// <returns>报表文件路径</returns> public string Generate(ReportDesignView designView, string formatFile, string reportFile) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(formatFile); StringBuilder sbRpt = new StringBuilder(); sbRpt.Append(xmlDoc.SelectSingleNode("//MainBody").FirstChild.Value); designView.DataSourceColumns.Clear(); ReportViewFacade rptFacade = new ReportViewFacade(this.DataProvider); RptViewDataSourceColumn[] objColumns = rptFacade.GetRptViewDataSourceColumnByDataSourceId(Convert.ToInt32(designView.DesignMain.DataSourceID)); for (int i = 0; objColumns != null && i < objColumns.Length; i++) { designView.DataSourceColumns.Add(objColumns[i].ColumnName, objColumns[i]); } sbRpt.Replace("<%ReportID%>", System.Guid.NewGuid().ToString().ToLower()); string strTable = ""; string strChart = ""; decimal iRptHeight = 0; decimal iRptWidth = 0; decimal iTableHeight = 0; if (designView.DesignMain.DisplayType == ReportDisplayType.Grid || designView.DesignMain.DisplayType == ReportDisplayType.GridChart) { strTable = this.BuildTable(designView, xmlDoc); iRptHeight = ((designView.GridGroups == null ? 0 : designView.GridGroups.Length) + 2) * 0.5M; foreach (decimal dWidth in dicColumnWidth.Values) { iRptWidth += dWidth; } iTableHeight = iRptHeight; } if (designView.DesignMain.DisplayType == ReportDisplayType.Chart || designView.DesignMain.DisplayType == ReportDisplayType.GridChart) { strChart = this.BuildChart(designView, xmlDoc); iRptHeight = iRptHeight + 9; if (iRptWidth == 0) { iRptWidth = 22; } } string strExtendText = BuildExtendText(designView, xmlDoc); strTable = strTable.Replace("<%Top%>", dRptExtendTextHeight.ToString()); strChart = strChart.Replace("<%Top%>", (iTableHeight + dRptExtendTextHeight).ToString()); iRptHeight = iRptHeight + dRptExtendTextHeight; sbRpt.Replace("<%ExtendText%>", strExtendText); sbRpt.Replace("<%Table%>", strTable); sbRpt.Replace("<%Chart%>", strChart); sbRpt.Replace("<%ReportHeight%>", iRptHeight.ToString() + "cm"); sbRpt.Replace("<%ReportWidth%>", iRptWidth.ToString() + "cm"); sbRpt.Replace("<%DataSet%>", this.BuildDataSet(designView, xmlDoc)); string strFileName = reportFile; System.IO.StreamWriter writer = new System.IO.StreamWriter(strFileName, false, Encoding.UTF8); writer.Write(sbRpt.ToString()); writer.Close(); return(strFileName); }
private void cmdPublish_ServerClick(object sender, EventArgs e) { if (ValidateInput() == false) { return; } UpdateReportDesignView(); this.SaveDesignView(designView); string strFileName = "", strRptFile = ""; if (string.IsNullOrEmpty(this.designView.DesignMain.ReportFileName) == true) { strFileName = this.designView.UploadFileName; strFileName = strFileName.Substring(strFileName.LastIndexOf("\\") + 1); strFileName = Server.MapPath("../ReportFiles") + "\\" + strFileName; strRptFile = strFileName.Substring(Server.MapPath("../").Length); this.designView.DesignMain.ReportFileName = strRptFile; } ReportViewFacade rptFacade = new ReportViewFacade(this.DataProvider); ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider) this.DataProvider).PersistBroker.OpenConnection(); this.DataProvider.BeginTransaction(); try { rptFacade.PublishUploadedReportFile(this.designView, strFileName, this.GetUserCode()); this.DataProvider.CommitTransaction(); } catch (Exception ex) { this.DataProvider.RollbackTransaction(); throw ex; } finally { ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider) this.DataProvider).PersistBroker.CloseConnection(); } string[] strVal = new string[this.designView.ReportSecurity.Length]; for (int i = 0; i < this.designView.ReportSecurity.Length; i++) { ////Modified by allen on 20081104 for change security: functiongroup //strVal[i] = this.designView.ReportSecurity[i].UserGroupCode; strVal[i] = this.designView.ReportSecurity[i].FunctionGroupCode; ////End Modified by allen on 20081104 for change security: functiongroup } this.rptSecuritySelect.SetSelectedItem(strVal); this.Session["PublishedReportId"] = this.designView.ReportID; string alertInfo = string.Format("<script language=javascript>alert('{0}');window.top.location.reload();</script>", this.languageComponent1.GetString("$ReportDesign_Publish_Success")); if (!this.ClientScript.IsClientScriptBlockRegistered("SaveSuccess")) { this.ClientScript.RegisterClientScriptBlock(typeof(string), "SaveSuccess", alertInfo); } this.cmdPublish.Disabled = true; this.cmdPublish.Attributes.Add("disabled", "disabled"); }