private void MenuItem_testCreateReport_Click(object sender, EventArgs e) { BuildReportDialog1 dlg = new BuildReportDialog1(); dlg.DataDir = Path.Combine(ClientInfo.DataDir, "report_def"); dlg.UiState = ClientInfo.Config.Get( "BuildReportDialog", "uiState", ""); dlg.ShowDialog(this); ClientInfo.Config.Set( "BuildReportDialog", "uiState", dlg.UiState); if (dlg.DialogResult == DialogResult.Cancel) { return; } string defFileName = Path.Combine(ClientInfo.DataDir, $"report_def\\{dlg.ReportType}.xml"); ReportWriter writer = new ReportWriter(); int nRet = writer.Initial(defFileName, out string strError); if (nRet == -1) { goto ERROR1; } writer.Algorithm = dlg.ReportType; string strOutputFileName = Path.Combine(ClientInfo.UserDir, "test.rml"); string strOutputHtmlFileName = Path.Combine(ClientInfo.UserDir, "test.html"); DatabaseConfig.ServerName = "localhost"; DatabaseConfig.DatabaseName = "testrep"; DatabaseConfig.UserName = "******"; DatabaseConfig.Password = "******"; Hashtable param_table = dlg.SelectedParamTable; using (var context = new LibraryContext()) { Report.BuildReport(context, param_table, // dlg.Parameters, writer, strOutputFileName); } // RML 格式转换为 HTML 文件 // parameters: // strCssTemplate CSS 模板。里面 %columns% 代表各列的样式 nRet = DigitalPlatform.dp2.Statis.Report.RmlToHtml(strOutputFileName, strOutputHtmlFileName, "", out strError); if (nRet == -1) { goto ERROR1; } // Process.Start("notepad", strOutputFileName); ReportViewerForm viewer = new ReportViewerForm(); viewer.DataDir = ClientInfo.UserTempDir; viewer.SetXmlFile(strOutputFileName); viewer.SetHtmlFile(strOutputHtmlFileName); viewer.ShowDialog(this); return; ERROR1: MessageBox.Show(this, strError); }