| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using CoreFS.CA06;
- using System.Data;
- using Infragistics.Win.UltraWinGrid;
- using System.Windows.Forms;
- using Infragistics.Win.UltraWinEditors;
- using Core.Mes.Client.Comm;
- namespace Pur.PublicTools
- {
- /// <summary>
- /// 自定义公共方法客户端服务端类
- /// </summary>
- class PublicServer
- {
- /// <summary>
- /// 从服务端查询数据(query)
- /// </summary>
- /// <param name="methodId">服务端MethodId</param>
- /// <param name="param">参数数组,需与服务端方法参数一致</param>
- /// <param name="ob">界面OB对象</param>
- /// <exception cref="MESException">自定义异常</exception>
- /// <returns>查询数据集</returns>
- public static DataTable GetData(string methodId, object[] param, OpeBase ob)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.IfShowErrMsg = false;
- ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
- ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
- ccp.ServerParams = param;
- ccp = ob.ExecuteSortResultByQueryToDataTable(ccp, CoreInvokeType.Internal);
- if (ccp == null)
- {
- throw new MESException("服务端处理失败!");
- }
- if (ccp.ReturnCode < 0)
- {
- throw new MESException(ReturnInfo(ccp.ReturnInfo));
- }
- return ccp.SourceDataTable;
- }
- /// <summary>
- /// 从服务端查询数据(query)
- /// </summary>
- /// <param name="methodId">服务端MethodId</param>
- /// <param name="param">参数数组,需与服务端方法参数一致</param>
- /// <param name="ob">界面OB对象</param>
- /// <exception cref="MESException">自定义异常</exception>
- /// <returns>查询数据集</returns>
- public static string GetDataTips(string methodId, object[] param, OpeBase ob)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.IfShowErrMsg = false;
- ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
- ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
- ccp.ServerParams = param;
- ccp = ob.ExecuteQuery(ccp, CoreInvokeType.Internal);
- if (ccp == null)
- {
- throw new MESException("服务端处理失败!");
- }
- if (ccp.ReturnCode < 0 && ccp.ReturnInfo != "YES")
- {
- throw new MESException(ReturnInfo(ccp.ReturnInfo));
- }
- return ccp.ReturnInfo;
- }
- /// <summary>
- /// 向服务端设置数据(insert、update、delete、procedure)
- /// </summary>
- /// <param name="methodId">服务端MethodId</param>
- /// <param name="param">参数数组,需与服务端方法参数一致</param>
- /// <param name="ob">界面OB对象</param>
- /// <exception cref="MESException">自定义异常</exception>
- /// <returns>count处理数据行数,0 or -num表示失败</returns>
- public static int SetData(string methodId, object[] param, OpeBase ob)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.IfShowErrMsg = false;
- ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
- ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
- ccp.ServerParams = param;
- ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp == null)
- {
- throw new MESException("服务端处理失败!");
- }
- if (ccp.ReturnCode < 0)
- {
- throw new MESException(ReturnInfo(ccp.ReturnInfo));
- }
- int count = 0;
- if (!int.TryParse(ccp.ReturnObject.ToString(), out count))
- {
- throw new MESException("服务端处理成功,但返回处理数量不是数字!");
- }
- return count;
- }
- public static string ReturnInfo(string strReturnInfo)
- {
- if (strReturnInfo != null)
- {
- if (strReturnInfo.IndexOf("IO 错误") >= 0)
- {
- //返回信息: The Network Adapter could not establish the connection, : Software caused connection abort: recv failed
- return "网络暂时无法连接,请检查网络情况或稍后尝试再次操作!";
- }
- else if (strReturnInfo.IndexOf("PreparedStatementCallback") >= 0 || strReturnInfo.IndexOf("找不到指定SQL语句!") >= 0 || strReturnInfo.IndexOf("事务处理失败") >= 0)
- {
- return "SQL语法错误,请联系编程人员!";
- }
- else if (strReturnInfo.IndexOf("网络错误") >= 0 || strReturnInfo.IndexOf("操作超时") >= 0)
- {
- return "网络连接超时,请尝试再次操作!";
- }
- else if (strReturnInfo.IndexOf("违反唯一约束条件") >= 0)
- {
- return "已存在相同编号信息,请尝试再次操作!";
- }
- else if (strReturnInfo.IndexOf("Java heap space") >= 0)
- {
- return "您查询的数据量过多请重新选择查询条件!";
- }
- return strReturnInfo;
- }
- else
- {
- return "未将对象引用到实例,请联系编程人员!";
- }
- }
- }
- }
|