测试线程静态前提交

This commit is contained in:
minjQiu
2024-08-07 18:44:46 +08:00
parent b13ae6ec88
commit 4e4316c6dc
33 changed files with 1596 additions and 380 deletions
@@ -1,7 +1,9 @@
using System;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.UI.WebControls;
// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo
@@ -11,8 +13,22 @@ namespace UFIDA.U8.Framework.Api.ControlObject.Common
{
public class BEHelper
{
protected readonly ILog logInfo = LogManager.GetLogger("logInfo");
private readonly dynamic _be;
private readonly PropertyInfo[] _props;
private string _invCode;
private string _free1;
private string _free2;
private string _free3;
private string _free4;
private string _free5;
private string _free6;
private string _free7;
private string _free8;
private string _free9;
private string _free10;
private int _bomVersion;
public BEHelper(dynamic be)
{
@@ -25,7 +41,10 @@ namespace UFIDA.U8.Framework.Api.ControlObject.Common
{
foreach (var key in dictionary.Keys)
{
if (key.Contains("define") && !key.Contains("chdefine"))
if(key != "body")
logInfo.Debug($"正在设置字段:{key}--{dictionary[key]}");
if (key.Contains("define") && !key.Contains("chdefine") && !key.Contains("cbdefine"))
{
var defineCode = int.Parse(key.Replace("define", ""));
if (dictionary.TryGetValue(key, out var bValue) && !string.IsNullOrWhiteSpace($"{bValue}"))
@@ -41,46 +60,86 @@ namespace UFIDA.U8.Framework.Api.ControlObject.Common
{
_be.ExtendUserDefineItem[defineCode] = dictionary[key];
}
} else if (key.Contains("cbdefine"))
{
var defineCode = int.Parse(key.Replace("cbdefine", ""));
if (dictionary.TryGetValue(key, out var bValue) && !string.IsNullOrWhiteSpace($"{bValue}"))
{
_be.ExtendUserDefineItem[defineCode] = dictionary[key];
}
}else if (key.Contains("free"))
{
var freeCode = int.Parse(key.Replace("free", ""));
SetFreeItem(freeCode, dictionary[key]);
}
else if (key != "body")
{
if (!string.IsNullOrWhiteSpace($"{dictionary[key]}") && _props.Any(a => string.Equals(a.Name, key, StringComparison.OrdinalIgnoreCase)))
if (string.Equals(key, "invCode", StringComparison.OrdinalIgnoreCase))
{
_invCode = $"{dictionary[key]}";
}else if (string.Equals(key, "bomversion", StringComparison.OrdinalIgnoreCase))
{
_bomVersion = int.Parse($"{dictionary[key]}");
}
else if(!string.IsNullOrWhiteSpace($"{dictionary[key]}") && _props.Any(a => string.Equals(a.Name, key, StringComparison.OrdinalIgnoreCase)))
{
var prop = _props.First(a => string.Equals(a.Name, key, StringComparison.OrdinalIgnoreCase));
if (prop.PropertyType == typeof(string))
{
prop.SetValue(_be, dictionary[key]);
}
if (prop.PropertyType == typeof(DateTime))
{
prop.SetValue(_be, DateTime.Parse($"{dictionary[key]}"));
}
if (prop.PropertyType == typeof(byte))
{
prop.SetValue(_be, byte.Parse($"{dictionary[key]}"));
}
if (prop.PropertyType == typeof(int))
{
prop.SetValue(_be, int.Parse($"{dictionary[key]}"));
}
if (prop.PropertyType == typeof(long))
{
prop.SetValue(_be, long.Parse($"{dictionary[key]}"));
}
if (prop.PropertyType == typeof(decimal))
{
prop.SetValue(_be, decimal.Parse($"{dictionary[key]}"));
}
CommonHelper.SetPropValue(prop, _be, dictionary[key]);
}
}
}
}
public void SetFreeItem(int i, object value)
{
switch (i)
{
case 1:
_free1 = $"{value}";
break;
case 2:
_free2 = $"{value}";
break;
case 3:
_free3 = $"{value}";
break;
case 4:
_free4 = $"{value}";
break;
case 5:
_free5 = $"{value}";
break;
case 6:
_free6 = $"{value}";
break;
case 7:
_free7 = $"{value}";
break;
case 8:
_free8 = $"{value}";
break;
case 9:
_free9 = $"{value}";
break;
case 10:
_free10 = $"{value}";
break;
}
}
public void SetPartId()
{
_be.SetPartId(_invCode, new[] { _free1, _free2, _free3, _free4, _free5, _free6, _free7, _free8, _free9, _free10 });
}
public void SetBomId()
{
_be.SetBomId(_be.PartId, _bomVersion);
}
}
}
@@ -0,0 +1,154 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using GetComObj;
using MSXML2;
using UFIDA.U8.Framework.Api.ControlObject.Json;
namespace UFIDA.U8.Framework.Api.ControlObject.Common
{
public static class CommonHelper
{
public static void SetPropValue(this PropertyInfo prop, object obj, object value)
{
if (prop.PropertyType == typeof(string))
{
prop.SetValue(obj, value);
}
if (prop.PropertyType == typeof(DateTime))
{
prop.SetValue(obj, DateTime.Parse($"{value}"));
}
if (prop.PropertyType == typeof(byte))
{
prop.SetValue(obj, byte.Parse($"{value}"));
}
if (prop.PropertyType == typeof(int))
{
prop.SetValue(obj, int.Parse($"{value}"));
}
if (prop.PropertyType == typeof(long))
{
prop.SetValue(obj, long.Parse($"{value}"));
}
if (prop.PropertyType == typeof(decimal))
{
prop.SetValue(obj, decimal.Parse($"{value}"));
}
}
public static IXMLDOMDocument2 ToDocument2(this Dictionary<string,object> dictionary,IXMLDOMDocument2 domDocument2=null)
{
if (domDocument2 == null)
{
domDocument2 = new DOMDocument();
}
var root = domDocument2.ClearDocument();
var newRow = SetRowData(dictionary, domDocument2);
root.appendChild(newRow);
return domDocument2;
}
public static IXMLDOMNode SetRowData(this Dictionary<string, object> dictionary, IXMLDOMDocument2 domDocument2 = null,string bodyKey="body")
{
if (domDocument2 == null)
{
domDocument2 = new DOMDocument();
}
var newRow = domDocument2.createElement("z:row");
foreach (var key in dictionary.Keys)
{
if(key==bodyKey)
continue;
var attr = domDocument2.createAttribute(key);
attr.value = dictionary[key];
newRow.attributes.setNamedItem(attr);
}
return newRow;
}
public static IXMLDOMDocument2 ToDocument2(this List<Dictionary<string, object>> dictionaryList, IXMLDOMDocument2 domDocument2 = null)
{
if (domDocument2 == null)
{
domDocument2 = new DOMDocument();
}
var root = domDocument2.ClearDocument();
foreach (var dictionary in dictionaryList)
{
var newRow = SetRowData(dictionary, domDocument2);
root.appendChild(newRow);
}
return domDocument2;
}
public static IXMLDOMNode ClearDocument(this IXMLDOMDocument2 domDocument2)
{
var root = domDocument2.selectSingleNode("//rs:data");
if (root == null)
{
root = domDocument2.createElement("rs:data");
domDocument2.appendChild(root);
}
var rows = domDocument2.selectNodes("//z:row");
if (rows != null && rows.length > 0)
{
for (var i = 0; i < rows.length; i++)
{
var row = rows[i];
root.removeChild(row);
}
}
return root;
}
public static void ResetDictionary(this Dictionary<string, object> dictionary, string bodyKey = "body")
{
if (dictionary.ContainsKey(bodyKey))
{
var body= dictionary[bodyKey].ToJson().ToList<Dictionary<string,object>>();
dictionary[bodyKey] = body;
}
}
public static dynamic GetComObject(this string comName)
{
var comInstance = new GetComInstance();
var obj = comInstance.GetComObject(ref comName);
return obj;
}
}
}