using SparkClient.Model.Helper; using SparkClient.ViewModel.Configuration.SettingsPages; using System.Data; using System.Windows; using System.Windows.Input; namespace SparkClient; public partial class LoginWindow : Window { public LoginWindow() { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; AccountTextBox.Text = Settings.SelectValueByName("SAVE_ACCOUNT"); PasswordBox.Password = Settings.SelectValueByName("SAVE_PASSWORD"); } private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ButtonState == MouseButtonState.Pressed) { this.DragMove(); } } private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { AccountTextBox.Text = string.Empty; } private void CloseButton_OnClick(object sender, RoutedEventArgs e) { this.Close(); Environment.Exit(0); } private void ConfirmButton_Click(object sender, RoutedEventArgs e) { #if DEBUG new MainWindow().Show(); this.Close(); #else string account = AccountTextBox.Text; string password = PasswordBox.Password; string passwordEnc = Common.GenerateMd5Hash(password); string passworddb = getPassword(account); if (string.IsNullOrEmpty(password) || !passworddb.Equals(passwordEnc)) { MessageBox.Show(MultilingualHelper.getString("NoPassword")); return; } savePassword(); new MainWindow().Show(); this.Close(); #endif } private void savePassword() { if (IsRemberPassword.IsChecked ?? false) { if (!"admin".Equals(AccountTextBox.Text)){ Settings saveAccount = new Settings() { Key = "SAVE_ACCOUNT", ItemName = "保存用户名", Value = AccountTextBox.Text, }; saveAccount.insert(); Settings savePassword = new Settings() { Key = "SAVE_PASSWORD", ItemName = "保存密码", Value = PasswordBox.Password, }; savePassword.insert(); } } else { Settings saveAccount = new Settings() { Key = "SAVE_ACCOUNT", ItemName = "保存用户名", Value = "", }; saveAccount.insert(); Settings savePassword = new Settings() { Key = "SAVE_PASSWORD", ItemName = "保存密码", Value = "", }; savePassword.insert(); } Settings PERMISSIONS = new Settings() { Key = "PERMISSIONS", ItemName = "权限", Value = AccountTextBox.Text, }; PERMISSIONS.insert(); } private string getPassword(string userName) { string password = string.Empty; string sql = $"SELECT USER_PASSWORD FROM USER WHERE USER_NAME='{userName}';"; DataTable dt = DataBaseHelper.ExecuteQuery(sql); if (dt != null && dt.Rows.Count > 0) { password = dt.Rows[0]["USER_PASSWORD"].ToString(); } return password; } }