ZGServerHelper.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using CoreFS.CA06;
  7. using Core.Mes.Client.Comm;
  8. namespace Core.StlMes.Client.ZGMil.Common
  9. {
  10. /// <summary>
  11. /// 连接服务端数据处理类
  12. /// </summary>
  13. public class ZGServerHelper
  14. {
  15. /// <summary>
  16. /// 从服务端查询数据(query)
  17. /// </summary>
  18. /// <param name="methodId">服务端MethodId</param>
  19. /// <param name="param">参数数组,需与服务端方法参数一致</param>
  20. /// <param name="ob">界面OB对象</param>
  21. /// <exception cref="MESException">自定义异常</exception>
  22. /// <returns>查询数据集</returns>
  23. public static DataTable GetData(string methodId, object[] param, OpeBase ob)
  24. {
  25. CoreClientParam ccp = new CoreClientParam();
  26. ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
  27. ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
  28. ccp.ServerParams = param;
  29. ccp = ob.ExecuteSortResultByQueryToDataTable(ccp, CoreInvokeType.Internal);
  30. if (ccp == null)
  31. {
  32. throw new MESException("服务端处理失败!");
  33. }
  34. //if (ccp.ReturnCode < 0)
  35. //{
  36. // throw new MESException("服务端处理失败!", ccp.ReturnCode, ccp.ReturnInfo);
  37. //}
  38. return ccp.SourceDataTable;
  39. }
  40. /// <summary>
  41. /// 向服务端设置数据(insert、update、delete、procedure)
  42. /// </summary>
  43. /// <param name="methodId">服务端MethodId</param>
  44. /// <param name="param">参数数组,需与服务端方法参数一致</param>
  45. /// <param name="ob">界面OB对象</param>
  46. /// <exception cref="MESException">自定义异常</exception>
  47. /// <returns>count处理数据行数,0 or -num表示失败</returns>
  48. public static int SetData(string methodId, object[] param, OpeBase ob)
  49. {
  50. CoreClientParam ccp = new CoreClientParam();
  51. ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
  52. ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
  53. ccp.ServerParams = param;
  54. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  55. if (ccp == null)
  56. {
  57. throw new MESException("服务端处理失败!");
  58. }
  59. if (ccp.ReturnCode < 0)
  60. {
  61. throw new MESException("服务端处理失败!", ccp.ReturnCode, ccp.ReturnInfo);
  62. }
  63. int count = 0;
  64. if (!int.TryParse(ccp.ReturnObject.ToString(), out count))
  65. {
  66. throw new MESException("服务端处理成功,但返回处理数量不是数字!");
  67. }
  68. return count;
  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>返回服务端的setResult中的数据</returns>
  78. public static object SetDataReturnObj(string methodId, object[] param, OpeBase ob)
  79. {
  80. CoreClientParam ccp = new CoreClientParam();
  81. ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
  82. ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
  83. ccp.ServerParams = param;
  84. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  85. if (ccp == null)
  86. {
  87. throw new MESException("服务端处理失败!");
  88. }
  89. if (ccp.ReturnCode < 0)
  90. {
  91. throw new MESException("服务端处理失败!", ccp.ReturnCode, ccp.ReturnInfo);
  92. }
  93. return ccp.ReturnObject;
  94. }
  95. }
  96. }