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 // ReSharper disable StringLiteralTypo 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; private readonly string _cCardNum; public BEHelper(dynamic be, string cCardNum="") { _be = be; var tp = be.GetType(); _props = tp.GetProperties(); _cCardNum = cCardNum; } public void SetValue(Dictionary dictionary) { foreach (var key in dictionary.Keys) { 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}")) { _be.UserDefinedItem[defineCode] = dictionary[key]; } } else if (key.Contains("chdefine")) { var defineCode = int.Parse(key.Replace("chdefine", "")); if (dictionary.TryGetValue(key, out var bValue) && !string.IsNullOrWhiteSpace($"{bValue}")) { _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.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)); 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); } public void SetMoAllocateId() { if (_cCardNum == "MO39") { _be.SetMoAllocateId(_be.PartId); } } } }