private void BtnCreateCustomer_Click(object sender, RoutedEventArgs e) { //Open the UserList window after Creating/Updating a user. Window srcUserlist = null; bool result = false; if (rbtnYes.IsChecked == true) { isAdministrator = 1; } //Store all textbox data into a User object. //Check weather this is a NEW user or to UPDATE user. if (BtnCreateCustomer.Content.ToString() == "Update Customer") { if (!string.IsNullOrEmpty(txtUsername.Text)) { result = true; } else { MessageBox.Show("Username cannot be empty", "Invalid username"); } if (!string.IsNullOrEmpty(txtPassword.Text)) { result = true; } else { MessageBox.Show("Password cannot be empty", "Invalid Password"); } if (result) { try { date = user.UserCreatedDate; user = new User(Convert.ToInt32(txtUserID.Text), txtUsername.Text, txtPassword.Text, Convert.ToBoolean(isAdministrator), date, false); //Update selected user UsersDB.UpdateCurrentUser(user); srcUserlist = new UserList(); srcUserlist.Show(); Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } } else { if (!string.IsNullOrEmpty(txtUsername.Text)) { result = true; } else { MessageBox.Show("Username cannot be empty", "Invalid username"); } if (!string.IsNullOrEmpty(txtPassword.Text)) { result = true; } else { MessageBox.Show("Password cannot be empty", "Invalid Password"); } if (result) { try { date = DateTime.Now; user = new User(txtUsername.Text, txtPassword.Text, Convert.ToBoolean(isAdministrator), date, false); //Create new user UsersDB.CreateNewUser(user); srcUserlist = new UserList(); srcUserlist.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } } }