using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using log4net;
namespace IntelligentControlForsx.Service.WindturbineInfo
{
public class UniformCodeInfoSvc
{
private static ILog logger = LogManager.GetLogger("AppInfoLog");
///
/// 从xml配置信息中读取统一编码等信息
///
/// 场站编号
/// 风机型号
/// 所属功能
///
public static IList GetUniformCode(string stationId, string modelId, string controlName, string part = null)
{
IList list = new List();
string path = Environment.CurrentDirectory;
string filePath = path + "\\conf\\UniformCode.xml";
XmlDocument xdoc = new XmlDocument();
xdoc.Load(filePath); //加载xml文档
XmlNodeList rootList = xdoc.SelectNodes("/root");
if (rootList != null && rootList.Count > 0)
{
XmlNodeList stationNodeList = rootList[0].ChildNodes;
foreach (XmlNode stationNode in stationNodeList)
{
string stationName = stationNode.Attributes["name"].Value;
if (stationName == stationId)
{
XmlNodeList modelNodeList = stationNode.ChildNodes;
foreach (XmlNode modelNode in modelNodeList)
{
string modelName = modelNode.Attributes["name"].Value;
if (modelName == modelId)
{
XmlNodeList controlNodeList = modelNode.ChildNodes;
foreach (XmlNode controlNode in controlNodeList)
{
string controlListName = controlNode.Attributes["name"].Value;
if (controlListName == controlName)
{
XmlNodeList partNodeList = controlNode.ChildNodes;
foreach (XmlNode partNode in partNodeList)
{
string partIndex = partNode.Attributes["index"].Value;
string partName = partNode.Attributes["text"].Value;
if (part != null)
{
if (partIndex == part)
{
XmlNodeList paramNodeList = partNode.ChildNodes;
foreach (XmlNode paramNode in paramNodeList)
{
string plcName = "";
string lblName = "";
int? lblIndex = null;
string lblUniformCode = "";
string lblUnit = "";
string lblWarningNum = "";
try
{
if (paramNode.Attributes["plcName"] != null)
plcName = paramNode.Attributes["plcName"].Value;
if (paramNode.Attributes["name"] != null)
lblName = paramNode.Attributes["name"].Value;
if (paramNode.Attributes["num"] != null)
lblIndex = Convert.ToInt32(paramNode.Attributes["num"].Value);
if (paramNode.Attributes["value"] != null)
lblUniformCode = paramNode.Attributes["value"].Value;
if (paramNode.Attributes["unit"] != null)
lblUnit = paramNode.Attributes["unit"].Value;
if (paramNode.Attributes["warningNum"] != null)
lblWarningNum = paramNode.Attributes["warningNum"].Value;
UniformCodeInfo data = new UniformCodeInfo();
data.PartIndex = partIndex;
data.PartName = partName;
data.UniformCode = lblUniformCode;
data.Index = lblIndex.HasValue ? lblIndex.Value : 0;
data.Unit = lblUnit;
data.Name = lblName;
data.PlcName = plcName;
data.WarningNum = lblWarningNum;
list.Add(data);
}
catch (Exception ex)
{
logger.Info("xml配置读取错误:" + ex.Message);
}
}
}
}
else
{
XmlNodeList paramNodeList = partNode.ChildNodes;
foreach (XmlNode paramNode in paramNodeList)
{
string plcName = "";
string lblName = "";
int? lblIndex = null;
string lblUniformCode = "";
string lblUnit = "";
string lblWarningNum = "";
try
{
if (paramNode.Attributes["plcName"] != null)
plcName = paramNode.Attributes["plcName"].Value;
if (paramNode.Attributes["name"] != null)
lblName = paramNode.Attributes["name"].Value;
if (paramNode.Attributes["num"] != null)
lblIndex = Convert.ToInt32(paramNode.Attributes["num"].Value);
if (paramNode.Attributes["value"] != null)
lblUniformCode = paramNode.Attributes["value"].Value;
if (paramNode.Attributes["unit"] != null)
lblUnit = paramNode.Attributes["unit"].Value;
if (paramNode.Attributes["warningNum"] != null)
lblWarningNum = paramNode.Attributes["warningNum"].Value;
UniformCodeInfo data = new UniformCodeInfo();
data.PartIndex = partIndex;
data.PartName = partName;
data.UniformCode = lblUniformCode;
data.Index = lblIndex.HasValue ? lblIndex.Value : 0;
data.Unit = lblUnit;
data.Name = lblName;
data.PlcName = plcName;
data.WarningNum = lblWarningNum;
list.Add(data);
}
catch (Exception ex)
{
logger.Info("xml配置读取错误:" + ex.Message);
}
}
}
}
}
}
}
}
}
}
}
return list;
}
}
}