Exemplo n.º 1
0
 private void AccountUpdate_Click(object sender, EventArgs e)
 {
     using (MySqlConnection mysqlCon = new MySqlConnection(@"Server=" + ip + ";Database=osa_queuing;Uid=root;Pwd=;"))
     {
         try
         {
             mysqlCon.Open();
             String sql = "UPDATE accounts SET username = @username, password = @password, first_name = @firstname, last_name = @lastname WHERE account_id = @accountid";
             if (!(Txt_Password.Text.Equals(Txt_ConfPass.Text)))
             {
                 MessageBox.Show("Both of your new passwords do not match. Please try again.", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else if (Txt_Firstname.Equals("") || Txt_Lastname.Equals("") || Txt_Username.Equals("") || Txt_Password.Equals(""))
             {
                 MessageBox.Show("Please fill in all the needed details.", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 MySqlCommand cmd = new MySqlCommand(sql, mysqlCon);
                 cmd.Parameters.AddWithValue("@username", Txt_Username.Text);
                 cmd.Parameters.AddWithValue("@password", GetPasswordHashed(Txt_Password.Text));
                 cmd.Parameters.AddWithValue("@firstname", Txt_Firstname.Text);
                 cmd.Parameters.AddWithValue("@lastname", Txt_Lastname.Text);
                 cmd.Parameters.AddWithValue("@accountid", Emp.empId);
                 cmd.ExecuteNonQuery();
                 MessageBox.Show("Your account has successfully updated!", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Close();
             }
         }
         catch (Exception)
         {
             MessageBox.Show("Sorry, we can't update your account details/credentials as your connection was interrupted.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        public void UpdatePassword()
        {
            String ip = Txt_ServerIP.Text;

            using (MySqlConnection mysqlCon = new MySqlConnection(@"Server=" + ip + ";Database=osa_queuing;Uid=root;Pwd=;"))
            {
                mysqlCon.Open();
                String sql = "UPDATE accounts SET password = @password WHERE username = @username";
                if (!(Txt_Password.Text.Equals(Txt_ConfPass.Text)))
                {
                    MessageBox.Show("Both of your new passwords do not match. Please try again.", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (Txt_Username.Equals("") || Txt_Password.Equals("") || Txt_ServerIP.Equals(""))
                {
                    MessageBox.Show("Please fill in all the needed details.", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MySqlCommand cmd = new MySqlCommand(sql, mysqlCon);
                    cmd.Parameters.AddWithValue("@username", Txt_Username.Text);
                    cmd.Parameters.AddWithValue("@password", GetPasswordHashed(Txt_Password.Text));
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Your account has successfully updated!", "Account Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
        }