none
Binding TextBlock Linq ToSQL RRS feed

  • Question


  • Hi, i have a LoginWindow with username and password to access in the software(wpf) after that the user authenticated i want show in the next window(the mainWindow of the software) the name of the user authenticated in a TextBlock ...i show a code snippet of my LoginWindow:

    public partial class Window1 : Window { public Window1() { InitializeComponent(); } 
     
        public bool ValidateApplicationUser(string userName, string password) 
        { 
          { 
                var AuthContext = new DataClasses1DataContext(); 
                var query = from c in  AuthContext.Users 
                            where (c.Username == userName.ToLower() && c.Password == password.ToLower()) 
                            select c; 
     
                if(query.Count() != 0 ) 
                { 
                    return true
                } 
     
                return false
            } 
     
        } 
     
        private void mahhh(object sender, RoutedEventArgs e) 
        { 
            bool authenticated = true
            { 
                if (usernameTextBox.Text !="" && passwordTextBox.Text != ""
                { 
                    authenticated = ValidateApplicationUser(usernameTextBox.Text , passwordTextBox.Text); 
                } 
     
            } 
            if (!authenticated) 
            { 
                MessageBox.Show("Invalid login. Try again."); 
            } 
            else 
            { 
                MessageBox.Show("Congradulations! You're a valid user!"); 
                MainWindow c = new MainWindow(); 
                c.ShowDialog(); 
     
            } 
        } 

     




    If i authenticate with the username"Marc" in the MainWindow i will show the username "Marc" in a TextBlock and i don't know i make it? How i can do it?




    Wednesday, March 4, 2009 5:01 PM

Answers

  • Change your MainWindow constructor so that it takes a string name and then pass it in from the if condition.

    e.g.

    in MainWindow.cs change public MainWindow() { ... } to public MainWindow(string username) { ... } and the line in the above file from MainWindow c = new MainWindow(); to MainWindow c = new MainWindow(usernameTextBox.Text);

    [)amien
    Thursday, March 5, 2009 1:18 AM
    Moderator

All replies

  • Change your MainWindow constructor so that it takes a string name and then pass it in from the if condition.

    e.g.

    in MainWindow.cs change public MainWindow() { ... } to public MainWindow(string username) { ... } and the line in the above file from MainWindow c = new MainWindow(); to MainWindow c = new MainWindow(usernameTextBox.Text);

    [)amien
    Thursday, March 5, 2009 1:18 AM
    Moderator
  • Thanks Damien,
    That's all right, you have right.
    I wish you a lucky day!!!
    Bye
    Thursday, March 5, 2009 4:56 AM