using System.Web.Mvc; using System.Web.UI; using Neo.Afx.Security; using System; using System.Configuration; using System.Web.Profile; using System.Linq; using Neo.LegitimateLicences.Common; using System.Web.Security; using Neo.Afx.Services.Audits; using Neo.LegitimateLicences.Common.ViewModels; using Neo.LegitimateLicences.Common.Helpers; using Neo.Afx.Services.Workflows; using Neo.LegitimateLicences.Web.Models.Afx; using Neo.Afx.Services.Workflows.Entities; using Neo.Afx.Services.Reports; using Neo.Afx.ViewModels; using System.Collections.Generic; using Neo.Afx.Services.Integration; using DevExpress.XtraReports.Web; using DevExpress.XtraReports.UI; namespace Neo.LegitimateLicences.Web.Controllers { public partial class AfxController { #region Reports public ActionResult Reports(int reportGroupID) { var reportDatabase = new ReportDatabase(); var userSecurables = Profile.Securables.ToList(); var definitions = reportDatabase.GetReportDefinitions(reportGroupID).Where(a => !a.SecurableID.HasValue || userSecurables.Any(b => b.SecurableID == a.SecurableID.Value)); var model = new AfxReportsModel() { UserID = Profile.UserID, UserRoles = Profile.Roles, UserName = Profile.UserName, ReportDefinitions = definitions, Lookups = null, ReportServerType = "DevExpress" //todo - make this dynamic }; WebHelper.SetLastPageVisited(HttpContext, "Applications/Reports"); ViewBag.Controller = "Afx"; ViewBag.Page = "Reports"; return View("~/Views/Shared/Afx/Reports/Reports.cshtml", model); } #endregion #region ReportDefinition public ActionResult ReportDefinition(long reportDefinitionID) { var reportDatabase = new ReportDatabase(); var model = new AfxReportDefinitionModel() { UserID = Profile.UserID, UserName = Profile.UserName, UserRoles = Profile.Roles, ReportDefinition = reportDatabase.GetReportDefinition(reportDefinitionID), Lookups = GetLookups(reportDatabase, reportDefinitionID) }; ViewBag.Controller = "Applications"; ViewBag.Page = "Reports"; return View("~/Views/Shared/Afx/Reports/ReportDefinition.cshtml", model); } #endregion #region ReportViewer public ActionResult ReportViewer(long reportDefinitionID) { var reportDatabase = new ReportDatabase(); var reportDefinition = reportDatabase.GetReportDefinitionWithServer(reportDefinitionID); var assembly = reportDefinition.Server.Url; var typename = assembly + "." + reportDefinition.ReportFolder + "." + reportDefinition.ReportName; var report = (XtraReport)Activator.CreateInstance(Type.GetType(typename + ", " + assembly)); var hasCustomParameter = false; foreach (var p in report.Parameters) { if (p.Name.ToLower() == "userid") { p.Visible = false; p.Value = Profile.UserID; } else if (p.Visible) { hasCustomParameter = true; if (p.Type == typeof(DateTime) && (p.Name.ToLower() == "fromdate" || p.Name.ToLower() == "datefrom" || p.Name.ToLower() == "startdate")) { p.Value = DateTime.Now.AddMonths(-1); } if (p.Type == typeof(DateTime) && (p.Name.ToLower() == "todate" || p.Name.ToLower() == "dateto" || p.Name.ToLower() == "enddate")) { p.Value = DateTime.Now; } } } report.RequestParameters = hasCustomParameter; var model = new AfxReportViewerModel() { UserID = Profile.UserID, UserName = Profile.UserName, UserRoles = Profile.Roles, ReportSource = new CachedReportSourceWeb(report) }; ViewBag.Controller = "Applications"; ViewBag.Page = "ReportViewer"; return View("~/Views/Shared/Afx/Reports/ReportViewer.cshtml", model); } public ActionResult UserActivityReportViewer(long reportDefinitionID, long forUserID) { var reportDatabase = new ReportDatabase(); var reportDefinition = reportDatabase.GetReportDefinitionWithServer(reportDefinitionID); var assembly = reportDefinition.Server.Url; var typename = assembly + "." + reportDefinition.ReportFolder + "." + reportDefinition.ReportName; var report = (XtraReport)Activator.CreateInstance(Type.GetType(typename + ", " + assembly)); var hasCustomParameter = false; foreach (var p in report.Parameters) { if (p.Name.ToLower() == "userid") { p.Visible = false; p.Value = Profile.UserID; } else if (p.Name.ToLower() == "foruserid") { p.Visible = false; p.Value = forUserID; } else if (p.Visible) { hasCustomParameter = true; if (p.Type == typeof(DateTime) && (p.Name.ToLower() == "fromdate" || p.Name.ToLower() == "datefrom" || p.Name.ToLower() == "startdate")) { p.Value = DateTime.Now.AddMonths(-1); } if (p.Type == typeof(DateTime) && (p.Name.ToLower() == "todate" || p.Name.ToLower() == "dateto" || p.Name.ToLower() == "enddate")) { p.Value = DateTime.Now; } } } report.RequestParameters = hasCustomParameter; var model = new AfxReportViewerModel() { UserID = Profile.UserID, UserName = Profile.UserName, UserRoles = Profile.Roles, ReportSource = new CachedReportSourceWeb(report) }; ViewBag.Controller = "Applications"; ViewBag.Page = "ReportViewer"; return View("~/Views/Shared/Afx/Reports/ReportViewer.cshtml", model); } #endregion #region GetLookups public List GetLookups(ReportDatabase reportDatabase, long reportDefinitionID) { var lookups = new List(); ////var integrationStore = new SqlIntegrationStore(); ////try ////{ //// integrationStore.Open(); //// if (reportDefinitionID > 0 && reportDatabase.GetReportDefinitionCriterias(reportDefinitionID).Count > 0) //// { //// lookups.AddRange(from criteria in reportDatabase.GetReportDefinitionCriterias(reportDefinitionID) //// where !string.IsNullOrEmpty(criteria.DataSourceName) //// select new LookupList("CaptureFieldLookup" + criteria.DataSourceName, integrationStore.GetDataEntities(criteria.DataSourceName, string.Empty))); //// } ////} ////finally ////{ //// integrationStore.Close(); ////} return lookups; } #endregion } }