public HighlightCollection<HighlightItem> Read() { HighlightCollection<HighlightItem> highlights = new HighlightCollection<HighlightItem>(); DbConnection.Open(); using (DbTransaction trans = DbConnection.BeginTransaction(System.Data.IsolationLevel.Serializable)) { using (DbDataAdapter adpt = Factory.CreateDataAdapter()) { using (DbCommand cmd = DbConnection.CreateCommand()) { cmd.Transaction = trans; cmd.CommandText = Constants.HIGHTLIGHTITEMS_SELECT_ALL; cmd.ExecuteNonQuery(); adpt.SelectCommand = cmd; using (DbCommandBuilder bld = Factory.CreateCommandBuilder()) { bld.DataAdapter = adpt; using (DataTable tbl = new DataTable()) { adpt.Fill(tbl); foreach (DataRow row in tbl.Rows) { HighlightItem item = new HighlightItem() { ID = int.Parse(row[0].ToString()), Pattern = row[1].ToString(), Order = int.Parse(row[2].ToString()), }; //HACK: System.Drawing.Color allows storing of the colour as one integer, gonna use this to populate DB and re-hydrate back in code. Easier! System.Drawing.Color tempCol = System.Drawing.Color.FromArgb(int.Parse(row[3].ToString())); Color tempCol2 = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B); item.ForeColour = tempCol2; tempCol = System.Drawing.Color.FromArgb(int.Parse(row[4].ToString())); tempCol2 = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B); item.BackColour = tempCol2; tempCol = System.Drawing.Color.FromArgb(int.Parse(row[5].ToString())); tempCol2 = Color.FromArgb(tempCol.A, tempCol.R, tempCol.G, tempCol.B); item.BorderColour = tempCol2; highlights.Add(item); } } } } } } DbConnection.Close(); return highlights; }
private void SortItems(HighlightItem item, ListSortDirection dir) { int? i = null; int? tmp = null; switch (dir) { case ListSortDirection.Ascending: i = ((HighlightCollection<HighlightItem>)this.listViewPatterns.DataContext).IndexOf(item); if (i != null && i > 0 && i < ((HighlightCollection<HighlightItem>)this.listViewPatterns.DataContext).Count) { tmp = item.Order; item.Order = ((HighlightItem)((HighlightCollection<HighlightItem>)this.listViewPatterns.DataContext)[i.Value - 1]).Order; ((HighlightItem)((HighlightCollection<HighlightItem>)this.listViewPatterns.DataContext)[i.Value - 1]).Order = tmp.Value; } break; case ListSortDirection.Descending: i = ((HighlightCollection<HighlightItem>)this.listViewPatterns.DataContext).IndexOf(item); if (i != null && i >= 0 && i < (((HighlightCollection<HighlightItem>)this.listViewPatterns.DataContext).Count - 1)) { tmp = item.Order; item.Order = ((HighlightItem)((HighlightCollection<HighlightItem>)this.listViewPatterns.DataContext)[i.Value + 1]).Order; ((HighlightItem)((HighlightCollection<HighlightItem>)this.listViewPatterns.DataContext)[i.Value + 1]).Order = tmp.Value; } break; default: break; } this.Sort(Constants.HIGHLIGHT_ITEM_SORT_HEADER, ListSortDirection.Descending); }
/// <summary> /// Gets the highlight item of a found piece of text /// </summary> /// <param name="line">The line of text to match</param> /// <returns></returns> private bool GetFoundHighlightItem(ref HighlightedItem item) { HighlightItem special = new HighlightItem(this.SearchText, Constants.DEFAULT_FORECOLOUR, Constants.DEFAULT_BACKCOLOUR); if (!string.IsNullOrEmpty(special.Pattern) && !string.IsNullOrEmpty(item.Text)) { if (item.Text == special.Pattern || _patternMatching.MatchPattern(item.Text, special.Pattern)) { item.Selected = true; return true; } else { item.Selected = false; return false; } } return false; }
protected void AddNewHighlightItem(string text, Color foreColour, Color backColour) { HighlightItem item = new HighlightItem(text, foreColour, backColour); item.Order = Patterns.Add(item); this.Sort(Constants.HIGHLIGHT_ITEM_SORT_HEADER, ListSortDirection.Descending); }