215 lines
7.2 KiB
C#
215 lines
7.2 KiB
C#
using DevExpress.Web.Mvc;
|
|
using EnVisage.Code.BLL;
|
|
using EnVisage.Code.HtmlHelpers;
|
|
using EnVisage.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Microsoft.AspNet.Identity;
|
|
using EnVisage.Code;
|
|
using Envisage.Code.DAL;
|
|
using EnVisage.Code.DAL;
|
|
using DevExpress.Xpo;
|
|
using Envisage.Code.BLL;
|
|
using System.IO;
|
|
using DevExpress.XtraReports.UI;
|
|
using DevExpress.XtraReports.Native;
|
|
|
|
namespace EnVisage.Controllers
|
|
{
|
|
[Authorize]
|
|
public class ReportingController : Controller
|
|
{
|
|
//
|
|
// GET: /Reporting/
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Read)]
|
|
public ActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Read)]
|
|
public ActionResult Viewer(string id)
|
|
{
|
|
var report = ReportManager.LoadReport(new ReportCallbackModel()
|
|
{
|
|
ReportId = id
|
|
});
|
|
var model = new ReportModel
|
|
{
|
|
ReportId = id,
|
|
Report = report
|
|
};
|
|
return View("BaseReportView", model);
|
|
}
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Read)]
|
|
public ActionResult Summary()
|
|
{
|
|
var report = ReportManager.LoadReport(new ReportCallbackModel()
|
|
{
|
|
ReportId = Constants.REPORT_SUMMARY_ID
|
|
});
|
|
var model = new ReportModel
|
|
{
|
|
ReportId = Constants.REPORT_SUMMARY_ID,
|
|
Report = report
|
|
};
|
|
return View("BaseReportView", model);
|
|
}
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Read)]
|
|
public ActionResult Test()
|
|
{
|
|
var report = ReportManager.LoadReport(new ReportCallbackModel()
|
|
{
|
|
ReportId = Constants.REPORT_TEST_ID
|
|
});
|
|
var model = new ReportModel
|
|
{
|
|
ReportId = Constants.REPORT_TEST_ID,
|
|
Report = report
|
|
};
|
|
return View("BaseReportView", model);
|
|
}
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Read)]
|
|
public ActionResult ForecastRevenue()
|
|
{
|
|
var report = ReportManager.LoadReport(new ReportCallbackModel()
|
|
{
|
|
ReportId = Constants.REPORT_FOREREVENUE_ID
|
|
});
|
|
var model = new ReportModel
|
|
{
|
|
ReportId = Constants.REPORT_FOREREVENUE_ID,
|
|
Report = report
|
|
};
|
|
return View("BaseReportView", model);
|
|
}
|
|
public ActionResult ForecastNonRevenue()
|
|
{
|
|
var report = ReportManager.LoadReport(new ReportCallbackModel()
|
|
{
|
|
ReportId = Constants.REPORT_NONFOREREVENUE_ID
|
|
});
|
|
var model = new ReportModel
|
|
{
|
|
ReportId = Constants.REPORT_NONFOREREVENUE_ID,
|
|
Report = report
|
|
};
|
|
return View("BaseReportView", model);
|
|
}
|
|
|
|
#region Callback handlers
|
|
public ActionResult CallbackPanelPartial(ReportCallbackModel model)
|
|
{
|
|
var report = ReportManager.LoadReport(model);
|
|
//we have to reset RequestParameters, otherwise report witl request parameters again but should reload sorted data without additional button click
|
|
report.RequestParameters = false;
|
|
return PartialView("_CallbackPanelPartial", report);
|
|
}
|
|
#endregion
|
|
|
|
#region Designer Actions
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Write)]
|
|
public ActionResult List()
|
|
{
|
|
using (var session = SessionFactory.Create())
|
|
{
|
|
var reports = session.Query<UserReport>()
|
|
.Select(x => new ReportListItemModel
|
|
{
|
|
Id = x.Oid.ToString(),
|
|
Name = x.Name
|
|
})
|
|
.ToArray();
|
|
var firstReport = reports.FirstOrDefault();
|
|
var model = new ReportListModel
|
|
{
|
|
SelectedReportId = firstReport != null ? firstReport.Id : string.Empty,
|
|
Reports = reports
|
|
};
|
|
return View(model);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Write)]
|
|
public ActionResult Delete(int id)
|
|
{
|
|
using (var session = SessionFactory.Create())
|
|
{
|
|
var report = session.GetObjectByKey<UserReport>(id);
|
|
session.Delete(report);
|
|
session.CommitChanges();
|
|
}
|
|
return RedirectToAction("List");
|
|
}
|
|
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Write)]
|
|
public ActionResult Add(string name)
|
|
{
|
|
return View("Designer", new DesignModel
|
|
{
|
|
NewName = name,
|
|
Report = GetNewReport(),
|
|
DataSource = CustomDataSourceSerializer.GetDataSource()
|
|
});
|
|
}
|
|
|
|
[HttpPost]
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Write)]
|
|
public ActionResult Edit(int id)
|
|
{
|
|
using (var session = SessionFactory.Create())
|
|
{
|
|
var reportEntity = session.GetObjectByKey<UserReport>(id);
|
|
using (var stream = new MemoryStream(reportEntity.Layout))
|
|
{
|
|
var report = XtraReport.FromStream(stream, true);
|
|
return View("Designer", new DesignModel { Id = id.ToString(), Report = report });
|
|
}
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Write)]
|
|
public JsonResult AddNewReport(string name)
|
|
{
|
|
var layout = ReportDesignerExtension.GetReportXml("reportDesigner");
|
|
using (var session = SessionFactory.Create())
|
|
{
|
|
var reportEntity = new UserReport(session)
|
|
{
|
|
Name = name,
|
|
Layout = layout
|
|
};
|
|
session.CommitChanges();
|
|
return Json(reportEntity.Oid);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[AreaSecurityAttribute(area = Areas.Reports, level = AccessLevel.Write)]
|
|
public JsonResult UpdateReport(int id)
|
|
{
|
|
var layout = ReportDesignerExtension.GetReportXml("reportDesigner");
|
|
using (var session = SessionFactory.Create())
|
|
{
|
|
var reportEntity = session.GetObjectByKey<UserReport>(id);
|
|
reportEntity.Layout = layout;
|
|
session.CommitChanges();
|
|
return Json(reportEntity.Oid);
|
|
}
|
|
}
|
|
|
|
static DevExpress.XtraReports.UI.XtraReport GetNewReport()
|
|
{
|
|
var report = new ReportBase();
|
|
report.Extensions[SerializationService.Guid] = CustomDataSourceSerializer.Name;
|
|
return report;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |