Sic.Framework-Nanjing-Baishi/MECF.Framework.Common/Aitex/Core/RT/EMS/MaintainerEditor2.cs

638 lines
26 KiB
C#
Raw Normal View History

2024-01-29 11:12:21 +08:00
using Aitex.Core.RT.DBCore;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using Aitex.Core.Util;
using MECF.Framework.Common.Account.Extends;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml;
using SciChart.Charting.Visuals.TradeChart.MultiPane;
using Aitex.Core.RT.DataCenter;
using DocumentFormat.OpenXml.Office2010.Excel;
using SciChart.Core.Extensions;
2024-03-15 19:17:00 +08:00
using static MECF.Framework.Common.Aitex.Core.RT.EMS.Maintainer;
using System.Windows.Forms;
using DocumentFormat.OpenXml.Wordprocessing;
using System.Collections.ObjectModel;
2024-01-29 11:12:21 +08:00
namespace MECF.Framework.Common.Aitex.Core.RT.EMS
{
public class MaintainerEditor2 : XmlLoader
{
#region Variables
/// <summary>
/// 维护项列表
/// </summary>
2024-03-15 19:17:00 +08:00
private List<IMaintainer> _allMaintainerList = new();
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
private List<MaintainerInfo> _allMaintainerInfoList = new();
private Dictionary<string, List<MaintainerInfo>> _enabledmaintainerInfodic = new();
private Dictionary<string, List<MaintainerInfo>> _allmaintainerInfodic = new();
private List<MaintainerItemConfigInfo> _allMaintainerItemConfigList = new();
2024-01-29 11:12:21 +08:00
Func<object, bool> _isSubscriptionAttribute;
Func<PropertyInfo, bool> _hasSubscriptionAttribute;
#endregion
public MaintainerEditor2(string fileName) : base(fileName)
{
_isSubscriptionAttribute = attribute => attribute is SubscriptionAttribute;
_hasSubscriptionAttribute = mi => mi.GetCustomAttributes(false).Any(_isSubscriptionAttribute);
}
#region Methods
protected override void AnalyzeXml()
{
if (XmlDoc == null)
{
return;
}
2024-03-15 19:17:00 +08:00
#region MaintenanceItem配置
var ConfigX = XmlDoc.Element("root")?.Element("AllMaintainerItemConfigs");
if (ConfigX == null)
{
return;
}
var maintainnamceItemsconfigX = from r in ConfigX.Descendants("MaintainerItemConfig")
select (r);
foreach (var itemX in maintainnamceItemsconfigX)
{
string parentName = itemX.Attribute("ParentName")?.Value;
string name = itemX.Attribute("Name")?.Value;
string uidstring = itemX.Attribute("UID")?.Value;
string indexstring = itemX.Attribute("Index")?.Value;
string description = itemX.Attribute("Description")?.Value ?? "";
string defaultrecord = itemX.Attribute("DefaultRecord")?.Value ?? "";
string filepath = itemX.Attribute("FilePath")?.Value ?? "";
int index = 0;
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(indexstring))
{
EV.PostWarningLog("Maintenance", $"XML failed:MaintainConfigSubItem Parameter Missing");
//log.error
continue;
}
if (!int.TryParse(indexstring, out index))
{
EV.PostWarningLog("Maintenance", $"XML failed:MaintainConfigSubItem({name}) Parameter (Index) Parse failed;");
//log.error
}
MaintainerItemConfigInfo mi2 = new MaintainerItemConfigInfo(parentName, name, uidstring, index, description, defaultrecord, filepath);
_allMaintainerItemConfigList.Add(mi2);
}
#endregion
#region Maintainer
2024-01-29 11:12:21 +08:00
var maintainersX = from r in XmlDoc.Descendants("Maintainer")
select (r);
foreach (var maintainerX in maintainersX)
{
string maintainertype = maintainerX.Attribute("Type")?.Value??"";
string maintainername = maintainerX.Attribute("Name")?.Value;
string maintainerdescription = maintainerX.Attribute("Description")?.Value ?? "";
string maintainermodule = maintainerX.Attribute("Module")?.Value ?? "";
string maintainerindexstring = maintainerX.Attribute("Index")?.Value ?? "";
string maintainerenablestring = maintainerX.Attribute("Enable")?.Value ?? "True";
string maintainerstartdatestring = maintainerX.Attribute("StartDate")?.Value;
string maintainerthresholdstring = maintainerX.Attribute("Threshold")?.Value;
string maintainertimedisplayunitstring = maintainerX.Attribute("TimeDisplayUnit")?.Value;
int maintainerindex = 0;
bool maintainerenable = false;
DateTime maintainerstartdate = DateTime.Now;
double maintainerthreshold = 100;
TimeUnit maintainertimedisplayunit = TimeUnit.Hours;
if (string.IsNullOrEmpty(maintainertype) ||
string.IsNullOrEmpty(maintainername) ||
string.IsNullOrEmpty(maintainerstartdatestring) ||
string.IsNullOrEmpty(maintainerthresholdstring))
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", "XML failed:Plan Parameter Missing");
2024-01-29 11:12:21 +08:00
continue;
}
if (!bool.TryParse(maintainerenablestring, out maintainerenable))
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", $"XML failed:Plan {maintainername} Parameter (enable) Parse failed;");
2024-01-29 11:12:21 +08:00
//log.error
}
if (!DateTime.TryParse(maintainerstartdatestring, out maintainerstartdate))
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", $"XML failed:Plan {maintainername} Parameter (startdate) Parse failed;");
2024-01-29 11:12:21 +08:00
//log.error
}
if (!double.TryParse(maintainerthresholdstring, out maintainerthreshold))
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", $"XML failed:Plan {maintainername} Parameter (threshold) Parse failed;");
2024-01-29 11:12:21 +08:00
//log.error
}
if (!Enum.TryParse(maintainertimedisplayunitstring, out maintainertimedisplayunit))
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", $"XML failed:Plan {maintainername} Parameter (timedisplayunit) Parse failed;");
2024-01-29 11:12:21 +08:00
//log.error
}
if (!int.TryParse(maintainerindexstring, out maintainerindex))
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", $"XML failed:Plan {maintainername} Parameter (Index) Parse failed;");
2024-01-29 11:12:21 +08:00
//log.error
}
MaintainerItemCollection collection = new MaintainerItemCollection();
2024-03-15 19:17:00 +08:00
var itemsX = from r in maintainerX.Descendants("MaintainerItem") select (r);
foreach (var itemX in itemsX)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
string itemuidstring = itemX.Attribute("UID")?.Value ?? "";
string itemenablestring = itemX.Attribute("Enable")?.Value ?? "";
string itemdatetimestring = itemX.Attribute("MaintainedDateLatest")?.Value ?? "2000-1-1 0:0:0";
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
bool enable2 = false;
DateTime date2 = new DateTime(2000, 1, 1);
if (string.IsNullOrEmpty(itemuidstring))
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", $"XML failed:Plan UID Parameter Missing");
2024-01-29 11:12:21 +08:00
//log.error
continue;
}
2024-03-15 19:17:00 +08:00
if (!bool.TryParse(itemenablestring, out enable2))
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", $"XML failed:Plan {maintainername}:MaintainItem Parameter (enable) Parse failed;");
//log.error
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
DateTime.TryParse(itemdatetimestring, out date2);
var cinfo = _allMaintainerItemConfigList.Find(i => i.UID == itemuidstring);
if (cinfo != null)
{
MaintainerItem mi = new MaintainerItem(itemuidstring, enable2, date2, cinfo);
collection.AddMaintainerItem(mi);
}
else
{
EV.PostWarningLog("Maintenance", $"XML failed:Plan {maintainername}:MaintainItem{itemuidstring} Config Missing;");
}
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
if (maintainertype == nameof(PlanMaintainer))
2024-01-29 11:12:21 +08:00
{
PlanMaintainer pm = new PlanMaintainer(collection,
maintainername,
maintainermodule,
maintainerindex,
maintainerdescription,
maintainerenable,
maintainerstartdate,
maintainerthreshold,
maintainertimedisplayunit);
pm.OnSave += SaveXml;
2024-03-15 19:17:00 +08:00
_allMaintainerList.Add(pm);
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
else if (maintainertype == nameof(PMMaintainer))
2024-01-29 11:12:21 +08:00
{
PMMaintainer pm = new PMMaintainer(collection,
maintainername,
maintainermodule,
maintainerindex,
maintainerdescription,
maintainerenable,
maintainerstartdate,
maintainerthreshold,
maintainertimedisplayunit);
pm.OnSave += SaveXml;
2024-03-15 19:17:00 +08:00
_allMaintainerList.Add(pm);
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
else if (maintainertype == nameof(CoatingMaintainer))
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
CoatingMaintainer pm = new CoatingMaintainer(collection,
2024-01-29 11:12:21 +08:00
maintainername,
maintainermodule,
maintainerindex,
maintainerdescription,
maintainerenable,
maintainerstartdate,
maintainerthreshold,
maintainertimedisplayunit);
pm.OnSave += SaveXml;
2024-03-15 19:17:00 +08:00
_allMaintainerList.Add(pm);
2024-01-29 11:12:21 +08:00
}
}
#endregion
2024-03-15 19:17:00 +08:00
#region
foreach (var item in _allMaintainerList)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
_allMaintainerInfoList.Add(item.GetInfo());
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
foreach (var m in _allMaintainerInfoList)
{
//重新赋值config
foreach (var item in m.MaintainerItemInfos)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
var c = _allMaintainerItemConfigList.Find(i => i.UID == item.UID);
if (c != null)
{
item.Config = c;
}
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
if (!_enabledmaintainerInfodic.ContainsKey(m.Name))
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
_enabledmaintainerInfodic.Add(m.Name, new());
_allmaintainerInfodic.Add(m.Name, new List<MaintainerInfo>());
//_obmaintainerconfigenableinfodic.Add(m.Name, new());
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
_allmaintainerInfodic[m.Name].Add(m);
if (m.Enable)
{
_enabledmaintainerInfodic[m.Name].Add(m);
2024-01-29 11:12:21 +08:00
}
}
2024-03-15 19:17:00 +08:00
OrderMaintainer();
#endregion
2024-01-29 11:12:21 +08:00
#region
SaveXml();
#endregion
}
protected bool SaveXml()
{
if (XmlDoc == null)
{
return false;
}
try
{
XmlDocument doc = new XmlDocument();
2024-03-15 19:17:00 +08:00
doc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><MaintenanceGroup></MaintenanceGroup><AllMaintainerItemConfigs></AllMaintainerItemConfigs></root>");
2024-01-29 11:12:21 +08:00
var root = doc.SelectSingleNode("root") as XmlElement;
#region _maintenancelist
2024-03-15 19:17:00 +08:00
var groups = root.GetElementsByTagName("MaintenanceGroup")[0];
foreach (var maintainer in _allMaintainerList)
2024-01-29 11:12:21 +08:00
{
var xmlElement2 = doc.CreateElement("Maintainer"); //一级列表
2024-03-15 19:17:00 +08:00
var info = maintainer.GetInfo();
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
xmlElement2.SetAttribute("Type", info.Type);
xmlElement2.SetAttribute("Name", info.Name);
xmlElement2.SetAttribute("Description", info.Description);
xmlElement2.SetAttribute("Index", info.Index.ToString());
if (!string.IsNullOrEmpty(info.Module))
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
xmlElement2.SetAttribute("Module", info.Module);
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
xmlElement2.SetAttribute("Enable", info.Enable.ToString());
xmlElement2.SetAttribute("StartDate", info.StartDate.ToString());
xmlElement2.SetAttribute("Threshold", info.Threshold.ToString());
xmlElement2.SetAttribute("TimeDisplayUnit", info.TimeDisplayUnit.ToString());
var ilist = maintainer.GetAllMaintainerItems();
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
foreach (var item2 in ilist)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
var xmlElement3 = doc.CreateElement("MaintainerItem"); //三级列表
xmlElement3.SetAttribute("UID", item2.UID.ToString());
//xmlElement3.SetAttribute("Name", item2.Name);
xmlElement3.SetAttribute("MaintainedDateLatest", item2.MaintainedDate.ToString());
xmlElement3.SetAttribute("Enable", item2.Enable.ToString());
2024-01-29 11:12:21 +08:00
xmlElement2.AppendChild(xmlElement3);
}
groups.AppendChild(xmlElement2);
}
#endregion
#region _maintenanceitemconfiglist
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
var configgroups = root.GetElementsByTagName("AllMaintainerItemConfigs")[0];
foreach (var item in _allMaintainerItemConfigList)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
var xmlElement = doc.CreateElement("MaintainerItemConfig"); //二级列表
xmlElement.SetAttribute("UID", item.UID);
xmlElement.SetAttribute("ParentName", item.ParentName);
2024-01-29 11:12:21 +08:00
xmlElement.SetAttribute("Name", item.Name);
xmlElement.SetAttribute("Index", item.Index.ToString());
2024-03-15 19:17:00 +08:00
xmlElement.SetAttribute("Description", item.Description);
xmlElement.SetAttribute("DefaultRecord", item.DefaultRecord);
xmlElement.SetAttribute("FilePath", item.FilePath);
2024-01-29 11:12:21 +08:00
configgroups.AppendChild(xmlElement);
}
#endregion
doc.Save(FileName);
XmlDoc = XDocument.Load(FileName);
}
catch (Exception ex)
{
LOG.Write(ex);
return false;
}
return true;
}
2024-03-15 19:17:00 +08:00
private void OrderMaintainer()
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
_enabledmaintainerInfodic.ForEachDo(i =>
{
var temp = i.Value.OrderBy(i => i.Index).ToList();
i.Value.Clear();
foreach (var item in temp)
{
i.Value.Add(item);
}
});
_allmaintainerInfodic.ForEachDo(i => {
var temp = i.Value.OrderBy(i => i.Index).ToList();
i.Value.Clear();
i.Value.AddRange(temp);
});
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
public List<IMaintainer> GetAllMaintainerList()
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
return _allMaintainerList;
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
public List<MaintainerItemConfigInfo> GetAllMaintainerConfigItemList()
{
return _allMaintainerItemConfigList;
}
public bool SetMaintain(string type,string name, string module, string parent, string itemname, string itemuid, DateTime date, string role, string detial)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
int index = _allMaintainerList.FindIndex(i =>i.EqualsNameModule(type,name,module));
2024-01-29 11:12:21 +08:00
if (index == -1)
return false;
2024-03-15 19:17:00 +08:00
if(_allMaintainerList[index].SetMaintain(itemuid,date))
2024-01-29 11:12:21 +08:00
{
string s = name + (module == "" ? "" : ("." + module));
2024-03-15 19:17:00 +08:00
EV.PostInfoLog("Maintenance", $"Item {parent}-{itemname}({itemuid}) in Plan {s} is Maintained");
2024-01-29 11:12:21 +08:00
#region DATABASE
string cmd = string.Format("Insert into \"maintenance_event_data\"" +
2024-03-15 19:17:00 +08:00
"(\"planname\",\"planmodule\",\"itemparentname\",\"itemname\",\"uid\",\"createtime\",\"role\",\"detial\")" +
" values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", name, module, parent, itemname, itemuid, date.ToString("yyyy/MM/dd HH:mm:ss.fff"), role, detial);
2024-01-29 11:12:21 +08:00
int result = DB.ExecuteNonQuery(cmd);
if (result <= 0)
{
2024-03-15 19:17:00 +08:00
EV.PostWarningLog("Maintenance", $"database execution faile => code: {cmd}");
2024-01-29 11:12:21 +08:00
}
#endregion
return SaveXml();
}
else return false;
}
#region
2024-03-15 19:17:00 +08:00
public bool ExchangeMaintainItemIndex(string uid1, string uid2)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
var item1 = _allMaintainerItemConfigList.Find(i => i.UID == uid1);
var item2 = _allMaintainerItemConfigList.Find(i => i.UID == uid2);
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
if (item1!=null && item2 !=null)
{
int tempindex = item1.Index;
item1.Index = item2.Index;
item2.Index = tempindex;
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
_allMaintainerList.ForEachDo(i => i.SortItemInfo());
}
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
EV.PostInfoLog("Maintenance", $"Maintainer {uid1} & {uid2} Index is exchanged ");
2024-01-29 11:12:21 +08:00
return SaveXml();
}
/// <summary>
/// 二级维护项enable设置根据名称和id确认唯一性
/// </summary>
2024-03-15 19:17:00 +08:00
/// <param name="type"></param>
2024-01-29 11:12:21 +08:00
/// <param name="name"></param>
/// <param name="module"></param>
2024-03-15 19:17:00 +08:00
/// <param name="itemuid"></param>
2024-01-29 11:12:21 +08:00
/// <param name="enable"></param>
/// <returns></returns>
2024-03-15 19:17:00 +08:00
public bool SetMaintainItemEnable(string type,string name, string module, string itemuid, bool enable)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
int index = _allMaintainerList.FindIndex(i => i.EqualsNameModule(type, name, module));
2024-01-29 11:12:21 +08:00
if (index == -1)
return false;
2024-03-15 19:17:00 +08:00
if (!_allMaintainerList[index].SetMaintainerItemEnable(itemuid, enable))
2024-01-29 11:12:21 +08:00
{
return false;
}
string s = name + (module == "" ? "" : ("." + module));
string result = enable ? "Enable" : "Disable";
2024-03-15 19:17:00 +08:00
EV.PostInfoLog("Maintenance", $"Item {itemuid} in Plan {s} is {result}");
2024-01-29 11:12:21 +08:00
return SaveXml();
}
/// <summary>
/// 修改Item参数
/// </summary>
/// <param name="parentname"></param>
/// <param name="name"></param>
2024-03-15 19:17:00 +08:00
/// <param name="itemuid"></param>
/// <param name="itemindex"></param>
2024-01-29 11:12:21 +08:00
/// <param name="description"></param>
/// <param name="defaultrecord"></param>
/// <param name="filepath"></param>
/// <returns></returns>
2024-03-15 19:17:00 +08:00
public bool SetMaintainItemParas(string parentname, string name, string itemuid, int itemindex, string description, string defaultrecord, string filepath)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
int index = _allMaintainerItemConfigList.FindIndex(i => i.UID == itemuid);
2024-01-29 11:12:21 +08:00
if (index == -1)
return false;
2024-03-15 19:17:00 +08:00
_allMaintainerItemConfigList[index].ParentName = parentname;
_allMaintainerItemConfigList[index].Name = name;
if (_allMaintainerItemConfigList[index].Index != itemindex)
{
_allMaintainerList.ForEachDo(i=>i.SortItemInfo());
_allMaintainerItemConfigList[index].Index = itemindex;
}
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
_allMaintainerItemConfigList[index].Description = description;
_allMaintainerItemConfigList[index].DefaultRecord = defaultrecord;
_allMaintainerItemConfigList[index].FilePath = filepath;
EV.PostInfoLog("Maintenance", $"Item {itemuid} Parameters is changed ");
2024-01-29 11:12:21 +08:00
return SaveXml();
}
/// <summary>
/// 新增Item
/// </summary>
/// <param name="parentname"></param>
/// <param name="name"></param>
2024-03-15 19:17:00 +08:00
/// <param name="itemuid"></param>
2024-01-29 11:12:21 +08:00
/// <param name="itemindex"></param>
/// <param name="description"></param>
/// <param name="defaultrecord"></param>
/// <param name="filepath"></param>
/// <returns></returns>
2024-03-15 19:17:00 +08:00
public bool AddMaintainItem(string parentname ,string name, string itemuid, int itemindex, string description, string defaultrecord, string filepath)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
MaintainerItemConfigInfo newconfigitem = new MaintainerItemConfigInfo(parentname, name,itemuid, itemindex, description, defaultrecord,filepath);
_allMaintainerItemConfigList.Add(newconfigitem);
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
foreach (var item in _allMaintainerList)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
item.AddMaintainerItem(new MaintainerItem(itemuid,false,new DateTime(2000,1,1),newconfigitem));
2024-01-29 11:12:21 +08:00
}
return SaveXml();
}
/// <summary>
/// 删除Item
/// </summary>
2024-03-15 19:17:00 +08:00
/// <param name="itemuid"></param>
2024-01-29 11:12:21 +08:00
/// <returns></returns>
2024-03-15 19:17:00 +08:00
public bool DeleteMaintainItem(string itemuid)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
foreach (var ma in _allMaintainerList)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
ma.RemoveMaintainerItem(itemuid);
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
int index = _allMaintainerItemConfigList.FindIndex(i => i.UID == itemuid);
if (index == -1)
return false;
2024-03-15 19:17:00 +08:00
_allMaintainerItemConfigList.RemoveAt(index);
EV.PostInfoLog("Maintenance", $"Maintenance Item {itemuid} deleted.");
2024-01-29 11:12:21 +08:00
return SaveXml();
}
#endregion
#region Plan增删改
2024-03-15 19:17:00 +08:00
public bool SetMaintainerParas(string type,string name, string oldmodule, string newmodule, int _index, bool enable, string description, DateTime date, double threshold, TimeUnit timeunit)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
int index = _allMaintainerList.FindIndex(i => i.EqualsNameModule(type, name, oldmodule));
2024-01-29 11:12:21 +08:00
if (index == -1)
return false;
2024-03-15 19:17:00 +08:00
var info = _allMaintainerList[index].GetInfo();
info.Module = newmodule;
info.Description = description;
info.Enable = enable;
info.Index = _index;
info.TimeDisplayUnit = timeunit;
if (info.Threshold != threshold)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
_allMaintainerList[index].SetThreshold(threshold, timeunit);
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
if (info.StartDate != date)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
_allMaintainerList[index].SetStartDate(date);
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
_allMaintainerList[index].UpdateInfo();
//if (_allMaintainerList[index] is PlanMaintainer pm1)
// pm1.UpdateInfo();
//else if (_allMaintainerList[index] is PMMaintainer pm2)
// pm2.UpdateInfo();
//else if (_allMaintainerList[index] is CoatingMaintainer pm3)
// pm3.UpdateInfo();
EV.PostInfoLog("Maintenance", $"{info.DisplayName} Parameters is changed ");
2024-01-29 11:12:21 +08:00
return SaveXml();
}
2024-03-15 19:17:00 +08:00
public bool AddMaintainer(string type,string name, string module, int _index ,bool enable, string description, DateTime date, double threshold, TimeUnit timeunit)
2024-01-29 11:12:21 +08:00
{
//ui 调用此函数前已判断重复性
var mc = new MaintainerItemCollection();
2024-03-15 19:17:00 +08:00
foreach (var maintainercitem in _allMaintainerItemConfigList)
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
mc.AddMaintainerItem(new MaintainerItem(maintainercitem.UID, false, new DateTime(2020, 1, 1), maintainercitem));
}
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
if (type == nameof(PlanMaintainer))
{
var plan = new PlanMaintainer(mc, name, module, _index, description, enable, date, threshold, timeunit);
plan.OnSave += SaveXml;
plan.UpdateInfo();
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
_allMaintainerList.Add(plan);
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
else if (type == nameof(PMMaintainer))
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
var pm = new PMMaintainer(mc, name, module, _index, description, enable, date, threshold, timeunit);
pm.OnSave += SaveXml;
pm.UpdateInfo();
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
_allMaintainerList.Add(pm);
2024-01-29 11:12:21 +08:00
}
2024-03-15 19:17:00 +08:00
else if (type == nameof(CoatingMaintainer))
2024-01-29 11:12:21 +08:00
{
2024-03-15 19:17:00 +08:00
var pm = new CoatingMaintainer(mc, name, module, _index, description, enable, date, threshold, timeunit);
pm.OnSave += SaveXml;
pm.UpdateInfo();
2024-01-29 11:12:21 +08:00
2024-03-15 19:17:00 +08:00
_allMaintainerList.Add(pm);
2024-01-29 11:12:21 +08:00
}
string s = name + (module == "" ? "" : ("." + module));
2024-03-15 19:17:00 +08:00
EV.PostInfoLog("Maintenance", $"Plan {s} created");
2024-01-29 11:12:21 +08:00
return SaveXml();
}
public bool DeleteMaintainer(string type,string name, string module)
{
2024-03-15 19:17:00 +08:00
int index = _allMaintainerList.FindIndex(i => i.EqualsNameModule(type, name, module));
2024-01-29 11:12:21 +08:00
if (index == -1)
return false;
2024-03-15 19:17:00 +08:00
if (_allMaintainerList.Remove(_allMaintainerList[index]))
2024-01-29 11:12:21 +08:00
{
string s = name + (module == "" ? "" : ("." + module));
2024-03-15 19:17:00 +08:00
EV.PostInfoLog("Maintenance", $"Plan {s} Delete");
2024-01-29 11:12:21 +08:00
return SaveXml();
}
else return false;
}
#endregion
#endregion
}
}