private void recentChangesListView_SelectedIndexChanged(object sender, EventArgs e) { PageListViewItem selectedItem = recentChangesListView.SelectedItems.Count > 0 ? (PageListViewItem)recentChangesListView.SelectedItems[0] : null; if (selectedItem != null) { string page = selectedItem.SubItems[2].Text; detailsListView.BeginUpdate(); detailsListView.SuspendLayout(); detailsListView.Items.Clear(); using (SQLiteCommand command = new SQLiteCommand(_connection)) { SQLiteParameter pageValue = new SQLiteParameter("@page"); pageValue.Value = selectedItem.Page; command.Parameters.Add(pageValue); SQLiteParameter namespaceValue = new SQLiteParameter("@namespace"); namespaceValue.Value = selectedItem.Namespace; command.Parameters.Add(namespaceValue); command.CommandText = @"SELECT timestamp, flags, size, user, summary, id, oldid FROM [edits] WHERE page=@page AND namespace=@namespace ORDER by timestamp DESC"; using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { int size; int.TryParse(reader[2].ToString(), out size); int flags; int.TryParse(reader[1].ToString(), out flags); long diff; long.TryParse(reader[5].ToString(), out diff); long oldid; long.TryParse(reader[6].ToString(), out oldid); EditListViewItem item = new EditListViewItem(reader[0].ToString(), WikiEdit.FlagsToString((EditFlags)flags), size, reader[3].ToString(), reader[4].ToString(), diff, oldid); detailsListView.Items.Add(item); } detailsListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); } } detailsListView.ResumeLayout(); detailsListView.EndUpdate(); } }
void UpdateViews() { if (InvokeRequired) { BeginInvoke(new StringParameterDelegate(UpdateViews), new object[] {}); } else { EditFlags mask = EditFlags.None; if (reviewedEditsToolStripMenuItem.Checked) { mask |= EditFlags.Unreviewed; } if (newArticlesToolStripMenuItem.Checked) { mask |= EditFlags.New; } if (minorEditsToolStripMenuItem.Checked) { mask |= EditFlags.Minor; } if (botEditsToolStripMenuItem.Checked) { mask |= EditFlags.Bot; } EditFlags onlyMask = EditFlags.None; if (onlyNewToolStripMenuItem.Checked) { mask |= EditFlags.New; onlyMask |= EditFlags.New; } if (onlyBotEditToolStripMenuItem.Checked) { mask |= EditFlags.Bot; onlyMask |= EditFlags.Bot; } if (onlyMinToolStripMenuItem.Checked) { mask |= EditFlags.Minor; onlyMask |= EditFlags.Minor; } if (onlyUnreviewedEditsToolStripMenuItem.Checked) { mask |= EditFlags.Unreviewed; onlyMask |= EditFlags.Unreviewed; } recentChangesListView.BeginUpdate(); recentChangesListView.Items.Clear(); recentChangesListView.Groups.Clear(); using (SQLiteCommand command = new SQLiteCommand(_connection)) { SQLiteParameter maskValue = new SQLiteParameter("@mask"); maskValue.Value = (int)mask; command.Parameters.Add(maskValue); SQLiteParameter onlyMaskValue = new SQLiteParameter("@onlyMask"); onlyMaskValue.Value = (int)onlyMask; command.Parameters.Add(onlyMaskValue); command.CommandText = @"SELECT max(timestamp), sum(flags & 4), page, count(timestamp), sum(size), group_concat(user), max(id), min(oldid), namespace, (namespace || ':' || page) AS name FROM [edits] WHERE (flags & @onlyMask) == @onlyMask AND (flags | @mask) == @mask GROUP BY name ORDER by max(timestamp) DESC"; using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { DateTime time = DateTime.Parse(reader[0].ToString()); string day = time.ToLongDateString(); string t = time.ToShortTimeString(); bool found = false; ListViewGroup group = null; for (int i = 0; i < recentChangesListView.Groups.Count; ++i) { if (recentChangesListView.Groups[i].Header == day) { group = recentChangesListView.Groups[i]; found = true; break; } } if (!found) { group = new ListViewGroup(day); recentChangesListView.Groups.Add(group); } string[] authorsList = reader[5].ToString().Split(new char[] { ',' }); string authors = string.Join(", ", authorsList.Distinct().ToArray()); int size; int.TryParse(reader[4].ToString(), out size); int flags; int.TryParse(reader[1].ToString(), out flags); int changes; int.TryParse(reader[3].ToString(), out changes); long diff; long.TryParse(reader[6].ToString(), out diff); long oldId; long.TryParse(reader[7].ToString(), out oldId); int nm; int.TryParse(reader[8].ToString(), out nm); PageListViewItem item = new PageListViewItem(t, WikiEdit.FlagsToString((EditFlags)flags), size, authors, changes, diff, oldId, reader[2].ToString(), nm); item.Group = group; recentChangesListView.Items.Add(item); } } } recentChangesListView.EndUpdate(); watchListView.BeginUpdate(); watchListView.Items.Clear(); watchListView.Groups.Clear(); using (SQLiteCommand command = new SQLiteCommand(_connection)) { command.CommandText = @"SELECT max(timestamp), sum(flags & 4), edits.page, count(timestamp), sum(size), group_concat(user), max(edits.id), min(oldid), edits.namespace, (edits.namespace || ':' || edits.page) AS name FROM [edits], [watched_pages] WHERE edits.page = watched_pages.page AND (edits.namespace=watched_pages.namespace OR edits.namespace=watched_pages.namespace + 1) GROUP BY name ORDER by max(timestamp) DESC"; using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { DateTime time = DateTime.Parse(reader[0].ToString()); string day = time.ToLongDateString(); string t = time.ToShortTimeString(); bool found = false; ListViewGroup group = null; for (int i = 0; i < watchListView.Groups.Count; ++i) { if (watchListView.Groups[i].Header == day) { group = watchListView.Groups[i]; found = true; break; } } if (!found) { group = new ListViewGroup(day); watchListView.Groups.Add(group); } string[] authorsList = reader[5].ToString().Split(new char[] { ',' }); string authors = string.Join(", ", authorsList.Distinct().ToArray()); int size; int.TryParse(reader[4].ToString(), out size); int flags; int.TryParse(reader[1].ToString(), out flags); int changes; int.TryParse(reader[3].ToString(), out changes); long diff; long.TryParse(reader[6].ToString(), out diff); long oldId; long.TryParse(reader[7].ToString(), out oldId); int nm; int.TryParse(reader[8].ToString(), out nm); PageListViewItem item = new PageListViewItem(t, WikiEdit.FlagsToString((EditFlags)flags), size, authors, changes, diff, oldId, reader[2].ToString(), nm); item.Group = group; watchListView.Items.Add(item); } } } watchListView.EndUpdate(); } }