user2178133
user2178133

Reputation: 43

How do I carry on running code after another window is closed

I have a booking application, so when you press save, it asks for a username and password, and if the username and password are correct, it saves the booking. However, when it opens the new window, and the new window closes, it doesn't carry on saving, how do i make it carry in saving once the window is closed?

This is the code for the save button.

 private void btnSave_Click(object sender, RoutedEventArgs e)
    {
        if (CheckClashes(Convert.ToDateTime(date_picker.SelectedDate)) == false)
        {

            // tries to see if validation is ok
            if (validate() == true)
            {
                var openLogin = new Login1();
                openLogin.Show();

                if (variables.login == true)
                {
//do save algorithm

Here is the code for the new window when it checks the user's username and password.

  private void submit_Click(object sender, RoutedEventArgs e)
    {
        if (Validate() == true)
        {

            try
            {
               //authenticates user here

                if (hash1 == existingpassword.ToString())
                {
                    variables.login = true;
                    MessageBox.Show("User accepted.");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Incorrect username or password.");

                    variables.login = false;
                }

Upvotes: 0

Views: 96

Answers (2)

Anthony
Anthony

Reputation: 510

I think the better way is showing form in modal mode, like this:

openLogin.ShowDialog();
if (openLogin.DialogResult == DialogResult.OK)
{
    //save here
}

Upvotes: 1

matei.navidad
matei.navidad

Reputation: 745

Replace openLogin.Show() with openLogin.ShowDialog(). This will block the calling thread until the Login window is closed.

Upvotes: 1

Related Questions