Example #1
0
        public static bool UpdateUserInfo(SqlConnection sqlConnection, UsersManagement.UserData newUserData)
        {
            //open sqlConnection
            try
            {
                sqlConnection.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }

            SqlCommand comm = new SqlCommand("UpdateUser", sqlConnection);

            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.Parameters.AddWithValue("@Email", SqlDbType.VarChar).Value = newUserData.email;
            comm.Parameters.AddWithValue("@Password", SqlDbType.Char).Value = newUserData.password;
            comm.Parameters.AddWithValue("@DOB", SqlDbType.DateTime2).Value = newUserData.dob;

            if (comm.ExecuteNonQuery() > 0)
            {
                sqlConnection.Close();
                return(true);
            }
            else
            {
                sqlConnection.Close();
                return(false);
            }
        }
Example #2
0
        private void OnClick(object sender, EventArgs e)
        {
            Button button = sender as Button;

            UsersManagement.UserData newUserData = userData;

            if (button == buttonSave)
            {
                //confirma os inputs para verificar quais os dados o utilizador quer mudar
                DataToChange dataToChange = ValidateUserNewInfo();

                //compara a nova e a velha password
                if (dataToChange.password)
                {
                    if (String.Compare(userData.password, textBox2.Text) != 0)
                    {
                        //se as passwords sao diferentes, confirma q a nova password é valida
                        if (!RegistrationUtility.IsPasswordValid(textBox2.Text))
                        {
                            MessageBox.Show("New Password not valid.");
                            return;
                        }
                        else
                        {
                            newUserData.password = textBox2.Text;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Your new password is the same as the old one.");
                        return;
                    }
                }

                //comparar datas de nascimento
                if (dataToChange.dob)
                {
                    if (!RegistrationUtility.IsDateValid(dateTimePicker1.Value))
                    {
                        MessageBox.Show("Your new date isnt valid!");
                        return;
                    }
                    else
                    {
                        newUserData.dob = dateTimePicker1.Value;
                    }
                }

                if (RegistrationUtility.UpdateUserInfo(Form1.sqlConnection, newUserData))
                {
                    MessageBox.Show("User info updated.");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Command failed.");
                }
            }
        }
Example #3
0
        public UpdateUserInfoForm(Form ownerForm, string email, DateTime dob)
        {
            InitializeComponent();

            buttonSave.Click += new EventHandler(OnClick);

            this.Owner = ownerForm;

            userData = UsersManagement.GetUserData(Form1.sqlConnection, email);

            labelEmaillabel.Text  = email;
            dateTimePicker1.Value = dob;
        }