ServerHelper.cs 4.1 KB

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