From c3a6219321f24eef97323a27b0db457e37a936b8 Mon Sep 17 00:00:00 2001 From: lihanbo Date: Mon, 7 Apr 2025 16:18:05 +0800 Subject: [PATCH] =?UTF-8?q?105040=20Add=20=E5=AF=B9=E6=8E=A5PLM=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DynaServerClient.cs | 67 ++- .../Model/User.cs | 15 + .../Model/UserGroup.cs | 18 + .../Model/UserRole.cs | 15 + .../Sinvo.EplanHpD.Plugin.DynaClient.csproj | 7 +- Sinvo.EplanHpD.Plugin.DynaClient/XMLMethod.cs | 97 ++++ .../XmlFormatStream.cs | 500 ++++++++++++++++++ Sinvo.EplanHpD.Plugin.DynaClient/app.config | 18 +- .../Model/UserInfo.cs | 18 + .../PluginServices.cs | 7 +- .../Sinvo.EplanHpD.Plugin.Service.csproj | 7 + .../Models/UserLoginModel.cs | 88 +++ .../Sinvo.EplanHpD.Plugin.WPFUI.csproj | 5 + .../View/LoginWindow.xaml | 196 +++++++ .../View/LoginWindow.xaml.cs | 239 +++++++++ .../CableLectotype/LectotypeViewModel.cs | 3 +- .../ViewModel/LoginViewModel.cs | 108 +++- Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs | 59 ++- 18 files changed, 1420 insertions(+), 47 deletions(-) create mode 100644 Sinvo.EplanHpD.Plugin.DynaClient/Model/User.cs create mode 100644 Sinvo.EplanHpD.Plugin.DynaClient/Model/UserGroup.cs create mode 100644 Sinvo.EplanHpD.Plugin.DynaClient/Model/UserRole.cs create mode 100644 Sinvo.EplanHpD.Plugin.DynaClient/XMLMethod.cs create mode 100644 Sinvo.EplanHpD.Plugin.DynaClient/XmlFormatStream.cs create mode 100644 Sinvo.EplanHpD.Plugin.Service/Model/UserInfo.cs create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/Models/UserLoginModel.cs create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml.cs diff --git a/Sinvo.EplanHpD.Plugin.DynaClient/DynaServerClient.cs b/Sinvo.EplanHpD.Plugin.DynaClient/DynaServerClient.cs index 0794bf8..5918475 100644 --- a/Sinvo.EplanHpD.Plugin.DynaClient/DynaServerClient.cs +++ b/Sinvo.EplanHpD.Plugin.DynaClient/DynaServerClient.cs @@ -1,4 +1,5 @@ using Sinvo.EplanHpD.Plugin.DynaClient.CADIService; +using Sinvo.EplanHpD.Plugin.DynaClient.Model; using System; using System.Collections.Generic; using System.Linq; @@ -10,25 +11,77 @@ namespace Sinvo.EplanHpD.Plugin.DynaClient { public class DynaServerClient { + private static DynaServerClient _inst; + public static DynaServerClient GetClient() + { + if(_inst == null) + { + _inst = new DynaServerClient(); + } + return _inst; + } + private CADIServicePortTypeClient _client; - public DynaServerClient( ) + private DynaServerClient( ) { InitClient(); } - - private void InitClient() + public DynaServerClient(string serverUrl) + { + InitClient(serverUrl); + } + private void InitClient(string serverUrl = "http://192.168.1.205:38080/axis2/services/CADIService?wsdl") { var binding = new BasicHttpBinding(); - var endpoint = new EndpointAddress("http://192.168.1.206:38080/axis2/services/CADIService?wsdl"); + var endpoint = new EndpointAddress(serverUrl); + // 启用Cookie管理 + binding.AllowCookies = true; _client = new CADIServicePortTypeClient(binding, endpoint); - //_client = new CADIServicePortTypeClient(); } - public object Login(string userName,string password,string role,string group,string clientType) + public User Login(string userName,string password,string role,string group,string clientType) { var hostName = Environment.MachineName; - return _client.login(userName, group, role, password, hostName, clientType); + var xml = _client.login(userName, group, role, password, hostName, clientType); + return XmlFormatStream.ConvertXMLToObjectList(xml)?.FirstOrDefault(); + } + + public List GetUserGroup(string userName) + { + var groupFieldName = "GUID|ID|NAME|LIBRARYGUID"; + var xml = _client.listGroupByUser(userName, groupFieldName); + return XmlFormatStream.ConvertXMLToObjectList(xml); + } + + public List GetUserRole(string userName,string groupId) + { + string roleFieldName = "ID|NAME"; + var xml = _client.listRoleByUserInGroup(userName, groupId, roleFieldName); + return XmlFormatStream.ConvertXMLToObjectList(xml); + + } + + public void LoginOut() + { + _client.logout(); + } + + + public bool IsLoginExpired() + { + var xml = _client.isSessionExpired(); + try + { + XmlFormatStream.CheckXmlException(xml); + return true; + } + catch (System.Exception) + { + return false; + } + + } } } diff --git a/Sinvo.EplanHpD.Plugin.DynaClient/Model/User.cs b/Sinvo.EplanHpD.Plugin.DynaClient/Model/User.cs new file mode 100644 index 0000000..ae8af83 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.DynaClient/Model/User.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.DynaClient.Model +{ + public class User + { + public string GUID { get; set; } + public string Name { get; set; } + public string ID { get; set; } + } +} diff --git a/Sinvo.EplanHpD.Plugin.DynaClient/Model/UserGroup.cs b/Sinvo.EplanHpD.Plugin.DynaClient/Model/UserGroup.cs new file mode 100644 index 0000000..0add859 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.DynaClient/Model/UserGroup.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.DynaClient.Model +{ + public class UserGroup + { + //GUID|ID|NAME|LIBRARYGUID + + public string GUID { get; set; } + public string Name { get; set; } + public string ID { get; set; } + public string LibraryGUID { get; set; } + } +} diff --git a/Sinvo.EplanHpD.Plugin.DynaClient/Model/UserRole.cs b/Sinvo.EplanHpD.Plugin.DynaClient/Model/UserRole.cs new file mode 100644 index 0000000..dbd693e --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.DynaClient/Model/UserRole.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.DynaClient.Model +{ + public class UserRole + { + //string roleFieldName = "ID|NAME"; + public string ID { get; set; } + public string Name { get; set; } + } +} diff --git a/Sinvo.EplanHpD.Plugin.DynaClient/Sinvo.EplanHpD.Plugin.DynaClient.csproj b/Sinvo.EplanHpD.Plugin.DynaClient/Sinvo.EplanHpD.Plugin.DynaClient.csproj index 754bfdf..fc9fc76 100644 --- a/Sinvo.EplanHpD.Plugin.DynaClient/Sinvo.EplanHpD.Plugin.DynaClient.csproj +++ b/Sinvo.EplanHpD.Plugin.DynaClient/Sinvo.EplanHpD.Plugin.DynaClient.csproj @@ -9,7 +9,7 @@ Properties Sinvo.EplanHpD.Plugin.DynaClient Sinvo.EplanHpD.Plugin.DynaClient - v4.8.1 + v4.8 512 true @@ -50,7 +50,12 @@ True Reference.svcmap + + + + + diff --git a/Sinvo.EplanHpD.Plugin.DynaClient/XMLMethod.cs b/Sinvo.EplanHpD.Plugin.DynaClient/XMLMethod.cs new file mode 100644 index 0000000..53bc821 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.DynaClient/XMLMethod.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace Sinvo.EplanHpD.Plugin.DynaClient +{ + public class XMLMethod + { + /// + /// XML的SelectSingleNode的替代方法 + /// + /// + /// + /// + public static XmlNode GetXmlNode(XmlDocument xmlDoc, string nodeFullName) + { + + if (xmlDoc.ChildNodes.Count > 0) + { + int index = nodeFullName.IndexOf("/"); + string nodeName = null; + if (index > -1) + { + nodeName = nodeFullName.Substring(0, index); + } + else + { + nodeName = nodeFullName; + } + foreach (XmlNode tempNode in xmlDoc.ChildNodes) + { + if (string.Compare(tempNode.Name, nodeName, true) == 0) + { + if (index > -1) + { + int fullNameLength = nodeFullName.Length - index - 1; + if (fullNameLength < 1) + { + return tempNode; + } + else + { + string childNodeFullName = nodeFullName.Substring(index + 1, fullNameLength); + return GetChildNode(tempNode, childNodeFullName); + } + } + else + { + return tempNode; + } + } + } + } + return null; + } + private static XmlNode GetChildNode(XmlNode node, string nodeFullName) + { + int index = nodeFullName.IndexOf("/"); + string nodeName = null; + if (index > -1) + { + nodeName = nodeFullName.Substring(0, index); + } + else + { + nodeName = nodeFullName; + } + foreach (XmlNode tempNode in node.ChildNodes) + { + if (string.Compare(tempNode.Name, nodeName, true) == 0) + { + if (index > -1) + { + int fullNameLength = nodeFullName.Length - index - 1; + if (fullNameLength < 1) + { + return tempNode; + } + else + { + string childNodeFullName = nodeFullName.Substring(index + 1, fullNameLength); + return GetChildNode(tempNode, childNodeFullName); + } + } + else + { + return tempNode; + } + } + } + return null; + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.DynaClient/XmlFormatStream.cs b/Sinvo.EplanHpD.Plugin.DynaClient/XmlFormatStream.cs new file mode 100644 index 0000000..d43e320 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.DynaClient/XmlFormatStream.cs @@ -0,0 +1,500 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace Sinvo.EplanHpD.Plugin.DynaClient +{ + class XmlFormatStream + { + private const string XTN_PDMOUT_STATUS = "pdmOut/status"; + private const string XTN_PDMOUT_MESSAGE = "pdmOut/message"; + private const string XTN_PDMOUT_RESULT = "pdmOut/result"; + private const string XTN_PDMOUT_RESULT_FIELDTYPE = "pdmOut/result/fieldtype"; + private const string XTN_PDMOUT_RESULT_FIELDNAME = "pdmOut/result/fieldname"; + private const string XTN_PDMOUT_RESULT_VALUE_ROW = "pdmOut/result/value/row"; + private const string XTN_PDMIN = "pdmIn"; + private const string XTN_PDM_IN_SERIAL = "serial"; + private const string XTN_PDM_IN_PARAM = "param"; + private const string XTN_PDM_IN_FIELD_TYPE = "fieldtype"; + private const string XTN_PDM_IN_FIELD_NAME = "fieldname"; + private const string XTN_PDM_IN_FIELD_VALUE = "value"; + private const string XTN_PDM_IN_FIELD_VALUE_ROW = "row"; + private const string XAN_PDM_IN_PARAM_TYPE = "type"; + + /// + /// 检查XML流是不是个异常 + /// + /// + public static void CheckXmlException(string xmlStream) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(xmlStream); + XmlNode statusNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_STATUS); + if (statusNode == null) + { + return; + } + string strStatus = statusNode.InnerText; + if (strStatus.CompareTo("1") == 0) + { + // 失败 + XmlNode msgNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_MESSAGE); + if (msgNode == null) + { + throw new Exception(); + } + string strFailedMsg = msgNode.InnerText; + throw new Exception(strFailedMsg); + } + else if (strStatus.CompareTo("201") == 0) + { + throw new Exception("登录过期!"); + } + } + /// + /// PDM XML格式返回值转化成String类型 + /// + /// xml流字符串 + /// + public static string PDMSimpleReturnXmlStreamToString(string xmlStream) + { + // + // simple + // 2009-07-08 10:40:00 + // 2009-07-08 10:40:02 + // 0/1 + // login sucessfully! + // + // 5F2BB7B637654441BB3460C3A55386A7 + // + + string strResult = ""; + + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(xmlStream); + + XmlNode statusNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_STATUS); + if (statusNode == null) + { + throw new Exception(); + } + string strStatus = statusNode.InnerText; + if (strStatus.CompareTo("1") == 0) + { + // 失败 + XmlNode msgNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_MESSAGE); + if (msgNode == null) + { + throw new Exception(); + } + string strFailedMsg = msgNode.InnerText; + throw new Exception(strFailedMsg); + } + else if (strStatus.CompareTo("201") == 0) + { + throw new Exception("登录过期!"); + } + else + { + XmlNode resultNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT); + if (resultNode == null) + { + throw new Exception(); + } + strResult = resultNode.InnerText; + return strResult; + } + } + + /// + /// 获取由PDMRecordReturnXMLStreamToString解析后的某个字段的值 + /// + /// 传入要获取的字段名 + /// 所要查找的所有字段类型 + /// 所要查找的所有字段名称 + /// 所要查找的所有字段值 + /// 返回查找字段的类型 + /// 返回查找字段的值 + /// + public static bool GetFieldValueByName(string strFieldName, string[] arrFieldTypeString, + string[] arrFieldNameString, string[] arrFieldValueString, + out string strFieldType, out string strFieldValue) + { + strFieldType = ""; + strFieldValue = ""; + if (string.IsNullOrEmpty(strFieldName)) + { + return false; + } + if ((arrFieldTypeString == null) || (arrFieldNameString == null) || (arrFieldValueString == null)) + { + return false; + } + if (arrFieldNameString.Length < 1) + { + return false; + } + if (arrFieldTypeString.Length != arrFieldNameString.Length) + { + return false; + } + if (arrFieldTypeString.Length != arrFieldValueString.Length) + { + return false; + } + + for (int i = 0; i < arrFieldNameString.Length; i++) + { + if (string.Compare(arrFieldNameString[i], strFieldName) == 0) + { + strFieldType = arrFieldTypeString[i]; + strFieldValue = arrFieldValueString[i]; + return true; + } + } + + return false; + } + + public static List PDMRecordReturnXMLStreamRowToList(string xmlStream) + { + // + // record + // 2014-11-25 17:19:16 + // 2014-11-25 17:19:16 + // 0 + // + // String + // filename <--字段名为FileName,其实传回的是文件的本地完整路径 + // + // D:\\ws\\SolidWorks\\测试博众-图档管理性能\\BZPART01.SLDPRT|D:\\ws\\SolidWorks\\测试博众-图档管理性能\\BZPART23.SLDPRT + // + // + // + XmlDocument doc = new XmlDocument(); + doc.LoadXml(xmlStream); + XmlNode pdmOut = doc.SelectSingleNode("pdmOut"); + if (pdmOut == null) + return null; + XmlNode rt = pdmOut.SelectSingleNode("result"); + if (rt == null) + return null; + XmlNode val = rt.SelectSingleNode("value"); + if (val == null) + return null; + XmlNode row = val.SelectSingleNode("row"); + if (row == null) + return null; + string[] strs = row.InnerText.Trim().Split('|'); + if (strs.Length > 0) + { + return new List(strs); + } + + return null; + } + + + public static void PDMRecordReturnXMLStreamToString(string xmlStream, + out string fieldTypeString, + out string fieldNameString, + out List fieldValueStringList) + + { + #region WebService XML流格式返回值格式 + // + // record + // 2009-07-08 10:40:00 + // 2009-07-08 10:40:02 + // 0/1 + // login sucessfully! + // + // + // string|string|string|boolean|byte|int|float|double|date|datetime + // guid|md$number|md$description|booleanValue|byteValue|intValue|floatValue|doubleValue|dateValue|datetimeValue + // + // doc$vf@8606abcd|doc-001|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:10:00 + // doc$vf@8606abce|doc-002|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:20:00 + // doc$vf@8606abd0|doc-003|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:30:00 + // doc$vf@8606abd1|doc-004|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:40:00 + // + // + // + #endregion + + fieldTypeString = ""; + fieldNameString = ""; + fieldValueStringList = new List(); + + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(xmlStream); + + XmlNode statusNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_STATUS); + if (statusNode == null) + { + throw new Exception(); + } + string strStatus = statusNode.InnerText; + if (strStatus.CompareTo("1") == 0) + { + // 失败 + XmlNode messageNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_MESSAGE); + if (messageNode == null) + { + throw new Exception(); + } + + string strFailedMsg = messageNode.InnerText; + throw new Exception(strFailedMsg); + } + else if (strStatus.CompareTo("201") == 0) + { + throw new Exception("登录过期!"); + } + else + { + XmlNode fieldTypeNode = null; + XmlNode fieldNameNode = null; + fieldTypeNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT_FIELDTYPE); + fieldNameNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT_FIELDNAME); + if (fieldTypeNode == null || fieldNameNode == null) + { + throw new Exception(); + } + fieldTypeString = fieldTypeNode.InnerText; + fieldNameString = fieldNameNode.InnerText; + XmlNodeList valueNodeList = xmlDoc.SelectNodes(XTN_PDMOUT_RESULT_VALUE_ROW); + if (valueNodeList != null) + { + foreach (XmlNode tmpNode in valueNodeList) + { + fieldValueStringList.Add(tmpNode.InnerText); + } + } + } + + } + + + /// + /// Record类型字符串转化成PDM XML流类型参数 + /// + /// 参数的类型组合字符串 + /// 参数名称组合字符串 + /// 参数值组合字符串列表 + /// XML流类型字符串 + public static string RecordParameterToXmlStream(string typeString, string fieldString, List valueStringList) + { + // + // + // record + // + // string|string|string|boolean|byte|int|float|double|date|datetime + // guid|md$number|md$description|booleanValue|byteValue|intValue|floatValue|doubleValue|dateValue|datetimeValue + // + // doc$vf@8606abcd|doc-001|11|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:10:00 + // doc$vf@8606abce|doc-002|22|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:20:00 + // doc$vf@8606abd0|doc-003|33|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:30:00 + // doc$vf@8606abd1|doc-004|44|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:40:00 + // + // + // + + XmlDocument xmlDoc = new XmlDocument(); + XmlElement rootElement = xmlDoc.CreateElement(XTN_PDMIN); + xmlDoc.AppendChild(rootElement); + + XmlElement serialElement = xmlDoc.CreateElement(XTN_PDM_IN_SERIAL); + serialElement.InnerText = "record"; + rootElement.AppendChild(serialElement); + + XmlElement paramElement = xmlDoc.CreateElement(XTN_PDM_IN_PARAM); + paramElement.SetAttribute(XAN_PDM_IN_PARAM_TYPE, "record"); + rootElement.AppendChild(paramElement); + + XmlElement typeElement = xmlDoc.CreateElement(XTN_PDM_IN_FIELD_TYPE); + typeElement.InnerText = typeString; + paramElement.AppendChild(typeElement); + + XmlElement fieldElement = xmlDoc.CreateElement(XTN_PDM_IN_FIELD_NAME); + fieldElement.InnerText = fieldString; + paramElement.AppendChild(fieldElement); + + XmlElement valueElement = xmlDoc.CreateElement(XTN_PDM_IN_FIELD_VALUE); + paramElement.AppendChild(valueElement); + + foreach (string tmpValueString in valueStringList) + { + XmlElement tmpRowElement = xmlDoc.CreateElement(XTN_PDM_IN_FIELD_VALUE_ROW); + tmpRowElement.InnerText = tmpValueString; + valueElement.AppendChild(tmpRowElement); + } + //LogFile.WriteMessageToLog($"RecordParameterToXmlStream->\r\n{xmlDoc.InnerXml}"); + return xmlDoc.InnerXml; + } + + /// + /// 从XML流中转换成对象 + /// + /// 要转换成的对象类型 + /// XML字符串 + /// 对象类型 + /// 转换后的对象 + public static List ConvertXMLToObjectList(string xml) + { + #region WebService XML流格式返回值格式 + // + // record + // 2009-07-08 10:40:00 + // 2009-07-08 10:40:02 + // 0/1 + // login sucessfully! + // + // + // string|string|string|boolean|byte|int|float|double|date|datetime + // guid|md$number|md$description|booleanValue|byteValue|intValue|floatValue|doubleValue|dateValue|datetimeValue + // + // doc$vf@8606abcd|doc-001|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:10:00 + // doc$vf@8606abce|doc-002|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:20:00 + // doc$vf@8606abd0|doc-003|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:30:00 + // doc$vf@8606abd1|doc-004|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:40:00 + // + // + // + #endregion + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(xml); + XmlNode statusNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_STATUS); + if (statusNode == null) + { + throw new Exception("XML流中未找到状态节点"); + } + + string strStatus = statusNode.InnerText; + if (strStatus.CompareTo("1") == 0) + { + // 失败 + XmlNode msgNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_MESSAGE); + if (msgNode == null) + { + throw new Exception("XML流中未找到消息节点"); + } + string strFailedMsg = msgNode.InnerText; + throw new Exception(strFailedMsg); + } + else if (strStatus.CompareTo("201") == 0) + { + throw new Exception("登录过期!"); + } + else + { + XmlNode resultNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT); + if (resultNode == null) + { + throw new Exception("XML流中未找到结果节点"); + } + + XmlNode fieldTypeNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT_FIELDTYPE); + XmlNode fieldNameNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT_FIELDNAME); + XmlNodeList valueNodeList = xmlDoc.SelectNodes(XTN_PDMOUT_RESULT_VALUE_ROW); + + if (fieldTypeNode == null || fieldNameNode == null || valueNodeList == null) + { + throw new Exception("XML流中数据格式不正确"); + } + + // 解析字段类型和字段名称 + string[] fieldTypes = fieldTypeNode.InnerText.Split('|'); + string[] fieldNames = fieldNameNode.InnerText.Split('|'); + + // 验证字段类型与字段名称数量是否匹配 + if (fieldTypes.Length != fieldNames.Length) + { + throw new Exception("字段类型和字段名称数量不匹配"); + } + + // 创建结果列表 + List resultList = new List(); + + // 处理每一行数据 + foreach (XmlNode rowNode in valueNodeList) + { + string[] values = rowNode.InnerText.Split('|'); + + // 验证值的数量是否匹配字段数量 + if (values.Length != fieldNames.Length) + { + throw new Exception($"字段值数量({values.Length})与字段名称数量({fieldNames.Length})不匹配"); + } + var clazz = typeof(T); + // 创建对象实例 + T obj = (T)Activator.CreateInstance(clazz); + + // 设置对象属性 + for (int i = 0; i < fieldNames.Length; i++) + { + try + { + // 获取属性信息 + var property = clazz.GetProperty(fieldNames[i], + System.Reflection.BindingFlags.Public | + System.Reflection.BindingFlags.Instance | + System.Reflection.BindingFlags.IgnoreCase); + + if (property != null && property.CanWrite) + { + // 根据字段类型转换值 + object convertedValue = ConvertValueByType(values[i], fieldTypes[i]); + property.SetValue(obj, convertedValue); + } + } + catch (Exception ex) + { + throw new Exception($"设置属性 {fieldNames[i]} 值失败: {ex.Message}"); + } + } + + resultList.Add(obj); + } + + // 如果只有一个结果,直接返回该对象 + return resultList; + } + } + + /// + /// 根据字段类型将字符串值转换为对应的类型 + /// + /// 字符串值 + /// 字段类型 + /// 转换后的对象 + private static object ConvertValueByType(string value, string type) + { + switch (type.ToLower()) + { + case "string": + return value; + case "boolean": + return Convert.ToBoolean(value); + case "byte": + return Convert.ToByte(value); + case "int": + return Convert.ToInt32(value); + case "float": + return Convert.ToSingle(value); + case "double": + return Convert.ToDouble(value); + case "date": + return DateTime.Parse(value).Date; + case "datetime": + return DateTime.Parse(value); + default: + return value; + } + } + + } +} diff --git a/Sinvo.EplanHpD.Plugin.DynaClient/app.config b/Sinvo.EplanHpD.Plugin.DynaClient/app.config index 65612fc..c896a56 100644 --- a/Sinvo.EplanHpD.Plugin.DynaClient/app.config +++ b/Sinvo.EplanHpD.Plugin.DynaClient/app.config @@ -1,24 +1,20 @@ - + - + - - + + - - + + - \ No newline at end of file + diff --git a/Sinvo.EplanHpD.Plugin.Service/Model/UserInfo.cs b/Sinvo.EplanHpD.Plugin.Service/Model/UserInfo.cs new file mode 100644 index 0000000..f1c20fe --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.Service/Model/UserInfo.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.Service.Model +{ + public class UserInfo + { + public string GUID { get; set; } + public string Name { get; set; } + public string ID { get; set; } + public string Role { get; set; } + public string Group { get; set; } + public string ServerUrl { get; set; } + } +} diff --git a/Sinvo.EplanHpD.Plugin.Service/PluginServices.cs b/Sinvo.EplanHpD.Plugin.Service/PluginServices.cs index 3d57250..ab2c1a5 100644 --- a/Sinvo.EplanHpD.Plugin.Service/PluginServices.cs +++ b/Sinvo.EplanHpD.Plugin.Service/PluginServices.cs @@ -1,4 +1,6 @@ -using System; +using Sinvo.EplanHpD.Plugin.DynaClient; +using Sinvo.EplanHpD.Plugin.Service.Model; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +10,8 @@ namespace Sinvo.EplanHpD.Plugin.Service { public class PluginServices { + public static UserInfo user; + + public static bool IsLogin => user != null && !string.IsNullOrEmpty(user.GUID) && DynaServerClient.GetClient().IsLoginExpired(); } } diff --git a/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj b/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj index 1c977ff..0b43136 100644 --- a/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj +++ b/Sinvo.EplanHpD.Plugin.Service/Sinvo.EplanHpD.Plugin.Service.csproj @@ -73,6 +73,7 @@ + @@ -81,5 +82,11 @@ 5.1.4.170 + + + {e87593a3-ca93-4563-aff6-b10413c18e64} + Sinvo.EplanHpD.Plugin.DynaClient + + \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/UserLoginModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/UserLoginModel.cs new file mode 100644 index 0000000..33594ee --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/UserLoginModel.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Models +{ + public class UserLoginModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private string _userName; + public string UserName + { + get => _userName; + set + { + _userName = value; + OnPropertyChanged(nameof(UserName)); + } + } + + private string _userPassword; + + public string UserPassword + { + get => _userPassword; + set + { + _userPassword = value; + OnPropertyChanged(nameof(UserPassword)); + } + } + + private string _userRole; + public string UserRole + { + get => _userRole; + set + { + _userRole = value; + OnPropertyChanged(nameof(UserRole)); + } + } + + private string _userGroup; + public string UserGroup + { + get => _userGroup; + set + { + _userGroup = value; + OnPropertyChanged(nameof(UserGroup)); + } + } + + + private string _userGUID; + public string UserGUID + { + get => _userGUID; + set + { + _userGUID = value; + OnPropertyChanged(nameof(UserGUID)); + } + } + private string _userNickName; + public string UserNickName + { + get => _userNickName; + set + { + _userNickName = value; + OnPropertyChanged(nameof(UserNickName)); + } + } + + + + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj index 2cc9f8a..4a3767d 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj @@ -268,6 +268,7 @@ + @@ -383,6 +384,10 @@ {60d3c75c-e71d-4116-bd7e-cac68c4dd96b} PdfiumViewer + + {e87593a3-ca93-4563-aff6-b10413c18e64} + Sinvo.EplanHpD.Plugin.DynaClient + {AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F} Sinvo.EplanHpD.Plugin.Service diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml new file mode 100644 index 0000000..f06b628 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml.cs new file mode 100644 index 0000000..4ba1d49 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LoginWindow.xaml.cs @@ -0,0 +1,239 @@ +using Sinvo.EplanHpD.Plugin.Service; +using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.View +{ + /// + /// LoginWindow.xaml 的交互逻辑 + /// + public partial class LoginWindow : Window + { + /// + /// 展开更多的时候,窗口的高度增加的固定值 + /// + private double expandFixedHeight = 100; + + private LoginViewModel viewModel; + + public LoginWindow() + { + InitializeComponent(); + this.DataContext = viewModel = new LoginViewModel(); + } + + /// + /// 强制显示为模态窗口 + /// + public new void Show() + { + this.ShowDialog(); + } + + #region 事件处理 + private void Expander_Expanded(object sender, RoutedEventArgs e) + { + if (sender is Expander expander) + { + this.Height += expandFixedHeight; + } + } + + private void Expander_Collapsed(object sender, RoutedEventArgs e) + { + if (sender is Expander expander) + { + this.Height -= expandFixedHeight; + + } + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + _ = LoadData(); + + } + + private async Task LoadData() + { + //if (viewModel.User != null) + //{ + // viewModel.GetGroup(); + //} + //if (viewModel.IsRemember) + //{ + // var groupIndex = viewModel.Groups.IndexOf(viewModel.Groups.FirstOrDefault(x => x.ID == viewModel.User.UserGroupId)); + // this.groupCbx.SelectedIndex = groupIndex; + // var roleIndex = viewModel.Roles.IndexOf(viewModel.Roles.FirstOrDefault(x => x.ID == viewModel.User.UserRoleId)); + // this.roleCbx.SelectedIndex = roleIndex; + //} + //if (EplSession.Current.Config != null) + //{ + // var serverIndex = viewModel.Servers.IndexOf(viewModel.Servers.FirstOrDefault(x => x.ServerUrl == EplSession.Current.Config.CurrentServer.ServerUrl)); + // this.serverCbx.SelectedIndex = serverIndex; + //} + } + + private void loginBtn_Click(object sender, RoutedEventArgs e) + { + this.viewModel.User.UserPassword = PasswordTxt.Password; + if (string.IsNullOrWhiteSpace(this.viewModel.User.UserName)) + { + this.msgTxt.Text = "请输入用户名!"; + this.msgTxt.Foreground = System.Windows.Media.Brushes.Red; + return; + } + if (string.IsNullOrWhiteSpace(this.viewModel.User.UserPassword)) + { + this.msgTxt.Text = "请输入密码!"; + this.msgTxt.Foreground = System.Windows.Media.Brushes.Red; + return; + } + if (string.IsNullOrWhiteSpace(this.groupCbx.SelectedValue as string)) + { + this.msgTxt.Text = "请选择部门!"; + this.msgTxt.Foreground = System.Windows.Media.Brushes.Red; + return; + } + if (string.IsNullOrWhiteSpace(this.roleCbx.SelectedValue as string)) + { + this.msgTxt.Text = "请选择角色!"; + this.msgTxt.Foreground = System.Windows.Media.Brushes.Red; + return; + } + viewModel.User.UserGroup = this.groupCbx.SelectedValue as string; + viewModel.User.UserRole = this.roleCbx.SelectedValue as string; + + //try + //{ + var result = viewModel.Login(); + if(result != null && !string.IsNullOrEmpty(result.GUID)) + { + PluginServices.user = new Service.Model.UserInfo + { + Group = viewModel.User.UserGroup, + Role = viewModel.User.UserRole, + //ServerUrl = viewModel.User.ServerUrl, + GUID = result.GUID, + ID = result.ID, + Name = result.Name + }; + this.DialogResult = true; + this.Close(); + } + else + { + MessageBox.Show("登录失败,请检查用户名和密码是否正确!"); + } + // if (result) + // { + // //MessageBox.Show("") + // var serverItem = this.serverCbx.SelectedItem as ServerItemModel; + // //new UserInfo().ShowInfo(viewModel.User.userNickName, serverItem); + // //EplSession.Current.CurServer = serverItem; + // EplSession.Current.SetUser(viewModel.User); + // EplSession.Current.Config.CurrentServer = serverItem; + // EplSession.Current.Config.RememberAccount = this.rememberChk.IsChecked ?? false; + + // if (this.rememberChk.IsChecked ?? false) + // { + // viewModel.RememberUser(); + // } + // else + // { + // viewModel.ForgetUser(); + // } + // // 登录成功,弹出用户信息小窗口 + // WindowRouter.ShowWindow("UserInfo", keepAlive: true); + // this.DialogResult = true; + // this.Close(); + // } + //} + //catch (System.Exception ex) + //{ + // // ERROR 是扩展方法,用于输出错误信息 + // ex.ToString().Error(); + // //MessageBox.Show(ex.Message); + // msgTxt.Text = ex.Message; + //} + } + + private void UsernameTxt_LostFocus(object sender, RoutedEventArgs e) + { + if (string.IsNullOrWhiteSpace(UsernameTxt.Text)) + { + return; + } + viewModel.User.UserName = UsernameTxt.Text; + LoadGroupAndRole(); + } + + private void cancelBtn_Click(object sender, RoutedEventArgs e) + { + this.Close(); + } + + private async void groupCbx_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + try + { + viewModel.User.UserGroup = this.groupCbx.SelectedValue as string; + await viewModel.GetRolesByCurrentSelect(); + if (viewModel.Roles?.Count > 0) + { + await this.Dispatcher.BeginInvoke(() => + { + this.roleCbx.SelectedIndex = 0; + }); + } + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message); + } + + } + #endregion + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + + } + + private void serverCbx_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + //var serverItem = this.serverCbx.SelectedItem as ServerItemModel; + //if (serverItem != null) + //{ + // viewModel.ChangeService(serverItem); + // LoadGroupAndRole(); + //} + } + + private void LoadGroupAndRole() + { + var task = viewModel.GetUserGroup(); + task.ContinueWith(x => + { + this.Dispatcher.InvokeAsync(() => + { + this.groupCbx.SelectedIndex = 0; + }); + + }); + + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotype/LectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotype/LectotypeViewModel.cs index 42c4c89..f1fd521 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotype/LectotypeViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotype/LectotypeViewModel.cs @@ -7,6 +7,7 @@ using EPLAN.Harness.ProjectCore.Occurrences; using EPLAN.Harness.ProjectCore.Occurrences.Designer; using HandyControl.Controls; using HandyControl.Tools.Extension; +using Sinvo.EplanHpD.Plugin.DynaClient.Model; using Sinvo.EplanHpD.Plugin.Service; using Sinvo.EplanHpD.Plugin.Service.Model; using Sinvo.EplanHpD.Plugin.WPFUI.Datas; @@ -42,7 +43,7 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged OnPropertyChanged(); } } - + private List _oriWires = []; public List OriWires { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LoginViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LoginViewModel.cs index d4d457e..5d74598 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LoginViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LoginViewModel.cs @@ -1,12 +1,116 @@ -using System; +using Sinvo.EplanHpD.Plugin.DynaClient; +using Sinvo.EplanHpD.Plugin.DynaClient.Model; +using Sinvo.EplanHpD.Plugin.Service; +using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using System; using System.Collections.Generic; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { - internal class LoginViewModel + public class LoginViewModel: INotifyPropertyChanged { + private readonly DynaServerClient client = DynaServerClient.GetClient(); + public event PropertyChangedEventHandler PropertyChanged; + public void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public LoginViewModel() + { + User = new UserLoginModel(); + } + + private UserLoginModel _user; + + public UserLoginModel User + { + get { return _user; } + set + { + _user = value; + OnPropertyChanged(nameof(User)); + } + } + + + private List _groups; + public List Groups + { + get { return _groups; } + set + { + _groups = value; + OnPropertyChanged(nameof(Groups)); + } + } + + private List _roles; + public List Roles + { + get { return _roles; } + set + { + _roles = value; + OnPropertyChanged(nameof(Roles)); + } + } + + private List _servers; + + public List Servers + { + get { return _servers; } + set + { + _servers = value; + OnPropertyChanged(nameof(Servers)); + } + } + + public async Task> GetUserGroup() + { + return await Task.Run(() => + { + var userGroup = client.GetUserGroup(User.UserName); + Groups = userGroup; + return userGroup; + }); + } + + internal Task GetRolesByCurrentSelect() + { + //var client = new DynaServerClient(); + var userRoles = client.GetUserRole(User.UserName,User.UserGroup); + Roles = userRoles; + return Task.CompletedTask; + } + + internal User Login() + { + try + { + + //var client = new DynaServerClient(); + // PLM 没有EPLAN的许可,所以只能使用SOLW的类型登录 + var user = client.Login(User.UserName, User.UserPassword, User.UserRole, User.UserGroup, "SOLW"); +#if DEBUG + //client.LoginOut(); +#endif + return user; + } + catch (Exception ex) + { + Debug.WriteLine(ex.ToString()); + return null; + } + } } } diff --git a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs index e21223e..a723d06 100644 --- a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs @@ -6,6 +6,7 @@ using Sinvo.EplanHpD.Plugin.Service; using Sinvo.EplanHpD.Plugin.WPFUI; using Sinvo.EplanHpD.Plugin.WPFUI.Extension; using Sinvo.EplanHpD.Plugin.WPFUI.Utils; +using Sinvo.EplanHpD.Plugin.WPFUI.View; using System; using System.Drawing; using System.IO; @@ -58,28 +59,42 @@ namespace Sinvo.EplanHpD.Plugin public void Execute(HpdApi api) { + + bool isLogin = false; + if (!PluginServices.IsLogin) + { + var LoginWindow = new LoginWindow(); + if(LoginWindow.ShowDialog() == true) + { + isLogin = PluginServices.IsLogin; + } + } + new DBHelper().CodeFirst(); - var doc = api.CurrentProject.GetActiveDocument(); - if(window == null) - { - window = new LectotypeWindow(doc.ID); - // 获取版本号并显示到窗口标题 - window.Title += $" V{Version} - {doc.Name}"; - ElementHost.EnableModelessKeyboardInterop(window); - var mainApp = BaseApp.ActiveApplication; - var helper = new System.Windows.Interop.WindowInteropHelper(window); - helper.Owner = mainApp.Handle; - window.Closed += delegate - { - window = null; - }; - window.Show(); - } - else + if (isLogin) { - window.WindowState = System.Windows.WindowState.Normal; - window.Activate(); + var doc = api.CurrentProject.GetActiveDocument(); + if (window == null) + { + window = new LectotypeWindow(doc.ID); + // 获取版本号并显示到窗口标题 + window.Title += $" V{Version} - {doc.Name}"; + ElementHost.EnableModelessKeyboardInterop(window); + var mainApp = BaseApp.ActiveApplication; + var helper = new System.Windows.Interop.WindowInteropHelper(window); + helper.Owner = mainApp.Handle; + window.Closed += delegate + { + window = null; + }; + window.Show(); + } + else + { + window.WindowState = System.Windows.WindowState.Normal; + window.Activate(); + } } } @@ -91,11 +106,7 @@ namespace Sinvo.EplanHpD.Plugin AppDomainDllLoader.SetLaoder(); ApplicationExt.InitApplication(); Consts.InitConfigs(); -#if DEBUG - var client = new DynaServerClient(); - // PLM 没有EPLAN的许可,所以只能使用SOLW的类型登录 - client.Login("105040", "blank", "ADMINISTRATOR", "ADMINISTRATOR", "SOLW"); -#endif + } }