Beispiel #1
0
        private void CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if ((e.ColumnIndex == 1) || (e.ColumnIndex == 2)) //text1 & text2
            {
                return;
            }
            CompareEntry entry = list[e.RowIndex];

            switch (entry.CompareResult)
            {
            case CompareEntry.CompareRes.Diff:
                e.CellStyle.ForeColor = Color.Red;
                break;

            case CompareEntry.CompareRes.NewIn1:
                e.CellStyle.ForeColor = Color.Blue;
                break;

            case CompareEntry.CompareRes.NewIn2:
                e.CellStyle.ForeColor = Color.Orange;
                break;

            case CompareEntry.CompareRes.Equal:
            default:
                break;
            }
        }
Beispiel #2
0
        private void BuildList()
        {
            if ((cliloc1 == null) || (cliloc2 == null))
            {
                return;
            }
            for (int i = 0; i < cliloc1.Entries.Count; i++)
            {
                CompareEntry entry = new CompareEntry();
                entry.CompareResult = CompareEntry.CompareRes.NewIn1;
                StringEntry entr = cliloc1.Entries[i];
                entry.Number = entr.Number;
                entry.Text1  = entr.Text;
                entry.Text2  = "";
                comparelist.Add(entry.Number, entry);
            }
            for (int i = 0; i < cliloc2.Entries.Count; i++)
            {
                StringEntry entr = cliloc2.Entries[i];
                if (comparelist.ContainsKey(entr.Number))
                {
                    CompareEntry entr1 = comparelist[entr.Number];
                    entr1.Text2 = entr.Text;
                    if (entr1.Text1 != entr.Text)
                    {
                        entr1.CompareResult = CompareEntry.CompareRes.Diff;
                    }
                    else
                    {
                        entr1.CompareResult = CompareEntry.CompareRes.Equal;
                    }
                }
                else
                {
                    CompareEntry entry = new CompareEntry();
                    entry.CompareResult = CompareEntry.CompareRes.NewIn2;
                    entry.Number        = entr.Number;
                    entry.Text1         = "";
                    entry.Text2         = entr.Text;
                    comparelist.Add(entry.Number, entry);
                }
            }
            list = new List <CompareEntry>();

            foreach (KeyValuePair <int, CompareEntry> key in comparelist)
            {
                if (ShowOnlyDiff)
                {
                    if (key.Value.CompareResult == CompareEntry.CompareRes.Equal)
                    {
                        continue;
                    }
                }
                list.Add(key.Value);
            }
            switch (sortcolumn)
            {
            case 0: list.Sort(new NumberComparer(sortorder == SortOrder.Descending)); break;

            case 1: list.Sort(new TextComparer1(sortorder == SortOrder.Descending)); break;

            case 2: list.Sort(new TextComparer2(sortorder == SortOrder.Descending)); break;

            case 3: list.Sort(new FlagComparer(sortorder == SortOrder.Descending)); break;
            }
            comparelist.Clear();
            source                   = new BindingSource();
            source.DataSource        = list;
            dataGridView1.DataSource = source;

            if (dataGridView1.Columns.Count > 0)
            {
                dataGridView1.Columns[0].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
                dataGridView1.Columns[0].Width = 60;
                dataGridView1.Columns[1].HeaderCell.SortGlyphDirection = SortOrder.None;
                dataGridView1.Columns[2].HeaderCell.SortGlyphDirection = SortOrder.None;
                dataGridView1.Columns[3].HeaderCell.SortGlyphDirection = SortOrder.None;
                dataGridView1.Columns[3].Width = 105;
            }
            dataGridView1.Invalidate();
        }