private void btnLogin_Click(object sender, RoutedEventArgs e) { //processing with the database DataAccessLayer dataAccessLayer = new DataAccessLayer(); foreach (Administrator admin in dataAccessLayer.QueryAdministratorByAll()) { if (txtUsername.Text.ToString() == admin.Name && passwordBox.Password == admin.Password) { IsLogin = true; this.Close(); } } if (IsLogin == false) { MessageBox.Show("帐号或密码错误!"); passwordBox.Password = null; } }
public MainWindow() { this.WindowStartupLocation = WindowStartupLocation.CenterScreen; InitializeComponent(); DataAccessLayer dataAccessLayer = new DataAccessLayer(); if (dataAccessLayer.DataBaseInit() == false) { MessageBox.Show("数据库连接失败!"); this.Close(); } else if (dataAccessLayer.QueryAdministratorByAll().Count() == 0) { //MessageBox.Show(dataAccessLayer.QueryAdministratorByAll().Count().ToString()); FirstUse_Window firstUseWnd = new FirstUse_Window(); firstUseWnd.WindowStartupLocation = WindowStartupLocation.CenterScreen; firstUseWnd.ShowDialog(); } }