| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- using Core.Mes.Client.Comm.Tool;
- using CoreFS.CA06;
- using CoreFS.SA06;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- using System.Reflection;
- namespace Core.StlMes.Client.Judge.Commons
- {
- public class Dal
- {
- private OpeBase _ob = null;
- public OpeBase Ob
- {
- get { return _ob; }
- set { _ob = value; }
- }
- public Dal(OpeBase ob)
- {
- _ob = ob;
- }
- public DataTable GetTable(string remoteStr, params object[] param)
- {
- CoreClientParam ccp = new CoreClientParam
- {
- ServerName = remoteStr.Substring(0, remoteStr.LastIndexOf(".")),
- MethodName = remoteStr.Substring(remoteStr.LastIndexOf(".") + 1),
- ServerParams = param
- };
- ccp = _ob.ExecuteSortResultByQueryToDataTable(ccp, CoreInvokeType.Internal);
- DataTable src = ccp.SourceDataTable;
- foreach (DataColumn col in src.Columns)
- {
- col.ColumnName = GetLanguageFormat(col.ColumnName, true);
- }
- return src;
- }
- /// <summary>
- /// 直接通过服务端xmlId获取数据
- /// </summary>
- /// <param name="xmlId"></param>
- /// <param name="parms"></param>
- /// <returns></returns>
- public DataTable GetTableByXmlId(string xmlId, params object[] parms)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.pss.judge.comm.ClientQueryHelper";
- ccp.MethodName = "query";
- ccp.ServerParams = new object[] { xmlId, parms };
- ccp = _ob.ExecuteSortResultByQueryToDataTable(ccp, CoreInvokeType.Internal);
- DataTable src = ccp.SourceDataTable;
- if (src != null)
- {
- foreach (DataColumn col in src.Columns)
- {
- col.ColumnName = GetLanguageFormat(col.ColumnName, true);
- }
- }
- return src;
- }
- public CoreClientParam Set(string remoteStr, params object[] param)
- {
- CoreClientParam ccp = new CoreClientParam
- {
- IfShowErrMsg = false,
- ServerName = remoteStr.Substring(0, remoteStr.LastIndexOf(".")),
- MethodName = remoteStr.Substring(remoteStr.LastIndexOf(".") + 1),
- ServerParams = param
- };
- ccp = _ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- return ccp;
- }
- /// <summary>
- /// 直接通过服务端xmlId获取数据
- /// </summary>
- /// <param name="methodName"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- public DataRow GetRow(string remoteStr, params object[] param)
- {
- DataTable dt = GetTable(remoteStr, param);
- if (dt.Rows.Count == 0)
- {
- return null;
- }
- else
- {
- return dt.Rows[0];
- }
- }
- public DataRow GetRowByXmlId(string xmlId, params object[] parms)
- {
- DataTable dt = GetTableByXmlId(xmlId, parms);
- if (dt.Rows.Count == 0)
- {
- return null;
- }
- else
- {
- return dt.Rows[0];
- }
- }
- private string GetLanguageFormat(string strName, bool isLowerBegin)
- {
- string[] strs = strName.Split('_');
- strName = "";
- for (int i = 0; i < strs.Length; i++)
- {
- if (i == 0 && isLowerBegin)
- {
- strName += strs[i].ToLower();
- }
- else
- {
- strName += strs[i].Substring(0, 1).ToUpper() + strs[i].Substring(1).ToLower();
- }
- }
- return strName;
- }
- public DataSourceList<T> GetEntitysByXmlId<T>(string xmlId, params object[] parms)
- {
- return GetEntitys<T>("com.steering.pss.judge.comm.ClientQueryHelper.query", new object[] { xmlId, parms });
- }
- public DataSourceList<T> GetEntitys<T>(string remoteStr, params object[] parms)
- {
- string key;
- try
- {
- DataSourceList<T> listResult = new DataSourceList<T>();
- CoreClientParam ccp = new CoreClientParam
- {
- ServerName = remoteStr.Substring(0, remoteStr.LastIndexOf(".")),
- MethodName = remoteStr.Substring(remoteStr.LastIndexOf(".") + 1),
- ServerParams = parms
- };
- ccp = _ob.ExecuteQuery(ccp, CoreInvokeType.Internal);
- string[] strColumns = (ccp.ReturnObject as CoreReturnSortObject).getColIdx();
- string[] strColumnsEntity = ConvertColumnName(strColumns);
- ArrayList list = (ccp.ReturnObject as CoreReturnSortObject).getResult();
- Type type = typeof(T);
- Dictionary<string, PropertyInfo> propertyInfoDic = new Dictionary<string, PropertyInfo>();
- for (int j = 0; j < strColumns.Length; j++)
- {
- string column = strColumns[j];
- string columnEntity = strColumnsEntity[j];
- PropertyInfo propertyInfo = type.GetProperty(columnEntity);
- if (propertyInfo == null) continue;
- if (propertyInfoDic.ContainsKey(column))
- {
- propertyInfoDic[column] = propertyInfo;
- }
- else
- {
- propertyInfoDic.Add(column, propertyInfo);
- }
- }
- for (int i = 0; i < list.Count; i++)
- {
- Hashtable hashtable = (Hashtable)list[i];
- ArrayList list2 = new ArrayList();
- T obj = (T)type.Assembly.CreateInstance(type.FullName);
- foreach (KeyValuePair<string, PropertyInfo> propertyInfoKV in propertyInfoDic)
- {
- key = propertyInfoKV.Key;
- object obj2 = hashtable[propertyInfoKV.Key];
- PropertyInfo propertyInfo = propertyInfoKV.Value;
- if ((obj2 != null) && typeof(Hashtable).Equals(obj2.GetType()))
- {
- Hashtable hashtable2 = (Hashtable)obj2;
- propertyInfo.SetValue(obj, ConvertDataType(propertyInfo.PropertyType, hashtable2["value"]), null);
- }
- else
- {
- propertyInfo.SetValue(obj, ConvertDataType(propertyInfo.PropertyType, obj2), null);
- }
- }
- listResult.Add(obj);
- }
- return listResult;
- }
- catch (Exception ex)
- {
- Debug.WriteLine(ex.Message);
- throw;
- }
- finally
- {
- }
- }
- private static object ConvertDataType(Type type, object objValue)
- {
- if (type == typeof(bool))
- {
- bool result;
- if (bool.TryParse(objValue.ToString(), out result))
- {
- return result;
- }
- else
- {
- return false;
- }
- }
- else if (type == typeof(bool?))
- {
- bool result;
- if (bool.TryParse(objValue.ToString(), out result))
- {
- return result;
- }
- else
- {
- return null;
- }
- }
- else if (type == typeof(int?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return int.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(long?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return long.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(short?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return short.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(float?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return float.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(double?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return double.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(decimal?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return decimal.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(DateTime?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return DateTime.Parse(objValue.ToString());
- }
- }
- else
- {
- return objValue == null ? "" : objValue.ToString();
- }
- }
- private string[] ConvertColumnName(string[] strColumns)
- {
- string[] strs = new string[strColumns.Length];
- for (int i = 0; i < strColumns.Length; i++)
- {
- strs[i] = GetLanguageFormat(strColumns[i], false);
- }
- return strs;
- }
- public string GetJsonData(string remoteStr, params object[] param)
- {
- CoreClientParam ccp = new CoreClientParam
- {
- ServerName = remoteStr.Substring(0, remoteStr.LastIndexOf(".")),
- MethodName = remoteStr.Substring(remoteStr.LastIndexOf(".") + 1),
- ServerParams = param
- };
- ccp = _ob.ExecuteQuery(ccp, CoreInvokeType.Internal);
- return ccp.ReturnObject.ToString2();
- }
- }
- }
|