NET8
This commit is contained in:
@ -1,43 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#if !NET8
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
#endif
|
||||
|
||||
#if NET8
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
#endif
|
||||
|
||||
using Fab2ApprovalSystem.DMO;
|
||||
using Fab2ApprovalSystem.Misc;
|
||||
using Fab2ApprovalSystem.Models;
|
||||
|
||||
#if !NET8
|
||||
using System.Collections.Generic;
|
||||
using Fab2ApprovalSystem.ViewModels;
|
||||
#endif
|
||||
|
||||
namespace Fab2ApprovalSystem.Controllers;
|
||||
|
||||
[Authorize]
|
||||
#if !NET8
|
||||
[SessionExpireFilter]
|
||||
#endif
|
||||
#if NET8
|
||||
[Route("[controller]")]
|
||||
#endif
|
||||
public class ReportsController : Controller {
|
||||
|
||||
public const String specialNullString = "~NULL~";
|
||||
private readonly AppSettings _AppSettings = GlobalVars.AppSettings;
|
||||
public const string specialNullString = "~NULL~";
|
||||
private readonly AppSettings? _AppSettings = GlobalVars.AppSettings;
|
||||
|
||||
// GET: Export
|
||||
public ActionResult Index() {
|
||||
UserAccountDMO userDMO = new UserAccountDMO();
|
||||
ViewBag.HasITARAccess = userDMO.GetITARAccess((int)Session[GlobalVars.SESSION_USERID]);
|
||||
UserAccountDMO userDMO = new();
|
||||
ViewBag.HasITARAccess = userDMO.GetITARAccess(GlobalVars.GetUserId(GetSession()));
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Report(String id, String docType = "") {
|
||||
if (String.IsNullOrEmpty(id))
|
||||
#if !NET8
|
||||
|
||||
public ActionResult Report(string id, string docType = "") {
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return RedirectToAction("Index");
|
||||
|
||||
UserAccountDMO userDMO = new UserAccountDMO();
|
||||
if (!userDMO.GetITARAccess((int)Session[GlobalVars.SESSION_USERID]))
|
||||
UserAccountDMO userDMO = new();
|
||||
if (!userDMO.GetITARAccess(GlobalVars.GetUserId(GetSession())))
|
||||
return View("UnAuthorizedAccess");
|
||||
|
||||
var m = new ReportViewModel<System.Web.Mvc.SelectListItem>();
|
||||
ReportViewModel<SelectListItem> m = new();
|
||||
var reports = GetReportList(docType);
|
||||
foreach (var report in reports) {
|
||||
if (String.Equals(report.ReportID, id, StringComparison.OrdinalIgnoreCase)) {
|
||||
if (string.Equals(report.ReportID, id, StringComparison.OrdinalIgnoreCase)) {
|
||||
m.ReportID = report.ReportID;
|
||||
m.ReportName = report.Name;
|
||||
m.Description = report.Description;
|
||||
@ -46,8 +63,8 @@ public class ReportsController : Controller {
|
||||
var c = SetupSSRSHelperClient();
|
||||
|
||||
m.Parameters = c.GetReportParameters(report.FullPath).Select(parm => {
|
||||
var r = new ReportParameterViewModel<System.Web.Mvc.SelectListItem>();
|
||||
r.Visible = (parm.PromptUser.HasValue == false || parm.PromptUser == true) && !String.IsNullOrEmpty(parm.Prompt);
|
||||
ReportParameterViewModel<SelectListItem> r = new();
|
||||
r.Visible = (parm.PromptUser.HasValue == false || parm.PromptUser == true) && !string.IsNullOrEmpty(parm.Prompt);
|
||||
r.Prompt = parm.Prompt;
|
||||
r.Name = parm.Name;
|
||||
r.HtmlID = "parm_" + parm.Name;
|
||||
@ -87,7 +104,7 @@ public class ReportsController : Controller {
|
||||
|
||||
public SSRSHelper.SSRSClient SetupSSRSHelperClient() {
|
||||
var useCfgForBindings = false;
|
||||
if (String.Equals(_AppSettings.SSRSBindingsByConfiguration, "true", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(_AppSettings.SSRSBindingsByConfiguration, "true", StringComparison.OrdinalIgnoreCase))
|
||||
useCfgForBindings = true;
|
||||
|
||||
var c = new SSRSHelper.SSRSClient(
|
||||
@ -112,27 +129,26 @@ public class ReportsController : Controller {
|
||||
return c.ListReports(folderName);
|
||||
}
|
||||
|
||||
public ActionResult GetReports(String docType) {
|
||||
public ActionResult GetReports(string docType) {
|
||||
var reports = GetReportList(docType);
|
||||
|
||||
return Json(new {
|
||||
return GetJsonResult(new {
|
||||
Data =
|
||||
reports.Select(r => new ReportViewModel<System.Web.Mvc.SelectListItem>() {
|
||||
reports.Select(r => new ReportViewModel<SelectListItem>() {
|
||||
ReportName = r.Name ?? "",
|
||||
Description = r.Description ?? "",
|
||||
ReportID = r.ReportID ?? "",
|
||||
DocType = docType
|
||||
})
|
||||
},
|
||||
JsonRequestBehavior.AllowGet);
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult ExportReport(String DocType, String ReportID) {
|
||||
public ActionResult ExportReport(string DocType, string ReportID) {
|
||||
var c = SetupSSRSHelperClient();
|
||||
var reports = GetReportList(DocType);
|
||||
|
||||
var report = reports.Where(r => String.Equals(r.ReportID, ReportID, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
var report = reports.Where(r => string.Equals(r.ReportID, ReportID, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (report == null)
|
||||
return Content("Invalid report ID");
|
||||
|
||||
@ -140,16 +156,16 @@ public class ReportsController : Controller {
|
||||
|
||||
var parms = new SSRSHelper.ReportParameterCollection();
|
||||
parms.Add("DocType", DocType);
|
||||
parms.Add("UserID", Convert.ToString(Session[GlobalVars.SESSION_USERID]));
|
||||
parms.Add("UserID", GlobalVars.GetUserIdValue(GetSession()));
|
||||
parms.Add("BaseURL", GlobalVars.hostURL);
|
||||
|
||||
foreach (var rp in reportParms) {
|
||||
if (rp.MultiValue.HasValue && rp.MultiValue.Value) {
|
||||
foreach (String v in Request.Params.GetValues("parm_" + rp.Name)) {
|
||||
foreach (string v in Request.Params.GetValues("parm_" + rp.Name)) {
|
||||
parms.Add(rp.Name, v);
|
||||
}
|
||||
} else {
|
||||
String value = null;
|
||||
string value = null;
|
||||
|
||||
if (Request.Params.AllKeys.Contains("parm_" + rp.Name))
|
||||
value = Request.Params.GetValues("parm_" + rp.Name).FirstOrDefault();
|
||||
@ -173,7 +189,7 @@ public class ReportsController : Controller {
|
||||
}
|
||||
}
|
||||
|
||||
var b = c.ExportReport(report.FullPath, @User.Identity.Name, parms, "EXCELOPENXML");
|
||||
var b = c.ExportReport(report.FullPath, GetUserIdentityName(), parms, "EXCELOPENXML");
|
||||
try {
|
||||
var b2 = c.FreezeExcelHeaders(b);
|
||||
return File(b2, "application/octet-stream", MakeFilename(report.Name) + ".xlsx");
|
||||
@ -182,8 +198,10 @@ public class ReportsController : Controller {
|
||||
return File(b, "application/octet-stream", MakeFilename(report.Name) + ".xlsx");
|
||||
}
|
||||
|
||||
protected String MakeFilename(String reportName) {
|
||||
String r = "";
|
||||
#endif
|
||||
|
||||
protected string MakeFilename(string reportName) {
|
||||
string r = "";
|
||||
char[] invalidChars = System.IO.Path.GetInvalidFileNameChars();
|
||||
foreach (char c in reportName) {
|
||||
if (invalidChars.Contains(c))
|
||||
@ -194,4 +212,33 @@ public class ReportsController : Controller {
|
||||
return r;
|
||||
}
|
||||
|
||||
#if !NET8
|
||||
|
||||
private System.Web.HttpSessionStateBase GetSession() =>
|
||||
Session;
|
||||
|
||||
private JsonResult GetJsonResult(object? data) =>
|
||||
Json(data, JsonRequestBehavior.AllowGet);
|
||||
|
||||
private bool IsAjaxRequest() =>
|
||||
Request.IsAjaxRequest();
|
||||
|
||||
#endif
|
||||
|
||||
#if NET8
|
||||
|
||||
private Microsoft.AspNetCore.Http.ISession GetSession() =>
|
||||
HttpContext.Session;
|
||||
|
||||
private JsonResult GetJsonResult(object? data) =>
|
||||
Json(data);
|
||||
|
||||
private bool IsAjaxRequest() =>
|
||||
Request.Headers.TryGetValue("X-Requested-With", out Microsoft.Extensions.Primitives.StringValues strings) && strings[0] == "XMLHttpRequest";
|
||||
|
||||
#endif
|
||||
|
||||
private string GetUserIdentityName() =>
|
||||
@User.Identity.Name;
|
||||
|
||||
}
|
Reference in New Issue
Block a user