コード例 #1
0
ファイル: UserTestLogic.cs プロジェクト: jmontano86/TeamMegan
        //Objective: Find ItemPairs
        //Create list that pairs up items
        public static List <ItemPair> getItemPair(int testID, List <ItemPair> itemPairList)
        {
            // Get all items from the database

            List <Item> itemList    = new List <Item>();
            string      errorString = "Could not load items: ";

            ItemList.getItems(itemList, testID, ref errorString);

            // Pair up items

            for (int j = 0; j <= itemList.Count - 2; j++)
            {
                //// Loops through and pairs up item starting at count +1
                for (int i = j + 1; i <= itemList.Count - 1; i++)
                {
                    // Creates new itempair instance
                    ItemPair itemInsta = new ItemPair();
                    // Populates first parameter of itemPair
                    itemInsta.Item1 = itemList[j];
                    itemInsta.Item2 = itemList[i];
                    itemPairList.Add(itemInsta);
                }
            }
            return(itemPairList);
        }
コード例 #2
0
ファイル: UserTestLogic.cs プロジェクト: jmontano86/TeamMegan
        /// <summary>
        /// Randmizes the number that will be used to assign itempairs to populate radio buttons
        /// </summary>
        public static List <Item> itemToAssign(ItemPair itemPair, List <Item> itemToAssign, Test currentTest)
        {
            List <Item> randomItemList = new List <Item>();
            // Assign "Undecided" as an item
            Item unChoice = new Item(0, "Undecided", itemPair.Item1.TestID);

            //Updated for Custom Test Presentation
            //If the custom test has the shuffle option selected, shuffle the options. JDM
            if (currentTest.Shuffle == 1)
            {
                // Generate random number
                Random rndNum = new Random();
                // Assigns rndNum to itemPair
                randomItemList.Add(itemPair.Item1);
                randomItemList.Add(itemPair.Item2);
                randomItemList.Add(unChoice);
                // items to assign
                // puts the itempair in random order
                while (randomItemList.Count > 0)
                {
                    int rndNumAssign = rndNum.Next(0, randomItemList.Count);
                    itemToAssign.Add(randomItemList[rndNumAssign]);
                    randomItemList.RemoveAt(rndNumAssign);
                }
            }
            else
            {
                itemToAssign.Add(itemPair.Item1);
                itemToAssign.Add(itemPair.Item2);
                itemToAssign.Add(unChoice);
            }
            return(itemToAssign);
        }
コード例 #3
0
ファイル: UserTestLogic.cs プロジェクト: jmontano86/TeamMegan
        // Check to see if the user
        public static bool userTookTest(UserClass currentUser, ItemPair itemPair)
        {
            List <TestSession> currentTestSessions = new List <TestSession>();
            List <Test>        testList            = new List <Test>();
            bool   alreadyTookTest = false;
            int    itemID          = 0;
            string errorStuff      = "Error getting test sessions";

            // Get Test ID but needs item id first
            itemID = itemPair.Item1.ItemID;
            // Grab Existing Test Sessions
            TestSessionDB.GetTestSessions(currentTestSessions, ref errorStuff);
            // Get list of tests
            int testID = 1;

            foreach (var currentTestSession in currentTestSessions)
            {
                if (currentTestSession.intTestID == testID && currentTestSession.intUserID == currentUser.intUserID)
                {
                    alreadyTookTest = true;
                }
            }
            return(alreadyTookTest);
        }
コード例 #4
0
        //Programmer: Jeremiah Montano
        //Date: November 11, 2018
        //Summary: Get list of ItemPairs for Custom Comparison
        public List <ItemPair> GetCustomItemPairs(int intTestID)
        {
            SqlConnection conn = DatabaseHelper.Connect();
            SqlCommand    cmd  = new SqlCommand("SPGetItemPairs", conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter(ITEMPAIRS_TESTID_COLUMN, intTestID));
            List <ItemPair> itemPairs = new List <ItemPair>();
            ItemPair        itemPair;

            try
            {
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    itemPair       = new ItemPair();
                    itemPair.Item1 = Item.getItem(Convert.ToInt32(reader[ITEMPAIRS_ITEMID1_COLUMN]));
                    itemPair.Item2 = Item.getItem(Convert.ToInt32(reader[ITEMPAIRS_ITEMID2_COLUMN]));

                    itemPairs.Add(itemPair);
                }
                return(itemPairs);
            }
            catch
            {
                return(null);
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }