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 { /// /// 自定义公共方法客户端服务端类 /// class PublicServer { /// /// 从服务端查询数据(query) /// /// 服务端MethodId /// 参数数组,需与服务端方法参数一致 /// 界面OB对象 /// 自定义异常 /// 查询数据集 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; } /// /// 从服务端查询数据(query) /// /// 服务端MethodId /// 参数数组,需与服务端方法参数一致 /// 界面OB对象 /// 自定义异常 /// 查询数据集 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; } /// /// 向服务端设置数据(insert、update、delete、procedure) /// /// 服务端MethodId /// 参数数组,需与服务端方法参数一致 /// 界面OB对象 /// 自定义异常 /// count处理数据行数,0 or -num表示失败 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 "未将对象引用到实例,请联系编程人员!"; } } } }