私はC#言語が初めてで、次のフォームがありMainwindow
ます:
public partial class MainWindow : Window
{
ConnectionManager DatabaseConnect = new ConnectionManager();
LoginController LoginControl = new LoginController();
public MainWindow()
{
InitializeComponent();
}
private void Done_btn_Click(object sender, RoutedEventArgs e)
{
LoginControl.Login();
}
private void Close_btn_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DatabaseConnect.ConnectDatabase();
Username_txtbox.Focus();
}
private void Username_txtbox_KeyDown(object sender, KeyEventArgs e)
{
LoginControl.KeyEnter(e);
}
private void Password_txtbox_KeyDown(object sender, KeyEventArgs e)
{
LoginControl.KeyEnter(e);
}
private void Password_txtbox_KeyDown_1(object sender, KeyEventArgs e)
{
LoginControl.KeyEnter(e);
}
}
クラス LoginController
class LoginController
{
private ConnectionManager DatabaseConnect = new ConnectionManager();
public void KeyEnter(KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Login();
}
}
public void Login()
{
MainWindow MainWindowPage = new MainWindow();
DatabaseConnect.ConnectDatabase();
System.Text.RegularExpressions.Regex EmailOnly = new Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
//Validates the textbox if it does not match the Regular expression of email address.
if (!EmailOnly.IsMatch(MainWindowPage.Username_txtbox.Text))
{
MessageBox.Show("Invalid email address!");
return;
}
else
{
if (MainWindowPage.Username_txtbox.Text.Length == 0 || MainWindowPage.Password_txtbox.Password.Length == 0)
{
MessageBox.Show("Enter on the login fields.");
}
if (MainWindowPage.Username_txtbox.Text != "" && MainWindowPage.Password_txtbox.Password != "")
{
DatabaseConnect.SqlStringQuery = "SELECT * FROM login_tbl WHERE user_email = '" + MainWindowPage.Username_txtbox.Text + "' AND password = '" + MainWindowPage.Password_txtbox.Password + "'";
DatabaseConnect.Getdata();
if (DatabaseConnect.SQLDR.HasRows == true)
{
DatabaseConnect.SQLDR.Close();
AdminForm AdminForm = new AdminForm();
AdminForm.Show();
MainWindowPage.Close();
}
else
{
DatabaseConnect.SQLDR.Close();
MessageBox.Show("Invalid user account!");
}
}
}
}
}
正しく検証されたメインウィンドウに Login() コードを配置してから、LoginController クラスに Login() を配置しましたが、クラスがメインウィンドウのテキストボックスの値を取得できないようで、常に「無効なメール」が表示されますmaindowテキストボックスに必要な値を入れても
何か案が?