Beispiel #1
0
        private void BtnChangePass_Click(object sender, EventArgs e)
        {
            if (txtOldPass.Text == "" || txtNewPass.Text == "" || txtRetypePass.Text == "")
            {
                MyMessageBox.ShowMessage("Please don't leave blank spaces!", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            }
            else if (txtNewPass.Text != txtRetypePass.Text)
            {
                txtRetypePass.Focus();
                lblPass.Visible = true;
                txtRetypePass.FocusedState.BorderColor = Color.FromArgb(232, 17, 35);
            }
            else if (txtOldPass.Text != lblPassword.Text)
            {
                MyMessageBox.ShowMessage("Please enter the correct password!", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                txtOldPass.Focus();
                lblPass.Visible = false;
                txtOldPass.FocusedState.BorderColor = Color.FromArgb(232, 17, 35);
            }
            else
            {
                try
                {
                    if (MyMessageBox.ShowMessage("Are you sure you want to change your password?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        cn.Open();
                        cm = new SqlCommand("UPDATE tblUser SET password = @password WHERE userID = @userID", cn);
                        cm.Parameters.AddWithValue("@userID", frm.lblID.Text);
                        cm.Parameters.AddWithValue("@password", txtNewPass.Text);
                        cm.ExecuteNonQuery();
                        cn.Close();

                        this.Close();
                        MyMessageBox.ShowMessage("Password changed successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        frm.LoadRecords();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #2
0
        private void BtnCreateAccount_Click(object sender, EventArgs e)
        {
            if (txtFullName.Text == "" || txtEmail.Text == "" || txtPassword.Text == "" || txtRetypePass.Text == "" || txtUsername.Text == "")
            {
                MyMessageBox.ShowMessage("Please don't leave blank spaces!", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            }
            else if (txtPassword.Text != txtRetypePass.Text)
            {
                txtRetypePass.Focus();
                lblPass.Visible = true;
                txtRetypePass.FocusedState.BorderColor = Color.FromArgb(232, 17, 35);
            }
            else
            {
                try
                {
                    if (MyMessageBox.ShowMessage("Are you sure you want to add " + txtFullName.Text + " as a new librarian?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        cn.Open();
                        cm = new SqlCommand("INSERT INTO tblUser VALUES (@username, @password, @fullName, @email, 'Active')", cn);
                        cm.Parameters.AddWithValue("@username", txtUsername.Text);
                        cm.Parameters.AddWithValue("@password", txtPassword.Text);
                        cm.Parameters.AddWithValue("@fullName", txtFullName.Text);
                        cm.Parameters.AddWithValue("@email", txtEmail.Text);
                        cm.ExecuteNonQuery();
                        cn.Close();

                        Logs();

                        Clear();
                        MyMessageBox.ShowMessage("Account created successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        frm.LoadRecords();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }