private void Profile_Load(object sender, EventArgs e) { this.usersTableAdapter.Fill(this.sepdb_SQL.users); // Maximise screen automatically. MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea; WindowState = FormWindowState.Maximized; // Get current user information. sepdbDataSetTableAdapters.usersTableAdapter user = new sepdbDataSetTableAdapters.usersTableAdapter(); // Using MVC. User loggedInUser = Program.GetCurrentUser(); // Display values. TxtFName.Text = loggedInUser.Fullname; TxtID.Text = loggedInUser.UserId.ToString(); TxtEmail.Text = loggedInUser.EmailAddress; TxtCC.Text = loggedInUser.CostCentre; TxtPhoneNo.Text = loggedInUser.PhoneNo; TxtNickname.Text = loggedInUser.Nickname; // Editing buttons not visible yet. CancelBtn.Visible = false; SaveBtn.Visible = false; }
// When save button is clicked. private void SaveBtn_Click(object sender, EventArgs e) { // Using MVC. User selectedUser = Program.GetCurrentUser(); sepdbDataSetTableAdapters.usersTableAdapter usersTable = new sepdbDataSetTableAdapters.usersTableAdapter(); // Update user details using SQL statement. usersTable.UpdateUserDetails(TxtEmail.Text, TxtPhoneNo.Text, Convert.ToInt32(TxtID.Text)); // Update fields. selectedUser.EmailAddress = TxtEmail.Text; selectedUser.PhoneNo = TxtPhoneNo.Text; // Check if email is valid. if (IsValidEmail(TxtEmail.Text) == false || TxtEmail.Text == null) { MessageBox.Show("Please enter a valid email address."); } else { // Load page. ProfileFormX profile = new ProfileFormX(); profile.Show(); this.Close(); } }
// On Login button click. private void LoginBtn_Click(object sender, EventArgs e) { string staffID = StaffIDTF.Text; string staffPassword = PasswordTF.Text; // Loading circle visible. loadingCircle.Visible = true; // Check for missing ID - later disable login button until values is filled. if (string.IsNullOrEmpty(StaffIDTF.Text)) { //if fields are empty/null. MessageBox.Show("Please enter your Staff ID", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); StaffIDTF.Focus(); return; } try { // Populate data points in User class. sepdbDataSetTableAdapters.usersTableAdapter user = new sepdbDataSetTableAdapters.usersTableAdapter(); sepdbDataSet.usersDataTable dt = user.Login(staffID, staffPassword); if (dt.Rows.Count > 0) { User loggedInUser = Program.GetCurrentUser(); DataRow dr = dt.Rows[0]; loggedInUser.UserId = int.Parse(dr["userid"].ToString()); loggedInUser.FirstName = dr["firstname"].ToString(); loggedInUser.LastName = dr["lastname"].ToString(); loggedInUser.EmailAddress = dr["emailAddress"].ToString(); loggedInUser.PhoneNo = dr["phoneNumber"].ToString(); loggedInUser.CostCentre = dr["costCentre"].ToString(); loggedInUser.Nickname = dr["nickname"].ToString(); loggedInUser.RoleId = int.Parse(dr["roleID"].ToString()); // Load form. Home homepage = new Home(); homepage.Show(); this.Hide(); } else { // Display message. MessageBox.Show("Login details incorrect."); StaffIDTF.Focus(); // Clear fields. StaffIDTF.Text = ""; PasswordTF.Text = ""; // Loading circle not visible. loadingCircle.Visible = false; return; } } // Error handling. catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); StaffIDTF.Text = ""; PasswordTF.Text = ""; StaffIDTF.Focus(); loadingCircle.Visible = false; return; } }