//fills in degree info from server, stores data in global vars protected void fillDegreeInfo() { //clear previous data ReqIDNumberNeeded = new Dictionary<int, int>(); ReqIDClassesNeeded = new Dictionary<int, List<string>>(); introReqID = new List<int>(); mainReqID = new List<int>(); introNeeded = false; SqlDataReader rdr; //queries tbl_opt_req_relationship for all reqIDs for selected degree option string sql = "SELECT ReqID, IsIntroductory FROM wi.tbl_opt_req_relationship " + "WHERE OptionID = " + ddlOption.SelectedValue.ToString(); MyConnection.Open(); SqlCommand cmd = new SqlCommand(sql, MyConnection); rdr = cmd.ExecuteReader(); while (rdr.Read()) { int ReqID = Convert.ToInt32(rdr.GetValue(0)); bool isIntro = Convert.ToBoolean(rdr.GetValue(1)); if (isIntro) { introNeeded = true; introReqID.Add(ReqID); } else { mainReqID.Add(ReqID); } } rdr.Close(); MyConnection.Close(); //queries tbl_requirement number of classes needed for each reqID foreach (int ReqID in introReqID.Concat(mainReqID)) { sql = "SELECT NumRequired FROM wi.tbl_requirement " + "WHERE ReqID = @ReqID;"; cmd = new SqlCommand(sql, MyConnection); cmd.Parameters.Add("@ReqID", System.Data.SqlDbType.VarChar); cmd.Parameters["@ReqID"].Value = ReqID; MyConnection.Open(); rdr = cmd.ExecuteReader(); while (rdr.Read()) { ReqIDNumberNeeded[ReqID] = Convert.ToInt32(rdr.GetValue(0)); } rdr.Close(); MyConnection.Close(); //ensures ReqID entries with an empty list exist in ReqIdClassesNeeded ReqIDClassesNeeded[ReqID] = new List<string>(); } //queries tbl_req_course_relationship and loads all classes with same ReqID into Dictionary foreach (int ReqID in introReqID.Concat(mainReqID)) { sql = "SELECT CourseNumber FROM wi.tbl_req_course_relationship " + "WHERE ReqID = @ReqID;"; cmd = new SqlCommand(sql, MyConnection); cmd.Parameters.Add("@ReqID", System.Data.SqlDbType.VarChar); cmd.Parameters["@ReqID"].Value = ReqID; MyConnection.Open(); rdr = cmd.ExecuteReader(); while (rdr.Read()) { //adds each class for given ReqID ReqIDClassesNeeded[ReqID].Add(rdr.GetValue(0).ToString()); } rdr.Close(); MyConnection.Close(); } MyConnection.Close(); //allows you to make sure classes are actually added /* foreach (int ReqID in introReqID.Concat(mainReqID)) { resultsBox.Items.Add(new ListItem(ReqID.ToString(), "alal")); foreach(string cl in ReqIDClassesNeeded[ReqID]) { resultsBox.Items.Add(new ListItem(cl, cl)); } } */ }