sync
This commit is contained in:
@ -15,6 +15,8 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public string AlertType { get; set; }
|
||||
public DateTime AlertTime_UTC { get; set; }
|
||||
public string AlertTime_UTCStr { get { return AlertTime_UTC == DateTime.MinValue ? "" : AlertTime_UTC.ToString(); } }
|
||||
public DateTime AlertLocalTime { get; set; }
|
||||
public string AlertLocalTimeStr { get { return AlertLocalTime == DateTime.MinValue ? "" : AlertLocalTime.ToString(); } }
|
||||
public bool Completed { get; set; }
|
||||
public long MachineID { get; set; }
|
||||
public int ModelID { get; set; }
|
||||
@ -51,7 +53,23 @@ namespace IronIntel.Contractor.Maintenance
|
||||
}
|
||||
}
|
||||
public string Description { get; set; }
|
||||
public string ServiceDescription { get; set; }
|
||||
public string FormatDescription(string desc)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(desc))
|
||||
{
|
||||
if (desc.IndexOf("\r\n") > 0)
|
||||
desc = desc.Substring(0, desc.IndexOf("\r\n"));
|
||||
if (desc.IndexOf("\n") > 0)
|
||||
desc = desc.Substring(0, desc.IndexOf("\n"));
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
public string ServiceDescription { get; set; } = "";
|
||||
public string ScheduleID { get; set; }
|
||||
public string IntervalID { get; set; }
|
||||
public bool Recurring { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public double ExpectedCost { get; set; }
|
||||
public int AlertCount { get; set; }
|
||||
public List<long> RepeatedAlerts { get; set; }
|
||||
public int OpenWorkOrderCount { get; set; }//针对Alert对应的机器
|
||||
@ -60,6 +78,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public string AcknowledgedByName { get; set; }
|
||||
public DateTime AcknowledgedTime_UTC { get; set; }
|
||||
public string AcknowledgedTime_UTCStr { get { return AcknowledgedTime_UTC == DateTime.MinValue ? "" : AcknowledgedTime_UTC.ToString(); } }
|
||||
public DateTime AcknowledgedTime_Local { get; set; }
|
||||
public string AcknowledgedTime_LocalStr { get { return AcknowledgedTime_Local == DateTime.MinValue ? "" : AcknowledgedTime_Local.ToString(); } }
|
||||
|
||||
public string AcknowledgedComment { get; set; }
|
||||
}
|
||||
|
||||
@ -99,9 +120,22 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public long ID { get; set; }
|
||||
public DateTime AlertTime { get; set; }
|
||||
public string AlertTimeStr { get { return AlertTime == DateTime.MinValue ? "" : AlertTime.ToString(); } }
|
||||
public DateTime AlertLocalTime { get; set; }
|
||||
public string AlertLocalTimeStr { get { return AlertLocalTime == DateTime.MinValue ? "" : AlertLocalTime.ToString(); } }
|
||||
public string AlertType { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string FormatDescription(string desc)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(desc))
|
||||
{
|
||||
if (desc.IndexOf("\r\n") > 0)
|
||||
desc = desc.Substring(0, desc.IndexOf("\r\n"));
|
||||
if (desc.IndexOf("\n") > 0)
|
||||
desc = desc.Substring(0, desc.IndexOf("\n"));
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
public long AssetID { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string AssetName { get; set; }
|
||||
@ -127,5 +161,6 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public string CompletedDateStr { get { return CompletedDate == null ? "" : CompletedDate.ToString(); } }
|
||||
|
||||
public AssetAlertCategory Category { get; set; }
|
||||
public string ServiceDescription { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,12 @@
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static IronIntel.Contractor.MapView.MachinesMapViewerManagement;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
@ -19,282 +17,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
}
|
||||
|
||||
const string SEL_ALERT = "select ALERTID,ALERTTYPE,ALERTTIME_UTC,COMPLETED,MACHINEID,VIN,MACHINENAME,ENGINGHOURS,ALERTDESC,PMTYPE from ALERTS";
|
||||
|
||||
public MachineInfoForAlert[] SearchMachineAlerts(string sessionid, string filtertext, string[] alertstatus, string[] alerttypes, string[] assetgroups, DateTime beginDate, DateTime endDate, string useriid)
|
||||
{
|
||||
string SQL = @"select a.ALERTID,w.WORKORDERID,wo.STATUS,ALERTTYPE,a.ALERTTIME_UTC,ISNULL(COMPLETED,0) COMPLETED,a.MACHINEID,a.VIN,a.MACHINENAME,a.ENGINGHOURS,m.ENGINEHOURS as CENGINGHOURS,ALERTDESC,m.MACHINENAME2
|
||||
,a.MAKEID,a.MODELID,pit.SERVICEDESCRIPTION
|
||||
,(select count(1) from WORKORDER wo1 where wo1.MACHINEID=a.MACHINEID and wo1.STATUS<>'Completed') as OpenWorkOrderCount,m.ONROAD,a.PMTYPE from ALERTS a with (nolock)
|
||||
left join WORKORDER_ALERTS w with (nolock) on a.ALERTID=w.ALERTID
|
||||
left join WORKORDER wo with (nolock) on w.WORKORDERID=wo.WORKORDERID
|
||||
left join MACHINES m with (nolock) on a.MACHINEID=m.MACHINEID
|
||||
left join PM_ALERTS pa with (nolock) on a.ALERTID=pa.ALERTID
|
||||
left join PM_INTERAVLS pit with (nolock) on pa.PMINTERVALID=pit.PMINTERVALID
|
||||
where m.MACHINEID is not null and (m.HIDE=0 or m.HIDE is null) and ISNULL(ACKNOWLEDGED,0)<>1 and a.ALERTTIME_UTC>={0} and a.ALERTTIME_UTC<={1} ";
|
||||
|
||||
if (Array.IndexOf(alertstatus, "Completed") >= 0 && Array.IndexOf(alertstatus, "Uncompleted") < 0)
|
||||
SQL = SQL + " and ISNULL(COMPLETED,0)=1 ";
|
||||
if (Array.IndexOf(alertstatus, "Completed") < 0 && Array.IndexOf(alertstatus, "Uncompleted") >= 0)
|
||||
SQL = SQL + " and ISNULL(COMPLETED,0)=0 ";
|
||||
if (Array.IndexOf(alertstatus, "Assigned") >= 0 && Array.IndexOf(alertstatus, "Unassigned") < 0)
|
||||
SQL = SQL + " and w.WORKORDERID is not null ";
|
||||
else if (Array.IndexOf(alertstatus, "Assigned") < 0 && Array.IndexOf(alertstatus, "Unassigned") >= 0)
|
||||
SQL = SQL + " and w.WORKORDERID is null ";
|
||||
|
||||
if (assetgroups.Length > 0)//asset group
|
||||
{
|
||||
SQL = SQL + string.Format(" and exists(select 1 from MACHINEGROUPMAP mg where mg.MACHINEID=m.MACHINEID and GROUPID in ('{0}'))", string.Join("','", assetgroups));
|
||||
}
|
||||
|
||||
string SQL_FILTER = SQL + " and (ALERTTYPE like {0} or a.MACHINEID like {0} or a.VIN like {0} or a.MACHINENAME like {0} or m.MACHINENAME2 like {0} or ALERTDESC like {0} or SERVICEDESCRIPTION like {0})";
|
||||
|
||||
string ORDER_BY = " order by ALERTID";
|
||||
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
if (beginDate != Helper.DBMinDateTime)
|
||||
beginDate = beginDate.AddHours(-timeadjust);
|
||||
if (endDate != DateTime.MaxValue)
|
||||
endDate = endDate.AddHours(-timeadjust);
|
||||
|
||||
DataTable dt = GetDataTableBySQL(SQL + ORDER_BY, beginDate, endDate);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MachineInfoForAlert[0];
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
MachineMake[] _makes = mc.GetMachineMakes();
|
||||
MachineModel[] _models = mc.GetMachineModels();
|
||||
|
||||
List<MachineInfoForAlert> results = new List<MachineInfoForAlert>(dt.Rows.Count);
|
||||
Dictionary<string, AssetEngineHour> machineEngineHours = GetAssetEngineHour();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
long mid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
string alerttype = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty).Trim();
|
||||
if (alerttypes.Length > 0 && !alerttypes.Contains(alerttype))//alerttype
|
||||
continue;
|
||||
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, timeadjust);
|
||||
|
||||
ai.ServiceDescription = FIDbAccess.GetFieldString(dr["SERVICEDESCRIPTION"], string.Empty);
|
||||
ai.WorkOrderID = FIDbAccess.GetFieldInt(dr["WORKORDERID"], 0);
|
||||
ai.WorkOrderStatus = FIDbAccess.GetFieldString(dr["STATUS"], string.Empty);
|
||||
ai.MakeID = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
ai.ModelID = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
string name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
string showname = name2;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.MachineName;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.VIN;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.MachineID.ToString();
|
||||
ai.MachineName = showname;
|
||||
|
||||
MachineMake mk = _makes.FirstOrDefault(m => m.ID == ai.MakeID);
|
||||
if (mk != null)
|
||||
ai.Make = mk.Name;
|
||||
MachineModel md = _models.FirstOrDefault(m => m.ID == ai.ModelID);
|
||||
if (md != null)
|
||||
ai.Model = md.Name;
|
||||
|
||||
MachineInfoForAlert mi = results.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 = FIDbAccess.GetFieldDouble(dr["CENGINGHOURS"], 0);// ai.EngineHours;
|
||||
if (machineEngineHours.ContainsKey(mi.MachineID.ToString()))
|
||||
{
|
||||
var meh = machineEngineHours[mi.MachineID.ToString()];
|
||||
mi.EngineHours = meh.EngineHours;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(filtertext))
|
||||
{
|
||||
if (Helper.Contains(ai.AlertType, filtertext)
|
||||
|| Helper.Contains(ai.MachineID.ToString(), filtertext)
|
||||
|| Helper.Contains(ai.VIN, filtertext)
|
||||
|| Helper.Contains(ai.MachineName, filtertext)
|
||||
|| Helper.Contains(ai.Description, filtertext)
|
||||
//|| Helper.Contains(ai.ServiceDescription, filtertext)
|
||||
|| Helper.Contains(mi.Make, filtertext)
|
||||
|| Helper.Contains(mi.Model, filtertext))
|
||||
results.Add(mi);
|
||||
}
|
||||
else
|
||||
results.Add(mi);
|
||||
}
|
||||
|
||||
if (ai.PMType == "PM_ALERT" || ai.PMType == "TBM_ALERT" || ai.PMType == "HM_ALERT"
|
||||
|| ai.PMType == "RDM_ALERT" || ai.PMType == "ADM_ALERT")
|
||||
mi.PMAlertCount++;
|
||||
else if (ai.AlertType == "Red-Inspect" || ai.AlertType == "Yellow-Inspect" || ai.AlertType == "Info-Inspect")
|
||||
mi.InspectAlertCount++;
|
||||
else
|
||||
mi.DTCAlertCount++;
|
||||
|
||||
AlertInfo oildai = mi.Alerts.FirstOrDefault(m => m.Description == ai.Description && m.MachineID == ai.MachineID);
|
||||
if (oildai == null)
|
||||
{
|
||||
ai.AlertCount = 1;
|
||||
mi.Alerts.Add(ai);
|
||||
}
|
||||
else
|
||||
{
|
||||
ai.AlertCount = oildai.AlertCount;
|
||||
int index = mi.Alerts.IndexOf(oildai);
|
||||
if (ai.AlertTime_UTC > oildai.AlertTime_UTC)
|
||||
{
|
||||
ai.AlertCount++;
|
||||
mi.Alerts[index] = ai;
|
||||
}
|
||||
else
|
||||
mi.Alerts[index].AlertCount++;
|
||||
}
|
||||
mi.OpenWorkOrders = FIDbAccess.GetFieldInt(dr["OpenWorkOrderCount"], 0);
|
||||
//mi.OpenWorkOrders = mi.Alerts.Where(m => m.WorkOrderID != 0 && m.WorkOrderStatus != "Completed").Select(m => m.WorkOrderID).Distinct().Count();
|
||||
var timealerts = mi.Alerts.OrderByDescending(m => m.AlertTime_UTC).ToArray();
|
||||
mi.LatestAlertDateTime = timealerts == null ? DateTime.MinValue : timealerts[0].AlertTime_UTC;
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] SearchAcknowledgedAlerts(string sessionid, string filtertext, string[] alertstatus, string[] alerttypes, string[] assetgroups, DateTime beginDate, DateTime endDate, string useriid)
|
||||
{
|
||||
string SQL = @"select a.ALERTID,w.WORKORDERID,wo.STATUS,ALERTTYPE,a.ALERTTIME_UTC,COMPLETED,a.MACHINEID,a.VIN,a.MACHINENAME, ENGINGHOURS,ALERTDESC,m.MACHINENAME2
|
||||
,a.MAKEID,a.MODELID,pit.SERVICEDESCRIPTION,a.PMTYPE
|
||||
,(select count(1) from WORKORDER wo1 where wo1.MACHINEID=a.MACHINEID and wo1.STATUS<>'Completed') as OpenWorkOrderCount
|
||||
,a.ACKNOWLEDGEDBY,a.ACKNOWLEDGEDDATE_UTC,a.ACKNOWLEDGMENTCOMMENT
|
||||
from ALERTS a with (nolock)
|
||||
left join WORKORDER_ALERTS w with (nolock) on a.ALERTID=w.ALERTID
|
||||
left join WORKORDER wo with (nolock) on w.WORKORDERID=wo.WORKORDERID
|
||||
left join MACHINES m with (nolock) on a.MACHINEID=m.MACHINEID
|
||||
left join PM_ALERTS pa with (nolock) on a.ALERTID=pa.ALERTID
|
||||
left join PM_INTERAVLS pit with (nolock) on pa.PMINTERVALID=pit.PMINTERVALID
|
||||
where m.MACHINEID is not null and (m.HIDE=0 or m.HIDE is null) and ISNULL(ACKNOWLEDGED,0)=1 and a.ALERTTIME_UTC>={0} and a.ALERTTIME_UTC<={1} ";
|
||||
|
||||
if (assetgroups.Length > 0)//asset group
|
||||
{
|
||||
SQL = SQL + string.Format(" and exists(select 1 from MACHINEGROUPMAP mg where mg.MACHINEID=m.MACHINEID and GROUPID in ('{0}'))", string.Join("','", assetgroups));
|
||||
}
|
||||
|
||||
const string ORDER_BY = " order by ALERTID";
|
||||
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
if (beginDate != Helper.DBMinDateTime)
|
||||
beginDate = beginDate.AddHours(-timeadjust);
|
||||
if (endDate != DateTime.MaxValue)
|
||||
endDate = endDate.AddHours(-timeadjust);
|
||||
|
||||
DataTable dt = GetDataTableBySQL(SQL + ORDER_BY, beginDate, endDate);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
MachineMake[] _makes = mc.GetMachineMakes();
|
||||
MachineModel[] _models = mc.GetMachineModels();
|
||||
UserInfo[] _users = UserManagement.GetAllAvailableUsers();
|
||||
|
||||
List<AlertInfo> result = new List<AlertInfo>(dt.Rows.Count);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
long mid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
string alerttype = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty).Trim();
|
||||
if (alerttypes.Length > 0 && !alerttypes.Contains(alerttype))//alerttype
|
||||
continue;
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, timeadjust);
|
||||
|
||||
ai.ServiceDescription = FIDbAccess.GetFieldString(dr["SERVICEDESCRIPTION"], string.Empty);
|
||||
ai.WorkOrderID = FIDbAccess.GetFieldInt(dr["WORKORDERID"], 0);
|
||||
ai.WorkOrderStatus = FIDbAccess.GetFieldString(dr["STATUS"], string.Empty);
|
||||
ai.MakeID = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
ai.ModelID = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
string name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
string showname = name2;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.MachineName;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.VIN;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.MachineID.ToString();
|
||||
ai.MachineName = showname;
|
||||
|
||||
MachineMake mk = _makes.FirstOrDefault(m => m.ID == ai.MakeID);
|
||||
if (mk != null)
|
||||
ai.Make = mk.Name;
|
||||
MachineModel md = _models.FirstOrDefault(m => m.ID == ai.ModelID);
|
||||
if (md != null)
|
||||
ai.Model = md.Name;
|
||||
|
||||
ai.AcknowledgedBy = FIDbAccess.GetFieldString(dr["ACKNOWLEDGEDBY"], string.Empty);
|
||||
ai.AcknowledgedTime_UTC = FIDbAccess.GetFieldDateTime(dr["ACKNOWLEDGEDDATE_UTC"], DateTime.MinValue);
|
||||
if (ai.AcknowledgedTime_UTC != DateTime.MinValue)
|
||||
ai.AcknowledgedTime_UTC = ai.AcknowledgedTime_UTC.AddHours(timeadjust);
|
||||
ai.AcknowledgedComment = FIDbAccess.GetFieldString(dr["ACKNOWLEDGMENTCOMMENT"], string.Empty);
|
||||
if (!string.IsNullOrWhiteSpace(ai.AcknowledgedBy))
|
||||
{
|
||||
UserInfo ui = _users.FirstOrDefault(m => m.IID == ai.AcknowledgedBy);
|
||||
if (ui != null)
|
||||
ai.AcknowledgedByName = ui.DisplayName;
|
||||
}
|
||||
|
||||
ai.OpenWorkOrderCount = FIDbAccess.GetFieldInt(dr["OpenWorkOrderCount"], 0);
|
||||
|
||||
AlertInfo existAlert = result.FirstOrDefault(m => m.Description == ai.Description && m.MachineID == ai.MachineID && m.AcknowledgedComment == ai.AcknowledgedComment);
|
||||
if (existAlert == null)
|
||||
{
|
||||
ai.AlertCount = 1;
|
||||
if (!string.IsNullOrWhiteSpace(filtertext))
|
||||
{
|
||||
if (Helper.Contains(ai.AlertType, filtertext)
|
||||
|| Helper.Contains(ai.MachineID.ToString(), filtertext)
|
||||
|| Helper.Contains(ai.VIN, filtertext)
|
||||
|| Helper.Contains(ai.MachineName, filtertext)
|
||||
|| Helper.Contains(ai.Description, filtertext)
|
||||
//|| Helper.Contains(ai.ServiceDescription, filtertext)
|
||||
|| Helper.Contains(ai.Make, filtertext)
|
||||
|| Helper.Contains(ai.Model, filtertext))
|
||||
result.Add(ai);
|
||||
}
|
||||
else
|
||||
result.Add(ai);
|
||||
}
|
||||
else
|
||||
{
|
||||
existAlert.AlertCount++;
|
||||
if (ai.AlertTime_UTC > existAlert.AlertTime_UTC)
|
||||
existAlert.AlertTime_UTC = ai.AlertTime_UTC;
|
||||
}
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public StringKeyValue[] GetAlertTypes()
|
||||
{
|
||||
const string SQL = "select distinct ltrim(rtrim(ALERTTYPE)) as ALERTTYPE from ALERTS where ISNULL(ALERTTYPE,'')<>'' order by ALERTTYPE";
|
||||
const string SQL = "select distinct ltrim(rtrim(ALERTTYPE)) as ALERTTYPE from ALERTS with(nolock) where ISNULL(ALERTTYPE,'')<>''";
|
||||
DataTable tb = GetDataTableBySQL(SQL);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
@ -309,29 +34,10 @@ namespace IronIntel.Contractor.Maintenance
|
||||
kv.Value = type;
|
||||
list.Add(kv);
|
||||
}
|
||||
return list.ToArray();
|
||||
return list.OrderBy(t => t.Key).ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] GetAlertByID(long[] alertid)
|
||||
{
|
||||
if (alertid == null || alertid.Length == 0)
|
||||
return new AlertInfo[0];
|
||||
string SQL = SEL_ALERT + string.Format(" where ALERTID in ({0})", string.Join(",", alertid));
|
||||
DataTable tb = GetDataTableBySQL(SQL);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
List<AlertInfo> ls = new List<AlertInfo>(tb.Rows.Count);
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
ls.Add(ConvertToAlertInfo(dr, timeadjust));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] GetAlertsByWorkOrder(long workorderid)
|
||||
public AlertInfo[] GetAlertsByWorkOrder(long workorderid, Foresight.Fleet.Services.User.UserInfo user)
|
||||
{
|
||||
const string SQL = @"select a.ALERTID,ALERTTYPE,a.ALERTTIME_UTC,COMPLETED,a.MACHINEID,a.VIN,a.MACHINENAME,a.ENGINGHOURS,a.ALERTDESC,pit.SERVICEDESCRIPTION,a.PMTYPE from ALERTS a
|
||||
left join PM_ALERTS pa on a.ALERTID=pa.ALERTID left join PM_INTERAVLS pit on pa.PMINTERVALID=pit.PMINTERVALID
|
||||
@ -342,73 +48,15 @@ namespace IronIntel.Contractor.Maintenance
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
List<AlertInfo> ls = new List<AlertInfo>(tb.Rows.Count);
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, timeadjust);
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, user);
|
||||
ai.ServiceDescription = FIDbAccess.GetFieldString(dr["SERVICEDESCRIPTION"], string.Empty);
|
||||
ls.Add(ai);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] GetAlertsByAlerts(long[] alertids)
|
||||
{
|
||||
const string SQL = SEL_ALERT + " where ALERTID in ({ALERTIDS}) order by ALERTID";
|
||||
|
||||
string gids = "'" + string.Join("','", alertids) + "'";
|
||||
DataTable tb = GetDataTableBySQL(SQL.Replace("{ALERTIDS}", gids));
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
List<AlertInfo> ls = new List<AlertInfo>(tb.Rows.Count);
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
ls.Add(ConvertToAlertInfo(dr, timeadjust));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] GetAlertsByMachineID(long machineid)
|
||||
{
|
||||
const string SQL = SEL_ALERT + " where MACHINEID={0} and ISNULL(COMPLETED,0)=0 and ALERTID not in(select ALERTID from WORKORDER_ALERTS)";
|
||||
|
||||
DataTable tb = GetDataTableBySQL(SQL, machineid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
List<AlertInfo> ls = new List<AlertInfo>(tb.Rows.Count);
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, timeadjust);
|
||||
|
||||
AlertInfo oildai = ls.FirstOrDefault(m => m.Description == ai.Description);
|
||||
if (oildai == null)
|
||||
{
|
||||
ai.AlertCount = 1;
|
||||
ls.Add(ai);
|
||||
}
|
||||
else
|
||||
{
|
||||
ai.AlertCount = oildai.AlertCount;
|
||||
int index = ls.IndexOf(oildai);
|
||||
if (ai.AlertTime_UTC > oildai.AlertTime_UTC)
|
||||
{
|
||||
ai.AlertCount++;
|
||||
ls[index] = ai;
|
||||
}
|
||||
else
|
||||
ls[index].AlertCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public void AcknowledgeAlert(string useriid, long[] alertids, string acknowledgmentcomment)
|
||||
{
|
||||
const string SQL = "update ALERTS set ACKNOWLEDGED=1,ACKNOWLEDGEDBY={1},ACKNOWLEDGMENTCOMMENT={2},ACKNOWLEDGEDDATE_UTC=GETUTCDATE() where ALERTID={0}";
|
||||
@ -446,121 +94,24 @@ namespace IronIntel.Contractor.Maintenance
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddMaintenanceLog(AlertInfo alert, List<Tuple<long, double, double, string>> machines, string useriid, FISqlConnection db)
|
||||
{
|
||||
const string SQL_MR = @" insert into MAINTENANCELOG(MAINTENANCEID,MACHINEID,MAINTENANCEDATE,MAINTENANCEHOURS,NOTES,ADDEDBY,ADDEDON,LASTUPDATEDBY,LASTUPDATEDON,
|
||||
ALERTID,ODOMETER,ODOMETERUOM,LOGTYPE,COMPLETEDBY,COMPLETED,COMPLETEDDATE_UTC) values({0},{1},getdate(),{2},{3},{4},GETUTCDATE(),{4},GETUTCDATE(),{5},{6},{7},{8},{4},1,GETUTCDATE())";
|
||||
|
||||
string logtype = "";
|
||||
double enginehours = 0;
|
||||
double odometer = 0;
|
||||
string odometeruom = "";
|
||||
var machine = machines.FirstOrDefault(m => m.Item1 == alert.MachineID);
|
||||
if (machine != null)
|
||||
{
|
||||
if (string.Compare(alert.PMType, "HM_ALERT", true) == 0
|
||||
|| string.Compare(alert.PMType, "PM_ALERT", true) == 0
|
||||
|| string.Compare(alert.PMType, "TBM_ALERT", true) == 0)
|
||||
{
|
||||
logtype = "Hours";
|
||||
enginehours = machine.Item2;
|
||||
enginehours = enginehours > 0 ? enginehours : 0;
|
||||
}
|
||||
else if (string.Compare(alert.PMType, "ADM_ALERT", true) == 0
|
||||
|| string.Compare(alert.PMType, "RDM_ALERT", true) == 0)
|
||||
{
|
||||
logtype = "Distance";
|
||||
odometer = machine.Item3;
|
||||
odometer = odometer > 0 ? odometer : 0;
|
||||
odometeruom = machine.Item4;
|
||||
}
|
||||
}
|
||||
db.ExecSQL(SQL_MR, Guid.NewGuid().ToString().ToUpper(), alert.MachineID, enginehours, alert.Description, useriid,
|
||||
alert.AlertID, odometer, odometeruom, logtype);
|
||||
}
|
||||
|
||||
private static List<Tuple<long, double, double, string>> GetMachines(FISqlConnection db)
|
||||
{
|
||||
const string SQL = "select MACHINEID,ENGINEHOURS,ODOMETER,ODOMETERUOM from MACHINES";
|
||||
List<Tuple<long, double, double, string>> list = new List<Tuple<long, double, double, string>>();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
long machineid = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0);
|
||||
double enginhours = FIDbAccess.GetFieldDouble(dr["ENGINEHOURS"], 0);
|
||||
double odometer = FIDbAccess.GetFieldDouble(dr["ODOMETER"], 0);
|
||||
string odometeruom = FIDbAccess.GetFieldString(dr["ODOMETERUOM"], string.Empty);
|
||||
Tuple<long, double, double, string> t = new Tuple<long, double, double, string>(machineid, enginhours, odometer, odometeruom);
|
||||
list.Add(t);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
private static StringKeyValue[] GetMachineJobSites(FISqlConnection db)
|
||||
{
|
||||
const string SQL = "select jm.MACHINEID,j.JOBSITENAME from JOBSITEMACHINES jm left join JOBSITES j on jm.JOBSITEID=j.JOBSITEID";
|
||||
List<StringKeyValue> list = new List<StringKeyValue>();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
StringKeyValue kv = new StringKeyValue();
|
||||
kv.Key = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0).ToString();
|
||||
kv.Value = FIDbAccess.GetFieldString(dr["JOBSITENAME"], string.Empty);
|
||||
list.Add(kv);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static AlertInfo ConvertToAlertInfo(DataRow dr, double timeadjust)
|
||||
private static AlertInfo ConvertToAlertInfo(DataRow dr, Foresight.Fleet.Services.User.UserInfo user)
|
||||
{
|
||||
AlertInfo ai = new AlertInfo();
|
||||
ai.AlertID = FIDbAccess.GetFieldInt(dr["ALERTID"], 0);
|
||||
ai.AlertType = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty);
|
||||
ai.AlertTime_UTC = FIDbAccess.GetFieldDateTime(dr["ALERTTIME_UTC"], DateTime.MinValue);
|
||||
if (ai.AlertTime_UTC != DateTime.MinValue)
|
||||
ai.AlertTime_UTC = ai.AlertTime_UTC.AddHours(timeadjust);
|
||||
ai.AlertLocalTime = SystemParams.ConvertToUserTimeFromUtc(user, ai.AlertTime_UTC);
|
||||
ai.Completed = FIDbAccess.GetFieldInt(dr["COMPLETED"], 0) == 1;
|
||||
ai.MachineID = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0);
|
||||
ai.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
ai.MachineName = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
ai.EngineHours = FIDbAccess.GetFieldDouble(dr["ENGINGHOURS"], 0);
|
||||
ai.Description = FIDbAccess.GetFieldString(dr["ALERTDESC"], string.Empty);
|
||||
ai.Description = ai.FormatDescription(ai.Description);
|
||||
ai.PMType = FIDbAccess.GetFieldString(dr["PMTYPE"], string.Empty);
|
||||
return ai;
|
||||
}
|
||||
|
||||
private static Dictionary<string, AssetEngineHour> GetAssetEngineHour()
|
||||
{
|
||||
const string SQL_EH = @"select * from(select AssetId as MACHINEID,AsofTime as ASOFTIME_UTC,Amount,UOM,ROW_NUMBER() over(partition by AssetId order by AsofTime desc) as RowIndex from AssetEngineHours where Datasource<>'Calamp') t where RowIndex=1";
|
||||
|
||||
DataTable tbeh = null;
|
||||
string dbString2 = SystemParams.GetIronIntelReportDataDbString(SystemParams.CompanyID);
|
||||
if (!string.IsNullOrWhiteSpace(dbString2))
|
||||
{
|
||||
var db2 = new FISqlConnection(dbString2);
|
||||
tbeh = db2.GetDataTableBySQL(SQL_EH);
|
||||
}
|
||||
|
||||
Dictionary<string, AssetEngineHour> machineEngineHours = new Dictionary<string, AssetEngineHour>();
|
||||
if (tbeh != null && tbeh.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tbeh.Rows)
|
||||
{
|
||||
string mID = FIDbAccess.GetFieldString(dr["MACHINEID"], string.Empty);
|
||||
var meh = new AssetEngineHour();
|
||||
meh.EngineHours = FIDbAccess.GetFieldDouble(dr["Amount"], -1);
|
||||
string uom = FIDbAccess.GetFieldString(dr["UOM"], string.Empty);
|
||||
if (uom.ToLower() == "s")
|
||||
meh.EngineHours = meh.EngineHours / 3600;
|
||||
meh.EngineHoursDate = FIDbAccess.GetFieldDateTime(dr["ASOFTIME_UTC"], DateTime.MinValue);
|
||||
if (meh.EngineHoursDate != DateTime.MinValue)
|
||||
meh.EngineHoursDate = meh.EngineHoursDate.AddHours(SystemParams.GetHoursOffset());
|
||||
|
||||
machineEngineHours[mID] = meh;
|
||||
}
|
||||
}
|
||||
|
||||
return machineEngineHours;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
28
IronIntelContractorBusiness/Maintenance/AlertQueryParams.cs
Normal file
28
IronIntelContractorBusiness/Maintenance/AlertQueryParams.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Foresight.Fleet.Services.AssetHealth;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class AlertQueryParams
|
||||
{
|
||||
public long AssetID { get; set; }
|
||||
public string SearchText { get; set; }
|
||||
public string[] AlertStatus { get; set; }
|
||||
public string[] AssetGroups { get; set; }
|
||||
public string[] AlertTypes { get; set; }
|
||||
public string[] JobSites { get; set; }
|
||||
public string BeginDate { get; set; }
|
||||
public string EndDate { get; set; }
|
||||
public bool IncludeunCompleted { get; set; }
|
||||
}
|
||||
|
||||
public class AutoAcknowledgeInfo : AutoAcknowledgeItem
|
||||
{
|
||||
public DateTime LocalUpdatedOn { get; set; }
|
||||
public string LocalUpdatedOnStr { get { return LocalUpdatedOn.ToString(); } }
|
||||
}
|
||||
}
|
@ -26,7 +26,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public string DriverName { get; set; }
|
||||
public string TicketNumber { get; set; }
|
||||
public DateTime TransactionDate { get; set; }
|
||||
public string TransactionDateStr { get { return TransactionDate == DateTime.MinValue ? "" : TransactionDate.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
public string TransactionDateStr { get { return TransactionDate == DateTime.MinValue ? "" : TransactionDate.ToString("M/d/yyyy h:m tt"); } }
|
||||
public DateTime TransactionLocalDate { get; set; }
|
||||
public string TransactionLocalDateStr { get { return TransactionLocalDate == DateTime.MinValue ? "" : TransactionLocalDate.ToString("M/d/yyyy h:m tt"); } }
|
||||
public string AssetModel { get; set; }
|
||||
public string AssetMake { get; set; }
|
||||
public string AssetType { get; set; }
|
||||
@ -36,6 +38,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public long FuelID { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
public string BrandName { get; set; }
|
||||
public int DistributedBy { get; set; }//0:Fueling Station 1:Fueling Asset
|
||||
public long FuelingAsset { get; set; }
|
||||
public string FuelingAssetName { get; set; }
|
||||
}
|
||||
|
||||
public class FuelRecordAuditItem : FuelRecordInfo
|
||||
@ -47,9 +52,14 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public string LasetUpdatedBy { get; set; }
|
||||
public string LasetUpdatedByName { get; set; }
|
||||
public DateTime AddedOn { get; set; }
|
||||
public string AddedOnStr { get { return AddedOn == DateTime.MinValue ? "" : AddedOn.ToString("MM/dd/yyyy HH:mm:ss"); } }
|
||||
public string AddedOnStr { get { return AddedOn == DateTime.MinValue ? "" : AddedOn.ToString("M/d/yyyy h:m:s tt"); } }
|
||||
public DateTime LastUpdatedOn { get; set; }
|
||||
public string LastUpdatedOnStr { get { return LastUpdatedOn == DateTime.MinValue ? "" : LastUpdatedOn.ToString("MM/dd/yyyy HH:mm:ss"); } }
|
||||
public string LastUpdatedOnStr { get { return LastUpdatedOn == DateTime.MinValue ? "" : LastUpdatedOn.ToString("M/d/yyyy h:m:s tt"); } }
|
||||
|
||||
public DateTime AddedOn_Local { get; set; }
|
||||
public string AddedOn_LocalStr { get { return AddedOn_Local == DateTime.MinValue ? "" : AddedOn_Local.ToString("M/d/yyyy h:m:s tt"); } }
|
||||
public DateTime LastUpdatedOn_Local { get; set; }
|
||||
public string LastUpdatedOn_LocalStr { get { return LastUpdatedOn_Local == DateTime.MinValue ? "" : LastUpdatedOn_Local.ToString("M/d/yyyy h:m:s tt"); } }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -81,9 +81,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
|
||||
private Dictionary<long, machinedata> _Machines = new Dictionary<long, machinedata>();
|
||||
|
||||
private machinedata GetMachinedata(long id)
|
||||
private machinedata GetMachinedata(FISqlConnection db, long id)
|
||||
{
|
||||
const string SQL = "select MACHINEID,VIN,MACHINENAME,MACHINENAME2,MAKEID,MODELID,TYPEID from MACHINES where MACHINEID={0}";
|
||||
const string SQL = "select MACHINEID,VIN,MACHINENAME,MACHINENAME2,MAKEID,MODELID,TYPEID from MACHINES with(nolock) where MACHINEID={0}";
|
||||
|
||||
machinedata m = null;
|
||||
if (_Machines.TryGetValue(id, out m))
|
||||
@ -91,7 +91,6 @@ namespace IronIntel.Contractor.Maintenance
|
||||
return m;
|
||||
}
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, id);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
@ -117,7 +116,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
|
||||
public void SyncAlerts()
|
||||
{
|
||||
const string SQL = "select top 100 * from IATCALERTS where ALERTID>(select isnull(max(IATCALERTID),-1) from ALERTS where SRC='LOCALTABLE_IATCALERTS') order by ALERTID";//process most 100 alerts each time
|
||||
const string SQL = "select top 100 * from IATCALERTS with(nolock) where ALERTID>(select isnull(max(IATCALERTID),-1) from ALERTS where SRC='LOCALTABLE_IATCALERTS') order by ALERTID";//process most 100 alerts each time
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL);
|
||||
@ -137,13 +136,13 @@ namespace IronIntel.Contractor.Maintenance
|
||||
|
||||
private void InsertData(FISqlConnection db, DataRow dr)
|
||||
{
|
||||
const string SQL = "if not exists(select 1 from ALERTS where SRC='LOCALTABLE_IATCALERTS' and IATCALERTID={0}) "
|
||||
const string SQL = "if not exists(select 1 from ALERTS with(nolock) where SRC='LOCALTABLE_IATCALERTS' and IATCALERTID={0}) "
|
||||
+ "insert into ALERTS(ALERTTIME_UTC,ALERTTYPE,ALERTTITLE,ALERTDESC,MACHINEID,VIN,MACHINENAME,MODELID,MODELNAME,"
|
||||
+ "MAKEID,MAKENAME,TYPEID,TYPENAME,ENGINGHOURS,LATITUDE,LONGITUDE,LOCDATE_UTC,SRC,INSERTTIME,REFID,IATCALERTID) "
|
||||
+ " values({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},'LOCALTABLE_IATCALERTS',getdate(),{0},{0})";
|
||||
+ "MAKEID,MAKENAME,TYPEID,TYPENAME,ENGINGHOURS,LATITUDE,LONGITUDE,LOCDATE_UTC,SRC,INSERTTIME,REFID,IATCALERTID,ACKNOWLEDGED,ACKNOWLEDGEDDATE_UTC) "
|
||||
+ " values({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},'LOCALTABLE_IATCALERTS',getdate(),{0},{0},{18},(case {18} when 1 then GETUTCDATE() else null end))";
|
||||
|
||||
long machineid = Convert.IsDBNull(dr["MACHINEID"]) ? -1 : Convert.ToInt64(dr["MACHINEID"]);
|
||||
machinedata m = GetMachinedata(machineid);
|
||||
machinedata m = GetMachinedata(db, machineid);
|
||||
if (m == null)
|
||||
{
|
||||
m = new machinedata();
|
||||
@ -166,7 +165,11 @@ namespace IronIntel.Contractor.Maintenance
|
||||
alerttype = DetermineAlertType(alerttype.Trim());
|
||||
if (alerttype == null)
|
||||
return;
|
||||
db.ExecSQL(SQL, alertid, alerttime, alerttype, title, desc, m.ID, m.VIN, m.CustName, m.ModelID, m.ModelName, m.MakeID, m.MakeName, m.TypeID, m.TypeName, hours, lat, lon, locdate);
|
||||
if (string.IsNullOrWhiteSpace(alerttype))
|
||||
alerttype = "";
|
||||
object obj = db.GetRC1BySQL("select isnull((select top 1 1 from AUTOACKNOWLEDGEALERTTYPES where ALERTTYPE={0}),0)", alerttype);
|
||||
bool autoAcknowledge = obj.ToString() == "1";
|
||||
db.ExecSQL(SQL, alertid, alerttime, alerttype, title, desc, m.ID, m.VIN, m.CustName, m.ModelID, m.ModelName, m.MakeID, m.MakeName, m.TypeID, m.TypeName, hours, lat, lon, locdate, autoAcknowledge ? 1 : 0);
|
||||
}
|
||||
|
||||
private string DetermineAlertType(string alerttype)
|
||||
|
@ -14,6 +14,24 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public string PmScheduleUom { get; set; }
|
||||
|
||||
public string PmScheduleType { get; set; } //PM,TBM,HM
|
||||
public string PmScheduleTypeStr
|
||||
{
|
||||
get
|
||||
{
|
||||
var rst = "";
|
||||
if (PmScheduleType == "PM")
|
||||
rst = "Absolute Hours";
|
||||
else if (PmScheduleType == "TBM")
|
||||
rst = "Relative Time";
|
||||
else if (PmScheduleType == "HM")
|
||||
rst = "Relative Hours";
|
||||
else if (PmScheduleType == "ADM")
|
||||
rst = "Absolute Distance";
|
||||
else if (PmScheduleType == "RDM")
|
||||
rst = "Relative Distance";
|
||||
return rst;
|
||||
}
|
||||
}
|
||||
public string Notes { get; set; }
|
||||
|
||||
public PmIntervalItem[] Intervals { get; set; }
|
||||
@ -29,6 +47,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
|
||||
public string ServiceName { get; set; }
|
||||
public bool Recurring { get; set; }
|
||||
public double ExpectedCost { get; set; }
|
||||
public int Priority { get; set; }
|
||||
|
||||
public string ServiceDescription { get; set; }
|
||||
@ -91,7 +110,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
if (AlertTime != DateTime.MinValue)
|
||||
{
|
||||
return AlertTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
return AlertTime.ToString("M/d/yyyy h:m:s tt");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ using Foresight.Fleet.Services.AssetHealth;
|
||||
using Foresight.Fleet.Services.User;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@ -19,11 +18,13 @@ namespace IronIntel.Contractor.Maintenance
|
||||
|
||||
#region PM SCHEDULES
|
||||
|
||||
public static PmScheduleInfo[] GetPmSchedule(string sessionid, string pmtype)
|
||||
public static PmScheduleInfo[] GetPmSchedule(string sessionid, string pmtype, string pmid, string filter)
|
||||
{
|
||||
var items = FleetServiceClientHelper.CreateClient<PMClient>(sessionid).GetPMScheduleItems(SystemParams.CompanyID, pmtype, string.Empty, true);
|
||||
var items = FleetServiceClientHelper.CreateClient<PMClient>(sessionid).GetPMScheduleItems(SystemParams.CompanyID, pmtype, filter, true);
|
||||
if (items == null || items.Length == 0)
|
||||
return new PmScheduleInfo[0];
|
||||
if (!string.IsNullOrEmpty(pmid))
|
||||
items = items.Where(m => m.Id == pmid).ToArray();
|
||||
List<PmScheduleInfo> list = new List<PmScheduleInfo>();
|
||||
foreach (var item in items)
|
||||
{
|
||||
@ -85,48 +86,6 @@ namespace IronIntel.Contractor.Maintenance
|
||||
|
||||
return pm;
|
||||
}
|
||||
//private static int[] GetAllIntervals(PMScheduleItem sc)
|
||||
//{
|
||||
// Dictionary<int, List<PMIntervalItem>> result = new Dictionary<int, List<PMIntervalItem>>();
|
||||
|
||||
// var intervals = sc.Intervals.Where(i => i.Recurring).OrderBy(i => i.Interval).ThenByDescending(i => i.Priority).ToList();
|
||||
// if (intervals.Count == 0)
|
||||
// return new int[0];
|
||||
|
||||
// int maxInterval = intervals[intervals.Count() - 1].Interval;
|
||||
// for (int i = intervals.Count - 1; i >= 0; i--)
|
||||
// {//从最大的Interval开始
|
||||
// PMIntervalItem ia = intervals[i];
|
||||
|
||||
// int tempInterval = ia.Interval;
|
||||
// var existIntervals = result.OrderBy(kv => kv.Key).Select(kv => kv.Key).ToList();
|
||||
|
||||
// if (!result.ContainsKey(tempInterval))//加入自己
|
||||
// {
|
||||
// result[tempInterval] = new List<PMIntervalItem>();
|
||||
// }
|
||||
// result[tempInterval].Add(ia);
|
||||
|
||||
// tempInterval += ia.Interval;
|
||||
// foreach (var ti in existIntervals)
|
||||
// {//result排序后找第一个比tempInterval大的值
|
||||
// while (tempInterval < ti)
|
||||
// {
|
||||
// if (!result.ContainsKey(tempInterval))
|
||||
// {
|
||||
// result[tempInterval] = new List<PMIntervalItem>();
|
||||
// }
|
||||
// result[tempInterval].Add(ia);
|
||||
// tempInterval += ia.Interval;
|
||||
// }
|
||||
|
||||
// tempInterval = ti;
|
||||
// tempInterval += ia.Interval;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return result.Select(r => r.Key).OrderBy(r => r).ToArray();
|
||||
//}
|
||||
|
||||
private static int[] GetAllIntervals(PMScheduleItem sc)
|
||||
{
|
||||
@ -140,11 +99,13 @@ namespace IronIntel.Contractor.Maintenance
|
||||
for (int i = 0; i < intervals.Count; i++)
|
||||
{
|
||||
PMIntervalItem ia = intervals[i];
|
||||
if (maxInterval == 0)
|
||||
if (maxInterval <= 0)
|
||||
maxInterval = ia.Interval;
|
||||
else
|
||||
maxInterval = GetMinCommonMultiple(maxInterval, ia.Interval);
|
||||
}
|
||||
if (maxInterval < 0 || maxInterval > 10240000)//溢出或数据过大
|
||||
maxInterval = intervals.LastOrDefault().Interval;
|
||||
for (int i = 0; i < intervals.Count; i++)
|
||||
{
|
||||
PMIntervalItem ia = intervals[i];
|
||||
@ -198,12 +159,14 @@ namespace IronIntel.Contractor.Maintenance
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static PMAssetAlertInfo[] GetPmScheduleByAsset(string sessionid, long assetid)
|
||||
public static PMAssetAlertInfo[] GetPmScheduleByAsset(string sessionid, long assetid, bool includeinterval)
|
||||
{
|
||||
List<PMAssetAlertInfo> result = new List<PMAssetAlertInfo>();
|
||||
var client = FleetServiceClientHelper.CreateClient<PMClient>(sessionid);
|
||||
var sches = client.GetPMScheduleItems(SystemParams.CompanyID, "", string.Empty, true);
|
||||
var aas = client.GetPMAssetAlertItems(SystemParams.CompanyID, assetid);
|
||||
PMAssetAlertItem[] aas = null;
|
||||
if (includeinterval)
|
||||
aas = client.GetPMAssetAlertItems(SystemParams.CompanyID, assetid);
|
||||
foreach (var item in sches)
|
||||
{
|
||||
PMAssetAlertInfo pm = new PMAssetAlertInfo();
|
||||
@ -212,7 +175,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
pm.PmScheduleUom = item.UOM;
|
||||
pm.PmScheduleType = item.ScheduleType;
|
||||
pm.Notes = item.Notes;
|
||||
if (item.Intervals != null || item.Intervals.Count > 0)
|
||||
if (includeinterval && item.Intervals != null || item.Intervals.Count > 0)
|
||||
{
|
||||
List<PmIntervalItem> lsinterval = new List<PmIntervalItem>();
|
||||
foreach (var pi in item.Intervals)
|
||||
@ -230,7 +193,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
else
|
||||
pm.Intervals = new PmIntervalItem[0];
|
||||
|
||||
if (aas != null)
|
||||
if (includeinterval && aas != null)
|
||||
{
|
||||
var aa = aas.FirstOrDefault(a => a.PMScheduleId.Equals(pm.PmScheduleID, StringComparison.OrdinalIgnoreCase));
|
||||
if (aa != null)
|
||||
@ -254,20 +217,6 @@ namespace IronIntel.Contractor.Maintenance
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static PmScheduleInfo GetPmScheduleByID(string sessionid, string scheduleid)
|
||||
{
|
||||
const string SQL = @"select PMSCHEDULEID,SCHEDULENAME,SCHEDULETYPE,NOTES,SCHEDULEUOM from PM_SCHEDULES where PMSCHEDULEID={0}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, scheduleid);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new PmScheduleInfo();
|
||||
}
|
||||
PmScheduleInfo si = ConvertPmScheduleInfo(dt.Rows[0]);
|
||||
si.Intervals = GetPmInterval(sessionid, si.PmScheduleID);
|
||||
return si;
|
||||
}
|
||||
|
||||
public static void UpdatePmSchedule(string sessionid, PmScheduleInfo si, string useriid)
|
||||
{
|
||||
PMScheduleItem pm = new PMScheduleItem();
|
||||
@ -300,103 +249,23 @@ namespace IronIntel.Contractor.Maintenance
|
||||
FleetServiceClientHelper.CreateClient<PMClient>(sessionid).UpdatePMInterval(SystemParams.CompanyID, interval, useriid);
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo[] GetPmMachinesByScheduleId(string scheduleid)
|
||||
{
|
||||
const string SQL = @"select a.MACHINEID,a.STARTDATE,a.STARTHOURS,a.STARTOTOMETER,b.MACHINENAME,b.MACHINENAME2,b.VIN,b.MAKEID,b.MODELID,b.TYPEID,b.HIDE,
|
||||
ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,ISNULL(b.ODOMETER,0) as ODOMETER,ISNULL(b.ODOMETERUOM,'Mile') AS ODOMETERUOM
|
||||
from PM_MACHINES a,MACHINES b where a.MACHINEID=b.MACHINEID and a.PMSCHEDULEID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, scheduleid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceMachineInfo[0];
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
List<MaintenanceMachineInfo> ls = new List<MaintenanceMachineInfo>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
MaintenanceMachineInfo mi = ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
ls.Add(mi);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
|
||||
private static object GetValueOrNull(DateTime v)
|
||||
{
|
||||
if (v == DateTime.MinValue || v == new DateTime(1900, 1, 1))
|
||||
return null;
|
||||
else
|
||||
return v;
|
||||
}
|
||||
|
||||
public static void DeletePmMachine(string scheduleid, string machineid)
|
||||
{
|
||||
const string SQL = "delete from PM_MACHINES where PMSCHEDULEID={0} and MACHINEID={1}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, scheduleid, machineid);
|
||||
}
|
||||
|
||||
private static bool CheckPmScheduleNameRepeat(string scheduleid, string schedulename)
|
||||
{
|
||||
const string SQL = "select COUNT(1) from PM_SCHEDULES where PMSCHEDULEID!={0} and SCHEDULENAME={1}";
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
object obj = db.GetRC1BySQL(SQL, scheduleid, schedulename);
|
||||
if (Convert.ToInt32(obj) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool CheckPmScheduleHasMachine(string scheduleid)
|
||||
{
|
||||
const string SQL_M = "select COUNT(1) from PM_MACHINES where PMSCHEDULEID={0}";
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
object objm = db.GetRC1BySQL(SQL_M, scheduleid);
|
||||
if (Convert.ToInt32(objm) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static PmScheduleInfo ConvertPmScheduleInfo(DataRow dr)
|
||||
{
|
||||
PmScheduleInfo si = new PmScheduleInfo();
|
||||
si.PmScheduleID = FIDbAccess.GetFieldString(dr["PMSCHEDULEID"], string.Empty);
|
||||
si.PmScheduleName = FIDbAccess.GetFieldString(dr["SCHEDULENAME"], string.Empty);
|
||||
si.PmScheduleType = FIDbAccess.GetFieldString(dr["SCHEDULETYPE"], string.Empty);
|
||||
si.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
si.PmScheduleUom = FIDbAccess.GetFieldString(dr["SCHEDULEUOM"], string.Empty);
|
||||
return si;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Maintenance Log
|
||||
|
||||
public static MaintenanceLogInfo[] GetMaintenanceLog(string sessionid, long assetid, string maintenancetype, int machinetype, string searchtxt, string useriid)
|
||||
public static MaintenanceLogInfo[] GetMaintenanceLog(string sessionid, long assetid, string maintenancetype, int machinetype, string searchtxt, DateTime starttime, DateTime endtime, string useriid)
|
||||
{
|
||||
const string SQL = @"select a.MAINTENANCEID,a.MACHINEID,a.MAINTENANCEDATE,a.MAINTENANCEHOURS,a.NOTES,a.ALERTID,b.MACHINENAME,b.MACHINENAME2, b.VIN,b.MAKEID, b.MODELID,b.TYPEID,ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,
|
||||
t.ALERTTYPE,t.ALERTTITLE,t.ALERTTIME_UTC,ISNULL(a.ODOMETER,0) AS ODOMETER,ISNULL(a.ODOMETERUOM,'Hour') AS ODOMETERUOM, isnull(LOGTYPE,'Hours') AS LOGTYPE ,a.COST,a.INVOICENUMBER,a.COMPLETEDBY,a.COMPLETEDBYUSERNAME,
|
||||
(select top 1 ATTACHID from ATTACHES where SOURCE='MaintenanceLog' and REFID=a.MAINTENANCEID and isnull(DELETED,0)=0) ATTACHID
|
||||
from MAINTENANCELOG a left join ALERTS t on a.ALERTID=t.ALERTID,MACHINES b
|
||||
where a.MACHINEID = b.MACHINEID and ISNULL(b.HIDE,0)<>1";
|
||||
(select top 1 ATTACHID from ATTACHES with(nolock) where SOURCE='MaintenanceLog' and REFID=a.MAINTENANCEID and isnull(DELETED,0)=0) ATTACHID
|
||||
from MAINTENANCELOG a with(nolock) left join ALERTS t with(nolock) on a.ALERTID=t.ALERTID,MACHINES b
|
||||
where a.MACHINEID = b.MACHINEID and ISNULL(b.HIDE,0)<>1 and a.MAINTENANCEDATE>={0} and a.MAINTENANCEDATE<={1} ";
|
||||
const string ORDER_BY = " ORDER BY a.ADDEDON DESC";
|
||||
|
||||
DateTime sttime = new DateTime(starttime.Year, starttime.Month, starttime.Day, 0, 0, 0);
|
||||
DateTime ettime = new DateTime(endtime.Year, endtime.Month, endtime.Day, 23, 59, 59);
|
||||
|
||||
string sql = SQL;
|
||||
//if (string.Compare("Distance", maintenancetype, true) == 0)
|
||||
//{
|
||||
// sql = SQL + " and a.LOGTYPE='" + maintenancetype + "'";
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// sql = SQL + " and a.LOGTYPE='" + maintenancetype + "'";
|
||||
// sql = SQL + " and (a.LOGTYPE='" + maintenancetype + "' or a.LOGTYPE is null)";
|
||||
//}
|
||||
if (assetid > 0)
|
||||
{
|
||||
sql = sql + " and a.MACHINEID=" + assetid;
|
||||
@ -411,7 +280,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
}
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(sql, useriid);
|
||||
DataTable dt = db.GetDataTableBySQL(sql, sttime, ettime);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceLogInfo[0];
|
||||
@ -423,9 +292,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
AssetMake[] makes = MachineManagement.GetMachineMakes();
|
||||
AssetModel[] models = MachineManagement.GetMachineModels();
|
||||
AssetType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
List<MaintenanceLogInfo> list = new List<MaintenanceLogInfo>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
@ -478,9 +347,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
}
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
AssetMake[] makes = MachineManagement.GetMachineMakes();
|
||||
AssetModel[] models = MachineManagement.GetMachineModels();
|
||||
AssetType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
MaintenanceLogInfo ml = ConvertToMaintenanceLogInfo(dt.Rows[0], makes, models, types);
|
||||
return ml;
|
||||
@ -501,9 +370,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
}
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
AssetMake[] makes = MachineManagement.GetMachineMakes();
|
||||
AssetModel[] models = MachineManagement.GetMachineModels();
|
||||
AssetType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
List<MaintenanceLogInfo> list = new List<MaintenanceLogInfo>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
@ -527,9 +396,9 @@ namespace IronIntel.Contractor.Maintenance
|
||||
return new MaintenanceLogInfo();
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
AssetMake[] makes = MachineManagement.GetMachineMakes();
|
||||
AssetModel[] models = MachineManagement.GetMachineModels();
|
||||
AssetType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
MaintenanceLogInfo ml = ConvertToMaintenanceLogInfo(dt.Rows[0], makes, models, types);
|
||||
return ml;
|
||||
@ -538,10 +407,10 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public static void UpdateMaintenanceLog(MaintenanceLogInfo ml, string addedby)
|
||||
{
|
||||
const string SQL = @"if exists(select 1 from MAINTENANCELOG where MAINTENANCEID={0}) update MAINTENANCELOG set MACHINEID ={1},MAINTENANCEDATE ={2},
|
||||
MAINTENANCEHOURS={3},NOTES={4},LASTUPDATEDBY={5},LASTUPDATEDON=GETUTCDATE(),ALERTID={6},ODOMETER={7},ODOMETERUOM={8},LOGTYPE={9},COST={10},INVOICENUMBER={11},COMPLETEDBYUSERNAME={12},COMPLETED={13},COMPLETEDDATE_UTC= (case {13} when 1 then GETUTCDATE() else null end) where MAINTENANCEID={0} else insert into MAINTENANCELOG(MAINTENANCEID,
|
||||
MACHINEID,MAINTENANCEDATE,MAINTENANCEHOURS,NOTES,ADDEDBY,ADDEDON,LASTUPDATEDBY,LASTUPDATEDON,ALERTID,ODOMETER,ODOMETERUOM,LOGTYPE,COST,INVOICENUMBER,COMPLETEDBYUSERNAME,COMPLETED,COMPLETEDDATE_UTC) values({0},{1},{2},{3},{4},{5},GETUTCDATE(),{5},GETUTCDATE(),{6},{7},{8},{9},{10},{11},{12},{13},(case {13} when 1 then GETUTCDATE() else null end))";
|
||||
MAINTENANCEHOURS={3},NOTES={4},LASTUPDATEDBY={5},LASTUPDATEDON=GETUTCDATE(),ALERTID={6},ODOMETER={7},ODOMETERUOM={8},LOGTYPE={9},COST={10},INVOICENUMBER={11},COMPLETEDBYUSERNAME={12},COMPLETED={13},COMPLETEDDATE_UTC= (case {13} when 1 then GETDATE() else null end) where MAINTENANCEID={0} else insert into MAINTENANCELOG(MAINTENANCEID,
|
||||
MACHINEID,MAINTENANCEDATE,MAINTENANCEHOURS,NOTES,ADDEDBY,ADDEDON,LASTUPDATEDBY,LASTUPDATEDON,ALERTID,ODOMETER,ODOMETERUOM,LOGTYPE,COST,INVOICENUMBER,COMPLETEDBYUSERNAME,COMPLETED,COMPLETEDDATE_UTC) values({0},{1},{2},{3},{4},{5},GETUTCDATE(),{5},GETUTCDATE(),{6},{7},{8},{9},{10},{11},{12},{13},(case {13} when 1 then GETDATE() else null end))";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, ml.MaintenanceID, ml.MachineID, ml.MaintenanceDate, ml.MaintenanceHours, ml.Notes, addedby, ml.AlertID, ml.ODOMeter, ml.ODOMemterUOM, ml.LogType, ml.Cost, ml.InvoiceNumber, ml.CompletedByName, ml.Completed ? 1 : 0);
|
||||
db.ExecSQL(SQL, ml.MaintenanceID, ml.MachineID, ml.MaintenanceDate, ml.MaintenanceHours, ml.Notes, addedby, ml.AlertID, ml.ODOMeter, ml.ODOMemterUOM, ml.LogType, ml.Cost, ml.InvoiceNumber, ml.CompletedByName, ml.Completed ? 1 : 0);//COMPLETEDDATE_UTC保存的GETDATE(),与WorkOrder里面的录入的实际保存一致
|
||||
}
|
||||
|
||||
public static void DeleteMaintenanceLog(string maintencelogid)
|
||||
@ -551,13 +420,6 @@ namespace IronIntel.Contractor.Maintenance
|
||||
db.ExecSQL(SQL, maintencelogid);
|
||||
}
|
||||
|
||||
public static bool HasMaintenanceLog(long machineid)
|
||||
{
|
||||
const string SQL = "SELECT count([MAINTENANCEDATE]) FROM [MAINTENANCELOG] where MACHINEID={0}";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
return (int?)db.GetRC1BySQL(SQL, machineid) > 0;
|
||||
}
|
||||
|
||||
public static PMAlert[] GetUnCompletedPMAlerts(long machineid, string maintencelogid)
|
||||
{
|
||||
List<PMAlert> alerts = new List<PMAlert>();
|
||||
@ -572,7 +434,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
alert.AlertTitle = FIDbAccess.GetFieldString(dr["ALERTTITLE"], string.Empty);
|
||||
DateTime at = FIDbAccess.GetFieldDateTime(dr["ALERTTIME_UTC"], DateTime.MinValue);
|
||||
if (at != DateTime.MinValue)
|
||||
alert.AlertTime = at.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
alert.AlertTime = at.ToString("M/d/yyyy h:m:s tt");
|
||||
alerts.Add(alert);
|
||||
}
|
||||
return alerts.ToArray();
|
||||
@ -585,7 +447,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
db.ExecSQL(SQL, completed ? 1 : 0, alertID, completedby);
|
||||
}
|
||||
|
||||
private static MaintenanceLogInfo ConvertToMaintenanceLogInfo(DataRow dr, MachineMake[] makes, MachineModel[] models, MachineType[] types)
|
||||
private static MaintenanceLogInfo ConvertToMaintenanceLogInfo(DataRow dr, AssetMake[] makes, AssetModel[] models, AssetType[] types)
|
||||
{
|
||||
MaintenanceLogInfo ml = new MaintenanceLogInfo();
|
||||
ml.MaintenanceID = FIDbAccess.GetFieldString(dr["MAINTENANCEID"], string.Empty);
|
||||
@ -606,40 +468,40 @@ namespace IronIntel.Contractor.Maintenance
|
||||
ml.CompletedByName = FIDbAccess.GetFieldString(dr["COMPLETEDBYUSERNAME"], "");
|
||||
|
||||
int makeid = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
MachineMake make = MachineManagement.GetMachineMake(makes, makeid);
|
||||
AssetMake make = MachineManagement.GetMachineMake(makes, makeid);
|
||||
ml.MachineMake = make == null ? string.Empty : make.Name;
|
||||
|
||||
int modelid = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
MachineModel model = MachineManagement.GetMachineModel(models, modelid);
|
||||
AssetModel model = MachineManagement.GetMachineModel(models, modelid);
|
||||
ml.MachineModel = model == null ? string.Empty : model.Name;
|
||||
|
||||
int typeid = FIDbAccess.GetFieldInt(dr["TYPEID"], 0);
|
||||
MachineType mtype = MachineManagement.GetMachineType(types, typeid);
|
||||
AssetType mtype = MachineManagement.GetMachineType(types, typeid);
|
||||
ml.MachineType = mtype == null ? string.Empty : mtype.Name;
|
||||
|
||||
return ml;
|
||||
}
|
||||
|
||||
public static WorkOrderInfo[] GetMaintenanceWorkOrders(string sessionid, string custid, string[] assignedusers, string[] asseitgroups, string filter, string useriid)
|
||||
public static WorkOrderListItemClient[] GetMaintenanceWorkOrders(string sessionid, string custid, string[] assignedusers, string[] asseitgroups, string filter, string useriid)
|
||||
{
|
||||
const string SQL = @"select m.MAINTENANCEID,m.COMPLETEDBY,(select USERNAME from USERS where USERS.USERIID=m.COMPLETEDBY) as ASSIGNEDTONAME,m.NOTES,m.MAINTENANCEDATE
|
||||
,b.MACHINEID,b.VIN,b.MACHINENAME,b.MACHINENAME2 from MAINTENANCELOG m left join MACHINES b on b.MACHINEID=m.MACHINEID
|
||||
where m.ALERTID not in (select ALERTID from WORKORDER_ALERTS) and m.MACHINEID = b.MACHINEID and ISNULL(b.HIDE,0)<>1 ";
|
||||
const string SQL = @"select m.MAINTENANCEID,m.COMPLETEDBY,(select USERNAME from USERS with(nolock) where USERS.USERIID=m.COMPLETEDBY) as ASSIGNEDTONAME,m.NOTES,m.MAINTENANCEDATE
|
||||
,b.MACHINEID,b.VIN,b.MACHINENAME,b.MACHINENAME2 from MAINTENANCELOG m with(nolock) left join MACHINES b with(nolock) on b.MACHINEID=m.MACHINEID
|
||||
where m.ALERTID not in (select ALERTID from WORKORDER_ALERTS with(nolock)) and m.MACHINEID = b.MACHINEID and ISNULL(b.HIDE,0)<>1 ";
|
||||
const string SQL_FILTER = " and (m.NOTES like {0} or b.MACHINEID like {0} or b.VIN like {0} or b.MACHINENAME like {0} or b.MACHINENAME2 like {0}) ";
|
||||
const string SQL_ORDERBY = " order by m.MAINTENANCEID";
|
||||
|
||||
var user = FleetServiceClientHelper.CreateClient<UserQueryClient>(custid, sessionid).GetUserByIID(useriid);
|
||||
if (user == null || (!user.Active))
|
||||
{
|
||||
return new WorkOrderInfo[0];
|
||||
return new WorkOrderListItemClient[0];
|
||||
}
|
||||
if (user == null || (!user.Active))
|
||||
{
|
||||
return new WorkOrderInfo[0];
|
||||
return new WorkOrderListItemClient[0];
|
||||
}
|
||||
if (string.Compare(user.CompanyID, SystemParams.CompanyID, true) != 0 && (!user.IsForesightUser))
|
||||
{
|
||||
return new WorkOrderInfo[0];
|
||||
return new WorkOrderListItemClient[0];
|
||||
}
|
||||
|
||||
string sql = SQL;
|
||||
@ -666,12 +528,12 @@ namespace IronIntel.Contractor.Maintenance
|
||||
dt = db.GetDataTableBySQL(sql + SQL_FILTER + SQL_ORDERBY, "%" + filter + "%");
|
||||
|
||||
if (dt.Rows.Count == 0)
|
||||
return new WorkOrderInfo[0];
|
||||
return new WorkOrderListItemClient[0];
|
||||
|
||||
List<WorkOrderInfo> list = new List<WorkOrderInfo>();
|
||||
List<WorkOrderListItemClient> list = new List<WorkOrderListItemClient>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
WorkOrderInfo wo = new WorkOrderInfo();
|
||||
WorkOrderListItemClient wo = new WorkOrderListItemClient();
|
||||
|
||||
long assetid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (assets != null && assets.Length > 0)
|
||||
@ -681,14 +543,15 @@ namespace IronIntel.Contractor.Maintenance
|
||||
continue;
|
||||
}
|
||||
}
|
||||
wo.AssetID = assetid;
|
||||
wo.AssignedTo = FIDbAccess.GetFieldString(dr["COMPLETEDBY"], string.Empty);
|
||||
wo.AssetId = assetid;
|
||||
wo.MaintenanceID = FIDbAccess.GetFieldString(dr["MAINTENANCEID"], string.Empty);
|
||||
wo.Description = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
wo.CompleteDate = FIDbAccess.GetFieldDateTime(dr["MAINTENANCEDATE"], DateTime.MinValue);
|
||||
wo.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
wo.AssetName = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
wo.AssignedToName = FIDbAccess.GetFieldString(dr["ASSIGNEDTONAME"], wo.AssignedTo);
|
||||
//var assignedTo = FIDbAccess.GetFieldString(dr["COMPLETEDBY"], string.Empty);
|
||||
//wo.AssignedToName = FIDbAccess.GetFieldString(dr["ASSIGNEDTONAME"], assignedTo);
|
||||
|
||||
wo.WorkOrderNumber = "";
|
||||
|
||||
list.Add(wo);
|
||||
}
|
||||
@ -717,7 +580,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
#region Machines
|
||||
|
||||
|
||||
public static MaintenanceMachineInfo[] GetMaintenanceMachines1(string sessionid, int machinetype, string searchtxt, string useriid, string companyid = null)
|
||||
public static MaintenanceMachineInfo[] GetMaintenanceMachines(string sessionid, int machinetype, string searchtxt, string useriid, string companyid = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
@ -727,7 +590,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
var client = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = client.GetAvailableAssetsForUsers(companyid, useriid);
|
||||
AssetBasicInfo[] assets = client.GetAssetBasicInfo(companyid, searchtxt, availableAssetsids);
|
||||
AssetBasicInfo[] assets = client.GetAssetBasicInfo(companyid, searchtxt, availableAssetsids, 0);
|
||||
if (assets != null && machinetype != -1)
|
||||
assets = assets.Where(m => m.TypeID == machinetype).ToArray();
|
||||
long[] mids = null;
|
||||
@ -749,7 +612,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
mi.TypeID = a.TypeID;
|
||||
mi.MachineType = a.TypeName;
|
||||
mi.Hide = a.Hide;
|
||||
mi.EngineHours = a.EngineHours;
|
||||
mi.EngineHours = a.EngineHours == null ? 0 : a.EngineHours.Value;
|
||||
if (odos != null && odos.Length > 0)
|
||||
{
|
||||
var odo = odos.FirstOrDefault((o) => o.AssetID == mi.MachineID);
|
||||
@ -763,104 +626,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo[] GetMaintenanceMachines(string sessionid, int machinetype, string searchtxt, string useriid, string companyid = null)
|
||||
{
|
||||
const string SQL = @"select m.MACHINEID,m.MACHINENAME2,m.MACHINENAME,m.MAKEID,m.MODELID,m.TYPEID,m.VIN,ISNULL(m.ENGINEHOURS,0) as ENGINEHOURS,
|
||||
ISNULL(m.ODOMETER,0) as ODOMETER,ISNULL(m.ODOMETERUOM,'Mile') AS ODOMETERUOM,m.HIDE from MACHINES m
|
||||
where 1=1";
|
||||
const string ORDER_BY = " order by MACHINEID";
|
||||
|
||||
string sql = string.Empty;
|
||||
if (machinetype >= 0)
|
||||
{
|
||||
sql = SQL + " and TYPEID=" + machinetype.ToString() + ORDER_BY;
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = SQL + ORDER_BY;
|
||||
}
|
||||
|
||||
FIDbAccess db = null;
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
{
|
||||
companyid = SystemParams.CompanyID;
|
||||
db = SystemParams.GetDbInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
string connetionstring = SystemParams.GetDbStringByCompany(companyid);
|
||||
db = new FISqlConnection(connetionstring);
|
||||
}
|
||||
|
||||
DataTable tb = db.GetDataTableBySQL(sql);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceMachineInfo[0];
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid).GetAvailableAssetsForUsers(companyid, useriid);
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
List<MaintenanceMachineInfo> ls = new List<MaintenanceMachineInfo>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
long mid = Convert.ToInt64(dr["MACHINEID"]);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
MaintenanceMachineInfo mi = ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
mi.Hide = FIDbAccess.GetFieldInt(dr["HIDE"], 0) == 1;
|
||||
if (mi.Hide) continue;
|
||||
if (!string.IsNullOrWhiteSpace(searchtxt))
|
||||
{
|
||||
if (Helper.Contains(mi.VIN, searchtxt)
|
||||
|| Helper.Contains(mi.MachineID.ToString(), searchtxt)
|
||||
|| Helper.Contains(mi.MachineName, searchtxt)
|
||||
|| Helper.Contains(mi.MachineName2, searchtxt)
|
||||
|| Helper.Contains(mi.Make, searchtxt)
|
||||
|| Helper.Contains(mi.MachineType, searchtxt)
|
||||
|| Helper.Contains(mi.Model, searchtxt))
|
||||
{
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo GetmachineByMachineID(long machineid)
|
||||
{
|
||||
string SQL = @"select MACHINEID,MACHINENAME,MACHINENAME2,MAKEID,MODELID,TYPEID,VIN,ISNULL(ENGINEHOURS,0) as ENGINEHOURS,
|
||||
ISNULL(ODOMETER,0) as ODOMETER,ISNULL(ODOMETERUOM,'Mile') AS ODOMETERUOM from MACHINES where MACHINEID={0}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, machineid);
|
||||
MaintenanceMachineInfo mi = new MaintenanceMachineInfo();
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
mi.MachineID = -1;
|
||||
return mi;
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
mi = ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
}
|
||||
return mi;
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo ConvertToMaintenanceMachineInfo(DataRow dr, MachineMake[] makes, MachineModel[] models, MachineType[] types)
|
||||
public static MaintenanceMachineInfo ConvertToMaintenanceMachineInfo(DataRow dr, AssetMake[] makes, AssetModel[] models, AssetType[] types)
|
||||
{
|
||||
MaintenanceMachineInfo mi = new MaintenanceMachineInfo();
|
||||
mi.MachineID = Convert.ToInt64(dr["MACHINEID"]);
|
||||
@ -871,15 +637,15 @@ namespace IronIntel.Contractor.Maintenance
|
||||
mi.Odometer = FIDbAccess.GetFieldDouble(dr["ODOMETER"], 0);
|
||||
|
||||
int makeid = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
MachineMake make = MachineManagement.GetMachineMake(makes, makeid);
|
||||
AssetMake make = MachineManagement.GetMachineMake(makes, makeid);
|
||||
mi.Make = make == null ? string.Empty : make.Name;
|
||||
|
||||
int modelid = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
MachineModel model = MachineManagement.GetMachineModel(models, modelid);
|
||||
AssetModel model = MachineManagement.GetMachineModel(models, modelid);
|
||||
mi.Model = model == null ? string.Empty : model.Name;
|
||||
|
||||
int typeid = FIDbAccess.GetFieldInt(dr["TYPEID"], 0);
|
||||
MachineType mtype = MachineManagement.GetMachineType(types, typeid);
|
||||
AssetType mtype = MachineManagement.GetMachineType(types, typeid);
|
||||
mi.TypeID = mtype == null ? 0 : mtype.ID;
|
||||
mi.MachineType = mtype == null ? string.Empty : mtype.Name;
|
||||
|
||||
@ -902,38 +668,5 @@ namespace IronIntel.Contractor.Maintenance
|
||||
|
||||
#endregion
|
||||
|
||||
public static string[] GetPMDescriptionByAssetID(string companyid, long assetid)
|
||||
{
|
||||
const string SQL_1 = @"select * from usvMaintenanceAlertsMapLayer ml with (nolock) right join
|
||||
(select cast(MachineID as nvarchar) + cast(max(MaintenanceDate) as nvarchar) as MaintenanceID from usvMaintenanceAlertsMapLayer with (nolock) where PMStatus = 'Complete'
|
||||
group by MachineID) a on ml.MaintenanceID = a.MaintenanceID where PMStatus = 'Complete' and MachineID={0}";
|
||||
const string SQL_2 = "select * from usvMaintenanceAlertsMapLayer with (nolock) where PMStatus = 'Overdue' and MachineID={0}";
|
||||
const string SQL_3 = "select * from usvMaintenanceAlertsMapLayer with (nolock) where PMStatus = 'Upcoming' and MachineID={0}";
|
||||
|
||||
|
||||
string connetionstring = SystemParams.DataDbConnectionString;
|
||||
if (SystemParams.IsDealer)
|
||||
connetionstring = SystemParams.GetDbStringByCompany(companyid);
|
||||
|
||||
FISqlConnection db = new FISqlConnection(connetionstring);
|
||||
DataTable dt = db.GetDataTableBySQL(SQL_1, assetid);
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
dt = db.GetDataTableBySQL(SQL_2, assetid);
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
dt = db.GetDataTableBySQL(SQL_3, assetid);
|
||||
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
return new string[0];
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string desc = FIDbAccess.GetFieldString(dr["DESCRIPTION"], string.Empty);
|
||||
list.Add(desc);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,5 +22,7 @@ namespace IronIntel.Contractor.Maintenance
|
||||
public DateTime? CompletedDate { get; set; }
|
||||
public string CompletedDateStr { get { return CompletedDate == null ? "" : CompletedDate.Value.ToShortDateString(); } }
|
||||
public string Component { get; set; }
|
||||
public bool Billable { get; set; }
|
||||
public string SegmentType { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,8 @@
|
||||
using System;
|
||||
using Foresight.Fleet.Services.AssetHealth.WorkOrder;
|
||||
using Foresight.Fleet.Services.Customer;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Contractor.Users;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -6,52 +10,133 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class WorkOrderInfo
|
||||
public class WorkOrderInfoClient : WorkOrderInfo
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string MaintenanceID { get; set; }
|
||||
public string WorkOrderType { get; set; }
|
||||
public string AssignedTo { get; set; }
|
||||
public string AssignedToName { get; set; }
|
||||
public string Status { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public string AssetName { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DateTime? DueDate { get; set; }
|
||||
public string MakeName { get; set; }
|
||||
public string ModelName { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
public string DueDateStr { get { return DueDate == null ? "" : DueDate.Value.ToShortDateString(); } }
|
||||
public DateTime? CompleteDate { get; set; }
|
||||
public string CompleteDateStr { get { return CompleteDate == null ? "" : CompleteDate.Value.ToShortDateString(); } }
|
||||
public string InvoiceNumber { get; set; }
|
||||
public string NextFollowUpDateStr { get { return NextFollowUpDate == null ? "" : NextFollowUpDate.Value.ToShortDateString(); } }
|
||||
public string PartsExpectedDateStr { get { return PartsExpectedDate == null ? "" : PartsExpectedDate.Value.ToShortDateString(); } }
|
||||
public string LastLaborDateStr { get { return LastLaborDate == null ? "" : LastLaborDate.Value.ToShortDateString(); } }
|
||||
public ContactInfoClient[] ContactsClient { get; set; }
|
||||
public WorkOrderFollowerInfo[] Followers { get; set; }
|
||||
}
|
||||
|
||||
public class WorkOrderDetailInfo : WorkOrderInfo
|
||||
public class ContactInfoClient : ContactInfo
|
||||
{
|
||||
public string MeterType { get; set; }
|
||||
public double HourMeter { get; set; }
|
||||
public string ContactPreferenceStr { get; set; }
|
||||
public int SaveToCustomer { get; set; }
|
||||
}
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
public class WorkOrderListItemClient : WorkOrderListItem
|
||||
{
|
||||
public string DueDateStr { get { return DueDate == null ? "" : DueDate.Value.ToShortDateString(); } }
|
||||
public string CompleteDateStr { get { return CompleteDate == null ? "" : CompleteDate.Value.ToShortDateString(); } }
|
||||
public string NextFollowUpDateStr { get { return NextFollowUpDate == null ? "" : NextFollowUpDate.Value.ToShortDateString(); } }
|
||||
public string CreateDateStr { get { return CreateDate == null ? "" : CreateDate.Value.ToShortDateString(); } }
|
||||
public string CreationDateStr { get { return CreationDate == null ? "" : CreationDate.Value.ToShortDateString(); } }
|
||||
public string LastCommunicationDateStr { get { return (LastCommunicationDate == null || LastCommunicationDate == DateTime.MinValue) ? "" : LastCommunicationDate.Value.ToShortDateString(); } }
|
||||
public string LastInternalCommunicationDateStr { get { return (LastInternalCommunicationDate == null || LastInternalCommunicationDate == DateTime.MinValue) ? "" : LastInternalCommunicationDate.Value.ToShortDateString(); } }
|
||||
public string PartsExpectedDateStr { get { return PartsExpectedDate == null ? "" : PartsExpectedDate.Value.ToShortDateString(); } }
|
||||
public string LastLaborDateStr { get { return LastLaborDate == null ? "" : LastLaborDate.Value.ToShortDateString(); } }
|
||||
|
||||
public string MaintenanceID { get; set; }
|
||||
public WorkOrderStatus[] WorkOrderStatus { get; set; }
|
||||
public UserInfo[] AssignedToUsers { get; set; }
|
||||
public DepartmentInfo[] Departments { get; set; }
|
||||
public CustomerLocation[] Locations { get; set; }
|
||||
public StringKeyValue[] Salespersons { get; set; }
|
||||
public string ContactsStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
var rst = "";
|
||||
if (Contacts != null && Contacts.Count > 0)
|
||||
{
|
||||
for (var i = 0; i < Contacts.Count; i++)
|
||||
{
|
||||
var contact = Contacts[i];
|
||||
var ptext = contact.Name;
|
||||
if ((int)contact.ContactPreference == 0)
|
||||
{
|
||||
ptext += " – T";
|
||||
if (contact.MobilePhoneDisplayText != "")
|
||||
ptext += " – " + contact.MobilePhoneDisplayText;
|
||||
}
|
||||
else if ((int)contact.ContactPreference == 1)
|
||||
{
|
||||
if (contact.Email != "")
|
||||
ptext += " - " + contact.Email;
|
||||
}
|
||||
else if ((int)contact.ContactPreference == 2)
|
||||
{
|
||||
ptext += " – P";
|
||||
if (contact.MobilePhoneDisplayText != "")
|
||||
ptext += " – " + contact.MobilePhoneDisplayText;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(rst))
|
||||
rst += ptext;
|
||||
else
|
||||
rst += ("\n" + ptext);
|
||||
}
|
||||
}
|
||||
return rst;
|
||||
}
|
||||
}
|
||||
public string OdometerUnits { get; set; }
|
||||
public decimal WorkOrderTotalCost { get; set; }
|
||||
public decimal HoursToComplete { get; set; }
|
||||
public string InternalID { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public decimal PartsCost { get; set; }
|
||||
public decimal TravelTimeCost { get; set; }
|
||||
public decimal LaborCost { get; set; }
|
||||
public decimal HourlyRate { get; set; }
|
||||
public decimal OtherCost { get; set; }
|
||||
}
|
||||
|
||||
public class TextMessageClient : TextMessage
|
||||
{
|
||||
public bool StatusIncorrect
|
||||
{//6219, 2022-09-20 17:50:00 以前的状态可能存在问题,界面上不显示状态
|
||||
get
|
||||
{
|
||||
return SystemParams.CustomerDetail.CustomerTimeToUtc(Time) < DateTime.Parse("2022-09-20 17:50:00");
|
||||
}
|
||||
}
|
||||
|
||||
public string FormatSender
|
||||
{
|
||||
get
|
||||
{
|
||||
var rst = "";
|
||||
if (IsReply)
|
||||
{
|
||||
if (Helper.IsEmail(Sender) || !Helper.IsNumber(Sender))
|
||||
rst = Sender;
|
||||
else
|
||||
rst = Foresight.Standard.PhoneNumber.FormatPhoneNumber(Sender);
|
||||
}
|
||||
return rst;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] OriPhoneNumbers
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> ls = new List<string>();
|
||||
if (Participator != null && Participator.Count > 0)
|
||||
{
|
||||
foreach (var p in Participator)
|
||||
{
|
||||
if (Helper.IsEmail(p.CustomerNumber))
|
||||
ls.Add(p.CustomerNumber);
|
||||
else
|
||||
{
|
||||
p.CustomerNumber = Foresight.Standard.PhoneNumber.PreparePhonenumber(p.CustomerNumber);
|
||||
ls.Add(p.CustomerNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
}
|
||||
public string TimeStr { get { return Time == DateTime.MinValue ? "" : Time.ToString("M/d/yyyy h:m tt"); } }
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,13 @@ using Foresight.Data;
|
||||
using System.Web;
|
||||
using Foresight.Fleet.Services.AssetHealth;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.AssetHealth.WorkOrder;
|
||||
using Foresight.Fleet.Services.Inspection;
|
||||
using Foresight.Chart.Drawer;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using Foresight.Chart.Drawer.Contracts;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
@ -47,8 +54,8 @@ namespace IronIntel.Contractor.Maintenance
|
||||
Int64.TryParse(mid, out assetid);
|
||||
else
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<WorkOrderClient>(sessionid);
|
||||
var workorder = client.GetWorkOrderDetail(SystemParams.CompanyID, Convert.ToInt64(woid));
|
||||
var client = FleetServiceClientHelper.CreateClient<WorkOrderProvider>(sessionid);
|
||||
var workorder = client.GetWorkOrderInfo(SystemParams.CompanyID, Convert.ToInt64(woid));
|
||||
assetid = workorder.AssetID;
|
||||
}
|
||||
long[] availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
@ -77,113 +84,756 @@ namespace IronIntel.Contractor.Maintenance
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static string GenerateWorkOrderPrintHtml(string sessionid, string companyid, long woid)
|
||||
public string[] GetLocations()
|
||||
{
|
||||
const string SQL = @"select distinct LOCATION from WORKORDER where ISNULL(LOCATION,'')<>''";
|
||||
|
||||
DataTable dt = GetDataTableBySQL(SQL);
|
||||
if (dt.Rows.Count == 0)
|
||||
return new string[0];
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string num = FIDbAccess.GetFieldString(dr["LOCATION"], string.Empty);
|
||||
if (!string.IsNullOrEmpty(num))
|
||||
list.Add(num);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public string[] GetDepartments()
|
||||
{
|
||||
const string SQL = @"select distinct DEPARTMENT from WORKORDER where ISNULL(DEPARTMENT,'')<>''";
|
||||
|
||||
DataTable dt = GetDataTableBySQL(SQL);
|
||||
if (dt.Rows.Count == 0)
|
||||
return new string[0];
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string num = FIDbAccess.GetFieldString(dr["DEPARTMENT"], string.Empty);
|
||||
if (!string.IsNullOrEmpty(num))
|
||||
list.Add(num);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public string[] GetAdvisors()
|
||||
{
|
||||
const string SQL = @"select distinct ADVISOR from WORKORDER where ISNULL(ADVISOR,'')<>''";
|
||||
|
||||
DataTable dt = GetDataTableBySQL(SQL);
|
||||
if (dt.Rows.Count == 0)
|
||||
return new string[0];
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string num = FIDbAccess.GetFieldString(dr["ADVISOR"], string.Empty);
|
||||
if (!string.IsNullOrEmpty(num))
|
||||
list.Add(num);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
public static string GenerateWorkOrderPrintHtml(string sessionid, string companyid, long woid, string lang)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<WorkOrderProvider>(companyid, sessionid);
|
||||
WorkOrderInfo wo = client.GetWorkOrderInfo(companyid, woid);
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.AppendLine("<H1 style='text-align:center;'>Work Order</H1>");
|
||||
str.AppendFormat("<div style='font-weight:bold;'>Details for work order <{0}> are listed below:</div>", woid);
|
||||
str.AppendLine("<H1 style='text-align:center;'>" + SystemParams.GetTextByKey(lang, "P_WORKORDER", "Work Order") + "</H1>");
|
||||
string detailstr = SystemParams.GetTextByKey(lang, "P_WO_DETAILFORWORKORDERARELISTEDBELOW", "Details for work order <{0}> are listed below:").Replace("<", "<").Replace(">", ">");
|
||||
str.AppendFormat("<div style='font-weight:bold;padding-bottom:5px;'>" + detailstr + "</div>", wo.WorkOrderNumber);
|
||||
str.AppendLine("");
|
||||
//str.AppendLine("<div class='label' style='text-align:left;'>Work Order Information:</div>");
|
||||
str.AppendLine("<div style='padding-left:30px;margin-bottom:36px;'>");
|
||||
|
||||
var client = FleetServiceClientHelper.CreateClient<WorkOrderClient>(companyid, sessionid);
|
||||
WorkOrderDetail wo = client.GetWorkOrderDetail(companyid, woid);
|
||||
str.Append(GenerateWorkOrderInfoHtml(wo));
|
||||
var aclient = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid);
|
||||
var asset = aclient.GetAssetDetailInfo(companyid, wo.AssetID);
|
||||
str.Append(GenerateWorkOrderInfoHtml(asset, wo, lang));
|
||||
str.AppendLine("</div>");
|
||||
//str.AppendLine("<div class='label' style='text-align:left;'>Segments:</div>");
|
||||
|
||||
WorkOrderSegmentItem[] segments = client.GetSegments(companyid, woid);
|
||||
WorkOrderSegmentInfo[] segments = client.GetSegments(companyid, woid);
|
||||
|
||||
if (segments != null && segments.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < segments.Length; i++)
|
||||
{
|
||||
var se = segments[i];
|
||||
str.Append(GenerateSegmentHtml(se, i + 1));
|
||||
str.Append(GenerateSegmentHtml(se, i + 1, lang));
|
||||
}
|
||||
}
|
||||
|
||||
str.Append("<div style='margin-bottom:36px;margin-left:30px;'>");
|
||||
str.Append(WorkorderAlertsFormart(woid, lang, sessionid));
|
||||
|
||||
AssetInspectItem[] insplectitems = client.GetWOInspectItems(SystemParams.CompanyID, woid);
|
||||
if (insplectitems != null && insplectitems.Length > 0)
|
||||
{
|
||||
foreach (AssetInspectItem isp in insplectitems)
|
||||
{
|
||||
var report = FleetServiceClientHelper.CreateClient<AssetInspectClient>(sessionid).GetInspection(SystemParams.CompanyID, isp.Id);
|
||||
str.Append(GenerateInspectionHtml(report, lang));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
str.Append("</div>");
|
||||
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
private static string GenerateWorkOrderInfoHtml(WorkOrderDetail wo)
|
||||
private static string GenerateWorkOrderInfoHtml(AssetDetailInfo asset, WorkOrderInfo wo, string lang)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.Append("<table>");
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>Work Order Type</td><td>{0}</td></tr>", wo.WorkOrderType);
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>" + SystemParams.GetTextByKey(lang, "P_WO_ASSETNAME", "Asset Name") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(asset.Name));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Assigned To</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.AssignedToName));
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_ASSETNAMECUSTOM", "Asset Name (Custom)") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(asset.Name2));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Status</td><td>{0}</td></tr>", wo.Status);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_VIN", "VIN/SN") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(asset.VIN));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Due Date</td><td>{0}</td></tr>", wo.DueDate == null ? "" : wo.DueDate.Value.ToShortDateString());
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_MAKE", "Make") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(asset.MakeName));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Description</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.Description).Replace("\n", "<br>"));
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_MODEL", "Model") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(asset.ModelName));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Meter Type</td><td>{0}</td></tr>", wo.MeterType);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_ASSETTYPE", "Asset Type") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(asset.TypeName));
|
||||
str.AppendLine("");
|
||||
if (string.Compare(wo.MeterType, "HourMeter", true) == 0
|
||||
|| string.Compare(wo.MeterType, "Both", true) == 0)
|
||||
str.AppendFormat("<tr><td class='label'>Hour Meter</td><td>{0}</td></tr>", wo.HourMeter);
|
||||
if (string.Compare(wo.MeterType, "Odometer", true) == 0
|
||||
|| string.Compare(wo.MeterType, "Both", true) == 0)
|
||||
str.AppendFormat("<tr><td class='label'>Odometer</td><td>{0} {1}</td></tr>", wo.Odometer, wo.OdometerUnits);
|
||||
str.AppendFormat("<tr><td class='label'>Work Order Total Costs ($)</td><td>{0}</td></tr>", wo.WorkOrderTotalCost);
|
||||
if (asset.OnRoad)
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_CURRENTODOMETER", "Current Odometer") + "</td><td>{0}</td></tr>", asset.CurrentOdometer == null ? "" : asset.CurrentOdometer.Corrected.ToString("#,##0"));
|
||||
else
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_CURRENTHOURS", "Current Hours") + "</td><td>{0}</td></tr>", asset.CurrentHours == null ? "" : asset.CurrentHours.Corrected.ToString("#,##0"));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Other Cost ($)</td><td>{0}</td></tr>", wo.OtherCost);
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>" + SystemParams.GetTextByKey(lang, "P_WO_CURRJOBSITE", "Current Jobsite") + " </td><td>{0}</td></tr>", HttpUtility.HtmlEncode(asset.CurrentJobSiteNames));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Parts Cost ($)</td><td>{0}</td></tr>", wo.PartsCost);
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>" + SystemParams.GetTextByKey(lang, "P_WO_CURRLOCATION", "Current Location") + " </td><td>{0}</td></tr>", asset.CurrentLocation == null ? "" : HttpUtility.HtmlEncode(asset.CurrentLocation.Address));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Travel Time Cost ($)</td><td>{0}</td></tr>", wo.TravelTimeCost);
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>" + SystemParams.GetTextByKey(lang, "P_WO_WORKORDERTYPE", "Work Order Type") + "</td><td>{0}</td></tr>", wo.WorkOrderType);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Labor Cost ($)</td><td>{0}</td></tr>", wo.LaborCost);
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>" + SystemParams.GetTextByKey(lang, "P_WO_COMPONENT", "Work Order Type") + "</td><td>{0}</td></tr>", wo.Completed);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Hourly Rate</td><td>{0}</td></tr>", wo.HourlyRate);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_ASSIGNEDTO", "Assigned To") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.AssignedToName));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Time To Complete(Hrs)</td><td>{0}</td></tr>", wo.HoursToComplete);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_STATUS", "Status") + "</td><td>{0}</td></tr>", wo.StatusName);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Completed Date</td><td>{0}</td></tr>", wo.CompleteDate == null ? "" : wo.CompleteDate.Value.ToShortDateString());
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_DUEDATE", "Due Date") + "</td><td>{0}</td></tr>", wo.DueDate == null ? "" : wo.DueDate.Value.ToShortDateString());
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Internal ID</td><td>{0}</td></tr>", wo.InternalID);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_NEXTFOLLOWUPDATE", "Next Follow Up Date") + "</td><td>{0}</td></tr>", wo.NextFollowUpDate == null ? "" : wo.NextFollowUpDate.Value.ToShortDateString());
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Invoice Number</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.InvoiceNumber));
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_DESCRIPTION", "Description") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.Description).Replace("\n", "<br>"));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Notes</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.Notes).Replace("\n", "<br>"));
|
||||
if (wo.Completed)
|
||||
{
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_METERTYPE", "Meter Type") + "</td><td>{0}</td></tr>", wo.MeterType);
|
||||
str.AppendLine("");
|
||||
if (string.Compare(wo.MeterType, "HourMeter", true) == 0
|
||||
|| string.Compare(wo.MeterType, "Both", true) == 0)
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_HOURMETER", "Hour Meter") + "</td><td>{0}</td></tr>", wo.HourMeter);
|
||||
if (string.Compare(wo.MeterType, "Odometer", true) == 0
|
||||
|| string.Compare(wo.MeterType, "Both", true) == 0)
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_ODOMETER", "Odometer") + "</td><td>{0} {1}</td></tr>", wo.Odometer, wo.OdometerUnits);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_WORKORDERTOTALCOST", "Work Order Total Costs ($)") + "</td><td>{0}</td></tr>", wo.WorkOrderTotalCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_OTHERCOST", "Other Cost ($)") + "</td><td>{0}</td></tr>", wo.OtherCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_PARTSCOST", "Parts Cost ($)") + "</td><td>{0}</td></tr>", wo.PartsCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_TRAVELTIMECOST", "Travel Time Cost ($)") + "</td><td>{0}</td></tr>", wo.TravelTimeCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_LABORCOST", "Labor Cost ($)") + "</td><td>{0}</td></tr>", wo.LaborCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_HOURLYRATE", "Hourly Rate") + "</td><td>{0}</td></tr>", wo.HourlyRate);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_TIMETOCOMPLATEHOURS", "Time To Complete(Hrs)") + "</td><td>{0}</td></tr>", wo.HoursToComplete);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_COMPLETEDDATE", "Completed Date") + "</td><td>{0}</td></tr>", wo.CompleteDate == null ? "" : wo.CompleteDate.Value.ToShortDateString());
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_INTERNALID", "Internal ID") + "</td><td>{0}</td></tr>", wo.InternalID);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_INVOICENUMBER", "Invoice Number") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.InvoiceNumber));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + "Billable" + "</td><td>{0}</td></tr>", wo.Billable ? "Yes" : "No");
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>" + "Bill To Job" + "</td><td>{0}</td></tr>", wo.BillToJobName);
|
||||
str.AppendLine("");
|
||||
}
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_NOTES", "Notes") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.Notes).Replace("\n", "<br>"));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("</table>");
|
||||
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
private static string GenerateSegmentHtml(WorkOrderSegmentItem se, int index)
|
||||
private static string GenerateSegmentHtml(WorkOrderSegmentInfo se, int index, string lang)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
//str.AppendFormat("<div style='margin-bottom:36px;margin-left:30px;{0}'>", (index - 2) % 4 == 0 ? "page-break-after: always;" : "");
|
||||
//str.AppendLine("");
|
||||
str.AppendLine("<div style='margin-bottom:36px;margin-left:30px;'>");
|
||||
str.AppendLine("<table>");
|
||||
str.AppendFormat("<tr><td class='label' colspan='2' style='text-align:left;'>Segment {0}</td></tr>", index);
|
||||
str.AppendFormat("<tr><td class='label' colspan='2' style='text-align:left;'>" + SystemParams.GetTextByKey(lang, "P_WO_SEGMENT", "Segment") + " {0}</td></tr>", index);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>User</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.UserName));
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>" + SystemParams.GetTextByKey(lang, "P_WO_USER", "User") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.UserName));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Hours</td><td>{0}</td></tr>", se.Hours);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_HOURS", "Hours") + "</td><td>{0}</td></tr>", se.Hours);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Job Site</td><td>{0}</td></tr>", se.JobsiteName);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_JOBSITE", "Jobsite") + "</td><td>{0}</td></tr>", se.JobsiteName);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Cost</td><td>{0}</td></tr>", se.Cost);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_COST", "Cost") + "</td><td>{0}</td></tr>", se.Cost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Component</td><td>{0}</td></tr>", se.Component);
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_COMPONENT", "Component") + "</td><td>{0}</td></tr>", se.Component);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Completed</td><td>{0}</td></tr>", se.Completed ? "Yes" : "No");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_COMPLETED", "Completed") + "</td><td>{0}</td></tr>", se.Completed ? "Yes" : "No");
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Completed Date</td><td>{0}</td></tr>", se.CompletedDate == null ? "" : se.CompletedDate.Value.ToShortDateString());
|
||||
str.AppendFormat("<tr><td class='label'>Description</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.Description));
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_COMPLETEDDATE", "Completed Date") + "</td><td>{0}</td></tr>", se.CompletedDate == null ? "" : se.CompletedDate.Value.ToShortDateString());
|
||||
str.AppendFormat("<tr><td class='label'>" + "Segment Type" + "</td><td>{0}</td></tr>", se.SegmentType);
|
||||
str.AppendFormat("<tr><td class='label'>" + "Billable" + "</td><td>{0}</td></tr>", se.Billable ? "Yes" : "No");
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_DESCRIPTION", "Description") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.Description));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Notes</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.Notes).Replace("\n", "<br>"));
|
||||
str.AppendFormat("<tr><td class='label'>" + SystemParams.GetTextByKey(lang, "P_WO_NOTES", "Notes") + "</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.Notes).Replace("\n", "<br>"));
|
||||
str.AppendLine("");
|
||||
str.AppendLine("</table>");
|
||||
str.AppendLine("</div>");
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
private static string GenerateInspectionHtml(InspectReportInfo report, string lang)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.AppendLine("<div style='margin-bottom:36px;'>");
|
||||
str.AppendLine("<table>");
|
||||
str.AppendFormat("<tr><td class='label' colspan='2' style='text-align:left;'>" + report.Template.Name + " <span style='margin-left:30px;'>" + (report.CommitTimeLocal == DateTime.MinValue ? "" : report.CommitTimeLocal.ToString("M/d/yyyy h:mm tt")) + "</span></td></tr>");
|
||||
str.AppendLine("");
|
||||
foreach (var page in report.Template.Pages)
|
||||
{
|
||||
foreach (var section in page.Sections)
|
||||
{
|
||||
foreach (var q in section.Questions)
|
||||
{
|
||||
//if (q.VisibleToCustomer)
|
||||
//{
|
||||
str.AppendLine("<tr><td class='label' style='width:170px;'>" + q.DisplayText + "</td>");
|
||||
var span_level = "<span style='float:right;padding-right:3px;'>" + ShowSeverityLevel(lang, (int)q.SeverityLevel) + "</span>";
|
||||
InspectResultItem[] anwers = report.Answers.Where(m => m.QuestionId.ToLower() == q.Id.ToLower()).ToArray();
|
||||
if (anwers != null && anwers.Length > 0)
|
||||
{
|
||||
foreach (var a in anwers)
|
||||
{
|
||||
int[] ids = new int[] { 5, 8, 9, 10, 14, 15 };
|
||||
if (!ids.Contains((int)q.QuestionType) || ((int)q.QuestionType == 15 && q.SubType != 15))
|
||||
{
|
||||
var result = a.Result;
|
||||
if (result == null)
|
||||
result = "";
|
||||
|
||||
if ((int)q.QuestionType == 6 && result.IndexOf(' ') >= 0)//Date do not show time
|
||||
result = result.Split(' ')[0];
|
||||
if ((int)q.QuestionType == 11//Odometer
|
||||
|| (int)q.QuestionType == 18 //FuelUsed
|
||||
|| ((int)q.QuestionType == 15 && q.SubType == 8)//FuelRecords Odometer
|
||||
|| ((int)q.QuestionType == 15 && q.SubType == 10))//FuelRecords Quantity
|
||||
result += " " + ConvertUnits(a.Units);
|
||||
|
||||
if ((int)q.QuestionType == 17 && q.TextToCompare != null && result.ToLower() != q.TextToCompare.ToLower()) // BarCodeValidate
|
||||
str.AppendLine("<td><span style='color:red'>" + result + "<span><span style='margin-left:6px'>(" + q.TextToCompare + ")<span>");
|
||||
else
|
||||
str.AppendLine("<td>" + result);
|
||||
|
||||
str.AppendLine(span_level + "</td>");
|
||||
break;
|
||||
}
|
||||
else if ((int)q.QuestionType == 5)//YesOrNo
|
||||
{
|
||||
if (a.SelectedItems != null && a.SelectedItems.Count > 0)
|
||||
{
|
||||
span_level = "<span style='float:right;padding-right:3px;'>" + ShowSeverityLevel(lang, (int)a.SelectedItems[0].SeverityLevel) + "</span>";
|
||||
var label = "<label style='margin-left:5px; '>" + a.SelectedItems[0].Text + "</lable>";
|
||||
var div_circle = "<div style=' width: 12px; height: 12px; border-radius: 6px; display: inline-block;'></div>";
|
||||
if (!string.IsNullOrEmpty(a.SelectedItems[0].BackgroundColor))
|
||||
{
|
||||
div_circle = "<div style=' width: 12px; height: 12px; border-radius: 6px; display: inline-block;background-color:" + a.SelectedItems[0].BackgroundColor + "'></div>";
|
||||
}
|
||||
|
||||
str.AppendLine("<td>" + div_circle + label + span_level + "</td>");
|
||||
}
|
||||
}
|
||||
else if ((int)q.QuestionType == 8 || (int)q.QuestionType == 9 || ((int)q.QuestionType == 15 && q.SubType == 6) || ((int)q.QuestionType == 15 && q.SubType == 9))//DropDown、List
|
||||
{
|
||||
if (q.MultipleSelect)
|
||||
{
|
||||
if (a.SelectedItems != null && a.SelectedItems.Count > 0)
|
||||
{
|
||||
StringBuilder str1 = new StringBuilder();
|
||||
str1.AppendLine("<table class='inptable'>");
|
||||
for (var j = 0; j < a.SelectedItems.Count; j++)
|
||||
{
|
||||
str1.AppendLine("<tr>");
|
||||
span_level = "<span style='float:right;padding-right:3px;'>" + ShowSeverityLevel(lang, (int)a.SelectedItems[j].SeverityLevel) + "</span>";
|
||||
var label = "<label style='margin-left:5px; '>" + (j + 1) + ". " + a.SelectedItems[j].Text + "</lable>";
|
||||
|
||||
var div_circle = "<div style=' width: 12px; height: 12px; border-radius: 6px; display: inline-block;'></div>";
|
||||
if (!string.IsNullOrEmpty(a.SelectedItems[j].BackgroundColor))
|
||||
{
|
||||
div_circle = "<div style=' width: 12px; height: 12px; border-radius: 6px; display: inline-block;background-color:" + a.SelectedItems[j].BackgroundColor + "'></div>";
|
||||
}
|
||||
str1.AppendLine("<td>" + div_circle + label + span_level + "</td>");
|
||||
str1.AppendLine("</tr>");
|
||||
}
|
||||
|
||||
str1.AppendLine("</table>");
|
||||
str.AppendLine("<td>" + str1.ToString() + "</td>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (a.SelectedItems != null && a.SelectedItems.Count > 0)
|
||||
{
|
||||
span_level = "<span style='float:right;padding-right:3px;'>" + ShowSeverityLevel(lang, (int)a.SelectedItems[0].SeverityLevel) + "</span>";
|
||||
var label = "<label style='margin-left:5px; '>" + a.SelectedItems[0].Text + "</lable>";
|
||||
|
||||
var div_circle = "<div style=' width: 12px; height: 12px; border-radius: 6px; display: inline-block;'></div>";
|
||||
if (!string.IsNullOrEmpty(a.SelectedItems[0].BackgroundColor))
|
||||
{
|
||||
div_circle = "<div style=' width: 12px; height: 12px; border-radius: 6px; display: inline-block;background-color:" + a.SelectedItems[0].BackgroundColor + "'></div>";
|
||||
}
|
||||
|
||||
str.AppendLine("<td>" + div_circle + label + span_level + "</td>");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((int)q.QuestionType == 14)//Email (Drop Down)
|
||||
{
|
||||
if (a.SelectedItems != null && a.SelectedItems.Count > 0)
|
||||
{
|
||||
StringBuilder str1 = new StringBuilder();
|
||||
str1.AppendLine("<table class='inptable'>");
|
||||
for (var j = 0; j < a.SelectedItems.Count; j++)
|
||||
{
|
||||
str1.AppendLine("<tr>");
|
||||
var label = "<label>" + (j + 1) + ". " + a.SelectedItems[j].Text + "<" + a.SelectedItems[j].Value + "</lable>"; ;
|
||||
str1.AppendLine("<td>" + label + "</td>");
|
||||
str1.AppendLine("</tr>");
|
||||
}
|
||||
str1.AppendLine("</table>");
|
||||
str.AppendLine("<td>" + str1.ToString() + "</td>");
|
||||
}
|
||||
}
|
||||
else if ((int)q.QuestionType == 10 || ((int)q.QuestionType == 15 && q.SubType == 15))//Picture
|
||||
{
|
||||
StringBuilder str1 = new StringBuilder();
|
||||
str1.AppendLine("<div style='min-height:80px;overflow:auto;'>");
|
||||
if (report.Medias != null && report.Medias.Count > 0)
|
||||
{
|
||||
for (var j = 0; j < report.Medias.Count; j++)
|
||||
{
|
||||
var m = report.Medias[j];
|
||||
if (m.AnswerId.ToLower() == a.Id.ToLower())
|
||||
{
|
||||
string[] pictypes = new string[] { ".mp4", ".mov" };
|
||||
if (pictypes.Contains(m.FileType.ToLower()))
|
||||
{
|
||||
str1.AppendLine("<div class='media'><span class='video'></span></div>");
|
||||
}
|
||||
else
|
||||
{
|
||||
str1.AppendLine("<img class='media' src='" + m.ThumbnailUrl + "'></img>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
str1.AppendLine("</div>");
|
||||
|
||||
str.AppendLine("<td>" + str1.ToString() + "</td>");
|
||||
}
|
||||
else
|
||||
str.AppendLine("<td></td>");
|
||||
}
|
||||
str.AppendLine("</tr>");
|
||||
str.AppendLine("");
|
||||
}
|
||||
else
|
||||
{
|
||||
str.AppendLine("<td></td>");
|
||||
str.AppendLine("</tr>");
|
||||
str.AppendLine("");
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
str.AppendLine("</table>");
|
||||
str.AppendLine("</div>");
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
private static string ConvertUnits(string u)
|
||||
{
|
||||
switch (u.ToLower())
|
||||
{
|
||||
case "mile":
|
||||
return "Mile(s)";
|
||||
case "kilometre":
|
||||
case "kilometer":
|
||||
return "Kilometer";
|
||||
case "percent":
|
||||
return "Percent";
|
||||
case "gallon":
|
||||
case "gal":
|
||||
return "Gallon";
|
||||
case "litre":
|
||||
return "Litre";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
private static string ShowSeverityLevel(string lang, int level)
|
||||
{
|
||||
var levertext = SystemParams.GetTextByKey(lang, "P_IPT_SEVERITYLEVEL_COLON", "Severity Level: ");
|
||||
if (level == 0)
|
||||
levertext = "";
|
||||
if (level == 1)
|
||||
levertext += SystemParams.GetTextByKey(lang, "P_IPT_SL_LOW", "Low");
|
||||
else if (level == 2)
|
||||
levertext += SystemParams.GetTextByKey(lang, "P_IPT_SL_MEDIUM", "Medium");
|
||||
else if (level == 3)
|
||||
levertext += SystemParams.GetTextByKey(lang, "P_IPT_SL_HIGH", "High");
|
||||
return levertext;
|
||||
}
|
||||
|
||||
public static string WorkorderAlertsFormart(long woid, string lang, string sessionid)
|
||||
{
|
||||
AlertItems items = GetWorkOrderAlerts(woid, sessionid);
|
||||
string EmailFormat = string.Empty;
|
||||
if (items != null)
|
||||
{
|
||||
if (items.DTCAlerts != null && items.DTCAlerts.Length > 0)
|
||||
EmailFormat += AlertsFormat(items.DTCAlerts, SystemParams.GetTextByKey(lang, "P_WO_DTCALERTS", "DTC Alerts"), lang);
|
||||
if (items.PMAlerts != null && items.PMAlerts.Length > 0)
|
||||
EmailFormat += AlertsFormat(items.PMAlerts, SystemParams.GetTextByKey(lang, "P_WO_PMALERTS", "PM Alerts"), lang);
|
||||
if (items.InspectAlerts != null && items.InspectAlerts.Length > 0)
|
||||
EmailFormat += AlertsFormat(items.InspectAlerts, SystemParams.GetTextByKey(lang, "P_WO_INSPECTALERTS", "Inspect Alerts"), lang);
|
||||
if (items.OilAlerts != null && items.OilAlerts.Length > 0)
|
||||
EmailFormat += AlertsFormat(items.OilAlerts, SystemParams.GetTextByKey(lang, "P_WO_OILALERTS", "Oil Alerts"), lang);
|
||||
}
|
||||
return EmailFormat;
|
||||
}
|
||||
|
||||
public static string AlertsFormat(AlertInfo[] alerts, string type, string lang)
|
||||
{
|
||||
string AlertsFormat = "<table style=\"border:solid 1px #e1dbdb;border-collapse: collapse;margin-bottom:36px;\"><tr>";
|
||||
AlertsFormat += "<td colspan=\"6\"><span style=\"font-weight:700;\">{0}</span></td></tr>";
|
||||
|
||||
AlertsFormat += "<tr style=\"height:30px; background-color:#f1f1f1;\">";
|
||||
AlertsFormat += "<td style=\"border:1px solid #e1dbdb;\">" + SystemParams.GetTextByKey(lang, "P_WO_HOURS", "Hours") + "</td>";
|
||||
AlertsFormat += "<td style=\"border:1px solid #e1dbdb;\">" + SystemParams.GetTextByKey(lang, "P_WO_ALERTTYPE", "Alert Type") + "</td>";
|
||||
AlertsFormat += "<td style=\"border:1px solid #e1dbdb;\">" + SystemParams.GetTextByKey(lang, "P_WO_DESCRIPTION", "Description") + "</td>";
|
||||
if (string.Compare(type, "PM Alerts", true) == 0)
|
||||
AlertsFormat += "<td style=\"border:1px solid #e1dbdb;\">" + SystemParams.GetTextByKey(lang, "P_WO_SERVICEDESCRIPTION", "Service Description") + "</td>";
|
||||
AlertsFormat += "<td style=\"border:1px solid #e1dbdb;\">" + SystemParams.GetTextByKey(lang, "P_WO_COUNT", "Count") + "</td>";
|
||||
AlertsFormat += "<td style=\"border:1px solid #e1dbdb;\">" + SystemParams.GetTextByKey(lang, "P_WO_LATESTDATETIME", "Latest DateTime") + "</td>";
|
||||
AlertsFormat += "</tr>";
|
||||
AlertsFormat += "{1}";//Alert Information
|
||||
AlertsFormat += "</table>";
|
||||
|
||||
if (alerts != null)
|
||||
{
|
||||
string tr_data = string.Empty;
|
||||
foreach (AlertInfo item in alerts)
|
||||
{
|
||||
tr_data += "<tr>";
|
||||
tr_data += "<td style=\"border:1px solid #e1dbdb;\">" + item.EngineHours + "</td>";
|
||||
tr_data += "<td style=\"border:1px solid #e1dbdb;\">" + item.AlertType + "</td>";
|
||||
tr_data += "<td style=\"border:1px solid #e1dbdb;\">" + item.Description + "</td>";
|
||||
if (string.Compare(type, "PM Alerts", true) == 0)
|
||||
tr_data += "<td style=\"border:1px solid #e1dbdb;\">" + item.ServiceDescription + "</td>";
|
||||
tr_data += "<td style=\"border:1px solid #e1dbdb;\">" + item.AlertCount + "</td>";
|
||||
tr_data += "<td style=\"border:1px solid #e1dbdb;\">" + item.AlertLocalTimeStr + "</td>";
|
||||
tr_data += "</tr>";
|
||||
}
|
||||
|
||||
return string.Format(AlertsFormat, type, tr_data);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static AlertItems GetWorkOrderAlerts(long workorderid, string sessionid)
|
||||
{
|
||||
AssetAlertItem[] alerts = FleetServiceClientHelper.CreateClient<WorkOrderProvider>(sessionid).GetWorkOrderAlerts(SystemParams.CompanyID, workorderid);
|
||||
|
||||
if (alerts != null)
|
||||
{
|
||||
AlertItems items = new AlertItems();
|
||||
var dtcalerts = new List<AlertInfo>();
|
||||
var pmaalerts = new List<AlertInfo>();
|
||||
var inspectalerts = new List<AlertInfo>();
|
||||
var oilalerts = new List<AlertInfo>();
|
||||
Dictionary<string, List<AlertInfo>> pmalertdic = new Dictionary<string, 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);
|
||||
|
||||
if (alertitem.Category == AssetAlertCategory.PMAlert)
|
||||
{
|
||||
if (!pmalertdic.ContainsKey(a.ScheduleID))
|
||||
pmalertdic[a.ScheduleID] = new List<AlertInfo>();
|
||||
pmalertdic[a.ScheduleID].Add(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
items.DTCAlerts = dtcalerts.ToArray();
|
||||
items.PMAlerts = pmaalerts.ToArray();
|
||||
items.InspectAlerts = inspectalerts.ToArray();
|
||||
items.OilAlerts = oilalerts.ToArray();
|
||||
items.AllExpectedCost = 0;
|
||||
|
||||
foreach (var dic in pmalertdic)
|
||||
{
|
||||
items.AllExpectedCost += dic.Value.Where(m => !m.Recurring).Sum(m => m.ExpectedCost);
|
||||
|
||||
int minPriority = dic.Value.Select(m => m.Priority).Min();
|
||||
var recalerts = dic.Value.Where(m => m.Priority == minPriority && m.Recurring && m.ExpectedCost > 0);
|
||||
if (recalerts != null && recalerts.Count() > 0)
|
||||
items.AllExpectedCost += recalerts.Sum(m => m.ExpectedCost);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private static 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.Description = ai.FormatDescription(ai.Description);
|
||||
ai.AlertTime_UTC = alertitem.AlertTime;
|
||||
ai.AlertLocalTime = alertitem.AlertLocalTime;
|
||||
ai.EngineHours = alertitem.EngineHours;
|
||||
ai.ServiceDescription = alertitem.ServiceDescription;
|
||||
ai.ScheduleID = alertitem.ScheduleID;
|
||||
ai.IntervalID = alertitem.IntervalID;
|
||||
ai.Recurring = alertitem.Recurring;
|
||||
ai.Priority = alertitem.Priority;
|
||||
ai.ExpectedCost = alertitem.ExpectedCost;
|
||||
|
||||
return ai;
|
||||
}
|
||||
|
||||
public static (string body, KeyValuePair<string, byte[]>[]) GetSurveyReportEmail(SurveyReportInfo report)
|
||||
{
|
||||
var list = new List<KeyValuePair<string, byte[]>>();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("<div>");
|
||||
sb.AppendLine($"<div style=\"font-size: 24px; font-weight: bold; text-align: center\">{HttpUtility.HtmlEncode(report.TemplateName)}</div>");
|
||||
sb.AppendLine($"<div style=\"font-size: 16px; font-weight: bold; text-align: center\">There are {report.SurveyCount} survey(s) in total.</div>");
|
||||
sb.AppendLine("<br/><br/>");
|
||||
int count = 0;
|
||||
foreach (var q in report.Questions)
|
||||
{
|
||||
string imgid;
|
||||
if (q.QuestionType == SurveyQuestionTypes.Choose)
|
||||
{
|
||||
sb.AppendLine($"<div style=\"font-size: 24px; font-weight: bold; padding-left: 10px\">{HttpUtility.HtmlEncode(q.Title)}</div>");
|
||||
imgid = "img" + (++count).ToString("000");
|
||||
sb.AppendLine($"<img src=\"cid:{imgid}\"/>");
|
||||
var chooseBarDrawer = new ColumnChartDrawer
|
||||
{
|
||||
Data = new ChartData
|
||||
{
|
||||
XAxis = q.Values.Select(v => new XValue { Label = v.DisplayText }).ToArray(),
|
||||
XInclinedValue = -45,
|
||||
Series = new[]
|
||||
{
|
||||
new DataSeries
|
||||
{
|
||||
SeriesType = SeriesType.Column,
|
||||
Color = Color.FromArgb(0x43, 0x86, 0xd8),
|
||||
DataPoints = q.Values.Select(v => new DataPoint { Y = v.Count }).ToArray()
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var bitmap = new Bitmap(800, 300);
|
||||
var result = chooseBarDrawer.DrawChart(bitmap);
|
||||
var ms = new MemoryStream();
|
||||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
ms.Flush();
|
||||
list.Add(new KeyValuePair<string, byte[]>(imgid, ms.ToArray()));
|
||||
|
||||
imgid = "img" + (++count).ToString("000");
|
||||
sb.AppendLine($"<img src=\"cid:{imgid}\"/>");
|
||||
var pieDrawer = new PieChartDrawer
|
||||
{
|
||||
Data = new ChartData
|
||||
{
|
||||
Series = new[]
|
||||
{
|
||||
new DataSeries
|
||||
{
|
||||
SeriesType = SeriesType.Pie,
|
||||
DataPoints = q.Values.Select(v => new DataPoint { Name = v.DisplayText, Y = v.Count, DisplayValue = v.Count.ToString() }).ToArray()
|
||||
}
|
||||
},
|
||||
ShowLegend = true
|
||||
}
|
||||
};
|
||||
bitmap = new Bitmap(800, 300);
|
||||
result = pieDrawer.DrawChart(bitmap);
|
||||
ms = new MemoryStream();
|
||||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
ms.Flush();
|
||||
list.Add(new KeyValuePair<string, byte[]>(imgid, ms.ToArray()));
|
||||
}
|
||||
else if (q.QuestionType == SurveyQuestionTypes.YesOrNo)
|
||||
{
|
||||
sb.AppendLine($"<div style=\"font-size: 24px; font-weight: bold; padding-left: 10px\">{HttpUtility.HtmlEncode(q.Title)}</div>");
|
||||
imgid = "img" + (++count).ToString("000");
|
||||
sb.AppendLine($"<img src=\"cid:{imgid}\"/>");
|
||||
var barDrawer = new BarChartDrawer
|
||||
{
|
||||
Data = new ChartData
|
||||
{
|
||||
XAxis = new[]
|
||||
{
|
||||
new XValue
|
||||
{
|
||||
Label = string.Empty
|
||||
}
|
||||
},
|
||||
Series = new[]
|
||||
{
|
||||
new DataSeries
|
||||
{
|
||||
Name = q.Values[0].DisplayText,
|
||||
SeriesType = SeriesType.Bar,
|
||||
DataPoints = new[]
|
||||
{
|
||||
new DataPoint { Y = q.Values[0].Count }
|
||||
}
|
||||
},
|
||||
new DataSeries
|
||||
{
|
||||
Name = q.Values[1].DisplayText,
|
||||
SeriesType = SeriesType.Bar,
|
||||
DataPoints = new[]
|
||||
{
|
||||
new DataPoint { Y = q.Values[1].Count }
|
||||
}
|
||||
}
|
||||
},
|
||||
ShowLegend = true
|
||||
}
|
||||
};
|
||||
var bitmap = new Bitmap(700, 220);
|
||||
var result = barDrawer.DrawChart(bitmap);
|
||||
var ms = new MemoryStream();
|
||||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
ms.Flush();
|
||||
list.Add(new KeyValuePair<string, byte[]>(imgid, ms.ToArray()));
|
||||
}
|
||||
else if (q.QuestionType == SurveyQuestionTypes.Score)
|
||||
{
|
||||
sb.AppendLine($"<div style=\"font-size: 24px; font-weight: bold; padding-left: 10px\">{HttpUtility.HtmlEncode(q.Title)}</div>");
|
||||
imgid = "img" + (++count).ToString("000");
|
||||
sb.AppendLine($"<img src=\"cid:{imgid}\"/>");
|
||||
var chooseBarDrawer = new ColumnChartDrawer
|
||||
{
|
||||
Data = new ChartData
|
||||
{
|
||||
XAxis = q.Values.Select(v => new XValue { Label = v.DisplayText }).ToArray(),
|
||||
XInclinedValue = -45,
|
||||
Series = new[]
|
||||
{
|
||||
new DataSeries
|
||||
{
|
||||
SeriesType = SeriesType.Column,
|
||||
Color = Color.FromArgb(0x43, 0x86, 0xd8),
|
||||
DataPoints = q.Values.Select(v => new DataPoint { Y = v.Count }).ToArray()
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var bitmap = new Bitmap(800, 300);
|
||||
var result = chooseBarDrawer.DrawChart(bitmap);
|
||||
var ms = new MemoryStream();
|
||||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
ms.Flush();
|
||||
list.Add(new KeyValuePair<string, byte[]>(imgid, ms.ToArray()));
|
||||
|
||||
imgid = "img" + (++count).ToString("000");
|
||||
sb.AppendLine($"<img src=\"cid:{imgid}\"/>");
|
||||
var pieDrawer = new PieChartDrawer
|
||||
{
|
||||
Data = new ChartData
|
||||
{
|
||||
Series = new[]
|
||||
{
|
||||
new DataSeries
|
||||
{
|
||||
SeriesType = SeriesType.Pie,
|
||||
DataPoints = q.Values.Select(v => new DataPoint { Name = v.DisplayText, Y = v.Count, DisplayValue = v.Count.ToString() }).ToArray()
|
||||
}
|
||||
},
|
||||
ShowLegend = true
|
||||
}
|
||||
};
|
||||
bitmap = new Bitmap(800, 300);
|
||||
result = pieDrawer.DrawChart(bitmap);
|
||||
ms = new MemoryStream();
|
||||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
ms.Flush();
|
||||
list.Add(new KeyValuePair<string, byte[]>(imgid, ms.ToArray()));
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sb.AppendLine("<br/><br/>");
|
||||
}
|
||||
sb.AppendLine("</div>");
|
||||
|
||||
return (sb.ToString(), list.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public class AlertItems
|
||||
{
|
||||
public AlertInfo[] DTCAlerts { get; set; }
|
||||
public AlertInfo[] PMAlerts { get; set; }
|
||||
public AlertInfo[] InspectAlerts { get; set; }
|
||||
public AlertInfo[] OilAlerts { get; set; }
|
||||
public double AllExpectedCost { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user