Exemple #1
0
        /// <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);
            }
        }
Exemple #2
0
        /// <summary>
        /// 无返回值操作
        /// </summary>
        /// <returns></returns>
        private void GeneralOperate(int functionId, Dictionary <T2Field, object> t2fields)
        {
            if (t2 == null)
            {
                throw new ApplicationException("The T2 data handler is null");
            }
            if (t2fields == null || t2fields.Count == 0)
            {
                throw new ArgumentNullException("t2fields");
            }

            IT2ESBMessage esbmsg = t2.GetT2Esbmsg();
            // 在T2Packer池中取T2打包器接口
            IT2Packer packer = t2.GetT2Packer(T2PackVersion.PACK_VERSION2);

            // 打包
            packer.BeginPack();
            T2Field field;

            foreach (KeyValuePair <T2Field, object> pair in t2fields)
            {
                field = pair.Key;
                packer.AddField(field.FieldName, field.FieldType, field.FieldWidth, pair.Value);
                packer.EndPack();
            }
            packer.EndPack();

            // 初始化报文,功能号码
            esbmsg.Prepare(T2TagDef.REQUEST_PACKET, functionId);
            // 设置报文包体部分数据
            esbmsg.MsgBody = packer.GetPackBuf();
            // 释放T2打包器接口
            t2.ReleaseT2Packer(packer);

            //同步发送
            t2.SynSendEsbMessage(ref esbmsg, 5000);

            // 在T2UnPacker池中取T2解包器接口
            IT2UnPacker unpacker = t2.GetT2UnPacker(esbmsg.MsgBody);

            t2.ReleaseT2Esbmsg(esbmsg);
            if ("error_no" == unpacker.GetColName(0))
            {
                // 如:获取错误号和错误信息
                int    errorNo   = unpacker.GetInt("error_no");
                string errorInfo = unpacker.GetStr("error_info");
                throw new BizException(errorNo, errorInfo);
            }

            // 释放T2解包器接口
            t2.ReleaseT2UnPacker(unpacker);
        }
        /// <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);
        }
        /// <summary>
        /// 获取角色菜单权限
        /// </summary>
        /// <param name="roles"></param>
        /// <param name="o4Identity"></param>
        /// <returns></returns>
        private List <MenuInfo> GetRoleMenus(List <RoleInfo> roles, HsIdentity o4Identity)
        {
            List <MenuInfo> menus = new List <MenuInfo>();

            if (roles == null || roles.Count == 0)
            {
                return(menus);
            }
            IT2ESBMessage esbmsg       = null;
            IT2Packer     packer       = null;
            IT2UnPacker   unpacker     = null;
            IT2UnPacker   funcUnpacker = null;

            try
            {
                esbmsg = t2.GetT2Esbmsg();
                packer = t2.GetT2Packer(T2PackVersion.PACK_VERSION2);

                packer.BeginPack();
                foreach (var roleInfo in roles)
                {
                    packer.AddField("role_id", T2FieldType.TYPE_INT, roleInfo.role_id);
                    packer.AddField("subsys_id", T2FieldType.TYPE_INT, o4Identity.SubSystemID);
                }
                packer.EndPack();

                esbmsg.Prepare(T2TagDef.REQUEST_PACKET, ROLE_MENU_QUERY);
                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
                {
                    while (!unpacker.EOF)
                    {
                        MenuInfo menu = new MenuInfo();
                        menu.menu_id          = unpacker.GetInt("menu_id");
                        menu.menu_parent_id   = unpacker.GetInt("menu_parent_id");
                        menu.menu_order       = unpacker.GetStr("menu_order");
                        menu.menu_name        = unpacker.GetStr("menu_name");
                        menu.menu_plugin_type = Convert.ToChar(unpacker.GetChar("menu_plugin_type"));
                        menu.menu_plugin_name = unpacker.GetStr("menu_plugin_name");
                        menu.menu_plugin_dll  = unpacker.GetStr("menu_plugin_dll");
                        menu.menu_is_leaf     = Convert.ToChar(unpacker.GetChar("menu_is_leaf"));
                        menu.menu_icon_name   = unpacker.GetStr("menu_icon_name");
                        menu.menu_shortcut    = unpacker.GetStr("menu_shortcut");
                        menu.menu_multi_open  = Convert.ToChar(unpacker.GetChar("menu_multi_open"));
                        menu.menu_auto_open   = Convert.ToChar(unpacker.GetChar("menu_auto_open"));
                        menu.menu_allow_close = Convert.ToChar(unpacker.GetChar("menu_allow_close"));

                        List <FuncInfo> funcs   = new List <FuncInfo>();
                        byte[]          funcbuf = unpacker.GetRaw("i_func_list");
                        funcUnpacker = t2.GetT2UnPacker(funcbuf);
                        while (!funcUnpacker.EOF)
                        {
                            FuncInfo func   = new FuncInfo();
                            int      funcId = funcUnpacker.GetInt("func_id");
                            if (funcId > 0)
                            {
                                func.func_id   = funcId;
                                func.func_name = funcUnpacker.GetStr("func_name");
                                funcs.Add(func);
                            }
                            funcUnpacker.Next();
                        }
                        menu.i_func_list = funcs;
                        menus.Add(menu);
                        unpacker.Next();
                    }
                }
            }
            finally
            {
                //释放T2打包器接口
                if (null != packer)
                {
                    t2.ReleaseT2Packer(packer);
                }
                if (null != esbmsg)
                {
                    t2.ReleaseT2Esbmsg(esbmsg);
                }
                if (null != unpacker)
                {
                    // 释放T2解包器接口
                    t2.ReleaseT2UnPacker(unpacker);
                }
                if (null != funcUnpacker)
                {
                    t2.ReleaseT2UnPacker(funcUnpacker);
                }
            }
            return(menus);
        }
        /// <summary>
        /// 根据用户id获取角色列表
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        private List <RoleInfo> GetUserRoles(int userId)
        {
            List <RoleInfo> roles    = new List <RoleInfo>();
            IT2ESBMessage   esbmsg   = null;
            IT2Packer       packer   = null;
            IT2UnPacker     unpacker = null;

            try
            {
                esbmsg = t2.GetT2Esbmsg();
                packer = t2.GetT2Packer(T2PackVersion.PACK_VERSION2);

                packer.BeginPack();
                packer.AddField("user_id", T2FieldType.TYPE_INT, userId);
                packer.EndPack();

                esbmsg.Prepare(T2TagDef.REQUEST_PACKET, USER_ROLE_QUERY);
                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
                {
                    while (!unpacker.EOF)
                    {
                        RoleInfo r = new RoleInfo();
                        r.role_id         = unpacker.GetInt("role_id");
                        r.role_name       = unpacker.GetStr("role_name");
                        r.cmp_id          = unpacker.GetInt("cmp_id");
                        r.remark          = unpacker.GetStr("remark");
                        r.auth_flag       = unpacker.GetInt("auth_flag");
                        r.auth_begin_date = unpacker.GetInt("auth_begin_date");
                        r.auth_begin_time = unpacker.GetInt("auth_begin_time");
                        r.auth_end_date   = unpacker.GetInt("auth_end_date");
                        r.auth_end_time   = unpacker.GetInt("auth_end_time");
                        roles.Add(r);
                        unpacker.Next();
                    }
                }
            }
            finally
            {
                //释放T2打包器接口
                if (null != packer)
                {
                    t2.ReleaseT2Packer(packer);
                }
                if (null != esbmsg)
                {
                    t2.ReleaseT2Esbmsg(esbmsg);
                }
                if (null != unpacker)
                {
                    // 释放T2解包器接口
                    t2.ReleaseT2UnPacker(unpacker);
                }
            }
            return(roles);
        }