阿斯顿撒

发布时间 2023-10-13 10:06:45作者: 矫情少年郎

撒旦撒旦阿斯顿阿斯顿阿斯顿

 

public void SignIn()
        {

            User user = _userService.GetUserByName(Username);

            if (user != null && user.Password == Password)
            {
                #region 记住登录信息
                //将当前的配置序列化为json字符串
                CurrentUser.Enabled = Enabled;
                CurrentUser.Role = user.Role;
                CurrentUser.Name = Username;
                CurrentUser.Password = Password;
                var content = JsonConvert.SerializeObject(CurrentUser);
                JsonUtil.WriteJsonFile(Environment.CurrentDirectory + @"\Configuration\user.json", content);
                Const.User = CurrentUser;
                #endregion

                // 获取主屏幕的分辨率
                double screenWidth = SystemParameters.PrimaryScreenWidth;
                double screenHeight = SystemParameters.PrimaryScreenHeight;
                MainView mainView = App.Current._host.Services.GetRequiredService<MainView>();
                mainView.Width = screenWidth * 0.678;
                mainView.Height = screenHeight * 0.678;
                mainView.DataContext = App.Current._host.Services.GetRequiredService<MainViewModel>();

                
                /*mainView.Loaded += ((s, e) =>
                {
                    try
                    {
                        double screenscale = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth;

                        // 获取窗体中的所有控件
                        IEnumerable<FrameworkElement> controls = WPFUtil.GetChildControls(mainView);

                        foreach (FrameworkElement control in controls)
                        {
                            *//*// 排除不需要缩放的控件类型,例如 Label 等
                            if (!(control is Button) && !(control is TextBox) && !(control is ComboBox))
                            {
                                continue;
                            }*//*

                            // 将控件的宽度和高度缩放
                            control.Width /= screenscale;
                            control.Height /= screenscale;

                            // 如果是字体大小可以缩放的控件,也可以进行缩放             
                            if (control is Control controlWithFont)
                            {
                                controlWithFont.FontSize /= screenscale;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // 错误处理:在控制台输出错误信息
                        Console.WriteLine($"Error while scaling controls: {ex.Message}");
                    }
                });*/

                mainView!.Show();

                App.Current._host.Services.GetRequiredService<LoginView>().Close();

                _log.Debug($"此次登录的用户名:{Username},密码:{Password},登录时间:{DateTime.Now}");
            }
            else
            {
                MessageBoxX.Show(Application.Current.MainWindow, "用户名或密码错误!", "提示", MessageBoxButton.OK, MessageBoxIcon.Error, DefaultButton.YesOK, 5);
            }



        }