Пример #1
0
        public string[] GetValues()
        {
            int propCount = _comparable.GetActivePropertiesCount();

            string[] values = new string[propCount];
            int      i      = 0;

            foreach (EntityProperty prop in _properties)
            {
                if (prop.Active)
                {
                    values[i] = prop.GetStringValue();
                    i++;
                }
            }

            return(values);
        }
Пример #2
0
        public void RefreshGrid()
        {
            _muteEvents = true;
            ComparisonsDGV.Rows.Clear();

            if (_left.Entities.Count == 0)
            {
                ComparisonsDGV.ColumnCount = 0;
                //MessageBox.Show("No \"Left\" entities to compare !");

                return;
            }
            else if (_left.Entities[0].Properties.Count == 0)
            {
                ComparisonsDGV.ColumnCount = 0;
                //MessageBox.Show("No \"Left\" properties to compare !");

                return;
            }

            if (_right.Entities.Count == 0)
            {
                ComparisonsDGV.ColumnCount = 0;
                MessageBox.Show("No \"Right\" entities to compare !");

                return;
            }
            else if (_right.Entities[0].Properties.Count == 0)
            {
                ComparisonsDGV.ColumnCount = 0;
                MessageBox.Show("No \"Right\" properties to compare !");

                return;
            }

            //Columns (properties)

            propertiesLV.Items.Clear();

            int propCount = _left.GetActivePropertiesCount();

            ComparisonsDGV.ColumnCount = propCount * 2 + 1;
            int counter = 0;

            foreach (EntityProperty prop in _left.Entities[0].Properties)
            {
                ListViewItem item = propertiesLV.Items.Add(prop.Name);
                if (prop.Active)
                {
                    item.Checked = true;

                    ComparisonsDGV.Columns[counter].Name = prop.Name + (prop.Transferable ? "*" : "");
                    ComparisonsDGV.Columns[counter + propCount + 1].Name = prop.Name + (prop.Transferable ? "*" : "");
                    counter++;
                }
            }

            ComparisonsDGV.Columns[propCount].Name = "SUMMARY";

            int nbItems  = 0;
            int nbTotal  = 0;
            int nbDiffer = 0;

            //Rows

            //"Left" first
            List <DataEntity> associatedEntities = new List <DataEntity>();

            foreach (DataEntity comparedEntity in _comp.Comparisons.Keys)
            {
                if (comparedEntity.Comparable == _left)
                {
                    nbTotal++;

                    object[] row = new object[propCount * 2 + 1];
                    comparedEntity.GetValues().CopyTo(row, 0);

                    Comparison rowComp = Comparison.LeftOnly;

                    if (comparedEntity.AssociatedEntity != null)
                    {
                        rowComp = Comparison.Differ;
                        associatedEntities.Add(comparedEntity.AssociatedEntity);
                        comparedEntity.AssociatedEntity.GetValues().CopyTo(row, propCount + 1);
                        rowComp = _comp.GetSummary(comparedEntity, comparedEntity.AssociatedEntity);
                    }

                    row[propCount] = rowComp;
                    if (rowComp != Comparison.Equals)
                    {
                        nbDiffer++;
                    }

                    if (_showEquals || rowComp != Comparison.Equals)
                    {
                        DataGridViewRow newRow = ComparisonsDGV.Rows[ComparisonsDGV.Rows.Add(row)];
                        nbItems++;

                        counter = 0;
                        foreach (EntityProperty prop in comparedEntity.Properties)
                        {
                            if (!prop.Active)
                            {
                                continue;
                            }

                            Comparison curComp = Comparison.Differ;

                            if (comparedEntity.AssociatedEntity != null)
                            {
                                if (_comp.Comparisons[comparedEntity][comparedEntity.AssociatedEntity][prop.Name] >= 1.0)
                                {
                                    curComp = Comparison.Equals;
                                }
                                newRow.Cells[counter].Style.BackColor = newRow.Cells[counter + propCount + 1].Style.BackColor = (curComp == Comparison.Equals ? EqualsLightColor : (prop.Mandatory ? DifferLightMandatoryColor : DifferLightColor));
                            }
                            else
                            {
                                newRow.Cells[counter + propCount + 1].Style.BackColor = comparedEntity.DontAssociate ? EmptyDontColor : EmptyColor;
                                newRow.Cells[counter].Style.BackColor = prop.Mandatory ? DifferLightMandatoryColor : DifferLightColor;
                            }
                            counter++;
                        }

                        newRow.Cells[propCount].Style.BackColor = (rowComp == Comparison.Equals ? EqualsColor : DifferColor);
                    }
                }
            }

            //"Right" orphan entities
            foreach (DataEntity comparedEntity in _comp.Comparisons.Keys)
            {
                if (comparedEntity.Comparable == _right && !associatedEntities.Contains(comparedEntity))
                {
                    nbTotal++;
                    nbDiffer++;

                    object[] row = new object[propCount * 2 + 1];
                    comparedEntity.GetValues().CopyTo(row, propCount + 1);
                    row[propCount] = Comparison.RightOnly;

                    DataGridViewRow newRow = ComparisonsDGV.Rows[ComparisonsDGV.Rows.Add(row)];
                    nbItems++;

                    counter = 0;
                    foreach (EntityProperty prop in comparedEntity.Properties)
                    {
                        if (!prop.Active)
                        {
                            continue;
                        }

                        newRow.Cells[counter].Style.BackColor = comparedEntity.DontAssociate ? EmptyDontColor : EmptyColor;
                        newRow.Cells[counter + propCount + 1].Style.BackColor = prop.Mandatory ? DifferLightMandatoryColor : DifferLightColor;
                        counter++;
                    }

                    newRow.Cells[propCount].Style.BackColor = DifferColor;
                }
            }

            toolStripStatusLabel1.Text = string.Format("{0} items / {1} items total ({2} Differ)", nbItems, nbTotal, nbDiffer);
            _muteEvents = false;
        }