PublicServer.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using CoreFS.CA06;
  6. using System.Data;
  7. using Infragistics.Win.UltraWinGrid;
  8. using System.Windows.Forms;
  9. using Infragistics.Win.UltraWinEditors;
  10. using Core.Mes.Client.Comm;
  11. namespace Pur.PublicTools
  12. {
  13. /// <summary>
  14. /// 自定义公共方法客户端服务端类
  15. /// </summary>
  16. class PublicServer
  17. {
  18. /// <summary>
  19. /// 从服务端查询数据(query)
  20. /// </summary>
  21. /// <param name="methodId">服务端MethodId</param>
  22. /// <param name="param">参数数组,需与服务端方法参数一致</param>
  23. /// <param name="ob">界面OB对象</param>
  24. /// <exception cref="MESException">自定义异常</exception>
  25. /// <returns>查询数据集</returns>
  26. public static DataTable GetData(string methodId, object[] param, OpeBase ob)
  27. {
  28. CoreClientParam ccp = new CoreClientParam();
  29. ccp.IfShowErrMsg = false;
  30. ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
  31. ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
  32. ccp.ServerParams = param;
  33. ccp = ob.ExecuteSortResultByQueryToDataTable(ccp, CoreInvokeType.Internal);
  34. if (ccp == null)
  35. {
  36. throw new MESException("服务端处理失败!");
  37. }
  38. if (ccp.ReturnCode < 0)
  39. {
  40. throw new MESException(ReturnInfo(ccp.ReturnInfo));
  41. }
  42. return ccp.SourceDataTable;
  43. }
  44. /// <summary>
  45. /// 从服务端查询数据(query)
  46. /// </summary>
  47. /// <param name="methodId">服务端MethodId</param>
  48. /// <param name="param">参数数组,需与服务端方法参数一致</param>
  49. /// <param name="ob">界面OB对象</param>
  50. /// <exception cref="MESException">自定义异常</exception>
  51. /// <returns>查询数据集</returns>
  52. public static string GetDataTips(string methodId, object[] param, OpeBase ob)
  53. {
  54. CoreClientParam ccp = new CoreClientParam();
  55. ccp.IfShowErrMsg = false;
  56. ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
  57. ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
  58. ccp.ServerParams = param;
  59. ccp = ob.ExecuteQuery(ccp, CoreInvokeType.Internal);
  60. if (ccp == null)
  61. {
  62. throw new MESException("服务端处理失败!");
  63. }
  64. if (ccp.ReturnCode < 0 && ccp.ReturnInfo != "YES")
  65. {
  66. throw new MESException(ReturnInfo(ccp.ReturnInfo));
  67. }
  68. return ccp.ReturnInfo;
  69. }
  70. /// <summary>
  71. /// 向服务端设置数据(insert、update、delete、procedure)
  72. /// </summary>
  73. /// <param name="methodId">服务端MethodId</param>
  74. /// <param name="param">参数数组,需与服务端方法参数一致</param>
  75. /// <param name="ob">界面OB对象</param>
  76. /// <exception cref="MESException">自定义异常</exception>
  77. /// <returns>count处理数据行数,0 or -num表示失败</returns>
  78. public static int SetData(string methodId, object[] param, OpeBase ob)
  79. {
  80. CoreClientParam ccp = new CoreClientParam();
  81. ccp.IfShowErrMsg = false;
  82. ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
  83. ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
  84. ccp.ServerParams = param;
  85. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  86. if (ccp == null)
  87. {
  88. throw new MESException("服务端处理失败!");
  89. }
  90. if (ccp.ReturnCode < 0)
  91. {
  92. throw new MESException(ReturnInfo(ccp.ReturnInfo));
  93. }
  94. int count = 0;
  95. if (!int.TryParse(ccp.ReturnObject.ToString(), out count))
  96. {
  97. throw new MESException("服务端处理成功,但返回处理数量不是数字!");
  98. }
  99. return count;
  100. }
  101. public static string ReturnInfo(string strReturnInfo)
  102. {
  103. if (strReturnInfo != null)
  104. {
  105. if (strReturnInfo.IndexOf("IO 错误") >= 0)
  106. {
  107. //返回信息: The Network Adapter could not establish the connection, : Software caused connection abort: recv failed
  108. return "网络暂时无法连接,请检查网络情况或稍后尝试再次操作!";
  109. }
  110. else if (strReturnInfo.IndexOf("PreparedStatementCallback") >= 0 || strReturnInfo.IndexOf("找不到指定SQL语句!") >= 0 || strReturnInfo.IndexOf("事务处理失败") >= 0)
  111. {
  112. return "SQL语法错误,请联系编程人员!";
  113. }
  114. else if (strReturnInfo.IndexOf("网络错误") >= 0 || strReturnInfo.IndexOf("操作超时") >= 0)
  115. {
  116. return "网络连接超时,请尝试再次操作!";
  117. }
  118. else if (strReturnInfo.IndexOf("违反唯一约束条件") >= 0)
  119. {
  120. return "已存在相同编号信息,请尝试再次操作!";
  121. }
  122. else if (strReturnInfo.IndexOf("Java heap space") >= 0)
  123. {
  124. return "您查询的数据量过多请重新选择查询条件!";
  125. }
  126. return strReturnInfo;
  127. }
  128. else
  129. {
  130. return "未将对象引用到实例,请联系编程人员!";
  131. }
  132. }
  133. }
  134. }