示例#1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            var isAdmin = false;

            if (rdbAdminYes.Checked)
            {
                isAdmin = true;
            }
            if (txtName.Text != "" && txtSurname.Text != "")
            {
                oleDbConnection.Open();
                var myCommand = new OleDbCommand();
                myCommand.Connection  = oleDbConnection;
                myCommand.CommandText = "Update Users set Employee_Name = '" + txtName.Text + "',Employee_Surname ='" +
                                        txtSurname.Text + "',Employee_Id = '" + txtUsername.Text
                                        + "',Admin_rights = " + isAdmin + ",Employee_Password ='******' WHERE ID =" + userID + "";
                myCommand.ExecuteNonQuery();
                MessageBox.Show("Data inserted successfully", "Database Updated", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                oleDbConnection.Close();

                Hide();
                var form = new AddandRemoveUser();
                form.Show();
            }
        }
示例#2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 0)
            {
                var result = MessageBox.Show("Do you want to delete this user?", "Delete User",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    var row = dataGridView1.SelectedRows[0];
                    var id  = row.Cells["Id"].Value.ToString();

                    var oleDbConnection = new OleDbConnection(Global.connString);

                    var update = new OleDbCommand("DELETE FROM Users WHERE ID = " + id + "", oleDbConnection);

                    oleDbConnection.Open();

                    update.ExecuteNonQuery();
                    oleDbConnection.Close();
                    var addRemoveAndUpdate = new AddandRemoveUser();
                    Close();
                    addRemoveAndUpdate.Show();
                }
            }
        }
示例#3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string Naam, Surname, userName;
            int    passWord;
            bool   isAdmin = false;

            if (rdbAdminYes.Checked)
            {
                isAdmin = true;
            }
            else if (rdbAdminNo.Checked)
            {
                isAdmin = false;
            }

            if (!Validation.EmployeeName(txtName.Text))
            {
                lblNaam.ForeColor = Color.Red;
            }
            else
            {
                lblNaam.ForeColor = Color.Black;
            }

            if (!Validation.EmployeeSurname(txtSurname.Text))
            {
                lblSurname.ForeColor = Color.Red;
            }
            else
            {
                lblSurname.ForeColor = Color.Black;
            }
            var oleDbConnection = new OleDbConnection(Global.connString);

            if (Validation.EmployeeName(txtName.Text) && Validation.EmployeeSurname(txtSurname.Text))
            {
                Naam     = txtName.Text;
                Surname  = txtSurname.Text;
                userName = Naam.Substring(0, 1) + Surname.Substring(0, 3);
                passWord = passRandom.Next(1000, 9999);
                oleDbConnection.Open();
                var myCommand = new OleDbCommand();
                myCommand.Connection  = oleDbConnection;
                myCommand.CommandText =
                    "INSERT INTO Users (Employee_Name,Employee_Surname,Employee_Id,Admin_rights,Employee_Password) Values ('" +
                    Naam + "','" + Surname + "','" + userName + "'," + isAdmin + "," + passWord + ")";
                myCommand.ExecuteNonQuery();
                MessageBox.Show("Data inserted successfully", "Inserted Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
                oleDbConnection.Close();

                Hide();
                var form = new AddandRemoveUser();
                form.Show();
            }
            else
            {
                MessageBox.Show("Please enter values into all field", "Error in field", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
示例#4
0
        private void addAndRemoveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var userAdd = new AddandRemoveUser();

            userAdd.StartPosition = FormStartPosition.CenterScreen;
            userAdd.MdiParent     = this;
            userAdd.Show();
        }
示例#5
0
        private void button1_Click(object sender, EventArgs e)
        {
            string userName;
            string passWord;
            //int admin = 0;
            //if (rdbAdminYes.Checked)
            //{
            //     admin = -1 ;
            //}

            var oleDbConnection = new OleDbConnection(Global.connString);

            if (txtNaam.Text != "" && txtSurname.Text != "")
            {
                Naam     = txtNaam.Text;
                Surname  = txtSurname.Text;
                userName = Naam.Substring(0, 1) + Surname.Substring(0, 3);
                Random passRandom = new Random();
                passWord = (passRandom.Next(1000, 9000)).ToString();
                oleDbConnection.Open();
                var myCommand = new OleDbCommand();
                myCommand.Connection  = oleDbConnection;
                myCommand.CommandText =
                    "INSERT INTO Users (Employee_Name,Employee_Surname,Employee_Id,Admin_rights) values('" +
                    Naam + "','" + Surname + "','" + userName + "'," + rdbAdminYes.Checked + ")";

                myCommand.ExecuteNonQuery();
                MessageBox.Show("Data inserted successfully");
                oleDbConnection.Close();

                Hide();
                AddandRemoveUser form = new AddandRemoveUser();
                form.Show();
            }
            else
            {
                MessageBox.Show("Invalid fields", "Invalid Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }