Cloud
Cloud-Dienstleistung für schnelle und effektive Analyse und Visualisierung von Daten für Ihr Business ohne eigene Applikationen zu erstellen oder zu programmieren.
StiMvcViewer component to the view page. Also, you need to pass the StiMvcViewerOptions object to the constructor. The minimum required options are two actions - GetReport and ViewerEvent:
@using Stimulsoft.Report.Mvc;
...
@Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
{
Actions =
{
GetReport = "GetReport",
ViewerEvent = "ViewerEvent"
}
})
StiDefaultCacheHelper class:
public class StiDefaultCacheHelper : StiCacheHelper
{
public override StiReport GetReport(string guid)
{
return base.GetReport(guid);
}
public override void SaveReport(StiReport report, string guid)
{
base.SaveReport(report, guid);
}
public override void RemoveReport(string guid)
{
base.RemoveReport(guid);
}
}
DefaultCacheController method:
public DefaultCacheController() {
StiMvcViewer.CacheHelper = new StiDefaultCacheHelper();
}
public ActionResult GetReport(int id = 1)
{
var report = new StiReport();
report.Load(Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt"));
return StiMvcViewer.GetReportResult(report);
}
StiFileCacheHelper class:
public class StiFileCacheHelper : StiCacheHelper
{
public override StiReport GetReport(string guid)
{
var path = Path.Combine(HttpContext.Server.MapPath("~/CacheFiles"), guid);
if (File.Exists(path))
{
var report = new StiReport();
var packedReport = File.ReadAllText(path);
if (guid.EndsWith(GUID_ReportTemplate)) report.LoadPackedReportFromString(packedReport);
else report.LoadPackedDocumentFromString(packedReport);
return report;
}
return null;
}
public override void SaveReport(StiReport report, string guid)
{
var packedReport = guid.EndsWith(GUID_ReportTemplate) ? report.SavePackedReportToString() : report.SavePackedDocumentToString();
var path = Path.Combine(HttpContext.Server.MapPath("~/CacheFiles"), guid);
File.WriteAllText(path, packedReport);
}
public override void RemoveReport(string guid)
{
var path = Path.Combine(HttpContext.Server.MapPath("~/CacheFiles"), guid);
if (File.Exists(path))
File.Delete(path);
}
}
FileCacheController method:
public FileCacheController()
{
StiMvcViewer.CacheHelper = new StiFileCacheHelper();
}
public ActionResult GetReport(int id = 1)
{
var report = new StiReport();
report.Load(Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt"));
return StiMvcViewer.GetReportResult(report);
}
StiMSSQLCacheHelper class:
public class StiMSSQLCacheHelper : StiCacheHelper
{
// Please use your own database connection
private string connectionString = @"Data Source=127.0.0.1;Initial Catalog=SampleDB;Integrated Security=False;User ID=******;Password=******;";
public override StiReport GetReport(string guid)
{
var connection = new SqlConnection(connectionString);
try
{
connection.Open();
var query = $"SELECT Guid, Value FROM ReportCache WHERE Guid='{guid}'";
var command = new SqlCommand(query, connection);
var reader = command.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
var packedReport = reader.GetString(1);
reader.Close();
var report = new StiReport();
if (guid.EndsWith(GUID_ReportTemplate)) report.LoadPackedReportFromString(packedReport);
else report.LoadPackedDocumentFromString(packedReport);
return report;
}
}
catch (SqlException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
connection.Close();
}
return null;
}
public override void SaveReport(StiReport report, string guid)
{
var connection = new SqlConnection(connectionString);
try
{
connection.Open();
var query = $"DELETE FROM ReportCache WHERE Guid='{guid}'";
var command = new SqlCommand(query, connection);
command.ExecuteNonQuery();
var packedReport = guid.EndsWith(GUID_ReportTemplate) ? report.SavePackedReportToString() : report.SavePackedDocumentToString();
query = $"INSERT INTO ReportCache (Guid, Value) VALUES ('{guid}', '{packedReport}')";
command = new SqlCommand(query, connection);
command.ExecuteNonQuery();
}
catch (SqlException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
connection.Close();
}
}
public override void RemoveReport(string guid)
{
var connection = new SqlConnection(connectionString);
try
{
connection.Open();
var query = $"DELETE FROM ReportCache WHERE Guid='{guid}'";
var command = new SqlCommand(query, connection);
command.ExecuteNonQuery();
}
catch (SqlException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
connection.Close();
}
}
}
MSSQLCacheController method:
public MSSQLCacheController()
{
StiMvcViewer.CacheHelper = new StiMSSQLCacheHelper();
}
public ActionResult GetReport(int id = 1)
{
var report = new StiReport();
report.Load(Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt"));
return StiMvcViewer.GetReportResult(report);
}