我制定了另一个解决方案,满足了上级提出的要求。
简而言之:我创建了一个包含事件的简单 HTML 日历。然后我将页面呈现为图像(如屏幕截图)并使用 SSRS 中的图像控件来加载它。SSRS 报告将其参数作为查询字符串传递给网页。
对于那些通过网络搜索找到这个问题的好奇者,这是我用来创建位图的方法:
private Bitmap CreateScreenshot(string url, int width, int height)
{
Bitmap screenshot = null;
var thread = new Thread(() =>
{
using (var browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.ScriptErrorsSuppressed = true;
browser.Width = width;
browser.Height = height;
browser.Navigate(url);
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
screenshot = new Bitmap(width, height);
browser.DrawToBitmap(screenshot, new Rectangle(0, 0, width, height));
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
return screenshot;
}
我从控制器内部调用它:
public void Action()
{
var model = new ViewModel
{
StartDate = new DateTime(2013, 6, 30),
EndDate = new DateTime(2013, 8, 10),
OpsId = ####
};
var url = Url.Action("ActionThatCallsCalendar", "Controller", new { area = "Area", viewModel = new JavaScriptSerializer().Serialize(model) }, Request.Url.Scheme);
Response.ContentType = "image/jpeg";
Response.Clear();
var screenshot = CreateScreenshot(url, 1400, 1050);
screenshot.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.Flush();
}