Exemplo n.º 1
0
        //might change to archive
        private void archive_Click(object sender, EventArgs e)
        {
            bool     containgroup = false;
            bool     containfile  = false;
            DateTime prevLockDate = new DateTime();

            if (vflag.Text == "A")
            {
                MessageBox.Show("User had been Archived.");
            }
            else if (statusDate.Text == null || statusDate.Text == "" || statusDate.Text == "NULL")
            {
                MessageBox.Show("Account need to be lock for more than 7 days before able to be deleted");
            }
            else
            {
                prevLockDate = DateTime.ParseExact(statusDate.Text, "dd'/'MM'/'yyyy HH:mm:ss", null);
                //check if the previous lock date has already pass 7 days
                if (prevLockDate >= DateTime.Now.AddDays(-7) || vflag.Text != "L")
                {
                    MessageBox.Show("Account need to be lock for more than 7 days before able to be deleted");
                }
                else
                {
                    //check existing group Ownership
                    using (MySqlConnection con = new MySqlConnection("server = 35.240.129.112; user id = asguarduser; database = da_schema"))
                    {
                        con.Open();
                        String       query   = "SELECT * FROM groupInfo where groupCreatorID = @groupcreatorID";
                        MySqlCommand command = new MySqlCommand(query, con);
                        command.Parameters.AddWithValue("@groupcreatorID", AdminSession.userid);
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (reader.GetString(reader.GetOrdinal("groupCreatorID")) != null)
                                {
                                    //
                                    containgroup = true;
                                }
                            }

                            if (reader != null)
                            {
                                reader.Close();
                            }
                        }
                    }
                    //check existing file Ownership
                    using (MySqlConnection con = new MySqlConnection("server = 35.240.129.112; user id = asguarduser; database = da_schema"))
                    {
                        con.Open();
                        String       query   = "SELECT * FROM fileInfo where fileOwnerID = @fileOwnerID";
                        MySqlCommand command = new MySqlCommand(query, con);
                        command.Parameters.AddWithValue("@fileOwnerID", AdminSession.userid);
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (reader.GetString(reader.GetOrdinal("fileOwnerID")) != null)
                                {
                                    //contain currently Own a file
                                    containfile = true;
                                }
                            }

                            if (reader != null)
                            {
                                reader.Close();
                            }
                        }
                    }
                    //if they are both false run archive
                    if (containgroup == false && containfile == false)
                    {
                        DialogResult dialogResult = MessageBox.Show("Archive the account? You will not be able to unlock it.", "Are you sure?", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            using (MySqlConnection con = new MySqlConnection("server = 35.240.129.112; user id = asguarduser; database = da_schema"))
                            {
                                con.Open();
                                //archive userInfo
                                string       archiveaccountQuery = "UPDATE Userinfo set verificationflag=@vflag, statusDate=@statusDate where userid = @userid";
                                MySqlCommand archiveaccount      = new MySqlCommand(archiveaccountQuery, con);
                                archiveaccount.Parameters.AddWithValue("@vflag", "A");
                                archiveaccount.Parameters.AddWithValue("@statusDate", DateTime.Now.ToString("dd'/'MM'/'yyyy HH:mm:ss"));
                                archiveaccount.Parameters.AddWithValue("@userid", AdminSession.userid);
                                archiveaccount.ExecuteNonQuery();
                                //may add deletion for other info relating to the user
                                dblog.Log("Account status changed(L -> A) by Admin", "Accounts", Logininfo.userid, Logininfo.email);
                                dblog.Log("User is Archived:" + AdminSession.userid, "Accounts", Logininfo.userid, Logininfo.email);

                                string       deleteGroupUserQuery = "Delete FROM groupUsers where userID = @userid";
                                MySqlCommand deleteGroupUser      = new MySqlCommand(deleteGroupUserQuery, con);
                                deleteGroupUser.Parameters.AddWithValue("@userid", AdminSession.userid);
                                deleteGroupUser.ExecuteNonQuery();

                                string       deletefileUserQuery      = "Delete FROM userFilePermissions where userID = @userid";
                                MySqlCommand deletefileUserPermission = new MySqlCommand(deletefileUserQuery, con);
                                deletefileUserPermission.Parameters.AddWithValue("@userid", AdminSession.userid);
                                deletefileUserPermission.ExecuteNonQuery();

                                MessageBox.Show("User have been archived.");
                                AccountDetails accountdetails = new AccountDetails();
                                accountdetails.Show();
                                Hide();
                            }
                        }
                    }
                    else
                    {
                        if (containgroup && containfile)
                        {
                            MessageBox.Show("User contains ownership of both files and group. Please request to change ownership before archiving");
                        }
                        else if (containgroup)
                        {
                            MessageBox.Show("User contains ownership of group. Please request to change ownership of group before archiving");
                        }
                        else if (containfile)
                        {
                            MessageBox.Show("User contains ownership of files. Please request to change ownership of file before archiving");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        //accountgrid buttons
        private void dataAccountGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            //check if the column is a button column and check if the column is where the button is when click
            //column 7 is Details button link to a more comprehensive information about the user
            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0 && e.ColumnIndex == 6)
            {
                DataGridViewRow row = new DataGridViewRow();
                row = dataAccountGrid.Rows[e.RowIndex];
                //TODO - Button Clicked - Execute Code Here
                //MessageBox.Show(row.Cells[0].Value.ToString());

                string userid = row.Cells[0].Value.ToString();

                //mainly for admin to know which account to properly check on to get a clearer information
                AdminSession.userid = userid;
                AccountDetails accountdetails = new AccountDetails();
                accountdetails.Show();
                Hide();
            }

            //check if the column is a button column and check if the column is where the button is when click
            //column 8 is unlock and lock button
            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0 && e.ColumnIndex == 7)
            {
                DataGridViewRow row = new DataGridViewRow();
                row = dataAccountGrid.Rows[e.RowIndex];
                //TODO - Button Clicked - Execute Code Here
                //MessageBox.Show(row.Cells[0].Value.ToString());

                string userid = row.Cells[0].Value.ToString();
                if (userid == "1")
                {
                    //admin is not application to status changes mainly for testting purpose
                    //string vflag = row.Cells[6].Value.ToString();
                    //if (vflag == "L")
                    //{
                    //    updateAccountstatus(userid, vflag);
                    //    MessageBox.Show("Account status of user have been updated!");
                    //    dataAccountGrid.Rows.Clear();
                    //    dataAccountGrid.Refresh();
                    //    retrieveAccounts();
                    //}
                    //else if (vflag == "F")
                    //{
                    //    MessageBox.Show(row.Cells[1].Value.ToString() + "user have not verify");
                    //}
                    //else if (vflag == "T")
                    //{
                    //    updateAccountstatus(userid, vflag);
                    //    MessageBox.Show("Account status of user have been updated!");
                    //    dataAccountGrid.Rows.Clear();
                    //    dataAccountGrid.Refresh();
                    //    retrieveAccounts();
                    //}
                }
                else
                {
                    string vflag = row.Cells[5].Value.ToString();
                    if (vflag == "L")
                    {
                        updateAccountstatus(userid, vflag);
                        MessageBox.Show("Account status of user have been updated!");
                        dataAccountGrid.Rows.Clear();
                        dataAccountGrid.Refresh();
                        retrieveAccounts();
                        dblog.Log("Account status changed(L -> T) by Admin", "Accounts", Logininfo.userid, Logininfo.email);
                    }
                    else if (vflag == "F")
                    {
                        MessageBox.Show(row.Cells[1].Value.ToString() + "user have not verify");
                    }
                    else if (vflag == "T")
                    {
                        updateAccountstatus(userid, vflag);
                        MessageBox.Show("Account status of user have been updated!");
                        dataAccountGrid.Rows.Clear();
                        dataAccountGrid.Refresh();
                        retrieveAccounts();
                        dblog.Log("Account status changed(T -> L) by Admin", "Accounts", Logininfo.userid, Logininfo.email);
                    }
                }
            }
        }