Example #1
0
        /// <summary>
        /// 利用反射动态生成控件
        /// </summary>
        /// <param name="menuItem"></param>
        /// <returns></returns>
        private static Control DynamicCreateControl(RoleResourceMapping menuItem)
        {
            string _controlName = menuItem.Resource.WinName.Trim();
            string _argument    = "";

            if (_controlName.IndexOf(" ") > 0)//控件带参数
            {
                _argument    = _controlName.Substring(_controlName.IndexOf(" ") + 1).Trim();
                _controlName = _controlName.Substring(0, _controlName.IndexOf(" "));
            }

            object  _obj;
            Control _control;

            try
            {
                //装载程序集
                Assembly _assembly;

                Type _type = Type.GetType(_controlName);
                if (_type == null)
                {
                    _assembly = Assembly.LoadFrom(Application.StartupPath + "\\" + menuItem.Resource.DllName.Trim() + ".dll");
                }
                else
                {
                    _assembly = System.Reflection.Assembly.GetAssembly(_type);
                }

                _type = _assembly.GetType(_controlName);
                if (_type == null)
                {
                    MessageBox.Show("程序集:" + menuItem.Resource.DllName.Trim() + ".dll中无类型为" + _controlName + "的控件!");
                    return(null);
                }

                object[] _arguments = null;
                if (!string.IsNullOrEmpty(_argument))
                {
                    _arguments    = new object[1];
                    _arguments[0] = _argument;
                }
                _obj = Activator.CreateInstance(_type, _arguments);
            }
            catch (Exception e)
            {
                SystemErrorForm _error = new SystemErrorForm(e);
                _error.ShowDialog();
                return(null);
            }

            _control      = _obj as Control;
            _control.Tag  = menuItem.Parameter;
            _control.Text = menuItem.Name;
            return(_control);
        }
Example #2
0
        private static TreeView CreateTree(string treeName, string treeDllName)
        {
            TreeView _tree = null;

            try
            {
                //装载程序集
                Assembly _assembly;

                Type _type = Type.GetType(treeName);
                if (_type == null)
                {
                    if (string.IsNullOrEmpty(treeDllName))
                    {
                        MessageBox.Show("树控件程序集名称不能为空!", "提示");
                        return(null);
                    }

                    _assembly = Assembly.LoadFrom(Application.StartupPath + "\\" + treeDllName.Trim() + ".dll");
                }
                else
                {
                    _assembly = System.Reflection.Assembly.GetAssembly(_type);
                }

                _type = _assembly.GetType(treeName);
                if (_type == null)
                {
                    MessageBox.Show("程序集:" + treeDllName.Trim() + ".dll中无类型为" + treeName + "的控件!");
                    return(null);
                }

                _tree = Activator.CreateInstance(_type) as TreeView;
            }
            catch (Exception e)
            {
                SystemErrorForm _error = new SystemErrorForm(e);
                _error.ShowDialog();
                return(null);
            }

            return(_tree);
        }
        public static int Login(string account, string password)
        {
            NeuPrincipal _principal = null;
            NeuIdentity  _identity  = null;

            if (Program.isMessageShow == true)
            {
                Program.isMessageShow = false;
                return(-1);
            }
            //认证
            PrivilegeService proxy = new PrivilegeService();

            try
            {
                _identity = proxy.Authenticate(account, password, "");
                ///
                ///查询该用户拥有的角色
                IList <Role> _roles;

                using (proxy as IDisposable)
                {
                    //表更改了,所以修改了SQL语句(张凯钧)Security.Org.GetRoleByUserID
                    _roles = proxy.QueryRole(_identity.User.Id);
                }

                if (_roles == null | _roles.Count == 0)
                {
                    Program.isMessageShow = false;
                    MessageBox.Show("该用户没有进行角色授权!");
                    Program.isMessageShow = true;
                    return(-1);
                }

                _principal = new NeuPrincipal(_identity, _roles);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    Program.isMessageShow = false;
                    MessageBox.Show(ex.Message);
                    Program.isMessageShow = true;
                }
                else
                {
                    SystemErrorForm _error = new SystemErrorForm(ex);
                    _error.ShowDialog();
                }

                return(-1);
            }

            if (_principal.Identity.IsAuthenticated)
            {
                //加载选择角色科室界面
                Role _role = SelectLoginRole((_principal.Identity as NeuIdentity).User, _principal.Roles);

                if (_role == null)
                {
                    Application.Exit();
                    //{AE0687E4-FE13-4b00-8865-738F84B74BB2}
                    return(-1);
                }

                //通过认证以后,给当前角色赋值;
                _principal.CurrentRole = _role;


                //设置登录时间
                _principal.LoginTime = Neusoft.FrameWork.Function.NConvert.ToDateTime(new Neusoft.FrameWork.Management.DataBaseManger().GetSysDateTime());

                //设置当前操作员信息
                SetLoginUser((_principal.Identity as NeuIdentity).User, (Neusoft.FrameWork.Models.NeuObject)_principal.CurrentRole, _principal.CurrentRole.UnitId);
            }
            return(0);
        }