//GetPairedCinderellas //gets up to 15 paired cinderellas //Input: a List to hold the paired cinderellas, and information pulled down from the DB //Output: the list has been filled with at most 15 paired cinderellas //precondition: the DB is in a correct and valid state //postcondition: the DB is stil in a correct and valid state, and no suplicates have been added to the list public void GetPairedCinderellas(ref List<CinderellaClass> PairedCinderella) { //sets up the query to get at most 15 paired cinderellas string query = sql.CinderellasList(15, 3); //sets up the connection and the sqlDataReader SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); SqlCommand command = new SqlCommand(query, conn); conn.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { //read from DB into cinderella class CinderellaClass cinder = new CinderellaClass(reader.GetString(1), reader.GetString(2), reader.GetInt32(0), reader.GetDateTime(3)); bool canInsert = true; foreach (CinderellaClass cinderella in PairedCinderella) {//checks to see if the paired cinderella is already in the list and if not add them to it if (cinderella.getCinderellaID() == cinder.getCinderellaID()) { canInsert = false; } } if (canInsert) { PairedCinderella.Add(cinder); } } //clean up reader.Close(); conn.Close(); }
//GetCinderellas //Fills a list with the cindererllas from the DB //Input: a list to hold the cinderellas, and information pulled down from the DB //Output: the list of cinderellas has been filled with at most 15 cinderellas //precondition: the DB is in a correct and valid state //postcondition: the DB is still in a correct and valid state,a nd no duplicate cinderellas ahve been added to the list public void GetCinderellas(ref List<CinderellaClass> Cinderella) { //sets up the query to get 15 cinderellas that have the correct status string query = sql.CinderellasList(15,2); //sets up the sql connection and sqlDataReader SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); SqlCommand command = new SqlCommand(query, conn); conn.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { //read from DB into cinderella class CinderellaClass cinder = new CinderellaClass(reader.GetString(1), reader.GetString(2), reader.GetInt32(0), Convert.ToDateTime(reader.GetDateTime(3))); //check to see if the cinderella is already in the list bool cinderellaExists = false; foreach (CinderellaClass cinderellaToAdd in Cinderella) { if (cinderellaToAdd.getCinderellaID() == cinder.getCinderellaID()) { cinderellaExists = true; } } //if the cinderella doesnt exist add them if (cinderellaExists == false) { Cinderella.Add(cinder); } } //clean up reader.Close(); conn.Close(); }
//GetCinderellas //Fills a list with the cindererllas from the database. //Input: the list of cindererllas that have been through matchmaking before, a list to fill with cindererllas, and the amount to get //Output: updated list of cindererllas pulled down from the db //precondition: all inputs are valid, and the database is functioning correctly and the data in it has no errors //postcondition: the queue is generated correctly void GetCinderellas(ref List<CinderellaClass> Cinderella, int count, ref List<int> oldCinderellas) { //sets up the query to get 15 cinderellas that have the correct status string query = sql.CinderellasList(15, 2); //sets up the sql connection and sqlDataReader SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); SqlCommand command = new SqlCommand(query, conn); conn.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { //read from DB into cinderella class CinderellaClass cinder = new CinderellaClass(reader.GetString(1), reader.GetString(2), reader.GetInt32(0), Convert.ToDateTime(reader.GetDateTime(3))); //check to see if the cinderella is already in the list bool cinderellaExists = false; bool priority = false; foreach (CinderellaClass cinderellaToAdd in Cinderella) { if (cinderellaToAdd.getCinderellaID() == cinder.getCinderellaID()) { cinderellaExists = true; } } if (cinderellaExists == false) //cinderella doesnt exist, add to list { if (count < 15) { //check to see if the cinderella has been through before foreach (int id in oldCinderellas) { if (cinder.getCinderellaID() == id) { priority = true; } } if (priority) //cinderella has been through before, she gets added to the front of the queue { Cinderella.Insert(0, cinder); } else //cinderella has not been through before, added normally { Cinderella.Add(cinder); } } count += 1; } } //clean up reader.Close(); conn.Close(); }