initial version with inspection edition

This commit is contained in:
2020-04-29 14:08:00 +08:00
commit 6a5629fc3b
186 changed files with 33984 additions and 0 deletions

View File

@ -0,0 +1,611 @@
using Foresight.Data;
using Foresight.Fleet.Services.AssetHealth;
using Foresight.ServiceModel;
using IronIntel.Contractor.Machines;
using IronIntel.Contractor.Maintenance;
using IronIntel.Contractor.Users;
using IronIntel.Services;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace IronIntel.Contractor.Site.Maintenance
{
public class AlertsBasePage : ContractorBasePage
{
protected void ProcessRequest(string method)
{
object result = null;
try
{
string methodName = Request.Params["MethodName"];
if (methodName != null)
{
switch (methodName.ToUpper())
{
case "GETALERTS":
result = GetAlerts();
break;
case "GETMACHINEALERTS":
result = GetMachineAlerts();
break;
case "SAVEACKNOWLEDGEALERT":
result = SaveAcknowledgeAlert();
break;
case "ASSIGNEDALERTSTOWORKORDER":
result = AssignedAlertsToWorkOrder();
break;
case "GETALERTSBYWORKORDER":
result = GetAlertsByWorkOrder();
break;
case "GETALERTSLISENCE":
result = GetAlertsLisence();
break;
case "GETWORKORDERALERTS":
result = GetWorkOrderAlerts();
break;
case "GETASSETALERTS":
result = GetAssetAlerts();
break;
case "GETASSETGROUPS":
result = GetAssetGroups();
break;
case "GETALERTTYPES":
result = GetAlertTypes();
break;
case "GETACKNOWLEDGEDALERTS":
result = GetAcknowledgedAlerts();
break;
}
}
}
catch (Exception ex)
{
SystemParams.WriteLog("error", "AlertsBasePage", ex.Message, ex.ToString());
throw ex;
}
string json = JsonConvert.SerializeObject(result);
Response.Write(json);
Response.End();
}
private object GetAlerts()
{
try
{
var session = GetCurrentLoginSession();
if (GetCurrentLoginSession() != null)
{
var clientdata = Context.Request.Params["ClientData"];
AlertQueryParams alertparam = JsonConvert.DeserializeObject<AlertQueryParams>(clientdata);
DateTime beginDate = Helper.DBMinDateTime;
DateTime endDate = DateTime.MaxValue;
if (!DateTime.TryParse(alertparam.BeginDate, out beginDate))
beginDate = Helper.DBMinDateTime;
//else
// beginDate = beginDate.ToUniversalTime();
if (!DateTime.TryParse(alertparam.EndDate, out endDate))
endDate = DateTime.MaxValue;
else
endDate = endDate.Date.AddDays(1).AddSeconds(-1);
int assigned = -1;
int completed = -1;
if (alertparam.AlertStatus != null && alertparam.AlertStatus.Length > 0)
{
if (alertparam.AlertStatus.Contains("Unassigned") && !alertparam.AlertStatus.Contains("Assigned"))
assigned = 0;
if (!alertparam.AlertStatus.Contains("Unassigned") && alertparam.AlertStatus.Contains("Assigned"))
assigned = 1;
if (alertparam.AlertStatus.Contains("Completed") && !alertparam.AlertStatus.Contains("Uncompleted"))
assigned = 1;
if (!alertparam.AlertStatus.Contains("Completed") && alertparam.AlertStatus.Contains("Uncompleted"))
assigned = 0;
}
AssetAlertGridViewItem[] assetalerts = CreateClient<WorkOrderClient>().GetAssetAlertGridViewItems(SystemParams.CompanyID, beginDate, endDate, alertparam.AlertTypes, alertparam.AssetGroups, assigned, completed, alertparam.SearchText, session.User.UID);
if (assetalerts == null || assetalerts.Length == 0)
return new AlertInfo[0];
List<AlertInfo> list = new List<AlertInfo>();
foreach (AssetAlertGridViewItem item in assetalerts)
{
AlertInfo ai = ConvertAlertObj(item);
ai.AlertTime_UTC = item.LastAlertLocalTime;
list.Add(ai);
}
return list.ToArray();
}
else
return new AlertInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAlerts", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetMachineAlerts()
{
try
{
var session = GetCurrentLoginSession();
if (GetCurrentLoginSession() != null)
{
var clientdata = Context.Request.Params["ClientData"];
AlertQueryParams alertparam = JsonConvert.DeserializeObject<AlertQueryParams>(clientdata);
DateTime beginDate = Helper.DBMinDateTime;
DateTime endDate = DateTime.MaxValue;
if (!DateTime.TryParse(alertparam.BeginDate, out beginDate))
beginDate = Helper.DBMinDateTime;
//else
// beginDate = beginDate.ToUniversalTime();
if (!DateTime.TryParse(alertparam.EndDate, out endDate))
endDate = DateTime.MaxValue;
else
endDate = endDate.Date.AddDays(1).AddSeconds(-1);
int assigned = -1;
int completed = -1;
if (alertparam.AlertStatus != null && alertparam.AlertStatus.Length > 0)
{
if (alertparam.AlertStatus.Contains("Unassigned") && !alertparam.AlertStatus.Contains("Assigned"))
assigned = 0;
if (!alertparam.AlertStatus.Contains("Unassigned") && alertparam.AlertStatus.Contains("Assigned"))
assigned = 1;
if (alertparam.AlertStatus.Contains("Completed") && !alertparam.AlertStatus.Contains("Uncompleted"))
assigned = 1;
if (!alertparam.AlertStatus.Contains("Completed") && alertparam.AlertStatus.Contains("Uncompleted"))
assigned = 0;
}
AssetAlertGridViewItem[] assetalerts = CreateClient<WorkOrderClient>().GetAssetAlertGridViewItems(SystemParams.CompanyID, beginDate, endDate, alertparam.AlertTypes, alertparam.AssetGroups, assigned, completed, alertparam.SearchText, session.User.UID);
if (assetalerts == null || assetalerts.Length == 0)
return new MachineInfoForAlert[0];
List<MachineInfoForAlert> machinealerts = new List<MachineInfoForAlert>();
foreach (AssetAlertGridViewItem item in assetalerts)
{
AlertInfo ai = ConvertAlertObj(item);
MachineInfoForAlert mi = machinealerts.FirstOrDefault((i) => i.MachineID == ai.MachineID);
if (mi == null)
{
mi = new MachineInfoForAlert();
mi.MachineID = ai.MachineID;
mi.MachineName = ai.MachineName;
mi.VIN = ai.VIN;
mi.Make = ai.Make;
mi.Model = ai.Model;
mi.EngineHours = ai.CurrentHours;
mi.OpenWorkOrders = ai.OpenWorkOrderCount;
machinealerts.Add(mi);
}
mi.Alerts.Add(ai);
int count = ai.RepeatedAlerts.Count + 1;
if (ai.AlertType == "Preventative Maintenance"
|| ai.AlertType == "PM_ALERT" || ai.AlertType == "TBM_ALERT" || ai.AlertType == "HM_ALERT"
|| ai.AlertType == "RDM_ALERT" || ai.AlertType == "ADM_ALERT")
mi.PMAlertCount += count;
else if (INSPECT.Contains(ai.AlertType, StringComparer.OrdinalIgnoreCase))
mi.InspectAlertCount += count;
else
mi.DTCAlertCount += count;
if (ai.AlertTime_UTC > mi.LatestAlertDateTime)
mi.LatestAlertDateTime = ai.AlertTime_UTC;
}
return machinealerts.ToArray();
}
else
return new MachineInfoForAlert[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAlerts", ex.Message, ex.ToString());
return ex.Message;
}
}
private AlertInfo ConvertAlertObj(AssetAlertGridViewItem item)
{
AlertInfo ai = new AlertInfo();
ai.AlertID = item.ID;
ai.WorkOrderID = item.WorkOrderId;
ai.WorkOrderStatus = item.WorkOrderStatus;
ai.AlertType = item.AlertType;
ai.AlertTime_UTC = item.LastAlertTime;
ai.Completed = item.Completed;
ai.MachineID = item.AssetID;
//ai.ModelID = item.ModelName;
ai.Model = item.ModelName;
//ai.MakeID = item.MakeName;
ai.Make = item.MakeName;
ai.VIN = item.VIN;
ai.MachineName = item.AssetName;
ai.EngineHours = item.EngineHours;
ai.CurrentHours = item.CurrentEngineHours;
ai.Description = item.Description;
ai.ServiceDescription = item.ServiceDescription;
ai.RepeatedAlerts = item.RepeatedAlerts;
ai.AlertCount = item.RepeatedAlerts.Count + 1;
ai.OpenWorkOrderCount = item.OpenWorkOrderCount;
return ai;
}
private object GetAcknowledgedAlerts()
{
try
{
var session = GetCurrentLoginSession();
if (GetCurrentLoginSession() != null)
{
var clientdata = Context.Request.Params["ClientData"];
AlertQueryParams alertparam = JsonConvert.DeserializeObject<AlertQueryParams>(clientdata);
DateTime beginDate = Helper.DBMinDateTime;
DateTime endDate = DateTime.MaxValue;
if (!DateTime.TryParse(alertparam.BeginDate, out beginDate))
beginDate = Helper.DBMinDateTime;
//else
// beginDate = beginDate.ToUniversalTime();
if (!DateTime.TryParse(alertparam.EndDate, out endDate))
endDate = DateTime.MaxValue;
else
endDate = endDate.Date.AddDays(1).AddSeconds(-1);
alertparam.AlertStatus = new string[0];
AlertManager am = new AlertManager(SystemParams.DataDbConnectionString);
AlertInfo[] alerts = am.SearchAcknowledgedAlerts(session.SessionID, alertparam.SearchText, alertparam.AlertStatus, alertparam.AlertTypes, alertparam.AssetGroups, beginDate, endDate, session.User.UID);
if (alerts == null)
return new AlertInfo[0];
return alerts.ToArray();
}
else
return new AlertInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAcknowledgedAlerts", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetAlertsLisence()
{
try
{
AlertsLisenceItem result = new AlertsLisenceItem();
if (GetCurrentLoginSession() != null)
{
LicenseInfo license = SystemParams.GetLicense();
if (license != null && license.Items.Count > 0)
{
var woitem = license.Items.FirstOrDefault(m => m.Key == "WorkOrder");
if (woitem != null && Helper.IsTrue(woitem.Value))
result.WorkOrder = true;
}
result.AcknowledgingAlerts = Helper.IsTrue(SystemParams.GetStringParam("AcknowledgingAlerts"));
}
return result;
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAlertsLisence", ex.Message, ex.ToString());
return ex.Message;
}
}
private string SaveAcknowledgeAlert()
{
try
{
Services.Users.LoginSession se = GetCurrentLoginSession();
if (se != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var ids = HttpUtility.HtmlDecode(clientdata[0]);
var acknowledgmentcomment = HttpUtility.HtmlDecode(clientdata[1]);
long[] list = JsonConvert.DeserializeObject<long[]>(ids);
AlertManager am = new AlertManager(SystemParams.DataDbConnectionString);
am.AcknowledgeAlert(se.User.UID, list, acknowledgmentcomment);
return "OK";
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private string AssignedAlertsToWorkOrder()
{
try
{
if (GetCurrentLoginSession() != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var id = HttpUtility.HtmlDecode(clientdata[0]);
var ids = HttpUtility.HtmlDecode(clientdata[1]);
long workorderid = Convert.ToInt64(id);
long[] alertids = JsonConvert.DeserializeObject<long[]>(ids);
if (alertids != null && alertids.Length == 0)
alertids = null;
AlertManager am = new AlertManager(SystemParams.DataDbConnectionString);
am.AssignedAlertsToWorkOrder(workorderid, alertids);
return "OK";
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object GetAlertsByWorkOrder()
{
try
{
if (GetCurrentLoginSession() != null)
{
var woid = Request.Form["ClientData"];
long workorderid = Convert.ToInt64(woid);
AlertManager am = new AlertManager(SystemParams.DataDbConnectionString);
AlertInfo[] alerts = am.GetAlertsByWorkOrder(workorderid);
if (alerts == null)
return new AlertInfo[0];
return alerts;
}
else
return new AlertInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAlertsByWorkOrder", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetWorkOrderAlerts()
{
try
{
if (GetCurrentLoginSession() != null)
{
var clientdata = Request.Form["ClientData"];
long workorderid = 0;
long.TryParse(clientdata, out workorderid);
AssetAlertItem[] alerts = CreateClient<WorkOrderClient>().GetAssignedAlerts(SystemParams.CompanyID, workorderid);
AlertItems items = new AlertItems();
if (alerts != null)
{
var dtcalerts = new List<AlertInfo>();
var pmaalerts = new List<AlertInfo>();
var inspectalerts = new List<AlertInfo>();
var oilalerts = new List<AlertInfo>();
foreach (AssetAlertItem alertitem in alerts.OrderByDescending(ai => ai.AlertTime))
{
List<AlertInfo> tempList = null;
if (alertitem.Category == AssetAlertCategory.PMAlert)
tempList = pmaalerts;
else if (alertitem.Category == AssetAlertCategory.InspectAlert)
tempList = inspectalerts;
else if (alertitem.Category == AssetAlertCategory.OilSampleAlert)
tempList = oilalerts;
else
tempList = dtcalerts;
var existalert = tempList.FirstOrDefault((ai) => ai.Description == alertitem.Description);
if (existalert != null)
{
existalert.AlertCount++;
if (existalert.RepeatedAlerts == null)
existalert.RepeatedAlerts = new List<long>();
existalert.RepeatedAlerts.Add(alertitem.ID);
}
else
{
var a = ConvertAlert(alertitem);
a.AlertCount = 1;
tempList.Add(a);
}
}
items.DTCAlerts = dtcalerts.ToArray();
items.PMAlerts = pmaalerts.ToArray();
items.InspectAlerts = inspectalerts.ToArray();
items.OilAlerts = oilalerts.ToArray();
}
return items;
}
else
return new AlertInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetWorkOrderAlerts", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetAssetAlerts()
{
try
{
if (GetCurrentLoginSession() != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var mid = HttpUtility.HtmlDecode(clientdata[0]);
var ids = HttpUtility.HtmlDecode(clientdata[1]);
long machineid = 0;
long.TryParse(mid, out machineid);
long[] alertids = JsonConvert.DeserializeObject<long[]>(ids);
AssetAlertGridViewItem[] alerts = CreateClient<WorkOrderClient>().GetAssetAlertGridViewItemsByAsset(SystemParams.CompanyID, machineid, Helper.DBMinDateTime, DateTime.MaxValue, null, -1, -1, "");
AlertItems items = new AlertItems();
if (alerts != null)
{
var dtcalerts = new List<AlertInfo>();
var pmaalerts = new List<AlertInfo>();
var inspectalerts = new List<AlertInfo>();
var oilalerts = new List<AlertInfo>();
foreach (AssetAlertGridViewItem alertitem in alerts.OrderByDescending(ai => ai.AlertTime))
{
if (alertids != null && alertids.Length > 0 && !alertids.Contains(alertitem.ID))
continue;
if (alertitem.Completed || alertitem.Acknowledged || alertitem.WorkOrderId > 0)
continue;
List<AlertInfo> tempList = null;
var category = DetermineAlertCategory(alertitem.AlertType);
if (category == AssetAlertCategory.PMAlert)
tempList = pmaalerts;
else if (category == AssetAlertCategory.InspectAlert)
tempList = inspectalerts;
else if (category == AssetAlertCategory.OilSampleAlert)
tempList = oilalerts;
else
tempList = dtcalerts;
var a = ConvertAlertObj(alertitem);
a.RepeatedAlerts = alertitem.RepeatedAlerts;
a.AlertCount = alertitem.RepeatedAlerts.Count + 1;
tempList.Add(a);
}
items.DTCAlerts = dtcalerts.ToArray();
items.PMAlerts = pmaalerts.ToArray();
items.InspectAlerts = inspectalerts.ToArray();
items.OilAlerts = oilalerts.ToArray();
}
return items;
}
else
return new AlertInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAssetAlerts", ex.Message, ex.ToString());
return ex.Message;
}
}
private static readonly string[] PMALERTS = new string[] { "Preventative Maintenance" };
private static readonly string[] INSPECT = new string[] { "Red-Inspect", "Yellow-Inspect", "Green-Inspect", "Info-Inspect" };
private static readonly string[] OILSAMPLE = new string[] { "Oil Sample Result" };
private static AssetAlertCategory DetermineAlertCategory(string alerttype)
{
if (PMALERTS.Contains(alerttype, StringComparer.OrdinalIgnoreCase))
{
return AssetAlertCategory.PMAlert;
}
if (INSPECT.Contains(alerttype, StringComparer.OrdinalIgnoreCase))
{
return AssetAlertCategory.InspectAlert;
}
if (OILSAMPLE.Contains(alerttype, StringComparer.OrdinalIgnoreCase))
{
return AssetAlertCategory.OilSampleAlert;
}
return AssetAlertCategory.DTCAlert;
}
private object GetAssetGroups()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var groups = MachineManagement.GetMachineGroupsByUser(session.User.UID, null);
List<StringKeyValue> list = new List<StringKeyValue>();
foreach (var gp in groups)
{
StringKeyValue kv = new StringKeyValue();
kv.Key = gp.GroupID;
kv.Value = gp.GroupName;
list.Add(kv);
}
return list.OrderBy((m) => m.Value).ToArray();
}
else
return new StringKeyValue[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAssetGroups", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetAlertTypes()
{
try
{
if (GetCurrentLoginSession() != null)
{
AlertManager am = new AlertManager(SystemParams.DataDbConnectionString);
return am.GetAlertTypes(); ;
}
else
return new StringKeyValue[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAlertTypes", ex.Message, ex.ToString());
return ex.Message;
}
}
private AlertInfo ConvertAlert(AssetAlertItem alertitem)
{
AlertInfo ai = new AlertInfo();
ai.AlertID = alertitem.ID;
ai.MachineID = alertitem.AssetID;
ai.AlertType = alertitem.AlertType;
ai.Description = alertitem.Description;
ai.AlertTime_UTC = alertitem.AlertTime;
ai.EngineHours = alertitem.EngineHours;
return ai;
}
}
public class AlertItems
{
public AlertInfo[] DTCAlerts { get; set; }
public AlertInfo[] PMAlerts { get; set; }
public AlertInfo[] InspectAlerts { get; set; }
public AlertInfo[] OilAlerts { get; set; }
}
public class AlertQueryParams
{
public string SearchText { get; set; }
public string[] AlertStatus { get; set; }
public string[] AssetGroups { get; set; }
public string[] AlertTypes { get; set; }
public string BeginDate { get; set; }
public string EndDate { get; set; }
}
public class AlertsLisenceItem
{
public bool WorkOrder = false;
public bool AcknowledgingAlerts = false;
}
}

View File

@ -0,0 +1,228 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using IronIntel.Contractor.Machines;
using IronIntel.Contractor.Maintenance;
using IronIntel.Services.Business.Admin;
using System.Web;
using IronIntel.Contractor.Users;
using Foresight.ServiceModel;
using Foresight.Fleet.Services.AssetHealth;
namespace IronIntel.Contractor.Site.Maintenance
{
public class FuelRecordBasePage : ContractorBasePage
{
protected void ProcessRequest(string methodName)
{
object result = null;
try
{
if (methodName != null)
{
switch (methodName.ToUpper())
{
case "GETFUELRECORDS":
result = GetFuelRecords();
break;
case "GETFUELRECORDCHANGEHISTORY":
result = GetFuelRecordChangeHistory();
break;
case "SAVEFUELRECORD":
result = SaveFuelRecord();
break;
case "DELETEFUELRECORD":
result = DeleteFuelRecord();
break;
case "GETFUELTYPES":
result = GetFuelTypes();
break;
}
}
}
catch (System.Threading.ThreadAbortException)
{
throw;
}
catch (Exception ex)
{
SystemParams.WriteLog("error", "FuelRecordsBasePage" + methodName, ex.Message, ex.ToString());
}
string json = JsonConvert.SerializeObject(result);
Response.Write(json);
Response.End();
}
private object GetFuelRecords()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var type = HttpUtility.HtmlDecode(clientdata[0]);
var sdatestr = HttpUtility.HtmlDecode(clientdata[1]);
var edatestr = HttpUtility.HtmlDecode(clientdata[2]);
var searchtxt = HttpUtility.HtmlDecode(clientdata[3]);
DateTime beginDate = DateTime.MinValue;
DateTime endDate = DateTime.MaxValue;
if (!DateTime.TryParse(sdatestr, out beginDate))
beginDate = DateTime.MinValue;
if (!DateTime.TryParse(edatestr, out endDate))
endDate = DateTime.MaxValue;
FuelRecord[] fuels = CreateClient<FuelManagementClient>().GetFuelRecords(SystemParams.CompanyID, Convert.ToInt64(type), beginDate, endDate, searchtxt);
List<FuelRecordInfo> list = new List<FuelRecordInfo>();
foreach (FuelRecord fuel in fuels)
{
FuelRecordInfo fi = new FuelRecordInfo();
Helper.CloneProperty(fi, fuel);
fi.TransactionDate = fi.TransactionDate.ToLocalTime();
list.Add(fi);
}
return list.ToArray();
}
else
return new FuelRecordInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "FuelRecordBasePage.GetFuelRecords", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetFuelRecordChangeHistory()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string clientdata = Request.Form["ClientData"];
long fuleid = Convert.ToInt64(HttpUtility.HtmlDecode(clientdata));
FuelRecordAuditInfo[] fuels = CreateClient<FuelManagementClient>().GetFuelRecordAuditItems(SystemParams.CompanyID, fuleid);
List<FuelRecordAuditItem> list = new List<FuelRecordAuditItem>();
foreach (FuelRecordAuditInfo fuel in fuels)
{
FuelRecordAuditItem fi = new FuelRecordAuditItem();
Helper.CloneProperty(fi, fuel);
fi.TransactionDate = fi.TransactionDate.ToLocalTime();
fi.AddedOn = fi.AddedOn.ToLocalTime();
fi.LastUpdatedOn = fi.LastUpdatedOn.ToLocalTime();
list.Add(fi);
}
return list.ToArray();
}
else
return new FuelRecordInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "FuelRecordBasePage.GetFuelRecords", ex.Message, ex.ToString());
return ex.Message;
}
}
private object SaveFuelRecord()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string clientdata = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
FuelRecordInfo fuelrecord = JsonConvert.DeserializeObject<FuelRecordInfo>(clientdata);
FuelRecord record = new FuelRecord();
Helper.CloneProperty(record, fuelrecord);
record.TransactionDate = record.TransactionDate.ToUniversalTime();
long fuleid = record.FuelID;
if (record.FuelID == -1)
{
FuelRecord fr = CreateClient<FuelManagementClient>().AddNewFuelRecord(SystemParams.CompanyID, record, session.User.UID);
fuleid = fr.FuelID;
}
else
{
CreateClient<FuelManagementClient>().UpdateFuelRecord(SystemParams.CompanyID, record, session.User.UID);
}
return fuleid;
}
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object DeleteFuelRecord()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string clientdata = Request.Form["ClientData"];
long fuleid = Convert.ToInt64(HttpUtility.HtmlDecode(clientdata));
CreateClient<FuelManagementClient>().DeleteFuelRecord(SystemParams.CompanyID, fuleid, session.User.UID);
return "OK";
}
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object GetFuelTypes()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
List<KeyValuePair<string, string>> list = FuelManagementClient.FuelTypes.OrderBy(m => m.Value).ToList();
var type1 = list.FirstOrDefault(m => m.Value == "Unleaded Regular");
var type2 = list.FirstOrDefault(m => m.Value == "Unleaded Plus");
var type3 = list.FirstOrDefault(m => m.Value == "Diesel #1");
list.Remove(type1);
list.Remove(type2);
list.Remove(type3);
list = list.OrderBy(m => m.Value).ToList();
list.Insert(0, type1);
list.Insert(1, type2);
list.Insert(2, type3);
return list.ToArray();
}
else
return new StringKeyValue[0];
}
catch (Exception ex)
{
AddLog("ERROR", "FuelRecordBasePage.GetFuelTypes", ex.Message, ex.ToString());
return ex.Message;
}
}
}
}

View File

@ -0,0 +1,458 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using IronIntel.Contractor.Machines;
using IronIntel.Contractor.Maintenance;
using IronIntel.Services.Business.Admin;
using System.Web;
using IronIntel.Contractor.Users;
using Foresight.ServiceModel;
using Foresight.Fleet.Services.Attachment;
using IronIntel.Contractor.Attachment;
namespace IronIntel.Contractor.Site.Maintenance
{
public class MaintanceRecordsBasePage : ContractorBasePage
{
protected void ProcessRequest(string methodName)
{
object result = null;
try
{
if (methodName != null)
{
switch (methodName.ToUpper())
{
case "GETTYPESDATA":
GetTypesData();
break;
case "GETRECORDS":
GetRecords();
break;
case "GETMACHINES":
Getmachines();
break;
case "GETMACHINEINFO":
GetmachineInfo();
break;
case "SEARCHMACHINELIST":
SearchmachineList();
break;
case "ADDMAINTENANCE":
result = Addmaintenance();
break;
case "GETRECORDSBYMACHINEID":
GetRecordsbymachineID();
break;
case "DELETEMAINTENANCE":
Deletemaintenance();
break;
case "GETUNCOMPLETEDPMALERTS":
result = GetUnCompletedPMAlerts();
break;
case "GETUSERSDATA":
GetUsersData();
break;
case "GETMAINTANENCELOGATTACHLIST":
result = GetMaintanenceLogAttachList();
break;
case "GETMAINTENANCEINFO":
result = GetMaintenanceInfo();
break;
case "GETATTACHMENTS":
result = GetAttachments();
break;
case "ADDATTACHMENT":
result = AddAttachment();
break;
case "DELETEATTACHMENT":
result = DeleteAttachment();
break;
}
}
}
catch (System.Threading.ThreadAbortException)
{
throw;
}
catch (Exception ex)
{
SystemParams.WriteLog("error", "MaintanceRecordsBasePage" + methodName, ex.Message, ex.ToString());
}
string json = JsonConvert.SerializeObject(result);
Response.Write(json);
Response.End();
}
private void GetTypesData()
{
string json = "";
List<KeyValuePair<int, string>> typeskeypair = new List<KeyValuePair<int, string>>();
MachineServiceClient2 mc = new MachineServiceClient2(SystemParams.SystemServiceAddresses[0]);
MachineType[] types = mc.GetMachineTypes();
foreach (MachineType item in types)
{
typeskeypair.Add(new KeyValuePair<int, string>(item.ID, item.Name));
}
if (typeskeypair.Count > 0)
{
typeskeypair = typeskeypair.OrderBy(t => t.Value).ToList();
}
json += JsonConvert.SerializeObject(typeskeypair);
Response.Write(json);
Response.End();
}
private void GetRecords()
{
var session = GetCurrentLoginSession();
string json = "";
long assetid = -1;
long.TryParse(Request.Params["assetid"], out assetid);
string maintenanceType = Request.Params["maintenancetype"];
string mtype = Request.Params["type"];
string searchtxt = HttpUtility.UrlDecode(Request.Params["searchtxt"]);
string sortype = HttpUtility.UrlDecode(Request.Params["sortype"]);
string sortdata = HttpUtility.UrlDecode(Request.Params["sortdata"]);
MaintenanceLogInfo[] logs = MaintenanceManagement.GetMaintenanceLog(session.SessionID, assetid, maintenanceType, string.IsNullOrWhiteSpace(mtype) ? -1 : Convert.ToInt32(mtype), searchtxt, session.User.UID);
if (!string.IsNullOrWhiteSpace(sortype))
{
if (string.Compare(sortype, "1", true) == 0)
{
if (string.Compare(sortdata, "DESC", true) == 0)
{
logs = logs.OrderByDescending(m => m.MaintenanceDate).ToArray();
}
else
{
logs = logs.OrderBy(m => m.MaintenanceDate).ToArray();
}
}
if (string.Compare(sortype, "2", true) == 0)
{
if (string.Compare(sortdata, "DESC", true) == 0)
{
logs = logs.OrderByDescending(m => m.AlertTime).ToArray();
}
else
{
logs = logs.OrderBy(m => m.AlertTime).ToArray();
}
}
}
json += JsonConvert.SerializeObject(logs);
Response.Write(json);
Response.End();
}
private object GetMaintenanceInfo()
{
try
{
if (GetCurrentLoginSession() != null)
{
var id = Request.Form["ClientData"];
MaintenanceLogInfo ml = MaintenanceManagement.GetMaintenanceInfo(id);
return ml;
}
else
return new MaintenanceLogInfo();
}
catch (Exception ex)
{
AddLog("ERROR", "MaintanceRecordsBasePage.GetMaintenanceInfo", ex.Message, ex.ToString());
return ex.Message;
}
}
private void GetRecordsbymachineID()
{
string json = "";
long mid = -1;
long.TryParse(Request.Params["machineID"].ToString(), out mid);
string maintenanceType = Request.Params["maintenancetype"];
MaintenanceLogInfo[] logs = MaintenanceManagement.GetMaintenanceLogByMachineID(mid, maintenanceType).OrderByDescending(log => log.MaintenanceDate).ToArray();
json += JsonConvert.SerializeObject(logs);
Response.Write(json);
Response.End();
}
private void GetmachineInfo()
{
string json = "";
long mid = -1;
long.TryParse(Request.Params["machineID"].ToString(), out mid);
MaintenanceMachineInfo machine = MaintenanceManagement.GetmachineByMachineID(mid);
json += JsonConvert.SerializeObject(machine);
Response.Write(json);
Response.End();
}
private void Getmachines()
{
var session = GetCurrentLoginSession();
string json = "";
string mtype = Request.Params["type"];
string searchtxt = HttpUtility.UrlDecode(Request.Params["searchtxt"]);
MaintenanceMachineInfo[] machines = MaintenanceManagement.GetMaintenanceMachines(session.SessionID, string.IsNullOrWhiteSpace(mtype) ? -1 : Convert.ToInt32(mtype), searchtxt, session.User.UID).OrderBy(t => t.VIN).ToArray();
json += JsonConvert.SerializeObject(machines);
Response.Write(json);
Response.End();
}
private void SearchmachineList()
{
var session = GetCurrentLoginSession();
string json = "";
string mtype = Request.Params["type"];
string searchtxt = HttpUtility.UrlDecode(Request.Params["searchtxt"]);
MaintenanceMachineInfo[] machines = MaintenanceManagement.GetMaintenanceMachines(session.SessionID, string.IsNullOrWhiteSpace(mtype) ? -1 : Convert.ToInt32(mtype), searchtxt, session.User.UID);
if (machines.Length > 0)
{
json = JsonConvert.SerializeObject(machines);
}
Response.Write(json);
Response.End();
}
private object Addmaintenance()
{
try
{
UserInfo u = GetCurrentUser();
if (u != null)
{
var clientdata = Request.Form["ClientData"];
MaintenanceLogInfo m = JsonConvert.DeserializeObject<MaintenanceLogInfo>(clientdata);
MaintenanceLogInfo oldinfo = null;
if (!string.IsNullOrEmpty(m.MaintenanceID))
{
oldinfo = MaintenanceManagement.GetMaintenanceLogByMaintenanceID(m.MaintenanceID);
}
if (oldinfo == null)
{
oldinfo = new MaintenanceLogInfo();
oldinfo.MaintenanceID = Guid.NewGuid().ToString().ToUpper();
}
oldinfo.MachineID = m.MachineID;
oldinfo.MaintenanceDate = m.MaintenanceDate;
oldinfo.MaintenanceHours = m.MaintenanceHours;
oldinfo.ODOMeter = m.ODOMeter;
oldinfo.ODOMemterUOM = m.ODOMemterUOM;
oldinfo.Notes = HttpUtility.UrlDecode(m.Notes);
oldinfo.LogType = m.LogType;
oldinfo.Cost = m.Cost;
oldinfo.InvoiceNumber = m.InvoiceNumber;
oldinfo.AttachmentIDs = m.AttachmentIDs;
if (oldinfo.AlertID != m.AlertID && oldinfo.AlertID > 0)
{//取消旧的Alert Completed状态
MaintenanceManagement.SetPMAlertCompleted(oldinfo.AlertID, false, "");
}
if (m.AlertID > 0)//对于Alert关联了Maintenance Rocord才认为是完成
{//更新新的Alert Completed状态
MaintenanceManagement.SetPMAlertCompleted(m.AlertID, true, m.CompletedByName);
}
oldinfo.CompletedByName = m.CompletedByName;
oldinfo.Completed = !string.IsNullOrWhiteSpace(m.CompletedByName);//对于Maintenance Rocord选择了Completed By就认为是完成
oldinfo.AlertID = m.AlertID;
MaintenanceManagement.UpdateMaintenanceLog(oldinfo, u.IID);
AttachmentsManagement.SaveAttach(oldinfo.MaintenanceID, u.IID, oldinfo.AttachmentIDs, AttachmentType.MaintenanceLog);
return new string[] { oldinfo.MaintenanceID, "Saved Successfully." };
}
else
return "Failed to save,The user is not logged.";
}
catch (Exception ex)
{
return ex.Message;
}
}
private void Deletemaintenance()
{
string maintenanceID = Request.Params["maintenanceid"].ToString();
UserInfo u = GetCurrentUser();
if (u != null)
{
MaintenanceLogInfo m = MaintenanceManagement.GetMaintenanceLogByMaintenanceID(maintenanceID);
if (m.AlertID > 0)//取消Alert Completed状态
MaintenanceManagement.SetPMAlertCompleted(m.AlertID, false, "");
MaintenanceManagement.DeleteMaintenanceLog(maintenanceID);
Response.Write(JsonConvert.SerializeObject("Deleted Successfully."));
}
else
Response.Write(JsonConvert.SerializeObject("Failed to delete record."));
Response.End();
}
private object GetUnCompletedPMAlerts()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
long machineid = -1;
long.TryParse(clientdata[0], out machineid);
string maintenanceid = clientdata[1];
PMAlert[] pmalerts = MaintenanceManagement.GetUnCompletedPMAlerts(machineid, maintenanceid);
return pmalerts;
}
else
return new PMAlert[0];
}
catch (Exception ex)
{
AddLog("ERROR", "MaintanceRecordsBasePage.GetUnCompletedPMAlerts", ex.Message, ex.ToString());
return ex.Message;
}
}
private void GetUsersData()
{
UserInfo[] user = UserManagement.GetUsers();
user = user.OrderBy((u) => u.DisplayName).ToArray();
string json = JsonConvert.SerializeObject(user);
Response.Write(json);
Response.End();
}
private object GetMaintanenceLogAttachList()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var id = HttpUtility.HtmlDecode(clientdata[0]);
var type = HttpUtility.HtmlDecode(clientdata[1]);
StringKeyValue[] attas = AttachmentsManagement.GetAttachList(id, type);
return attas;
}
else
return new StringKeyValue[0];
}
catch (Exception ex)
{
AddLog("ERROR", "MaintanceRecordsBasePage.GetMaintanenceLogAttachList", ex.Message, ex.ToString());
return ex.Message;
}
}
#region Attachment
private object GetAttachments()
{
try
{
if (GetCurrentLoginSession() != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var woid = HttpUtility.HtmlDecode(clientdata[0]);
AttachmentInfo[] atts = CreateClient<AttachmentClient>().GetAttachments(SystemParams.CompanyID, "MaintenanceLog", woid);
if (atts == null || atts.Length <= 0)
return new AttachmentItem[0];
List<AttachmentItem> list = new List<AttachmentItem>();
foreach (AttachmentInfo att in atts)
{
AttachmentItem item = new AttachmentItem();
Helper.CloneProperty(item, att);
item.AddedOn = item.AddedOn.ToLocalTime();
list.Add(item);
}
return list.OrderBy(m => m.AddedOn).ToArray();
}
else
return new AttachmentItem[0];
}
catch (Exception ex)
{
return ex.Message;
}
}
private object AddAttachment()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string woid = HttpUtility.HtmlDecode(Request.Form["ClientData"]);
HttpPostedFile uploadFile = null;
byte[] iconfilebyte = null;
if (Request.Files.Count > 0)
{
uploadFile = Request.Files[0];
iconfilebyte = ConvertFile2bytes(uploadFile);
}
AttachmentInfo attachment = new AttachmentInfo();
attachment.StringID = Guid.NewGuid().ToString().ToUpper();
attachment.FileName = uploadFile == null ? "" : uploadFile.FileName;
attachment.Source = "MaintenanceLog";
attachment.SourceID = woid;
attachment.FileData = iconfilebyte;
attachment.AddedByUserIID = session.User.UID;
string attid = CreateClient<AttachmentClient>().AddAttachmentLegacy(SystemParams.CompanyID, attachment);
return "OK";
}
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object DeleteAttachment()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string attachid = HttpUtility.HtmlDecode(Request.Form["ClientData"]);
CreateClient<AttachmentClient>().DeleteAttachmentLegacy(SystemParams.CompanyID, attachid, session.User.UID);
return "OK";
}
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
#endregion
}
}

