|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- using CnasSynchrousModel;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Text;
-
- namespace CnasSynchronusClient
- {
- /// <summary>
- /// 全局通用方法类
- /// </summary>
- public class GlobalCommonOperation
- {
- public static string strUserName = "";
- public static string strLoginName = "";
- public static string strStartWebApi = "";
- public static string strStartGeneralVersion = "";
- public static string strWebApiUrl = "";
- public static string strTargetDbType = "MYSQL";
- /// <summary>
- /// 定义的一些静态全局参数,后面将改成配置参数存储
- /// </summary>
-
- #region 写死的关键字段,已放弃
- public static Dictionary<string, List<string>> dictPrimaryKey = new Dictionary<string, List<string>>()
- {
- { "水分仪" ,new List<string>(){ "SerialNumber" } },
- { "测硫仪" ,new List<string>(){"id" } },
- { "工业分析仪" ,new List<string>(){ "SerialNumber" } },
- { "灰熔点" ,new List<string>(){ "SampleNo" } },
- { "红外测硫仪" ,new List<string>(){ "Number" } }
- };
-
- public static InstrumentType GetInstruTypeBySelectedItem(string strTitle)
- {
- InstrumentType type = InstrumentType.None;
- switch (strTitle)
- {
- case "水分仪":
- type = InstrumentType.MoistureMeter;
- break;
- case "测硫仪":
- type = InstrumentType.SulphurMeter;
- break;
- case "灰熔点":
- type = InstrumentType.AshMeltingPoint;
- break;
- case "红外测硫仪":
- type = InstrumentType.InfraredSulfurMeter;
- break;
- case "工业分析仪":
- type = InstrumentType.IndustrialAnalyzer;
- break;
- case "元素分析仪":
- type = InstrumentType.ElementalAnalyzer;
- break;
- case "量热仪":
- type = InstrumentType.CalorimetricApparatus;
- break;
- default:
- type = InstrumentType.None;
- break;
- }
-
- return type;
- }
-
- public static string GetTitleByInstruType(InstrumentType type)
- {
- string strReturn = "";
- switch (type)
- {
- case InstrumentType.SulphurMeter:
- strReturn = "测硫仪";
- break;
- case InstrumentType.IndustrialAnalyzer:
- strReturn = "工业分析仪";
- break;
- case InstrumentType.AshMeltingPoint:
- strReturn = "灰熔点";
- break;
- case InstrumentType.MoistureMeter:
- strReturn = "水分仪";
- break;
- case InstrumentType.InfraredSulfurMeter:
- strReturn = "红外测硫仪";
- break;
- case InstrumentType.CalorimetricApparatus:
- strReturn = "量热仪";
- break;
- case InstrumentType.None:
- default:
- strReturn = "";
- break;
- }
- return strReturn;
- }
-
- /// <summary>
- /// 检查存储映射数据是否存在主键值
- /// </summary>
- /// <returns></returns>
- public static string CheckInstuDataHaveKey(List<SyncInstrumentItemInfo> itemInfos)
- {
- string strErrorMsg = "";
- foreach (var item in itemInfos)
- {
- switch (item.InstruType)
- {
- case InstrumentType.SulphurMeter:
- if(!CheckContainPrimaryKey(item.LstSyncPramas, dictPrimaryKey["测硫仪"]))
- strErrorMsg = $"仪器{item.Code}映射列必须包含唯一标识列{ListRowToColumn(dictPrimaryKey["测硫仪"])},无法保存!";
- break;
- case InstrumentType.IndustrialAnalyzer:
- if (!CheckContainPrimaryKey(item.LstSyncPramas, dictPrimaryKey["工业分析仪"]))
- strErrorMsg = $"仪器{item.Code}映射列必须包含唯一标识列{ListRowToColumn(dictPrimaryKey["工业分析仪"])},无法保存!";
- break;
- case InstrumentType.AshMeltingPoint:
- if (!CheckContainPrimaryKey(item.LstSyncPramas, dictPrimaryKey["灰熔点"]))
- strErrorMsg = $"仪器{item.Code}映射列必须包含唯一标识列{ListRowToColumn(dictPrimaryKey["灰熔点"])},无法保存!";
- break;
- case InstrumentType.MoistureMeter:
- if (!CheckContainPrimaryKey(item.LstSyncPramas, dictPrimaryKey["水分仪"]))
- strErrorMsg = $"仪器{item.Code}映射列必须包含唯一标识列{ListRowToColumn(dictPrimaryKey["水分仪"])},无法保存!";
- break;
- case InstrumentType.InfraredSulfurMeter:
- if (!CheckContainPrimaryKey(item.LstSyncPramas, dictPrimaryKey["红外测硫仪"]))
- strErrorMsg = $"仪器{item.Code}映射列必须包含唯一标识列{ListRowToColumn(dictPrimaryKey["红外测硫仪"])},无法保存!";
- break;
- case InstrumentType.CalorimetricApparatus:
- if (!CheckContainPrimaryKey(item.LstSyncPramas, dictPrimaryKey["量热仪"]))
- strErrorMsg = $"仪器{item.Code}映射列必须包含唯一标识列{ListRowToColumn(dictPrimaryKey["红外测硫仪"])},无法保存!";
- break;
- case InstrumentType.None:
- default:
- strErrorMsg = $"仪器{item.Code}未指定仪器类型,无法保存,请先制定仪器类型!";
- break;
- }
- }
- return strErrorMsg;
- }
-
- private static bool CheckContainPrimaryKey(List<SyncParamasInfo> syncParamasInfos, List<string> primaryKeys)
- {
- bool bContains = true;
- foreach (var key in primaryKeys)
- {
- if (syncParamasInfos.Where(s => s.SourceField == key).Count() <= 0)
- {
- bContains = false;
- break;
- }
- }
- return bContains;
- }
-
- private static string ListRowToColumn(List<string> lst)
- {
- string strReturnString = "";
- foreach (var item in lst)
- {
- strReturnString += item + ",";
- }
- if (strReturnString != "")
- strReturnString= strReturnString.Substring(0, strReturnString.Length - 1);
- return strReturnString;
- }
- #endregion
-
- /// <summary>
- /// 解析IFThen类型字符串
- /// </summary>
- public static List<IFThenConditionParams> AnanlysisIFThenString(string strString)
- {
- List<IFThenConditionParams> lstparams = new List<IFThenConditionParams>();
-
- string[] strStringConditions = strString.Split(new string[] {";" }, StringSplitOptions.RemoveEmptyEntries);
- if (strStringConditions.Length > 0)
- {
- foreach (string strConditionString in strStringConditions)
- {
- string[] strStrings = strConditionString.Split(new string[] { "IF", "THEN", "{", "}"}, StringSplitOptions.RemoveEmptyEntries);
- if (strStrings.Length == 4)
- {
- IFThenConditionParams conditionParam = new IFThenConditionParams
- {
- ConditionColumnName = strStrings[0],
- ConditionAlgorithm=strStrings[1],
- ConditionColumnValue=strStrings[2],
- ColumnValue=strStrings[3]
- };
- lstparams.Add(conditionParam);
- }
- }
- }
- return lstparams;
- }
-
- /// <summary>
- /// datarow转换成datatable
- /// </summary>
- /// <param name="dr"></param>
- /// <returns></returns>
- public static DataTable ConvertDataRowToTable(DataRow dr)
- {
- DataTable dt = dr.Table.Clone();
- DataRow drNew = dt.NewRow();
- drNew.ItemArray = dr.ItemArray;
- dt.Rows.Add(drNew);
- return dt;
- }
-
-
- /// <summary>
- /// 对象的复制方法
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="RealObject"></param>
- /// <returns></returns>
- public static T Clone<T>(T RealObject)
- {
- using (Stream objectStream = new MemoryStream())
- {
- //利用 System.Runtime.Serialization序列化与反序列化完成引用对象的复制
- IFormatter formatter = new BinaryFormatter();
- formatter.Serialize(objectStream, RealObject);
- objectStream.Seek(0, SeekOrigin.Begin);
- return (T)formatter.Deserialize(objectStream);
- }
- }
- }
- }
|