private void btnLogin_Click(object sender, RoutedEventArgs e) { MainWindow chatWindow = null; try { chatWindow = new MainWindow(); App.Connect(chatWindow); string username = txtUsername.Text; string password = txtPassword.Password; if (App.Proxy.Login(username, password)) { //MessageBox.Show("Login Success"); NotificationHelper.NotifyInfo("Login Success"); ZolaService.User user = App.Proxy.GetUserInformation(username); chatWindow.Init(user); this.Hide(); chatWindow.ShowDialog(); App.Proxy.Logout(user); } else { //MessageBox.Show("Login Fail"); NotificationHelper.NotifyError("Login Fail"); } } catch (Exception ex) { //MessageBox.Show(ex.Message); NotificationHelper.NotifyError(ex.Message); } finally { App.Disconnect(); if (chatWindow != null) { chatWindow.Hide(); chatWindow.Close(); } this.Show(); } }
private void btnRegister_Click(object sender, RoutedEventArgs e) { string username = txtUsername.Text; string password = txtPassword.Password; string confirmPassword = txtConfirmPassword.Password; string name = txtName.Text; //Validate if (username.Length <= 2) { //MessageBox.Show("Username must have more than 2 chars", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); NotificationHelper.NotifyError("Username must have more than 2 chars"); } else if (password.Length < 5) { //MessageBox.Show("Password must have more than 4 chars", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); NotificationHelper.NotifyError("Password must have more than 4 chars"); } else if (name.Length < 1) { //MessageBox.Show("Please input name", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); NotificationHelper.NotifyError("Please input name"); } else if (password != confirmPassword) { //MessageBox.Show("Password confirm not match!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); NotificationHelper.NotifyError("Password confirm not match!"); } else { App.Connect(new CallbackObject()); try { if (App.Proxy.Register(username, password, name) == true) { this.DialogResult = true; } else { this.DialogResult = false; } } catch (Exception ex) { //MessageBox.Show(ex.Message); NotificationHelper.NotifyError(ex.Message); } finally { try { App.Disconnect(); } catch (Exception ex) { //MessageBox.Show(ex.Message); NotificationHelper.NotifyError(ex.Message); } } } }