/// <summary>
 /// 保存主题
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_SaveTheme_Click(object sender, RoutedEventArgs e)
 {
     if (DataRWLocalFileRepository.SaveObjToFile <SettingLocal>(_PageViewModel.LocalSettings, AppSet.LocalSettingFileName))
     {
         AppFuns.ShowMessage("颜色主题保存成功!");
     }
 }
        private async void Btn_Login_ClickAsync(object sender, RoutedEventArgs e)
        {
            string V_UserId  = Text_UserId.Text.Trim();
            string V_UserPwd = Text_UserPwd.Password.Trim();

            if (V_UserId.Length < 1 || V_UserPwd.Length < 1)
            {
                AppFuns.ShowMessage("请输入用户名和密码。", "警告");
                return;
            }
            //显示Loading
            this.CanVas_loadding.Visibility = Visibility.Visible;
            try
            {
                //请求token
                string TokenResult = await DataApiRepository.GetAccessToken(V_UserId, V_UserPwd);

                if (TokenResult != "Ok")
                {
                    if (TokenResult.Trim().Equals("invalid_grant", StringComparison.Ordinal))
                    {
                        AppFuns.ShowMessage("用户名或密码错误!", "警告");
                    }
                    else
                    {
                        AppFuns.ShowMessage(TokenResult, "错误", isErr: true);
                    }
                    CanVas_loadding.Visibility = Visibility.Collapsed;
                    return;
                }
                //从服务器读取指定的用户并在服务器上登陆
                Lib.UserDto LoginUser = await DataUserRepository.GetOneById(V_UserId);

                if (LoginUser != null)
                {
                    DataRWLocalFileRepository.SaveObjToFile <SettingLocal>(AppSet.LocalSetting, AppSet.LocalSettingFileName);
                    AppSet.LoginUser = LoginUser;
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.Show();
                    mainWindow.Activate();
                    this.Close();
                }
                else
                {
                    this.CanVas_loadding.Visibility = Visibility.Collapsed;
                    AppFuns.ShowMessage("读取当前用户信息出错!", "警告");
                }
            }
            catch (Exception ex)
            {
                this.CanVas_loadding.Visibility = Visibility.Collapsed;
                AppFuns.ShowMessage(ex.Message, "错误", isErr: true);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查并升级系统
        /// </summary>
        /// <returns></returns>
        private async Task CheckAppUpdateAsync()
        {
            _UpdateAppTimer.Stop();
            //1.检查是否需要更新。
            List <string> NeedUpdateFiles = new List <string>();
            //读取服务器端本系统程序的信息。
            AppUpdateInfo UpdateInfo = await DataFileUpdateAppRepository.GetAppUpdateInfo();

            if (UpdateInfo == null)
            {
                this.notifyIcon.ShowBalloonTip(1000, "错误", "获取程序升级信息时出错...", ToolTipIcon.Error);
                _UpdateAppTimer.Start();
                return;
            }
            //如果服务器程序升级信息比本地记录的晚,则升级之。
            if (UpdateInfo.UpdateDate > AppSet.LocalSetting.AppUpDateTime)
            {
                NeedUpdateFiles = UpdateInfo.UpdateFiles.ToList <string>();
            }
            else
            {
                _UpdateAppTimer.Start();
                return;
            }

            if (NeedUpdateFiles != null && NeedUpdateFiles.Count > 0)
            {
                AppFuns.ShowMessage($"发现新版本程序,点击确定开始升级。", $"新版本[{UpdateInfo.UpdateDate:yyyy-MM-dd HH:mm}]");
                WinUpdateDialog winUpdate = new WinUpdateDialog(NeedUpdateFiles);
                winUpdate.ShowDialog();
                if (!CheckDownResult(UpdateInfo))
                {
                    AppFuns.ShowMessage("下载升级文件不正确,无法更新。", "错误", isErr: true);
                    ShutDownApp();
                    return;
                }
                //升级程序路径。
                string updateProgram = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UpdateApp.exe");
                if (File.Exists(updateProgram))
                {
                    //下载成功,更新本地时间。
                    AppSet.LocalSetting.AppUpDateTime = UpdateInfo.UpdateDate;
                    if (DataRWLocalFileRepository.SaveObjToFile(AppSet.LocalSetting, AppSet.LocalSettingFileName))
                    {
                        //启动升级程序
                        _ = Task.Run(() =>
                        {
                            int UpdateExitCode = System.Diagnostics.Process.Start(updateProgram).ExitCode;
                        }).ConfigureAwait(false);
                    }
                }
                else
                {
                    AppFuns.ShowMessage("未找到更新程序,请与开发人员联系。", "错误", isErr: true);
                }
                //关闭本程序
                Thread.Sleep(500);
                ShutDownApp();
            }
            else
            {
                _UpdateAppTimer.Start();
            }
        }
 /// <summary>
 /// 保存设置的网址
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_Save_Click(object sender, RoutedEventArgs e)
 {
     DataRWLocalFileRepository.SaveObjToFile <SettingLocal>(AppSet.LocalSetting, AppSet.LocalSettingFileName);
     CanVas_UrlSet.Visibility   = Visibility.Collapsed;
     CanVas_loadding.Visibility = Visibility.Collapsed;
 }