View File

@ -0,0 +1,138 @@
using Foresight.ServiceModel;
using IronIntel.Services;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IronIntel.Contractor.Site.Maintenance
{
public class MaintenanceBasePage : ContractorBasePage
{
protected void ProcessRequest(string methodName)
{
object result = null;
if (methodName != null)
{
switch (methodName.ToUpper())
{
case "GETNAVS":
result = GetNavigations();
break;
}
}
string json = JsonConvert.SerializeObject(result);
Response.Write(json);
Response.End();
}
private MaintenanceNavigateItem[] GetNavigations()
{
List<MaintenanceNavigateItem> list = GetNavigateItems();
LicenseInfo license = SystemParams.GetLicense();
if (license != null && license.Items.Count > 0)
{
var alitem = license.Items.FirstOrDefault(m => m.Key == "AlertsManagement");
if (alitem == null || !Helper.IsTrue(alitem.Value))
{
MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_alertsmanagement");
list.Remove(item);
}
var woitem = license.Items.FirstOrDefault(m => m.Key == "WorkOrder");
if (woitem == null || !Helper.IsTrue(woitem.Value))
{
MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_workorder");
list.Remove(item);
}
var fuelitem = license.Items.FirstOrDefault(m => m.Key == "FuelRecords");
if (fuelitem == null || !Helper.IsTrue(fuelitem.Value))
{
MaintenanceNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_fuelrecord");
list.Remove(item);
}
}
return list.ToArray();
}
private static List<MaintenanceNavigateItem> GetNavigateItems()
{
List<MaintenanceNavigateItem> list = new List<MaintenanceNavigateItem>();
MaintenanceNavigateItem item1 = new MaintenanceNavigateItem();
item1.ID = "nav_alertsmanagement";
item1.Title = "Alerts Management **New**";
item1.Url = "AlertsManagement.aspx";
item1.IconPath = "img/alert.png";
list.Add(item1);
MaintenanceNavigateItem item6 = new MaintenanceNavigateItem();
item6.ID = "nav_workorder";
item6.Title = "Work Order **New**";
item6.Url = "WorkOrderMaintenance.aspx";
item6.IconPath = "img/workorder.png";
list.Add(item6);
MaintenanceNavigateItem item3 = new MaintenanceNavigateItem();
item3.ID = "nav_preventative";
item3.Title = "Absolute Hours Maintenance";
item3.Url = "PreventativeMaintenance.aspx";
item3.IconPath = "img/preventative.png";
list.Add(item3);
MaintenanceNavigateItem item4 = new MaintenanceNavigateItem();
item4.ID = "nav_timebased";
item4.Title = "Relative Time Maintenance";
item4.Url = "TimeBasedMaintenance.aspx";
item4.IconPath = "img/timebased.png";
list.Add(item4);
MaintenanceNavigateItem item7 = new MaintenanceNavigateItem();
item7.ID = "nav_hours";
item7.Title = "Relative Hours Maintenance";
item7.Url = "HoursMaintenance.aspx";
item7.IconPath = "img/hours.png";
list.Add(item7);
MaintenanceNavigateItem item5 = new MaintenanceNavigateItem();
item5.ID = "nav_absolutedistance";
item5.Title = "Absolute Distance Maintenance";
item5.Url = "AbsoluteDistanceMaintenance.aspx";
item5.IconPath = "img/preventative.png";
list.Add(item5);
MaintenanceNavigateItem item8 = new MaintenanceNavigateItem();
item8.ID = "nav_relativedistance";
item8.Title = "Relative Distance Maintenance";
item8.Url = "RelativeDistanceMaintenance.aspx";
item8.IconPath = "img/hours.png";
list.Add(item8);
MaintenanceNavigateItem item2 = new MaintenanceNavigateItem();
item2.ID = "nav_record";
item2.Title = "Maintenance Record **Legacy**";
item2.Url = "MaintanceRecordsManagement.aspx";
item2.IconPath = "img/record.png";
list.Add(item2);
MaintenanceNavigateItem item9 = new MaintenanceNavigateItem();
item9.ID = "nav_fuelrecord";
item9.Title = "Fuel Records";
item9.Url = "FuelRecordManagement.aspx";
item9.IconPath = "img/fuelrecord.png";
list.Add(item9);
return list;
}
public class MaintenanceNavigateItem
{
public string ID { get; set; }
public string Title { get; set; }
public string Url { get; set; }
public string IconPath { get; set; }
}
}
}

