CinderellaMGS.SQL_Queries.MatchMakerProcess C# (CSharp) 메소드

MatchMakerProcess() 공개 메소드

MatchMaker Process begins here! This Process is what currently will match cinderellas and fairygodmothers and also change ther statuses to the appropriate setting. It is only called in the server form
public MatchMakerProcess ( ) : void
리턴 void
        public void MatchMakerProcess()
        {
            if (GlobalVar.masterPairSwitch == true)
            {
                //List for available godmothers
                List<int> gML = new List<int>();
                //List for Waiting Cinderellas
                List<int> cL = new List<int>();
                //
                //get godmother ids
                //Forms a dataset called gmds from the data from the sql statement getGodmotherStatus
                //It requires first a status then what its ordering by and finally a bool value
                //to see if filtering by day
                DataSet gmds = getGodmotherStatus("Available", "transID", false);
                //a loop to loop through the rows of the dataset gmds
                foreach (DataRow dr in gmds.Tables[0].Rows)
                {
                    //This will add the fairyGodmotherID at the current row of the dataset gmds
                    //to the list gML
                    gML.Add(int.Parse(dr["fairyGodmotherID"].ToString()));
                }
                //get cinderella ids
                //Forms a dataset called cds from the data from the sql statement getCinderellaStatus
                //It requires first a status then what its ordering by
                DataSet cds = getCinderellaStatus("Waiting", "transID");
                //a loop to loop through the rows of the dataset cds
                foreach (DataRow dr in cds.Tables[0].Rows)
                {
                    //This will add the cinderellaID at the current row of the dataset cds
                    //to the list cL
                    cL.Add(int.Parse(dr["cinderellaID"].ToString()));
                }
                //check match
                //create two int to track pairing of the two lists
                //gML and cL
                //tracks pairs through loop
                int numOfPairsCount = 0;
                //sets limit to smallest list
                int countBackPairs = 0;
                //find smalliest list between gML and cL
                //first look to see if cL is the shortest of the two lists
                if (gML.Count > cL.Count)
                {
                    //if cL is the shortest then set countBackPairs to its item count
                    countBackPairs = cL.Count;
                }
                else
                {
                    //if cL is not the shortest list then
                    //set countBackPairs equal to gML item count
                    countBackPairs = gML.Count;
                }
                //set pairings in db
                //This while loop will happen as long as gML and cL have counts greater then 0
                while (gML.Count > 0 && cL.Count > 0)
                {
                    //only enters this if statement when countBackPairs is greater then numOfPairsCount
                    if (countBackPairs > numOfPairsCount)
                    {
                        //temps
                        //holds the current gmID
                        string gmidTemp;
                        //holds the current cID
                        string cidTemp;
                        //takes the ID from list gML at pisition numOfPairsCount and adds to temp
                        gmidTemp = gML[numOfPairsCount].ToString();
                        //takes the ID from list cL at pisition numOfPairsCount and adds to temp
                        cidTemp = cL[numOfPairsCount].ToString();
                        //
                        //set paired status
                        //Uses the method setStatus to insert the updated status of
                        //godmother with the id in the gmidtemp
                        setStatus(gmidTemp, "Paired", false, true);
                        //Uses the method setStatus to insert the updated status of
                        //cinderella with the id in the cidtemp
                        setStatus(cidTemp, "Paired", true, true);
                        //add pairings to paired table
                        setPairing(gmidTemp, cidTemp);
                        //increment count of pairs
                        numOfPairsCount++;
                    }
                    else
                    {
                        //when countBackPairs is no longer greater then numOfPairsCount then break the loop
                        break;
                    }
                }
            }//end match maker
        }