Beispiel #1
0
        //登录
        public async void Login(object param)
        {
            Login loginWindow = param as Login;

            //显示等待圆圈
            loginWindow.loadPic.Visibility = Visibility.Visible;

            User user = null;
            await Task.Run(new Action(() =>
            {
                //模拟登陆等待时间
                Thread.Sleep(2000);
                user = UserService.QueryByNameAndPwd(userName, pwd);
            }));


            if (user != null)
            {
                AppCache.CurUser = user;
                AppCache.Ids     = User_MenuService.QueryMenuById(user.Id);
                Home home = new Home();
                home.Show();
                //隐藏等待圆圈
                loginWindow.loadPic.Visibility = Visibility.Hidden;
                loginWindow.Close();
            }
            else
            {
                ShowTip("账户或密码错误");
                return;
            }

            //先登录成功,再进行记录
            CheckRemeberPwd((bool)loginWindow.rememberPwd.IsChecked);
            loginWindow = null;
        }
Beispiel #2
0
        public PermissionViewModel()
        {
            UserService      = new UserService();
            MenuService      = new MenuService();
            User_MenuService = new User_MenuService();

            Users        = new ObservableCollection <User>();
            Menus        = new ObservableCollection <Menu>();
            CurUserMenus = new ObservableCollection <Menu>();

            MenuService.Query().ForEach(m => {
                m.IsSelected = false;
                Menus.Add(m);
            });

            UserService.Query().ForEach(u =>
            {
                Users.Add(u);
            });

            //选择项改变
            selectedChangedCommand = new DelegateCommand();
            selectedChangedCommand.ExcuteAction = new Action <object>(o =>
            {
                ListBox listBox = o as ListBox;
                if (listBox != null)
                {
                    foreach (var item in Menus)
                    {
                        item.IsSelected = false;
                    }
                    CurUserMenus.Clear();

                    var id      = (listBox.SelectedItem as User).Id;
                    var menuIds = User_MenuService.QueryMenuById(id);
                    //MenuService.QueryByIds(menuIds).ForEach(m=> CurUserMenus.Add(m));
                    foreach (var mId in menuIds)
                    {
                        foreach (var item in Menus)
                        {
                            if (item.Id == mId)
                            {
                                item.IsSelected = true;
                            }
                        }
                    }
                }
            });

            //保存权限修改
            savePermissCommand = new DelegateCommand();
            savePermissCommand.ExcuteAction = new Action <object>(o =>
            {
                var list = o as List <object>;
                if (list != null)
                {
                    var uId           = (((list[0] as ListBox).SelectedItem) as User).Id;
                    List <Menu> menus = new List <Menu>();
                    var items         = (list[1] as ListBox).SelectedItems;
                    foreach (var item in items)
                    {
                        menus.Add(item as Menu);
                    }
                    List <int> mIds = new List <int>();
                    menus.ForEach(m => mIds.Add(m.Id));
                    if (User_MenuService.Modify(uId, mIds))
                    {
                        ShowTip("保存成功");
                    }
                    else
                    {
                        ShowTip("保存失败");
                    }
                }
            });
        }
Beispiel #3
0
        public LoginViewModel()
        {
            UserService      = new UserService();
            User_MenuService = new User_MenuService();
            userNames        = new List <string>();

            loginCommand = new DelegateCommand();
            loginCommand.ExcuteAction = new Action <object>(Login);

            //moveCommand.ExcuteAction = new Action<object>((o) =>
            //{
            //    var win = o as Window;
            //    win.DragMove();
            //});

            closeCommand.ExcuteAction = new Action <object>(o =>
            {
                Application.Current.Shutdown();
            });

            loadNameAndPwdCommand = new DelegateCommand();
            //加载用户名列表和加载上次登录用户的密码
            loadNameAndPwdCommand.ExcuteAction = new Action <object>(o =>
            {
                Thread.Sleep(2000);
                var config = JsonHelper.ReadJsonFileToStr <Configs>(AppDomain.CurrentDomain.BaseDirectory + @"config/configs.json");
                if (config != null)
                {
                    if (config.UserConfig.Count > 0)
                    {
                        UserName = config.UserConfig[0].UserName;
                        config.UserConfig.ForEach(u =>
                        {
                            //添加到用户名列表
                            UserNames.Add(u.UserName);
                        });
                        if (!string.IsNullOrEmpty(config.UserConfig[0].Token))
                        {
                            //根据用户名和token获取密码
                            Pwd = UserService.GetPwdByTokenAndName(UserName, config.UserConfig[0].Token);
                        }
                    }
                }
            });

            //选择项改变
            selectChangeCommand = new DelegateCommand();
            selectChangeCommand.ExcuteAction = new Action <object>(o =>
            {
                var combox = o as ComboBox;

                var config = JsonHelper.ReadJsonFileToStr <Configs>(AppDomain.CurrentDomain.BaseDirectory + @"config/configs.json");
                foreach (var item in config.UserConfig)
                {
                    if (item.UserName == combox.SelectedItem as string)
                    {
                        if (!string.IsNullOrEmpty(item.Token))
                        {
                            //根据用户名和token获取密码
                            Pwd = UserService.GetPwdByTokenAndName(item.UserName, item.Token);
                            return;
                        }
                    }
                }
                Pwd = "";
            });
        }