View File

@ -0,0 +1,26 @@
using IronIntel.Contractor.Maintenance;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IronIntel.Contractor.Site.Maintenance
{
public class ScheduleSaveArgs
{
public string IID { get; set; }
public string Name { get; set; }
public string ScheduleUom { get; set; }
public string Type { get; set; }
public string Notes { get; set; }
public PmIntervalItem[] Intervals { get; set; }
}
public class ScheduleMachineArgs
{
public string IID { get; set; }
public MaintenanceMachineInfo[] Machines { get; set; }
}
}

View File

@ -0,0 +1,449 @@
using Foresight.Fleet.Services.AssetHealth;
using IronIntel.Contractor.Machines;
using IronIntel.Contractor.Maintenance;
using IronIntel.Services.Business.Admin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace IronIntel.Contractor.Site.Maintenance
{
public class PreventativeMaintenanceBasePage : ContractorBasePage
{
protected void ProcessRequest(string methodName)
{
object result = null;
try
{
if (methodName != null)
{
switch (methodName.ToUpper())
{
case "GETPMSCHEDULE":
result = GetPmSchedule();
break;
case "DELETEPMSCHEDULE":
result = DeletePmScheule();
break;
case "SAVEPMSCHEDULE":
result = SavePmSchedule();
break;
case "ADDPMINTERVAL":
result = AddPmInterval();
break;
case "UPDATEPMINTERVAL":
result = UpdatePmInterval();
break;
case "DELETEPMINTERVAL":
result = DeletePmInterval();
break;
case "GETMACHINETYPES":
Machines.MachineManagement.RefreshMachineTypes();
result = MachineManagement.GetMachineTypes().OrderBy(m => m.Name).Select(t => new
{
ID = t.ID,
Name = t.Name
});
break;
case "GETMACHINELIST":
result = GetMachineList();
break;
case "GETSELECTEDMACHINES":
result = GetSelectedMachines();
break;
case "SAVEMACHINES":
result = SaveMachines();
break;
case "REMOVEPMASSETS":
result = RemovePMAssets();
break;
case "GETPMINTERVALBYSCHEDULEID":
result = GetPmIntervalByScheduleID();
break;
case "GETPMSCHEDULEBYID":
result = GetPMScheduleByID();
break;
}
}
}
catch (Exception ex)
{
result = ex.Message;
SystemParams.WriteLog("Error", "PreventativeMaintenanceBasePage.ProcessRequest", ex.Message, ex.ToString());
}
string json = JsonConvert.SerializeObject(result);
Response.Write(json);
Response.End();
}
private object GetPmIntervalByScheduleID()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string scheduleid = Request.Form["ClientData"];
return MaintenanceManagement.GetPmInterval(session.SessionID, scheduleid);
}
else
return new PmIntervalItem[0];
}
catch (Exception ex)
{
AddLog("ERROR", "PreventativeMaintenanceBasePage.GetPmIntervalByScheduleID", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetPmSchedule()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string pmtype = Request.Form["ClientData"];
if (string.IsNullOrWhiteSpace(pmtype))
pmtype = "PM";
return MaintenanceManagement.GetPmSchedule(session.SessionID, pmtype);
}
else
return new PmScheduleInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "PreventativeMaintenanceBasePage.GetPmSchedule", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetPMScheduleByID()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string scheduleid = Request.Form["ClientData"];
return MaintenanceManagement.GetPMScheduleByID(session.SessionID, scheduleid);
}
else
return null;
}
catch (Exception ex)
{
AddLog("ERROR", "PreventativeMaintenanceBasePage.GetPMScheduleByID", ex.Message, ex.ToString());
return ex.Message;
}
}
private object DeletePmScheule()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var iid = Request.Form["ClientData"];
CreateClient<PMClient>().DeletePMSchedule(SystemParams.CompanyID, iid, session.User.UID);
return string.Empty;
}
else
return "Failed";
}
catch (Exception ex)
{
return "Failed to delete schedule: " + ex.Message;
}
}
private object SavePmSchedule()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var s = HttpUtility.HtmlDecode(Request.Form["ClientData"]);
var item = JsonConvert.DeserializeObject<ScheduleSaveArgs>(s);
if (string.IsNullOrWhiteSpace(item.Name))
{
return "The schedule name cannot be empty or just whitespaces.";
}
PmScheduleInfo si;
if (item.Intervals == null)
{
item.Intervals = new PmIntervalItem[0];
}
else
{
for (int i = 0; i < item.Intervals.Length; i++)
{
if (string.IsNullOrEmpty(item.Intervals[i].PmIntervalID))
item.Intervals[i].PmIntervalID = Guid.NewGuid().ToString();
item.Intervals[i].ServiceName = item.Intervals[i].ServiceName.Trim();
}
}
si = new PmScheduleInfo
{
PmScheduleID = string.IsNullOrWhiteSpace(item.IID) ? Guid.NewGuid().ToString() : item.IID,
PmScheduleName = item.Name.Trim(),
PmScheduleType = item.Type,
PmScheduleUom = item.ScheduleUom,
Notes = item.Notes,
Intervals = item.Intervals
};
MaintenanceManagement.UpdatePmSchedule(session.SessionID, si, session.User.UID);
return si.PmScheduleID;
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private string AddPmInterval()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var s = HttpUtility.HtmlDecode(Request.Form["ClientData"]);
PmScheduleInfo item;
item = JsonConvert.DeserializeObject<PmScheduleInfo>(s);
PmIntervalItem piclient = item.Intervals[0];
piclient.PmIntervalID = Guid.NewGuid().ToString();
piclient.ScheduleId = item.PmScheduleID;
if (string.IsNullOrWhiteSpace(piclient.ServiceName))
{
return "Service Name cannot be empty.";
}
else
{
piclient.ServiceName = piclient.ServiceName.Trim();
}
MaintenanceManagement.UpdatePmInterval(session.SessionID, piclient, session.User.UID);
return string.Empty;
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object UpdatePmInterval()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var s = HttpUtility.HtmlDecode(Request.Form["ClientData"]);
PmIntervalItem item = JsonConvert.DeserializeObject<PmIntervalItem>(s);
if (string.IsNullOrWhiteSpace(item.ServiceName))
{
return "Service Name cannot be empty.";
}
else
{
item.ServiceName = item.ServiceName.Trim();
}
MaintenanceManagement.UpdatePmInterval(session.SessionID, item, session.User.UID);
return string.Empty;
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private string DeletePmInterval()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var iid = Request.Form["ClientData"];
CreateClient<PMClient>().DeletePMIntervals(SystemParams.CompanyID, new string[] { iid }, session.User.UID);
return string.Empty;
}
else
return "Failed";
}
catch (Exception ex)
{
return "Failed to delete interval: " + ex.Message;
}
}
private MaintenanceMachineInfo[] GetMachineList()
{
var session = GetCurrentLoginSession();
var s = Request.Form["ClientData"];
var type = JsonConvert.DeserializeObject<MachineItem>(s);
//MaintenanceMachineInfo[] selected;
//if (!string.IsNullOrWhiteSpace(type.VIN))
//{
// selected = MaintenanceManagement.GetPmMachinesByScheduleId(type.VIN);
//}
//else
//{
// selected = new MaintenanceMachineInfo[0];
//}
var machines = MaintenanceManagement.GetMaintenanceMachines1(session.SessionID, (int)type.MachineID, type.Name, session.User.UID)
//.Where(m => !selected.Any(t => t.MachineID == m.MachineID))
.OrderBy(m => m.VIN)
.ToArray();
return machines;
}
private PMAssetItem[] GetSelectedMachines()
{
var iid = Request.Form["ClientData"];
List<PMAssetItem> result = new List<PMAssetItem>();
var assets = CreateClient<PMClient>().GetPMAssets(SystemParams.CompanyID, iid);
foreach (var asset in assets)
{
PMAssetItem a = new PMAssetItem();
Helper.CloneProperty(a, asset);
a.EngineHours = asset.CurrentEngineHours;
a.Odometer = asset.CurrentOdometer;
result.Add(a);
}
return result.ToArray();
}
private string SaveMachines()
{
var u = GetCurrentUser();
if (u != null)
{
var s = Request.Form["ClientData"];
var p = JsonConvert.DeserializeObject<ScheduleAssetArgs>(s);
//MaintenanceManagement.UpdatePmMachines(ids.IID, ids.Assets);
List<PMAssetInfo> assets = new List<PMAssetInfo>();
if (p.Assets != null)
{
foreach (var a in p.Assets)
{
PMAssetInfo pmAsset = new PMAssetInfo();
pmAsset.AssetId = a.AssetId;
pmAsset.StartHours = a.StartHours;
pmAsset.StartOdometer = a.StartOdometer;
pmAsset.StartDate = a.StartDate;
pmAsset.StartIntervalValue = a.StartIntervalValue;
assets.Add(pmAsset);
}
}
CreateClient<PMClient>().UpdatePMScheduleAssets(SystemParams.CompanyID, p.IID, assets.ToArray(), u.IID);
}
return string.Empty;
}
private string RemovePMAssets()
{
var u = GetCurrentUser();
if (u != null)
{
var s = Request.Form["ClientData"];
var p = JsonConvert.DeserializeObject<RemovePMAssetsArgs>(s);
CreateClient<PMClient>().DeleteAssetsFromSchedule(SystemParams.CompanyID, p.ScheduleID, p.Assets, u.IID);
}
return string.Empty;
}
class RemovePMAssetsArgs
{
public string ScheduleID { get; set; }
public long[] Assets { get; set; }
}
class ScheduleAssetArgs
{
public string IID { get; set; }
public PMAssetItem[] Assets { get; set; }
}
class PMAssetItem
{
public string ModelName { get; set; }
public string Notes { get; set; }
public double? StartOdometer { get; set; }
public double? StartHours { get; set; }
public DateTime? StartDate { get; set; }
public string TypeName { get; set; }
public int AlertsCount { get; set; }
public int UnMaintainedAlert { get; set; }
public string MakeName { get; set; }
public string Name { get; set; }
public string VIN { get; set; }
public long AssetId { get; set; }
public double? EngineHours { get; set; }
public double? Odometer { get; set; }
public string PMScheduleId { get; set; }
public int? StartIntervalValue { get; set; }
public string StartDateString
{
get
{
if (StartDate == null)
return "";
else
return StartDate.Value.ToString("MM/dd/yyyy");
}
}
}
class ScheduleSaveArgs
{
public string IID { get; set; }
public string Name { get; set; }
public string ScheduleUom { get; set; }
public string Type { get; set; }
public string Notes { get; set; }
public PmIntervalItem[] Intervals { get; set; }
}
}
}

