Ejemplo n.º 1
0
Archivo: Msg.cs Proyecto: LimGoSky/ZFS
        /// <summary>
        /// 全局异常处理
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="notify"></param>
        /// <returns></returns>
        public static void Error(Exception ex, Notify notify = Notify.Error)
        {
            string Icon  = string.Empty;
            string Color = string.Empty;
            bool   Hide  = true;

            switch (notify)
            {
            case Notify.Error:
                Icon  = "\xe676";
                Color = "#FF4500";
                break;

            case Notify.Warning:
                Icon  = "\xe623";
                Color = "#FF8247";
                break;

            case Notify.Info:
                Icon  = "\xe764";
                Color = "#1C86EE";
                break;

            default:
                Icon  = "\xe676";
                Color = "#FF4500";
                break;
            }
            MsgHostBoxViewModel msgBox = new MsgHostBoxViewModel();
            var    dialog = ServiceProvider.Instance.Get <IModelDialog>("MsgHostBoxViewDlg");
            string msg    = ExceptionLibrary.GetErrorMsgByExpId(ex);

            dialog.BindViewModel(new MsgHostBoxViewModel()
            {
                Msg     = msg,
                Icon    = Icon,
                Color   = Color,
                BtnHide = Hide
            });
            dialog.ShowDialog(null, msgBox.ExtendedClosingEventHandler);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 登陆系统
        /// </summary>
        public async void Login()
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(Password))
                {
                    this.IsCancel = false;
                    IUser user = ZFSBridge.BridgeFactory.BridgeManager.GetUserManager();
                    this.Report = "正在验证登录 . . .";
                    var LoginTask     = user.Login(UserName, CEncoder.Encode(Password));
                    var timeouttask   = Task.Delay(3000);
                    var completedTask = await Task.WhenAny(LoginTask, timeouttask);

                    if (completedTask == timeouttask)
                    {
                        this.Report = "系统连接超时,请联系管理员!";
                    }
                    else
                    {
                        var task = await LoginTask;
                        if (task.Success)
                        {
                            if (UserChecked)
                            {
                                SaveLoginInfo();
                            }

                            #region 设置用户基础信息
                            var req = task.Results as tb_User;
                            Loginer.LoginerUser.Account  = req.Account;
                            Loginer.LoginerUser.UserName = req.UserName;
                            Loginer.LoginerUser.IsAdmin  = req.FlagAdmin == "1" ? true : false;
                            Loginer.LoginerUser.Email    = req.Email;
                            #endregion

                            #region 加载用户资料
                            this.Report = "加载用户信息 . . .";
                            var response = await ZFSBridge.BridgeFactory.BridgeManager.GetUserManager().GetAuthority(Loginer.LoginerUser.Account);

                            Loginer.LoginerUser.UserAuthority = response.Results;

                            #endregion

                            #region 初始化首页
                            this.Report = "初始化首页 . . .";
                            MainViewModel model = new MainViewModel();
                            model.InitDefaultView();
                            var dialog = ServiceProvider.Instance.Get <IModelDialog>("MainViewDlg");
                            dialog.BindViewModel(model);
                            Messenger.Default.Send(string.Empty, "ApplicationHiding");
                            bool taskResult = await dialog.ShowDialog(null, model.ExtendedClosingEventHandler);

                            this.ApplicationShutdown();
                            #endregion
                        }
                        else
                        {
                            this.Report = task.Message;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.Report = ExceptionLibrary.GetErrorMsgByExpId(ex);
            }
            finally
            {
                this.IsCancel = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 登陆系统
        /// </summary>
        public async void LoginAsync(string hander)
        {
            try
            {
                string phone = string.Empty;
                string pwd   = string.Empty;
                switch (hander)
                {
                case "登录":
                {
                    phone = LoginCollection.UserName;
                    pwd   = LoginCollection.Password;
                    break;
                }

                default:
                {
                    if (string.IsNullOrEmpty(RestCollection.Verification))
                    {
                        Msg.Info("请输入验证码");
                        return;
                    }
                    if (!RestCollection.Password.Equals(RestCollection.ConfirmPassword))
                    {
                        Msg.Info("密码不一致,请重新输入");
                        return;
                    }
                    phone = RestCollection.UserName;
                    pwd   = RestCollection.Password;
                    ServiceResponse genrator = new ServiceResponse();
                    IUser           user     = BridgeFactory.BridgeManager.GetUserManager();
                    genrator = hander.Equals("注册")
                                ? await user.Register(RestCollection.Password, RestCollection.UserName, RestCollection.Verification)
                                : await user.ResetPwdByCode(RestCollection.Password, RestCollection.UserName, RestCollection.Verification);

                    if (genrator.code != "000")
                    {
                        Msg.Info(genrator.Message);
                        return;
                    }
                    break;
                }
                }
                ServiceResponse genratorlogin;
                if (!string.IsNullOrWhiteSpace(phone) && !string.IsNullOrWhiteSpace(pwd))
                {
                    LoginCollection.IsCancel = false;
                    IUser user = BridgeFactory.BridgeManager.GetUserManager();
                    if (phone.Equals("13666142357"))
                    {
                        genratorlogin = await user.Login("123", pwd, phone);

                        if (genratorlogin.code != "000")
                        {
                            Msg.Info(genratorlogin.Message);
                            return;
                        }
                    }
                    else
                    {
                        genratorlogin = await user.Login(Loginer.LoginerUser.macAdd, pwd, phone);

                        if (genratorlogin.code != "000")
                        {
                            Msg.Info(genratorlogin.Message);
                            return;
                        }
                    }

                    var Results = JsonConvert.DeserializeObject <Loginer>(genratorlogin.result.ToString());
                    Network.Authorization             = Results.token;
                    Loginer.LoginerUser.Authorization = Results.token;
                    Loginer.LoginerUser.UserName      = Results.phone;
                    Loginer.LoginerUser.balance       = Results.balance;
                    Loginer.LoginerUser.freeCount     = Results.freeCount;
                    Loginer.LoginerUser.vipInfo       = Results.vipInfo;
                    Loginer.LoginerUser.vipType       = Results.vipType;
                    Loginer.LoginerUser.ToolEntities  = CommonsCall.ReadUserAllGame();

                    string vipType = string.Empty;
                    if (Loginer.LoginerUser.vipType.Equals("1") || Loginer.LoginerUser.vipType.Equals("2"))
                    {
                        Loginer.LoginerUser.IsAdmin = true;
                    }
                    switch (Loginer.LoginerUser.vipType)
                    {
                    case "0":
                    {
                        vipType = "普通用户";
                        break;
                    }

                    case "1":
                    {
                        vipType = "月费用户";
                        break;
                    }

                    case "2":
                    {
                        vipType = "年费用户";
                        break;
                    }
                    }
                    CommonsCall.UserBalance = Loginer.LoginerUser.balance;
                    CommonsCall.ShowUser    = Loginer.LoginerUser.UserName + "  余额:" + Loginer.LoginerUser.balance + "鹰币   " + Loginer.LoginerUser.vipInfo;
                }
                else
                {
                    Msg.Info("请输入用户名和密码");
                    return;
                }

                SaveLoginInfo(phone, pwd);
                MainViewModel model = new MainViewModel();
                model.InitDefaultView();
                var dialog = ServiceProvider.Instance.Get <IModelDialog>("MainViewDlg");
                dialog.BindViewModel(model);
                Messenger.Default.Send(string.Empty, "ApplicationHiding");
                bool taskResult = await dialog.ShowDialog();
            }
            catch (Exception ex)
            {
                LoginCollection.Report = ExceptionLibrary.GetErrorMsgByExpId(ex);
                Msg.Error(ex);
            }
            finally
            {
                LoginCollection.IsCancel = true;
            }
        }