public static Database.Spec RoleThen(int id, DateTime when1, DateTime when2) { Database.AndSpec datefilter = new Database.AndSpec( new Database.SpecLE("startdate", when1), new Database.SpecGE("enddate", when2), new Database.OrSpec( new Database.SpecEQ("type", "prez"), new Database.SpecEQ("type", "sen"), new Database.SpecEQ("type", "rep")) ); if (id == -1) { return(datefilter); } return(new Database.AndSpec( new Database.SpecEQ("personid", id), datefilter)); }
public object GetVotes2(int start, int count, int year) { Database.Spec dateSpec = new Database.UserSpec("1"); if (count == -1) { if (year == -1) { year = DateTime.Now.Year; } string startDate = year + "-01-01"; string endDate = year + "-12-31"; dateSpec = new Database.AndSpec( new Database.SpecGE("votes.date", startDate), new Database.SpecLE("votes.date", endDate)); } string subjectJoin = ""; Database.Spec subjectSpec = new Database.UserSpec("1"); if (HttpContext.Current.Request["subject"] != null) { subjectJoin = " LEFT JOIN billindex ON votes.billsession=billindex.session and votes.billtype=billindex.type and votes.billnumber=billindex.number"; subjectSpec = new Database.AndSpec( new Database.SpecEQ("billindex.idx", "crs"), new Database.SpecEQ("billindex.value", HttpContext.Current.Request["subject"])); } string personvoteJoin = "", personvoteCols = ""; ArrayList people = new ArrayList(); string people_join_type = "LEFT"; if (HttpContext.Current.Request["person"] != null) { people.Add(int.Parse(HttpContext.Current.Request["person"])); if (HttpContext.Current.Request["person2"] != null) { people.Add(int.Parse(HttpContext.Current.Request["person2"])); } people_join_type = "INNER"; } else { foreach (string p in Login.GetMonitors()) { Monitor m = Monitor.FromString(p); if (m is PersonMonitor) { people.Add(((PersonMonitor)m).Person); } } } if (people.Count > 0) { personvoteJoin = " " + people_join_type + " JOIN people_votes ON votes.id = people_votes.voteid" + " AND " + new Database.SpecIn("people_votes.personid", people).ToString(); personvoteCols = ", people_votes.personid, people_votes.vote, people_votes.displayas"; } Database.Spec billSpec = new Database.UserSpec("1"); if (HttpContext.Current.Request["bill"] != null) { BillRef br = BillRef.FromID(HttpContext.Current.Request["bill"]); billSpec = new Database.AndSpec( new Database.SpecEQ("votes.billsession", br.Session), new Database.SpecEQ("votes.billtype", br.TypeCode), new Database.SpecEQ("votes.billnumber", br.Number)); dateSpec = new Database.UserSpec("1"); // must not filter } Table table = Util.Database.DBSelect("votes" + subjectJoin + personvoteJoin, "votes.id, votes.date, votes.description, votes.result" //+ ", billstatus.title" + ", votes.billsession, votes.billtype, votes.billnumber" + personvoteCols, dateSpec, new Database.SpecOrder("votes.date", false), (subjectJoin == "" && personvoteJoin == "") ? (Database.Spec) new Database.SpecOrder("votes.seq", false) : (Database.Spec) new Database.UserSpec("1"), new Database.UserSpec(HttpContext.Current.Request["chamber"] == null ? "1" : "votes.id LIKE '" + HttpContext.Current.Request["chamber"][0] + "%'"), subjectSpec, billSpec, new Database.SpecLimit(count, start - 1) ); if (personvoteJoin == "") { return(table); } // Collapse table rows. ArrayList ret = new ArrayList(); Hashtable row_hash = new Hashtable(); foreach (TableRow row in table) { string vid = (string)row["id"]; Hashtable v = (Hashtable)row_hash[vid]; if (v == null) { v = new Hashtable(row); row_hash[vid] = v; ret.Add(v); v["people_votes"] = new Hashtable(); } if (row["personid"] != null) // did the person vote in this vote { ((Hashtable)v["people_votes"])[row["personid"]] = new string[] { (string)row["vote"], (string)row["displayas"] } } ; } bool diffsonly = HttpContext.Current.Request["differences"] != null && HttpContext.Current.Request["differences"] == "1"; bool samesonly = HttpContext.Current.Request["differences"] != null && HttpContext.Current.Request["differences"] == "2"; ArrayList ret2 = new ArrayList(); foreach (Hashtable row in ret) { ArrayList votes = new ArrayList(); string[] v = null; bool diff = false; foreach (int pid in people) { string[] vv = (string[])((Hashtable)row["people_votes"])[pid]; if (v == null) { v = vv; } else if (vv != null && !v[0].Equals(vv[0])) { diff = true; } votes.Add(vv); } if (people.Count > 1 && diffsonly && !diff) { continue; } if (people.Count > 1 && samesonly && diff) { continue; } row.Remove("people_votes"); row["votes"] = votes; ret2.Add(row); } return(ret2); }