예제 #1
0
        //___________________________Deletes item(User or test) at the accepted key from the relevant table in db_________________________________________
        public bool DeleteSelectedItem(int key, bool delUser)
        {
            bool deleteSuccess = false;

            //__________________Deletes a User if delUser bool is true_________________________________
            if (delUser)
            {
                if (MessageBox.Show("This will permenantly delete User: "******" " + UserObjDictionary[key].Surname + ", as well as all Tests the user has created and all marks associated to the tests.", "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
                {
                    UserObjDictionary.Remove(key);
                    DatabaseUtilities.DeleteFromDB("Users", "userID", key);
                    deleteSuccess = true;
                }
            }
            //__________________Deletes a Test if delUser bool is false_________________________________
            else
            {
                if (MessageBox.Show("This will permenantly delete " + TestObjDictionary[key].TestName + ", as well as all Questions and Marks associated with the test.", "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
                {
                    TestObjDictionary.Remove(key);
                    DatabaseUtilities.DeleteFromDB("Tests", "testID", key);
                    deleteSuccess = true;
                }
            }
            return(deleteSuccess);
        }
예제 #2
0
 //____Async methods to populate all Properties needed for a tesst object, made async to run on a seperate thread for efficiency_________
 public async Task PopulateTests()
 {
     foreach (String nextLine in DatabaseUtilities.ReadDB(@"Tests"))
     {
         String[] singleTest = nextLine.Split('#');
         TestsDictionary.Add(int.Parse(singleTest[0]), singleTest[1]);
         TestObjDictionary.Add(int.Parse(singleTest[0]), (new TestObj {
             TestName = singleTest[1], NumberOfQuestions = int.Parse(singleTest[2]), UserID = int.Parse(singleTest[3])
         }));
         NewTestID = int.Parse(singleTest[0]);
     }
 }