fleet-contractor/Site/Inspection/Inspection.aspx.cs
2024-03-26 15:56:31 +08:00

130 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Foresight.Fleet.Services.User;
using IronIntel.Contractor;
using IronIntel.Contractor.Site;
public partial class Inspection : InspectionBasePage
{
public bool ShowTemplate = false;
public bool TemplateReadonly = false;
public bool ShowReport = false;
public bool ReportReadonly = false;
public bool ShowGlobalSections = false;
public bool ShowFuelLog = false;
public bool ShowExportPackage = false;
public string BeginDate = "";
public string EndDate = "";
public bool IsCustomerRecord = false;
public bool AllowReassignWorkorders = false;
protected void Page_Load(object sender, EventArgs e)
{
if (!CheckLoginSession())
{
RedirectToLoginPage();
}
else
{
string methodName = Request.Form["MethodName"];
string requesttype = Request.Params["rt"];
if (!string.IsNullOrEmpty(methodName))
{
ProcessRequest(methodName);
}
else if (!string.IsNullOrEmpty(requesttype) && requesttype.ToLower() == "f")
{
ProcessFileRequest();
}
else if (!IsPostBack)
{
this.Title = PageTitle;
bool inspect = SystemParams.HasLicense("Inspection");
bool fuellog = SystemParams.HasLicense("FuelLog");
//bool inspectionpkg = SystemParams.HasLicense("ExportInspectionPackage");
if (!inspect && !fuellog)
RedirectToLoginPage();
IsCustomerRecord = SystemParams.HasLicense("CustomerRecord");
AllowReassignWorkorders = CheckRight(SystemParams.CompanyID, Feature.REASSIGN_WORKORDERS);
var user = GetCurrentUser();
ShowExportPackage = inspect && user.UserType == IronIntel.Contractor.Users.UserTypes.SupperAdmin;
if (inspect)
{
if (user.UserType == IronIntel.Contractor.Users.UserTypes.SupperAdmin || user.UserType == IronIntel.Contractor.Users.UserTypes.Admin)
{
ShowTemplate = true;
ShowReport = true;
ShowGlobalSections = true;
}
else if (user.UserType == IronIntel.Contractor.Users.UserTypes.Common)
{
var client = FleetServiceClientHelper.CreateClient<PermissionProvider>();
Tuple<Feature, Permissions>[] pmss = client.GetUserPermissions(SystemParams.CompanyID, user.IID);
if (pmss.Length > 0)
{
Tuple<Feature, Permissions> temppms = pmss.FirstOrDefault(m => m.Item1.Id == Feature.INSPECTION_TEMPLATES);
Tuple<Feature, Permissions> reportpms = pmss.FirstOrDefault(m => m.Item1.Id == Feature.INSPECTION_REPORTS);
if (temppms != null)
{
ShowTemplate = true;
if (temppms.Item2 == Permissions.ReadOnly)
TemplateReadonly = true;
}
if (reportpms != null)
{
ShowReport = true;
if (reportpms.Item2 == Permissions.ReadOnly)
ReportReadonly = true;
}
}
if (ShowTemplate == false && ShowReport == false)
RedirectToEntryPage();
}
}
if (fuellog)
{
if (user.UserType == IronIntel.Contractor.Users.UserTypes.SupperAdmin || user.UserType == IronIntel.Contractor.Users.UserTypes.Admin)
ShowFuelLog = true;
else if (user.UserType == IronIntel.Contractor.Users.UserTypes.Common)
ShowFuelLog = ShowReport;
}
}
DateTime userlocaldate = SystemParams.ConvertToUserTimeFromUtc(GetCurrentLoginSession().User, DateTime.UtcNow);
BeginDate = userlocaldate.AddDays(-13).ToString("yyyy-MM-dd");
EndDate = userlocaldate.ToString("yyyy-MM-dd");
}
}
public bool IsForesight
{
get
{
var user = GetCurrentUser();
if (user.UserType == IronIntel.Contractor.Users.UserTypes.SupperAdmin)
return true;
else
return false;
}
}
public bool IsAdmin
{
get
{
var user = GetCurrentUser();
if (user.UserType == IronIntel.Contractor.Users.UserTypes.SupperAdmin || user.UserType == IronIntel.Contractor.Users.UserTypes.Admin)
return true;
else
return false;
}
}
}