protected DataTable GetPatientDataTable(int staff_id) { Staff staff = StaffDB.GetByID(staff_id); Hashtable staffHashOriginal = StaffDB.GetAllInHashtable(true, true, true, false); Hashtable staffHash = new Hashtable(); foreach (Staff s in staffHashOriginal.Values) { staffHash[s.Person.PersonID] = s; } DataTable tbl = PatientDB.GetPatientsAddedByStaff(staff_id, GetFromDate(), GetToDate()); // sort by most common referrer tbl.Columns.Add("referrer_count", typeof(int)); tbl.Columns.Add("added_by_name", typeof(String)); for (int i = 0; i < tbl.Rows.Count; i++) { int refCount = 0; if (tbl.Rows[i]["referrer_info_referrer_id"] != DBNull.Value) { for (int j = 0; j < tbl.Rows.Count; j++) { if (tbl.Rows[j]["referrer_info_referrer_id"] != DBNull.Value && Convert.ToInt32(tbl.Rows[j]["referrer_info_referrer_id"]) == Convert.ToInt32(tbl.Rows[i]["referrer_info_referrer_id"])) { refCount++; } } } tbl.Rows[i]["referrer_count"] = refCount; tbl.Rows[i]["added_by_name"] = staff.Person.FullnameWithoutMiddlename; } tbl.DefaultView.Sort = "referrer_count DESC, referrer_info_surname, referrer_info_firstname, surname, firstname, middlename"; tbl = tbl.DefaultView.ToTable(); return(tbl); }