Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var index = new FrmIndexForm();
            if (lstUsers.Text != string.Empty)
            {
                Registration = chkListbox.GetItemChecked(0) == false ? "0" : "1";
                Verification = chkListbox.GetItemChecked(1) == false ? "0" : "1";
                CastVote = chkListbox.GetItemChecked(2) == false ? "0" : "1";
                Admin = chkListbox.GetItemChecked(3) == false ? "0" : "1";
                Report = chkListbox.GetItemChecked(4) == false ? "0" : "1";

                const string @update =
                    "update Privileges set Registration=@reg, Verification=@verify, CastVote=@cast," +
                    "[Admin]=@admin, Report=@report Where Username=@username";
                using (_cnn = new SqlConnection(Settings.Default.DBConn))
                {
                    _cnn.Open();
                    using (_cmd = new SqlCommand(update, _cnn))
                    {
                        _cmd.Parameters.AddWithValue("username", lstUsers.Text);
                        _cmd.Parameters.AddWithValue("@reg", Registration);
                        _cmd.Parameters.AddWithValue("@verify", Verification);
                        _cmd.Parameters.AddWithValue("@cast", CastVote);
                        _cmd.Parameters.AddWithValue("@admin", Admin);
                        _cmd.Parameters.AddWithValue("@report", Report);
                        _cmd.ExecuteNonQuery();
                        MessageBox.Show(@"Privilege assigned successfully", @"Assign Privilege to Users");
                        GetUsers();
                    }
                }
            }
            else
                MessageBox.Show(@"Please select a username", @"Assign Privilege to Users");
        }
Ejemplo n.º 2
0
        private void btnLogin_Click(object sender, System.EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text))
            {
                MessageBox.Show(@"Username or Password must not be empty", @"User Login");
            }
            else
            {
                if (CheckUser(txtUsername.Text, txtPassword.Text))
                {
                    int x = 0;
                    progressBar1.Visible = true;
                    progressBar1.Minimum = 1;
                    progressBar1.Maximum = 100000;
                    progressBar1.Step = 1;

                    for (x = 1; x <= 100000; x++)
                    {
                        progressBar1.PerformStep();
                    }

                    Hide();
                    var form = new FrmIndexForm {Username = txtUsername.Text};
                    form.Show();
                }
                else
                {
                    int x = 0;
                    progressBar1.Visible = true;
                    progressBar1.Minimum = 1;
                    progressBar1.Maximum = 100000;
                    progressBar1.Step = 1;

                    for (x = 1; x <= 100000; x++)
                    {
                        progressBar1.PerformStep();
                    }
                    MessageBox.Show(@"You have entered a wrong username or password", @"User Login");
                    progressBar1.Value = 1;
                    txtPassword.Clear();
                    txtUsername.Clear();
                    txtUsername.Focus();
                }
            }
        }