View File

@ -0,0 +1,879 @@
using Foresight.Data;
using Foresight.Fleet.Services.Asset;
using Foresight.Fleet.Services.AssetHealth;
using Foresight.Fleet.Services.Attachment;
using Foresight.Fleet.Services.JobSite;
using Foresight.ServiceModel;
using IronIntel.Contractor.Attachment;
using IronIntel.Contractor.JobSites;
using IronIntel.Contractor.Machines;
using IronIntel.Contractor.Maintenance;
using IronIntel.Contractor.MapView;
using IronIntel.Contractor.Users;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace IronIntel.Contractor.Site.Maintenance
{
public class WorkOrderBasePage : ContractorBasePage
{
protected void ProcessRequest(string methodName)
{
object result = null;
if (methodName != null)
{
switch (methodName.ToUpper())
{
case "GETWORKORDERS":
result = GetWorkOrders();
break;
case "SAVEWORKORDER":
result = SaveWorkOrder();
break;
case "DELETEWORKORDER":
result = DeleteWorkOrder();
break;
case "GETCONTACTS":
result = GetContacts();
break;
case "GETMACHINES":
result = GetMachines();
break;
case "GETWORKORDERINFO":
result = GetWorkOrderInfo();
break;
case "GETOPENWORKORDERID":
result = GetOpenWorkOrderID();
break;
case "GETSEGMENTS":
result = GetSegments();
break;
case "SAVESEGMENT":
result = SaveSegment();
break;
case "DELETESEGMENT":
result = DeleteSegment();
break;
case "GETSEGMENTCLIENT":
result = GetSegmentClient();
break;
case "GETNONEASSIGNEDALERTS":
result = GetNoneAssignedAlerts();
break;
case "ADDORREMOVEALERTSFROMWORKORDER":
result = AddOrRemoveAlertsFromWorkOrder();
break;
case "GETATTACHMENTS":
result = GetAttachments();
break;
case "ADDATTACHMENT":
result = AddAttachment();
break;
case "DELETEATTACHMENT":
result = DeleteAttachment();
break;
case "GETASSETATTACHMENTS":
result = GetAssetAttachments();
break;
case "GETMACHINECONTACTS":
result = GetMachineContacts();
break;
case "SENDWORKORDER":
result = SendWorkOrder();
break;
case "GETINVOICENUMBER":
result = GetInvoiceNumber();
break;
case "GETALERTSFORWORKORDER":
result = GetAlertsForWorkOrder();
break;
}
}
string json = JsonConvert.SerializeObject(result);
Response.Write(json);
Response.End();
}
private object GetWorkOrders()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var clientdata = Request.Form["ClientData"];
clientdata = HttpUtility.HtmlDecode(clientdata);
WorkOrderQueryParams p = JsonConvert.DeserializeObject<WorkOrderQueryParams>(clientdata);
WorkOrderItem[] workorders = null;
if (p.AssetID > 0)
workorders = CreateClient<WorkOrderClient>().GetWorkOrderItemsByAsset(SystemParams.CompanyID, p.AssetID);
else
workorders = CreateClient<WorkOrderClient>().GetWorkOrderItems(SystemParams.CompanyID, p.Contacts, p.Status, p.AssetGroups, p.SearchText, session.User.UID);
WorkOrderInfo[] maintenanceworkorders = null;//
if (p.ShowMaintenance)
maintenanceworkorders = MaintenanceManagement.GetMaintenanceWorkOrders(session.SessionID, SystemParams.CompanyID, p.Contacts, p.AssetGroups, p.SearchText, session.User.UID);
//普通用户机器权限过滤
var user = GetCurrentUser();
long[] availableAssetsids = null;
if (user.UserType < UserTypes.Admin)
availableAssetsids = CreateClient<AssetQueryClient>().GetAvailableAssetsForUsers(SystemParams.CompanyID, session.User.UID);
List<WorkOrderInfo> list = new List<WorkOrderInfo>();
if (maintenanceworkorders != null)
{
foreach (WorkOrderInfo wi in maintenanceworkorders)
{
if (availableAssetsids != null && !availableAssetsids.Contains(wi.AssetID))
continue;
list.Add(wi);
}
}
foreach (WorkOrderItem wo in workorders)
{
WorkOrderInfo wi = new WorkOrderInfo();
Helper.CloneProperty(wi, wo);
if (availableAssetsids != null && !availableAssetsids.Contains(wi.AssetID))
continue;
list.Add(wi);
}
return list.OrderBy(m => m.ID).ToArray();
}
else
return new WorkOrderInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "WorkOrderBasePage.GetWorkOrders", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetWorkOrderInfo()
{
try
{
if (GetCurrentLoginSession() != null)
{
var woid = Request.Form["ClientData"];
WorkOrderDetail wod = CreateClient<WorkOrderClient>().GetWorkOrderDetail(SystemParams.CompanyID, Convert.ToInt64(woid));
WorkOrderDetailInfo wo = new WorkOrderDetailInfo();
Helper.CloneProperty(wo, wod);
return wo;
}
else
return new WorkOrderDetailInfo();
}
catch (Exception ex)
{
AddLog("ERROR", "WorkOrderBasePage.GetWorkOrderInfo", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetAlertsForWorkOrder()
{
try
{
if (GetCurrentLoginSession() != null)
{
var clientdata = Request.Form["ClientData"];
clientdata = HttpUtility.HtmlDecode(clientdata);
string[] ps = JsonConvert.DeserializeObject<string[]>(clientdata);
var woid = ps[0];
var aid = ps[1];
long workorderid = Convert.ToInt64(woid);
long assetid = Convert.ToInt64(aid);
AlertManager am = new AlertManager(SystemParams.DataDbConnectionString);
AlertInfo[] alerts = am.GetAlertsByWorkOrder(workorderid);
AssetAlertItem[] aAlerts = CreateClient<WorkOrderClient>().GetNoneAssignedAlerts(SystemParams.CompanyID, assetid);
List<AlertInfo> assetAlerts = new List<AlertInfo>();
if (aAlerts != null)
{
foreach (var aa in aAlerts)
{
AlertInfo ai = new AlertInfo();
ai.AlertID = aa.ID;
ai.MachineID = aa.AssetID;
ai.AlertType = aa.AlertType;
ai.Description = aa.Description;
ai.AlertTime_UTC = aa.AlertTime;
assetAlerts.Add(ai);
}
}
WorkorderAlerts wa = new WorkorderAlerts();
wa.Alerts = alerts;
wa.AssetAlerts = assetAlerts.ToArray(); ;
return wa;
}
else
return null;
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetAlertsByWorkOrder", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetOpenWorkOrderID()
{
try
{
if (GetCurrentLoginSession() != null)
{
var mid = Request.Form["ClientData"];
long aid = 0;
long.TryParse(mid, out aid);
var wos = CreateClient<WorkOrderClient>().GetWorkOrderItemsByAsset(SystemParams.CompanyID, aid);
List<long> workorderids = new List<long>();
foreach (var wo in wos)
{
if (!wo.Completed)
workorderids.Add(wo.ID);
}
//WorkOrderManager workordermanager = new WorkOrderManager(SystemParams.DataDbConnectionString);
//long[] workorderids = workordermanager.GetOpenWorkOrderID(mid);
string ids = string.Join(", ", workorderids);
ids = mid + "|" + ids;
return ids;
}
else
return new WorkOrderInfo();
}
catch (Exception ex)
{
AddLog("ERROR", "WorkOrderBasePage.GetOpenWorkOrderID", ex.Message, ex.ToString());
return ex.Message;
}
}
private object SaveWorkOrder()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var workorderitem = HttpUtility.HtmlDecode(clientdata[0]);
var ids = HttpUtility.HtmlDecode(clientdata[1]);
long[] alertids = JsonConvert.DeserializeObject<long[]>(ids);
WorkOrderDetailInfo wdi = JsonConvert.DeserializeObject<WorkOrderDetailInfo>(workorderitem);
if (wdi.CompleteDate != null)
wdi.Status = "Completed";
WorkOrderDetail wo = new WorkOrderDetail();
Helper.CloneProperty(wo, wdi);
long workorderid = wo.ID;
if (wo.ID == -1)
{
wo = CreateClient<WorkOrderClient>().AddNewWorkOrder(SystemParams.CompanyID, wo, alertids, session.User.UID);
workorderid = wo.ID;
}
else
{
WorkOrderDetail oldwo = CreateClient<WorkOrderClient>().GetWorkOrderDetail(SystemParams.CompanyID, workorderid);
var user = UserManagement.GetUserByIID(session.User.UID);
if (oldwo.Status == "Completed" && user.UserType < UserTypes.Admin)
{
return "";
}
CreateClient<WorkOrderClient>().UpdateWorkOrder(SystemParams.CompanyID, wo, session.User.UID);
}
return workorderid;
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object DeleteWorkOrder()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string clientdata = Request.Form["ClientData"];
int id = Convert.ToInt32(HttpUtility.HtmlDecode(clientdata));
CreateClient<WorkOrderClient>().DeleteWorkOrder(SystemParams.CompanyID, id, session.User.UID);
return "OK";
}
return "Failed";
}
catch (Exception ex)
{
return ex.Message; ;
}
}
private UserInfo[] GetContacts()
{
var session = GetCurrentLoginSession();
UserInfo[] users = null;
if (GetCurrentLoginSession() != null)
{
//contact = ContactManagement.GetContacts();
users = UserManagement.GetActiveUsers(session.SessionID);
users = users.OrderBy(u => u.DisplayName).ToArray();
}
else
{
users = new UserInfo[0];
}
return users;
}
private MachineItem[] GetMachines()
{
var session = GetCurrentLoginSession();
MachineItem[] machines = null;
if (GetCurrentLoginSession() != null)
{
machines = MachineManagement.GetMachines(session.SessionID, session.User.UID, "");
}
else
{
machines = new MachineItem[0];
}
return machines.Where(m => m.Hide == false).OrderBy(m => m.ShowName).ToArray();
}
private object GetNoneAssignedAlerts()
{
try
{
if (GetCurrentLoginSession() != null)
{
var id = Request.Form["ClientData"];
long assetid = Convert.ToInt64(id);
AssetAlertItem[] alerts = CreateClient<WorkOrderClient>().GetNoneAssignedAlerts(SystemParams.CompanyID, assetid);
if (alerts == null || alerts.Length == 0)
return new AssetAlertInfo[0];
List<AssetAlertInfo> list = new List<AssetAlertInfo>();
foreach (AssetAlertItem alert in alerts)
{
AssetAlertInfo ai = new AssetAlertInfo();
Helper.CloneProperty(ai, alert);
ai.AlertTime = ai.AlertTime.ToLocalTime();
ai.CompletedDate = ai.AlertTime.ToLocalTime();
list.Add(ai);
}
return list.ToArray();
}
else
return new AssetAlertInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "AlertsBasePage.GetNoneAssignedAlerts", ex.Message, ex.ToString());
return ex.Message;
}
}
private object AddOrRemoveAlertsFromWorkOrder()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var woid = HttpUtility.HtmlDecode(clientdata[0]);
var ids = HttpUtility.HtmlDecode(clientdata[1]);
var isaddstr = HttpUtility.HtmlDecode(clientdata[2]);
bool isadd = Helper.IsTrue(isaddstr);
long[] alertids = JsonConvert.DeserializeObject<long[]>(ids);
CreateClient<WorkOrderClient>().AddOrRemoveAlertsFromWorkOrder(SystemParams.CompanyID, Convert.ToInt64(woid), alertids, isadd, session.User.UID);
return "OK";
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
#region Segment
private object GetSegmentClient()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
SegmentClient client = new SegmentClient();
client.Users = UserManagement.GetUsers();
if (client.Users == null)
client.Users = new UserInfo[0];
var jss = CreateClient<JobSiteProvider>().GetJobSiteItems(SystemParams.CompanyID, "", false);
List<JobSiteViewItem> list = new List<JobSiteViewItem>();
foreach (var js in jss)
{
JobSiteViewItem item = new JobSiteViewItem();
item.ID = js.ID;
item.Name = js.Name;
list.Add(item);
}
client.JobSites = list.ToArray();
if (client.JobSites == null)
client.JobSites = new JobSiteViewItem[0];
return client;
}
else
return new SegmentClient();
}
catch (Exception ex)
{
AddLog("ERROR", "WorkOrderBasePage.GetSegmentClient", ex.Message, ex.ToString());
return ex.Message;
}
}
private object GetSegments()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string clientdata = Request.Form["ClientData"];
long woid = Convert.ToInt64(HttpUtility.HtmlDecode(clientdata));
WorkOrderSegmentItem[] segments = CreateClient<WorkOrderClient>().GetSegments(SystemParams.CompanyID, woid);
if (segments == null || segments.Length == 0)
return new SegmentInfo[0];
List<SegmentInfo> list = new List<SegmentInfo>();
foreach (WorkOrderSegmentItem se in segments)
{
SegmentInfo si = new SegmentInfo();
Helper.CloneProperty(si, se);
list.Add(si);
}
return list.ToArray();
}
else
return new SegmentInfo[0];
}
catch (Exception ex)
{
AddLog("ERROR", "WorkOrderBasePage.GetSegments", ex.Message, ex.ToString());
return ex.Message;
}
}
private object SaveSegment()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string clientdata = Request.Form["ClientData"];
SegmentInfo si = JsonConvert.DeserializeObject<SegmentInfo>(clientdata);
if (si.CompletedDate != null)
si.Completed = true;
WorkOrderSegmentItem segment = new WorkOrderSegmentItem();
Helper.CloneProperty(segment, si);
long segmentid = segment.SegmentID;
if (segmentid == -1)
{
segment = CreateClient<WorkOrderClient>().AddSegment(SystemParams.CompanyID, segment, session.User.UID);
segmentid = segment.SegmentID;
}
else
{
CreateClient<WorkOrderClient>().UpdateSegment(SystemParams.CompanyID, segment, session.User.UID);
}
return segmentid;
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object DeleteSegment()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string clientdata = Request.Form["ClientData"];
int id = Convert.ToInt32(HttpUtility.HtmlDecode(clientdata));
CreateClient<WorkOrderClient>().DeleteSegment(SystemParams.CompanyID, id, session.User.UID);
return "OK";
}
return "Failed";
}
catch (Exception ex)
{
return ex.Message; ;
}
}
#endregion
#region Attachment
private object GetAttachments()
{
try
{
if (GetCurrentLoginSession() != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var woid = HttpUtility.HtmlDecode(clientdata[0]);
AttachmentInfo[] atts = CreateClient<AttachmentClient>().GetAttachments(SystemParams.CompanyID, "WorkOrder", woid);
if (atts == null || atts.Length <= 0)
return new AttachmentItem[0];
List<AttachmentItem> list = new List<AttachmentItem>();
foreach (AttachmentInfo att in atts)
{
AttachmentItem item = new AttachmentItem();
Helper.CloneProperty(item, att);
item.AddedOn = item.AddedOn.AddHours(SystemParams.GetHoursOffset());
list.Add(item);
}
return list.OrderBy(m => m.AddedOn).ToArray();
}
else
return new AttachmentItem[0];
}
catch (Exception ex)
{
return ex.Message;
}
}
private object AddAttachment()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string woid = HttpUtility.HtmlDecode(Request.Form["ClientData"]);
HttpPostedFile uploadFile = null;
byte[] iconfilebyte = null;
if (Request.Files.Count > 0)
{
uploadFile = Request.Files[0];
iconfilebyte = ConvertFile2bytes(uploadFile);
}
AttachmentInfo attachment = new AttachmentInfo();
attachment.StringID = Guid.NewGuid().ToString().ToUpper();
attachment.FileName = uploadFile == null ? "" : uploadFile.FileName;
attachment.Source = "WorkOrder";
attachment.SourceID = woid;
attachment.FileData = iconfilebyte;
attachment.AddedByUserIID = session.User.UID;
string attid = CreateClient<AttachmentClient>().AddAttachmentLegacy(SystemParams.CompanyID, attachment);
return "OK";
}
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object DeleteAttachment()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
string attachid = HttpUtility.HtmlDecode(Request.Form["ClientData"]);
CreateClient<AttachmentClient>().DeleteAttachmentLegacy(SystemParams.CompanyID, attachid, session.User.UID);
return "OK";
}
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private object GetAssetAttachments()
{
try
{
if (GetCurrentLoginSession() != null)
{
var assetid = Request.Form["ClientData"];
AssetAttachmentInfo[] atts = CreateClient<AssetAttachmentProvider>().GetAttachments(SystemParams.CompanyID, Convert.ToInt64(assetid)).Where(m => m.VisibleOnWorkOrder == true).ToArray();
if (atts == null || atts.Length <= 0)
return new AssetAttachmentItem[0];
List<AssetAttachmentItem> list = new List<AssetAttachmentItem>();
foreach (AssetAttachmentInfo att in atts)
{
AssetAttachmentItem item = new AssetAttachmentItem();
Helper.CloneProperty(item, att);
item.AddedOn = item.AddedOn.AddHours(SystemParams.GetHoursOffset());
list.Add(item);
}
return list.OrderBy(m => m.AddedOn).ToArray();
}
else
return new AssetAttachmentInfo[0];
}
catch (Exception ex)
{
return ex.Message;
}
}
#endregion
#region Sned Email
private object GetMachineContacts()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var assetid = Request.Form["ClientData"];
return UserManagement.GetUsersByAssetID(session.SessionID, Convert.ToInt64(assetid), SystemParams.CompanyID);
}
else
return new UserInfo[0];
}
catch (Exception ex)
{
return ex.Message;
}
}
private object SendWorkOrder()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
var clientdata = Request.Form["ClientData"].Split((char)170);
var woid = HttpUtility.HtmlDecode(clientdata[0]);
var address = HttpUtility.HtmlDecode(clientdata[1]);
var desc = HttpUtility.HtmlDecode(clientdata[2]);
string[] emailaddress = JsonConvert.DeserializeObject<string[]>(address);
WorkOrderDetail wod = CreateClient<WorkOrderClient>().GetWorkOrderDetail(SystemParams.CompanyID, Convert.ToInt64(woid));
WorkOrderDetailInfo wo = new WorkOrderDetailInfo();
Helper.CloneProperty(wo, wod);
SendMail(wo, emailaddress, desc, session.User);
return "OK";
}
else
return "Failed";
}
catch (Exception ex)
{
return ex.Message;
}
}
private void SendMail(WorkOrderDetailInfo wo, string[] emailaddress, string desc, Services.Users.UserInfoEx user)
{
if (emailaddress == null || emailaddress.Length == 0)
return;
string Subject = "Work Order " + wo.ID;
string Body = OrdinaryEmailFormat(wo, desc, user.ID);
CreateClient<AttachmentClient>().SendWorkOrderEmail(SystemParams.CompanyID, wo.ID, Subject, Body, emailaddress.ToArray(), user.UID);
}
private string OrdinaryEmailFormat(WorkOrderDetailInfo wo, string desc, string userid)
{
string EmailFormat = "<table>";
EmailFormat += "<tr><td><span>Details for work order <lable style=\"color:red;\"> <{3}> </lable> are listed below.To view or edit this work order,please click the below link:<br/></span><a href=\"{4}\">Link</a></td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:bold;\">Message from:&nbsp;</span>{0}</td></tr>";
EmailFormat += "<tr><td style=\"font-weight:700;\">Description:&nbsp;</td></tr>";
EmailFormat += "<tr><td style=\"padding-left:30px;padding-right:20px;\">{1}</td></tr>";
EmailFormat += "<tr><td style=\"font-weight:700;\">Work Order Information:&nbsp;</td></tr>";
EmailFormat += "<tr><td style=\"padding-left:30px;\">{2}</td></tr>";
EmailFormat += "</table>";
string absuri = Context.Request.Url.AbsoluteUri;
string wourl = absuri.Substring(0, absuri.LastIndexOf("/Maintenance", StringComparison.OrdinalIgnoreCase));
wourl = wourl + "/jump.aspx?p=" + Convert.ToBase64String(Encoding.UTF8.GetBytes("jt=woe;woid=" + wo.ID));
return string.Format(EmailFormat, userid, desc.Replace("\n", "<br>"), WorkOrderFormat(wo), wo.ID, wourl);
}
public static string WorkOrderFormat(WorkOrderDetailInfo wo)
{
string EmailFormat = "<table>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Work Order Type:&nbsp;</span>{0}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Assigned To:&nbsp;</span>{1}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Status:&nbsp;</span>{2}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Due Date:&nbsp;</span>{3}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Description:&nbsp;</span>{4}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Meter Type:&nbsp;</span>{5}</td></tr>";
if (string.Compare(wo.MeterType, "HourMeter", true) == 0 || string.Compare(wo.MeterType, "Both", true) == 0)
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Hour Meter:&nbsp;</span>{6}</td></tr>";
if (string.Compare(wo.MeterType, "Odometer", true) == 0 || string.Compare(wo.MeterType, "Both", true) == 0)
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Odometer:&nbsp;</span>{7}&nbsp;{8}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Work Order Total Costs ($):&nbsp;</span>{9}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Other Cost ($):&nbsp;</span>{19}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Parts Cost ($):&nbsp;</span>{14}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Travel Time Cost ($):&nbsp;</span>{15}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Labor Cost ($):&nbsp;</span>{16}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Hourly Rate:&nbsp;</span>{17}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Time To Complete(Hrs):&nbsp;</span>{10}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Completed Date:&nbsp;</span>{11}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Internal ID:&nbsp;</span>{12}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Invoice Number:&nbsp;</span>{18}</td></tr>";
EmailFormat += "<tr><td><span style=\"font-weight:700;\">Notes:&nbsp;</span>{13}</td></tr>";
EmailFormat += "</table>";
string SendStr = string.Format(EmailFormat,
HttpUtility.HtmlEncode(wo.WorkOrderType),
HttpUtility.HtmlEncode(wo.AssignedToName),
HttpUtility.HtmlEncode(wo.Status),
HttpUtility.HtmlEncode(wo.DueDateStr),
HttpUtility.HtmlEncode(wo.Description).Replace("\n", "<br>"),
HttpUtility.HtmlEncode(wo.MeterType),
HttpUtility.HtmlEncode(wo.HourMeter),
HttpUtility.HtmlEncode(wo.Odometer),
HttpUtility.HtmlEncode(wo.OdometerUnits),
HttpUtility.HtmlEncode(wo.WorkOrderTotalCost),
HttpUtility.HtmlEncode(wo.HoursToComplete),
HttpUtility.HtmlEncode(wo.CompleteDateStr),
HttpUtility.HtmlEncode(wo.InternalID),
HttpUtility.HtmlEncode(wo.Notes).Replace("\n", "<br>"),
HttpUtility.HtmlEncode(wo.PartsCost),
HttpUtility.HtmlEncode(wo.TravelTimeCost),
HttpUtility.HtmlEncode(wo.LaborCost),
HttpUtility.HtmlEncode(wo.HourlyRate),
HttpUtility.HtmlEncode(wo.InvoiceNumber),
HttpUtility.HtmlEncode(wo.OtherCost));
return SendStr;
}
#endregion
private object GetInvoiceNumber()
{
try
{
if (GetCurrentLoginSession() != null)
{
var woid = Request.Form["ClientData"];
return new WorkOrderManager(SystemParams.DataDbConnectionString).GetInvoiceNumber(woid);
}
else
return new string[0];
}
catch (Exception ex)
{
return ex.Message;
}
}
}
public class SegmentClient
{
public UserInfo[] Users { get; set; }
public JobSiteViewItem[] JobSites { get; set; }
}
public class WorkOrderQueryParams
{
public long AssetID { get; set; }
public string SearchText { get; set; }
public string[] Contacts { get; set; }
public string[] Status { get; set; }
public string[] AssetGroups { get; set; }
public bool ShowMaintenance { get; set; }
}
class WorkorderAlerts
{
public AlertInfo[] Alerts { get; set; }
public AlertInfo[] AssetAlerts { get; set; }
}
}