2017-07-03 48 views
0

我花了很多天試圖在論壇/ samples/github上找到的所有內容,我想要做什麼: - 我在Sql Server中有一個表 - 我有一個報告(Stimulsoft reports.js) - 我需要用表格的行填充報表(以便用戶可以預覽報表)。將Stimulsoft報告綁定到MSSQL表

目前,該報告模板創建服務器端(asp.net核心),使用此代碼:

[HttpPost] 
public override async Task Post([FromBody] Report[] elements) 
{ 
var report = new StiReport(); 

var ds = GetDocumentDataSet(); 
report.RegData(AppName, ds); 
report.Dictionary.Synchronize(); 
foreach (var element in elements) 
element.Layout = report.SaveToJsonString(); 
return await base.Post(elements); 
} 
private DataSet GetDocumentDataSet() 
{ 
DataSet ds = new DataSet(); 
using (var connection = Use().GetConnection()) 
{ 
using (var command = connection.CreateCommand()) 
{ 
var table = new DataTable($"{nameof(Document)}"); 
command.CommandText = $"select top 1 * from {nameof(Document)}"; 

connection.Open(); 
table.Load(command.ExecuteReader()); 
ds.Tables.Add(table); 
} 
} 
return ds; 
} 

這段代碼放在桌子上,列有它們的類型在dictionnary,它的工作原理。客戶端,當我使用此代碼加載報告:

report.load(dataReport.Layout); 

我可以在dictionnary看到:http://imgur.com/a/SJ4Yr

這很酷,我剛纔提供的數據,服務器端的我得到的數據這種方式:

public async Task ReportSearch() 
{ 
var rows = new List(); 
var columns = new List(); 
var types = new List(); 
using (var connection = Use().GetConnection()) 
using (var command = connection.CreateCommand()) 
{ 
command.CommandText = $"select * from {nameof(Document)}"; 
connection.Open(); 
var reader = await command.ExecuteReaderAsync(); 
while (await reader.ReadAsync()) 
{ 
var values = new object[reader.FieldCount]; 
reader.GetValues(values); 
rows.Add(values); 
} 
foreach (DataRow c in reader.GetSchemaTable().Rows) 
{ 
columns.Add((string)c["ColumnName"]); 
types.Add(((Type)c["DataType"]).FullName); 
} 
} 

return new // As seen in your github sample 
{ 
columns = columns, 
notice = "", 
types = types, 
rows = rows, 
success = true 
}; 
} 

和客戶端,我試着填寫了這種方式:

const report = new Stimulsoft.Report.StiReport(); 
if (dataReport.Layout != null && dataReport.Layout != "") { 
report.load(dataReport.Layout); 
} 
$.ajax({ 
type: "Post", 
url: "api/Search/ReportSearch", 
dataType: "json", 
contentType: "application/json", 
success: (data) => { 

var dataSet = new Stimulsoft.System.Data.DataSet(appName); 
dataSet.readJson(JSON.stringify(data)); 

report.regData(dataSet.dataSetName, dataSet.dataSetName, dataSet); 
report.dictionary.synchronize(); 
designer.report = report; 
} 
}); 

但我得到這個:(:http://imgur.com/a/FQ9kQ

相信我,我已經嘗試了我找到的一切。我寧願將數據作爲表格(對象數組數組)發送,而不是發送json對象數組,因爲每個對象都具有相同的屬性,所以第一種方法比第二種方法更加靈活,並且將傳輸/解析。

有人可以幫忙嗎?

回答

0

您應該GitHub線(74-86)使用示例:

 if (requestParams.Connection.Type == StiConnectionType.MSSQL) 
     { 
      string connectionString = requestParams.Connection.ConnectionString; 
      string queryString = requestParams.Connection.QueryString; 

      StiDataResult result = new StiDataResult() 
      { 
       Columns = new string[2] { "Column1", "Column2" }, 
       Types = new string[2] { "number", "string" }, 
       Rows = new string[3][] { new string[2] { "1", "Row1" }, new string[2] { "2", "Row2" }, new string[2] { "3", "Row3" } } 
      }; 
      return StiNetCoreViewer.GetReportDataResult(this, result); 
     }