}//end VentureSearchesExpert Repeater ClickEvent protected void btnSearchExperts_Click(object sender, EventArgs e)//a venture company searches experts { Debug.WriteLine("Entering btnSearchExperts_"); SelectedSkillsList = SelectSkills(); List <VentureSearchObj> ventureSkillSearch = new List <VentureSearchObj>(); List <VentureSearchObj> distinctTuIds = new List <VentureSearchObj>(); DataSet dsVentureSkillSearchResults = new DataSet("VentureSkillSearchResults"); int x = 0; lblSearchError.Text = " "; string txtTemp = txtFullName.Text.Replace(" ", String.Empty); //clear both repeaters rpVentureSearchResults.DataSource = null; rpExpertSearchResults.DataSource = null; rpVentureSearchResults.DataBind(); rpExpertSearchResults.DataBind(); if (!string.IsNullOrWhiteSpace(txtTemp) && Regex.IsMatch(txtTemp, "^[a-zA-Z]+$") == false) { lblSearchError.Text = "Illegal characters used. Please only use text in Search Experts by name."; } else if (SelectedSkillsList.Count == 0 && string.IsNullOrWhiteSpace(txtTemp)) { lblSearchError.Text = "Please search by skills, expert name or both."; } else if (SelectedSkillsList.Count == 0 && !string.IsNullOrWhiteSpace(txtTemp)) {//only get the expert with this name //we are searching for an expert that is close to the full name from the text box var names = txtFullName.Text.Split(' '); string firstName = ""; string lastName = ""; if (names.Length == 1) { firstName = names[0]; } else if (names.Length > 2) { firstName = names[0]; lastName = names[1]; } DataTable results = DbMethods.SearchExpertsByName(firstName, lastName); distinctTuIds = Data.CreateListFromTable <VentureSearchObj>(results); foreach (VentureSearchObj expert in distinctTuIds) { if (expert.Picture != null) { expert.image = d.ConvertToImage((byte[])expert.Picture);//returns string url } else {//in case expert's profile pic is null byte[] imageBytes; MemoryStream ms = new MemoryStream(); System.Drawing.Image img = System.Drawing.Image.FromFile("Images/TUOwls_logo.png"); img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); imageBytes = ms.ToArray(); expert.image = d.ConvertToImage(imageBytes); } } } else { //search experts by skills and expert name int skillGroupId = Convert.ToInt32(ddlSkillGroup.SelectedValue); if (skillGroupId == 0) //use a modified version of searchVenture that accomodats SkillGroupId of 0 { //The Search Portion of the CLick Event foreach (GvSearchObj gvObj in SelectedSkillsList) { DataSet results = DbMethods.SearchExpertsALG(gvObj.SkillName);//get search result of all experts that match the searched skillName if (results.Tables.Count == 0) { break; } else { DataTable resultTable = results.Tables[0].Copy(); resultTable.TableName = "Table " + x; resultTable.AcceptChanges(); dsVentureSkillSearchResults.Tables.Add(resultTable);//add search results of one skill to DataSet as DataTable x++; } }//END of the Search Portion of the CLick Event } else { foreach (GvSearchObj gvObj in SelectedSkillsList) { DataSet results = DbMethods.SearchExperts(gvObj.SkillName, skillGroupId); //get search result of all experts that match the searched skillName if (results.Tables.Count == 0) { break; } else { DataTable resultTable = results.Tables[0].Copy(); resultTable.TableName = "Table " + x; resultTable.AcceptChanges(); dsVentureSkillSearchResults.Tables.Add(resultTable); //add search results of one skill to DataSet as DataTable x++; } } //END of the Search Portion of the CLick Event } if (dsVentureSkillSearchResults.Tables.Count == 0) { lblSearchError.Text = "Your search query yeilded no results."; } else { //Add all tables into one table for (int z = 0; z < dsVentureSkillSearchResults.Tables.Count; z++) { dsVentureSkillSearchResults.Tables[0].Merge(dsVentureSkillSearchResults.Tables[z]); } //add to Mega List from first table in ds, b/c that has all merged tables ventureSkillSearch = Data.CreateListFromTable <VentureSearchObj>(dsVentureSkillSearchResults.Tables[0]); var temp = ventureSkillSearch.Select(o => o.TUID).Distinct(); //get all unique tuids foreach (var i in temp) { //add unique tuids to a new list distinctTuIds.Add(new VentureSearchObj { TUID = i.ToString() }); //only contains TUIDs } foreach (VentureSearchObj dtuid in distinctTuIds) { //loading each unique tuid with their skills into their object var newList = (from n in ventureSkillSearch where n.TUID.Equals(dtuid.TUID, StringComparison.OrdinalIgnoreCase) select n.SkillName).Distinct(); DataTable currentTUID = DbMethods.GetExpertInfo(dtuid.TUID).Tables[0]; //get that tuid's info and add all necessary data to the current object dtuid.Username = currentTUID.Rows[0][1].ToString(); dtuid.LastName = currentTUID.Rows[0][2].ToString(); dtuid.FirstName = currentTUID.Rows[0][3].ToString(); dtuid.Email = currentTUID.Rows[0][4].ToString(); if (!Convert.IsDBNull(currentTUID.Rows[0][11])) { dtuid.image = d.ConvertToImage((byte[])currentTUID.Rows[0][11]); //returns string url } else { //in case expert's profile pic is null byte[] imageBytes; MemoryStream ms = new MemoryStream(); System.Drawing.Image img = System.Drawing.Image.FromFile("TUOwls_logo.png"); img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); imageBytes = ms.ToArray(); dtuid.image = d.ConvertToImage(imageBytes); } foreach (var j in newList) { //add all skillNames associated with the distinct tuid into its SkillName list in VentureSearch obj dtuid.AllExpertSkills.Add(j.ToString()); dtuid.cdsAllExpertSkills += j.ToString() + " "; } } //The Comparison Portion of the CLick Event using (var gvSO = SelectedSkillsList.GetEnumerator()) using (var dtuid = distinctTuIds.GetEnumerator()) { while (dtuid.MoveNext()) { var dtuidItem = dtuid.Current; while (gvSO.MoveNext()) { var gvSoItem = gvSO.Current; foreach (var k in dtuidItem.AllExpertSkills) { if (k.ToString().Equals(gvSoItem.SkillName, StringComparison.OrdinalIgnoreCase)) { dtuidItem.ExpertRank = dtuidItem.ExpertRank + 1; } } } } }//END of the Comparison Portion of the CLick Event } }//end else just searching by name if (distinctTuIds.Count != 0) { List <VentureSearchObj> SortedList = distinctTuIds.OrderBy(o => o.ExpertRank).ToList(); this.rpExpertSearchResults.DataSource = SortedList; this.rpExpertSearchResults.DataBind(); } ClearControls(); txtFullName.Text = string.Empty;//clear name textxBox }//end btnSearchExperts_Click