/// <summary> /// 根据设置的查询字段列表信息,得到数据表。该方法得到的列表数据主要用于列表页面的网格控件 /// </summary> /// <param name="functionId">功能号</param> /// <param name="queryfields">查询字段列表</param> /// <returns>数据列表</returns> private DataTable GetDataTable(int functionId, Dictionary <T2Field, object> queryfields) { if (t2 == null) { throw new ApplicationException("The T2 data handler is null"); } // 在T2ESBMessage池中取T2报文操纵接口 IT2ESBMessage esbmsg = t2.GetT2Esbmsg(); // 在T2Packer池中取T2打包器接口 IT2Packer packer = t2.GetT2Packer(T2PackVersion.PACK_VERSION2); // 打包 packer.BeginPack(); T2Field field; foreach (KeyValuePair <T2Field, object> pair in queryfields) { field = pair.Key; packer.AddField(field.FieldName, field.FieldType, field.FieldWidth, pair.Value); packer.EndPack(); } packer.EndPack(); // 初始化报文 esbmsg.Prepare(T2TagDef.REQUEST_PACKET, functionId); //esbmsg.Prepare(T2TagDef.REQUEST_PACKET, 70); // 设置报文包体部分数据 esbmsg.MsgBody = packer.GetPackBuf(); // 释放T2打包器接口 t2.ReleaseT2Packer(packer); //同步发送 t2.SynSendEsbMessage(ref esbmsg, 5000); // 在T2UnPacker池中取T2解包器接口 IT2UnPacker unpacker = t2.GetT2UnPacker(esbmsg.MsgBody); t2.ReleaseT2Esbmsg(esbmsg); // 数据为空 或 存在error_no字段(表示出错)返回 if (unpacker.GetColName(0) == "error_no") { // 如:获取错误号和错误信息 int errorNo = unpacker.GetInt("error_no"); string errorInfo = unpacker.GetStr("error_info"); throw new BizException(errorNo, errorInfo); } else { DataTable dt = unpacker.ToDataTable(null); // 释放T2解包器接口 t2.ReleaseT2UnPacker(unpacker); return(dt); } }
/// <summary> /// 登录 /// </summary> /// <param name="userID"></param> /// <param name="pwd"></param> /// <returns></returns> public HsIdentity Login(string userID, string pwd) { IT2ESBMessage esbmsg = null; IT2Packer packer = null; IT2UnPacker unpacker = null; HsIdentity identity = null; try { esbmsg = t2.GetT2Esbmsg(); packer = t2.GetT2Packer(T2PackVersion.PACK_VERSION2); packer.BeginPack(); packer.AddField("user_login_id", T2FieldType.TYPE_STRING, userID); packer.AddField("user_pwd", T2FieldType.TYPE_STRING, pwd); packer.AddField("ws_mac", T2FieldType.TYPE_STRING, GetMacAddress()); packer.EndPack(); esbmsg.Prepare(T2TagDef.REQUEST_PACKET, USER_LOGIN); esbmsg.MsgBody = packer.GetPackBuf(); t2.SynSendEsbMessage(ref esbmsg, 5000); if (esbmsg.ReturnCode != 0) { if (esbmsg.ReturnCode == 1 || esbmsg.ReturnCode == -1) { throw new T2Exception(esbmsg.ErrorNo, esbmsg.ErrorInfo); } } unpacker = t2.GetT2UnPacker(esbmsg.MsgBody); if (esbmsg.ReturnCode > 1) //说明有错 { int errorNo = unpacker.GetInt("error_no"); string errorInfo = unpacker.GetStr("error_info"); throw new T2Exception(errorNo, errorInfo); } else { identity = new HsIdentity(); identity.OperId = unpacker.GetInt("user_id"); identity.OperCode = unpacker.GetStr("user_login_id"); identity.CmpId = unpacker.GetInt("cmp_id"); identity.SubSystemID = 1;//目前默认为1 } } finally { //释放T2打包器接口 if (null != packer) { t2.ReleaseT2Packer(packer); } if (null != esbmsg) { t2.ReleaseT2Esbmsg(esbmsg); } if (null != unpacker) { // 释放T2解包器接口 t2.ReleaseT2UnPacker(unpacker); } } return(identity); }