initial version with inspection edition

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

View File

@ -0,0 +1,45 @@
using Foresight.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IronIntel.Contractor.Users
{
public static class Acl
{
public static string[] GetUserAvailableContractors(string useriid)
{
const string SQL = @"select distinct CONTRACTORID from USERTOCONTRACTOR where USERIID={0}
or USERIID in(select GROUPID from USERGROUPMAP where USERIID ={0})";
FIDbAccess db = SystemParams.GetDbInstance();
DataTable dt = db.GetDataTableBySQL(SQL, useriid);
List<string> list = new List<string>();
foreach (DataRow dr in dt.Rows)
{
list.Add(FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty));
}
return list.ToArray();
}
public static AppModuleInfo[] GetAvailableAppModuleInfos(UserInfo user)
{
return AppModulesManagement.GetAvailableAppModuleInfos(user);
}
public static AppModuleInfo[] GetAvailableAppModuleInfos(string useriid)
{
UserInfo ui = UserManagement.GetUserByIID(useriid);
return GetAvailableAppModuleInfos(ui);
}
public static SecurityNavigateItem[] GetSecurityNavigateItems(UserInfo user)
{
return AppModulesManagement.GetSecurityNavigateItems(user);
}
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Foresight.Data;
namespace IronIntel.Contractor.Users
{
public class AppModuleInfo
{
public string ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool Visible { get; set; }
public string Url { get; set; }
public string IconPath { get; set; }
public string BackColor { get; set; }
public string ForeColor { get; set; }
public bool OpenInNewWindow { get; set; }
public AppModuleType ModuleType { get; set; }
}
public class SecurityNavigateItem
{
public string ID { get; set; }
public string Title { get; set; }
public string Url { get; set; }
public string IconPath { get; set; }
}
public enum AppModuleType
{
System,
Workspace
}
}

View File

@ -0,0 +1,195 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Foresight.Data;
using IronIntel.Contractor.Users;
using IronIntel.Services;
namespace IronIntel.Contractor.Users
{
class AppModulesManagement
{
private const string FITracker = "FITracker";
private const string Inspect = "Inspection";
private const string TeamIntelligence = "TeamIntelligence";
public static AppModuleInfo[] GetAvailableAppModuleInfos(UserInfo user)
{
const string SQL = @"select ID,APPMODULENAME,APPMODULEDESC,URL,ICONPATH,BACKCOLOR,FORECOLOR,OPENINNEWWINDOW from APPMODULES where VISIBLE>0 and (isnull(SITETYPE,'All')='All' or SITETYPE={0}) ";
if (user == null)
{
return new AppModuleInfo[0];
}
string sql = SQL;
switch (user.UserType)
{
case UserTypes.Readonly:
sql = SQL + " and SECURITYLEVEL=0";
break;
case UserTypes.Common:
sql = SQL + " and SECURITYLEVEL<=1";
break;
case UserTypes.Admin:
sql = SQL + " and SECURITYLEVEL<=2";
break;
case UserTypes.SupperAdmin:
sql = SQL + " and SECURITYLEVEL<=3";
break;
default:
sql = SQL;
break;
}
sql = sql + " order by ORDERINDEX ";
FIDbAccess db = SystemParams.GetDbInstance();
DataTable dt = db.GetDataTableBySQL(sql, SystemParams.CustomerDetail.CustomerType);
CustUIStyle style = SystemParams.GetUIStyle(user.IID);//获取样式设置
string moudleBackgroundColor = "#0078D7";
if (style != null && !string.IsNullOrEmpty(style.MenuBackgroundColor))
moudleBackgroundColor = style.MenuBackgroundColor;
List<AppModuleInfo> list = new List<AppModuleInfo>();
bool fitracter = SystemParams.HasLicense(FITracker);
bool inspect = SystemParams.HasLicense(Inspect);
bool teamintelligence = SystemParams.HasLicense(TeamIntelligence);
foreach (DataRow dr in dt.Rows)
{
AppModuleInfo ami = ConvertToAppModule(dr);
ami.BackColor = moudleBackgroundColor;
if (ami.ID.Equals(FITracker, StringComparison.OrdinalIgnoreCase))
{
if (fitracter)
list.Add(ami);
}
else if (ami.ID.Equals(Inspect, StringComparison.OrdinalIgnoreCase))
{
if (inspect)
list.Add(ami);
}
else if (ami.ID.Equals(TeamIntelligence, StringComparison.OrdinalIgnoreCase))
{
if (teamintelligence)
list.Add(ami);
}
else
list.Add(ami);
}
AppModuleInfo[] wsps = GetFICWorkspace(user);
foreach (AppModuleInfo ap in wsps)
{
if (!Exists(ap.Url, list))
{
ap.BackColor = moudleBackgroundColor;
list.Add(ap);
}
}
return list.ToArray();
}
private static bool Exists(string url, IEnumerable<AppModuleInfo> items)
{
foreach (AppModuleInfo item in items)
{
if (string.Compare(url, item.Url, true) == 0)
{
return true;
}
}
return false;
}
private static AppModuleInfo ConvertToAppModule(DataRow dr)
{
AppModuleInfo ai = new AppModuleInfo();
ai.ID = FIDbAccess.GetFieldString(dr["ID"], string.Empty);
ai.Name = FIDbAccess.GetFieldString(dr["APPMODULENAME"], string.Empty);
ai.Description = FIDbAccess.GetFieldString(dr["APPMODULEDESC"], string.Empty);
ai.Url = FIDbAccess.GetFieldString(dr["URL"], string.Empty);
ai.IconPath = FIDbAccess.GetFieldString(dr["ICONPATH"], string.Empty);
ai.BackColor = FIDbAccess.GetFieldString(dr["BACKCOLOR"], string.Empty);
ai.ForeColor = FIDbAccess.GetFieldString(dr["FORECOLOR"], string.Empty);
ai.OpenInNewWindow = FIDbAccess.GetFieldInt(dr["OPENINNEWWINDOW"], 0) == 1;
ai.Visible = true;
ai.ModuleType = AppModuleType.System;
return ai;
}
private static AppModuleInfo[] GetFICWorkspace(UserInfo user)
{
if (string.IsNullOrWhiteSpace(SystemParams.FICDbConnectionString))
{
return new AppModuleInfo[0];
}
string SQL = @"select w.IID,isnull(l.WorkSpaceName,w.WSPNAME) as WSPNAME,w.WSPDESCRIPTION from WORKSPACE w
left join WorkSpaceLanguage l on w.IID=l.WorkspaceIID and l.LanguageCode='en-us'
where (ISPUBLIC=1 or ISPUBLIC>10)";
FISqlConnection db = new FISqlConnection(SystemParams.FICDbConnectionString);
if (user.UserType == UserTypes.Readonly)
{
SQL += " and w.IID in( select ObjectValue from UserDefaultInfo where UserID='" + user.IID + "' and UserDefaultType=0)";
}
SQL += " order by isnull(l.WorkspaceName,w.WSPNAME)";
DataTable tb = db.GetDataTableBySQL(SQL);
List<AppModuleInfo> ls = new List<AppModuleInfo>();
foreach (DataRow dr in tb.Rows)
{
AppModuleInfo ap = new AppModuleInfo();
ap.ID = dr["IID"].ToString();
ap.Name = FIDbAccess.GetFieldString(dr["WSPNAME"], string.Empty);
ap.OpenInNewWindow = false;
ap.Description = FIDbAccess.GetFieldString(dr["WSPDESCRIPTION"], string.Empty);
ap.Visible = true;
if (string.IsNullOrWhiteSpace(ap.Description))
{
ap.Description = ap.Name;
}
ap.ForeColor = "white";
ap.Url = @"fic/Workspace.aspx?IID=" + ap.ID;
ap.IconPath = @"img/modules/pie1.png?t=0";
ap.ModuleType = AppModuleType.Workspace;
ls.Add(ap);
}
return ls.ToArray();
}
public static SecurityNavigateItem[] GetSecurityNavigateItems(UserInfo user)
{
const string SQL = "select * from SECURITYNAVNODE where (isnull(SITETYPE,'All')='All' or SITETYPE={0}) order by ORDERINDEX";
if ((user == null) || (user.UserType == UserTypes.Readonly) || (user.UserType == UserTypes.Common))
{
return new SecurityNavigateItem[0];
}
FIDbAccess db = SystemParams.GetDbInstance();
DataTable dt = db.GetDataTableBySQL(SQL, SystemParams.CustomerDetail.CustomerType);
List<SecurityNavigateItem> ls = new List<SecurityNavigateItem>();
foreach (DataRow dr in dt.Rows)
{
SecurityNavigateItem si = new SecurityNavigateItem();
si.ID = FIDbAccess.GetFieldString(dr["NODEID"], string.Empty);
si.Title = FIDbAccess.GetFieldString(dr["TITLE"], string.Empty);
si.IconPath = FIDbAccess.GetFieldString(dr["ICONPATH"], string.Empty);
si.Url = FIDbAccess.GetFieldString(dr["TARGETURL"], string.Empty);
if ("nav_dts" == si.ID.ToLower())
si.Url = "../fic/fic/Management/DataTablePermission.aspx";
if ("nav_filters" == si.ID.ToLower())
si.Url = "../fic/fic/Management/FiltersManagement.aspx";
ls.Add(si);
}
return ls.ToArray();
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IronIntel.Contractor.Users
{
public class UserGroupInfo
{
public string ID { get; set; }
public string Name { get; set; }
public string Notes { get; set; }
public UserInfo[] Users { get; set; }
}
public class UserToContractorInfo
{
public string ID { get; set; }
public string Name { get; set; }
public bool IsChecked { get; set; }
public bool AuthorizedIngroup { get; set; } //用户权限是否继承至组权限
}
}

View File

@ -0,0 +1,84 @@
using FI.FIC;
using FI.FIC.Contracts.DataObjects.BaseObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IronIntel.Contractor.Users
{
public class UserInfo
{
private static string[] ContactTypeNames = { "Foreman", "Driver", "Inventory Manager", "Rental Manager", "Service Manager", "Fleet Manager", "Technician", "Other" };
public string IID { get; set; }
public string ID { get; set; }
public string DisplayName { get; set; }
public string TextAddress { get; set; }
public bool IsUser { get; set; }
public ContactTypes ContactType { get; set; }
public string Mobile { get; set; }
public string BusinessPhone { get; set; }
public string Notes { get; set; }
public bool Active { get; set; }
public UserTypes UserType { get; set; }
public string TransPass { get; set; }
public string ManagerIID { get; set; }
public string ManagerName { get; set; }
public bool EmailOptOut { get; set; }
public bool InspectEmailList { get; set; }
public bool TeamIntelligenceUser { get; set; }
public string FOB { get; set; }
public decimal HourlyRate { get; set; }
public string[] GroupIDs { get; set; }
public string[] GroupNames { get; set; }
public string GroupNamesStr { get { return (GroupNames == null || GroupNames.Length == 0) ? "" : string.Join(",", GroupNames); } }
public string ContactTypeName
{
get
{
int cType = (int)ContactType;
if (cType > 7)
cType = 7;
return ContactTypeNames[cType];
}
}
}
public class UserObject
{
public UserInfo UserInfo { get; set; }
public SubscribeMessageByEmail Subscribe { get; set; }
public KeyValuePair<int, Foresight.Fleet.Services.User.Permissions[]>[] Features { get; set; }
public EmailSchedule Schedule { get; set; }
}
public enum UserTypes
{
Readonly = 0,
Common = 1,
Admin = 2,
SupperAdmin = 3
}
public enum ContactTypes
{
Foreman = 0,
Driver = 1,
InventoryManager = 2,
RentalManager = 3,
ServiceManager = 4,
FleetManager = 5,
Technician = 6,
Other = 100
}
public class UserNameInfoItem
{
public string IID { get; set; }
public string ID { get; set; }
public string Name { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,423 @@
using Foresight;
using Foresight.Data;
using Foresight.Fleet.Services.User;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace IronIntel.Contractor.Users
{
public static class UserParams
{
private const string _AutoRecenterMap = "AutoRecenterMap";
private const string _BaseMap = "BaseMap";
private const string _MapViewContratorID = "MapViewContratorID";
private const string _MapAlertLayer = "MapAlertLayer";
public const string _SystemStyleID = "SystemStyleID";
private const string _MapRefreshInterval = "MapRefreshInterval";
private const string _AssetDefaultSearch = "AssetDefaultSearch";
private const string _JobSiteDefaultSearch = "JobSiteDefaultSearch";
private const string _AssetGroupDefaultSearch = "AssetGroupDefaultSearch";
private const string _UnShownMachines = "UnShownMachines";
private const string _UnShownJobsites = "UnShownJobsites";
private const string _UnShownJobsiteMachines = "UnShownJobsiteMachines";
private const string _Onroad = "Onroad";
private const string _ExcludeNoLocation = "ExcludeNoLocation";
private const string _MapViewSearches = "MapViewSearches";
public static UserParamInfo GetUserParams(string sessionid, string useriid)
{
UserParamInfo userParams = new UserParamInfo();
string sql = "select PARAMNAME,PARAMVALUE from USERSPARAM where USERIID={0} ";
FIDbAccess db = SystemParams.GetDbInstance();
DataTable dt = db.GetDataTableBySQL(sql, useriid);
foreach (DataRow dr in dt.Rows)
{
string name = FIDbAccess.GetFieldString(dr["PARAMNAME"], "");
string value = FIDbAccess.GetFieldString(dr["PARAMVALUE"], "");
switch (name)
{
case _AutoRecenterMap:
userParams.AutoRecenterMap = Helper.IsTrue(value);
break;
case _BaseMap:
userParams.BaseMap = value;
break;
case _MapViewContratorID:
userParams.MapViewContratorID = value;
break;
case _MapAlertLayer:
userParams.MapAlertLayer = value;
break;
case _SystemStyleID:
userParams.SystemStyleID = value;
break;
case _AssetDefaultSearch:
userParams.AssetDefaultSearch = value;
break;
case _JobSiteDefaultSearch:
userParams.JobSiteDefaultSearch = value;
break;
case _AssetGroupDefaultSearch:
userParams.AssetGroupDefaultSearch = value;
break;
case _UnShownMachines:
userParams.UnShownMachines = value.Split(',');
break;
case _UnShownJobsites:
userParams.UnShownJobsites = value.Split(',');
break;
case _UnShownJobsiteMachines:
userParams.UnShownJobsiteMachines = value.Split(',');
break;
case _Onroad:
userParams.Onroad = int.Parse(value);
break;
case _ExcludeNoLocation:
userParams.ExcludeNoLocation = int.Parse(value) == 1;
break;
}
}
userParams.MapViewSearches = GetMapViewSearches(sessionid, useriid);
//if (string.IsNullOrEmpty(userParams.SystemStyleID))
//{
// var defaultStyle = SystemParams.GetUIStyle();//获取系统默认Style
// userParams.SystemStyleID = defaultStyle.UIStyleID.ToString();
//}
string intervalStr = SystemParams.GetStringParam(_MapRefreshInterval);
int interval = 0;
if (!string.IsNullOrWhiteSpace(intervalStr) && int.TryParse(intervalStr, out interval) && interval > 60)
userParams.MapRefreshInterval = interval;
else
userParams.MapRefreshInterval = 60;
userParams.MachineIconURL = SystemParams.MachineTypeMapViewIconUrl;
return userParams;
}
public static void SetUserParams(string useriid, UserParamInfo userParams)
{
const string SQL = @"if exists(select 1 from USERSPARAM where USERIID={0} and PARAMNAME={1})
update USERSPARAM set PARAMVALUE = {2}, BINCONTENT = null where USERIID = {0} and PARAMNAME = {1}
else insert into USERSPARAM(USERIID, PARAMNAME, PARAMVALUE, BINCONTENT) values({0},{1},{2},null) ";
const string SQL_Delete = @"delete from USERSPARAM where USERIID={0} and PARAMNAME={1} ";
FIDbAccess db = SystemParams.GetDbInstance();
db.ExecSQL(SQL, useriid, _AutoRecenterMap, userParams.AutoRecenterMap ? "true" : "false");
if (!string.IsNullOrEmpty(userParams.BaseMap))
db.ExecSQL(SQL, useriid, _BaseMap, userParams.BaseMap);
else
db.ExecSQL(SQL_Delete, useriid, _BaseMap);
if (!string.IsNullOrEmpty(userParams.MapViewContratorID))
db.ExecSQL(SQL, useriid, _MapViewContratorID, userParams.MapViewContratorID);
else
db.ExecSQL(SQL_Delete, useriid, _MapViewContratorID);
if (!string.IsNullOrEmpty(userParams.MapAlertLayer))
db.ExecSQL(SQL, useriid, _MapAlertLayer, userParams.MapAlertLayer);
else
db.ExecSQL(SQL_Delete, useriid, _MapAlertLayer);
if (!string.IsNullOrEmpty(userParams.SystemStyleID))
db.ExecSQL(SQL, useriid, _SystemStyleID, userParams.SystemStyleID);
else
db.ExecSQL(SQL_Delete, useriid, _SystemStyleID);
if (!string.IsNullOrEmpty(userParams.AssetDefaultSearch))
db.ExecSQL(SQL, useriid, _AssetDefaultSearch, userParams.AssetDefaultSearch);
else
db.ExecSQL(SQL_Delete, useriid, _AssetDefaultSearch);
if (!string.IsNullOrEmpty(userParams.JobSiteDefaultSearch))
db.ExecSQL(SQL, useriid, _JobSiteDefaultSearch, userParams.JobSiteDefaultSearch);
else
db.ExecSQL(SQL_Delete, useriid, _JobSiteDefaultSearch);
if (!string.IsNullOrEmpty(userParams.AssetGroupDefaultSearch))
db.ExecSQL(SQL, useriid, _AssetGroupDefaultSearch, userParams.AssetGroupDefaultSearch);
else
db.ExecSQL(SQL_Delete, useriid, _AssetGroupDefaultSearch);
if (userParams.UnShownMachines != null && userParams.UnShownMachines.Length > 0)
db.ExecSQL(SQL, useriid, _UnShownMachines, string.Join(",", userParams.UnShownMachines));
else
db.ExecSQL(SQL_Delete, useriid, _UnShownMachines);
if (userParams.UnShownJobsites != null && userParams.UnShownJobsites.Length > 0)
db.ExecSQL(SQL, useriid, _UnShownJobsites, string.Join(",", userParams.UnShownJobsites));
else
db.ExecSQL(SQL_Delete, useriid, _UnShownJobsites);
if (userParams.UnShownJobsiteMachines != null && userParams.UnShownJobsiteMachines.Length > 0)
db.ExecSQL(SQL, useriid, _UnShownJobsiteMachines, string.Join(",", userParams.UnShownJobsiteMachines));
else
db.ExecSQL(SQL_Delete, useriid, _UnShownJobsiteMachines);
if (userParams.Onroad >= 0)
db.ExecSQL(SQL, useriid, _Onroad, userParams.Onroad);
else
db.ExecSQL(SQL_Delete, useriid, _Onroad);
if (userParams.ExcludeNoLocation)
db.ExecSQL(SQL, useriid, _ExcludeNoLocation, userParams.ExcludeNoLocation ? 1 : 0);
}
public static string GetStringParameter(string useriid, string paramname)
{
const string SQL = "select PARAMVALUE from USERSPARAM where USERIID={0} and PARAMNAME={1}";
FIDbAccess db = SystemParams.GetDbInstance();
object obj = db.GetRC1BySQL(SQL, useriid, paramname);
return FIDbAccess.GetFieldString(obj, string.Empty);
}
public static void SetStringParameter(string useriid, string paramname, string value)
{
const string SQL = @"if exists(select 1 from USERSPARAM where USERIID={0} and PARAMNAME={1})
update USERSPARAM set PARAMVALUE = {2}, BINCONTENT = null where USERIID = {0} and PARAMNAME = {1}
else insert into USERSPARAM(USERIID, PARAMNAME, PARAMVALUE, BINCONTENT) values({0},{1},{2},null) ";
FIDbAccess db = SystemParams.GetDbInstance();
db.ExecSQL(SQL, useriid, paramname, value);
}
public static byte[] GetBinaryParameter(string useriid, string paramname)
{
const string SQL = "select BINCONTENT from USERSPARAM where USERIID={0} and PARAMNAME={1}";
FIDbAccess db = SystemParams.GetDbInstance();
object obj = db.GetRC1BySQL(SQL, useriid, paramname);
return FIDbAccess.GetFieldBytes(obj);
}
public static void SetBinaryParameter(string useriid, string paramname, byte[] buffer)
{
const string SQL = @"if exists(select 1 from USERSPARAM where USERIID={0} and PARAMNAME={1})
update USERSPARAM set PARAMVALUE = '', BINCONTENT = {2} where USERIID = {0} and PARAMNAME = {1}
else insert into USERSPARAM(USERIID, PARAMNAME, PARAMVALUE, BINCONTENT) values({0},{1},'',{2})";
FIDbAccess db = SystemParams.GetDbInstance();
db.ExecSQL(SQL, useriid, paramname, buffer);
}
private static MapViewSearchItem[] GetMapViewSearches(string sessionid, string useriid)
{
try
{
string xmlstr = FleetServiceClientHelper.CreateClient<UserProfileProvider>(sessionid).GetUserParams(SystemParams.CompanyID, useriid, _MapViewSearches);
List<MapViewSearchItem> searches = MapViewSearcheHelper.FromXML(xmlstr);
return searches.OrderByDescending(s => s.IsDefault).ThenBy(s => s.Name).ToArray();
}
catch
{
return new MapViewSearchItem[0];
}
}
public static MapViewSearchItem[] SaveMapViewSearch(string sessionid, string useriid, MapViewSearchItem search)
{
var client = FleetServiceClientHelper.CreateClient<UserProfileProvider>(sessionid);
string xmlstr = client.GetUserParams(SystemParams.CompanyID, useriid, _MapViewSearches);
List<MapViewSearchItem> searches = MapViewSearcheHelper.FromXML(xmlstr);
var item = searches.FirstOrDefault((s) => s.Name.Equals(search.Name, StringComparison.OrdinalIgnoreCase));
if (item != null)//如果已经存在,先移除
searches.Remove(item);
if (search.IsDefault)
{
foreach (var s in searches)
{
s.IsDefault = false;
}
}
searches.Add(search);
client.SetUserParam(SystemParams.CompanyID, useriid, _MapViewSearches, MapViewSearcheHelper.ToXml(searches).InnerXml);
return searches.OrderByDescending(s => s.IsDefault).ThenBy(s => s.Name).ToArray();
}
private static MapViewSearchItem[] AddSearchItem(MapViewSearchItem[] searches, string search, bool isDefault)
{
List<MapViewSearchItem> result = null;
if (searches != null)
{
result = searches.ToList();
var item = result.FirstOrDefault((s) => s.Name.Equals(search, StringComparison.OrdinalIgnoreCase));
if (item != null)//already exists, remove it
result.Remove(item);
}
else
result = new List<MapViewSearchItem>();
if (isDefault)
{
foreach (var s in result)
{
s.IsDefault = false;
}
}
result.Add(new MapViewSearchItem() { Name = search, IsDefault = isDefault });
return result.ToArray();
}
public static MapViewSearchItem[] DeleteMapViewSearch(string sessionid, string useriid, string searchName)
{
var client = FleetServiceClientHelper.CreateClient<UserProfileProvider>(sessionid);
string xmlstr = client.GetUserParams(SystemParams.CompanyID, useriid, _MapViewSearches);
List<MapViewSearchItem> searches = MapViewSearcheHelper.FromXML(xmlstr);
var item = searches.FirstOrDefault((s) => s.Name.Equals(searchName, StringComparison.OrdinalIgnoreCase));
if (item != null)// remove it
searches.Remove(item);
client.SetUserParam(SystemParams.CompanyID, useriid, _MapViewSearches, MapViewSearcheHelper.ToXml(searches).InnerXml);
return searches.OrderByDescending(s => s.IsDefault).ThenBy(s => s.Name).ToArray();
}
private static MapViewSearchItem[] RemoveSearchItem(MapViewSearchItem[] searches, string search)
{
if (searches == null) return null;
List<MapViewSearchItem> result = searches.ToList();
var item = result.FirstOrDefault((s) => s.Name.Equals(search, StringComparison.OrdinalIgnoreCase));
if (item != null)// remove it
result.Remove(item);
return result.ToArray();
}
}
public class UserParamInfo
{
public bool AutoRecenterMap { get; set; } = false;
public string BaseMap { get; set; }
public string MapViewContratorID { get; set; }
public string MapAlertLayer { get; set; }
public string SystemStyleID { get; set; }
public int MapRefreshInterval { get; set; }
public string MachineIconURL { get; set; }
public string AssetDefaultSearch { get; set; }
public string JobSiteDefaultSearch { get; set; }
public string AssetGroupDefaultSearch { get; set; }
public string[] UnShownMachines { get; set; }
public string[] UnShownJobsites { get; set; }
public string[] UnShownJobsiteMachines { get; set; }
public int Onroad { get; set; } = -1;
public bool ExcludeNoLocation { get; set; } = true;
public MapViewSearchItem[] MapViewSearches { get; set; }
}
public class MapViewSearcheHelper
{
public static List<MapViewSearchItem> FromXML(string xmlstr)
{
List<MapViewSearchItem> searches = new List<MapViewSearchItem>();
if (!string.IsNullOrEmpty(xmlstr))
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlstr);
XmlNode ch = doc.DocumentElement.FirstChild;
if (string.Compare(ch.Name, "Searches", true) == 0)
{
foreach (XmlNode node in ch.ChildNodes)
{
searches.Add(FromXml(node));
}
}
}
return searches;
}
private static MapViewSearchItem FromXml(XmlNode node)
{
MapViewSearchItem item = new MapViewSearchItem();
foreach (XmlNode ch in node.ChildNodes)
{
if (string.Compare(ch.Name, "Name", true) == 0)
item.Name = ch.InnerText;
else if (string.Compare(ch.Name, "IsDefault", true) == 0)
item.IsDefault = Helper.IsTrue(ch.InnerText);
else if (string.Compare(ch.Name, "Onroad", true) == 0)
item.Onroad = Convert.ToInt32(ch.InnerText);
else if (string.Compare(ch.Name, "AssetDefaultSearch", true) == 0)
item.AssetDefaultSearch = ch.InnerText;
else if (string.Compare(ch.Name, "JobSiteDefaultSearch", true) == 0)
item.JobSiteDefaultSearch = ch.InnerText;
else if (string.Compare(ch.Name, "AssetGroupDefaultSearch", true) == 0)
item.AssetGroupDefaultSearch = ch.InnerText;
else if (string.Compare(ch.Name, "ExcludeNoLocation", true) == 0)
item.ExcludeNoLocation = Convert.ToInt32(ch.InnerText) == 1;
else if (string.Compare(ch.Name, "UnShownMachines", true) == 0)
item.UnShownMachines = ch.InnerText.Split(',');
else if (string.Compare(ch.Name, "UnShownJobsites", true) == 0)
item.UnShownJobsites = ch.InnerText.Split(',');
else if (string.Compare(ch.Name, "UnShownJobsiteMachines", true) == 0)
item.UnShownJobsiteMachines = ch.InnerText.Split(',');
}
return item;
}
public static XmlDocument ToXml(List<MapViewSearchItem> searches)
{
XmlDocument doc = XmlHelper.CreateXmlDocument();
XmlNode node = XmlHelper.AppendChildNode(doc.DocumentElement, "Searches", "");
if (searches != null && searches.Count > 0)
{
foreach (var search in searches)
{
var sn = AddSubNode(node, "Search", "");
AddSubNode(sn, "Name", search.Name);
AddSubNode(sn, "IsDefault", search.IsDefault ? "Yes" : "No");
if (!string.IsNullOrEmpty(search.AssetDefaultSearch))
AddSubNode(sn, "AssetDefaultSearch", search.AssetDefaultSearch);
if (!string.IsNullOrEmpty(search.JobSiteDefaultSearch))
AddSubNode(sn, "JobSiteDefaultSearch", search.JobSiteDefaultSearch);
if (!string.IsNullOrEmpty(search.AssetGroupDefaultSearch))
AddSubNode(sn, "AssetGroupDefaultSearch", search.AssetGroupDefaultSearch);
AddSubNode(sn, "Onroad", search.Onroad.ToString());
AddSubNode(sn, "ExcludeNoLocation", search.ExcludeNoLocation ? "1" : "0");
if (search.UnShownMachines != null && search.UnShownMachines.Length > 0)
AddSubNode(sn, "UnShownMachines", string.Join(",", search.UnShownMachines));
if (search.UnShownJobsites != null && search.UnShownJobsites.Length > 0)
AddSubNode(sn, "UnShownJobsites", string.Join(",", search.UnShownJobsites));
if (search.UnShownJobsiteMachines != null && search.UnShownJobsiteMachines.Length > 0)
AddSubNode(sn, "UnShownJobsiteMachines", string.Join(",", search.UnShownJobsiteMachines));
}
}
return doc;
}
private static XmlNode AddSubNode(XmlNode parent, string nodename, string innertext)
{
XmlNode node = parent.OwnerDocument.CreateNode(XmlNodeType.Element, nodename, string.Empty);
if (!string.IsNullOrEmpty(innertext))
{
node.InnerText = innertext;
}
parent.AppendChild(node);
return node;
}
}
public class MapViewSearchItem
{
public string Name { get; set; }
public bool IsDefault { get; set; }
public int Onroad { get; set; } = -1;
public string AssetDefaultSearch { get; set; } = "";
public string JobSiteDefaultSearch { get; set; } = "";
public string AssetGroupDefaultSearch { get; set; } = "";
public bool ExcludeNoLocation { get; set; } = true;
public string[] UnShownMachines { get; set; }
public string[] UnShownJobsites { get; set; }
public string[] UnShownJobsiteMachines { get; set; }
}
}