Пример #1
0
        public CriterionOrdering.OrderingRelation GetRelationTo(
            Criterion c)
        {
            if (CriterionOrderings != c.CriterionOrderings)
            {
                throw new RelationshipError();
            }

            // First check relation between this and c

            CriterionOrdering.OrderingRelation greatestRelation = CriterionOrdering.OrderingRelation.IsEqualTo;

            string Next = Name;

            while (true)
            {
                if (!CriterionOrderings.ContainsKey(Next))
                {
                    break;
                }

                CriterionOrdering co = CriterionOrderings[Next];

                if (co.Relation > greatestRelation)
                {
                    greatestRelation = co.Relation;
                }

                if (co.Right.Name == c.Name)
                {
                    return(greatestRelation);
                }

                Next = co.Right.Name;
            }

            throw new RelationshipError();
        }
Пример #2
0
        void Criteria_Drop(object sender, DragEventArgs e)
        {
            DataGrid dg = sender as DataGrid;

            if (fromRowIndex < 0)
            {
                return;
            }

            int toRowIndex = this.GetDataGridItemCurrentRowIndex(dg, e.GetPosition);

            //The current Rowindex is -1 (No selected)
            if (toRowIndex < 0)
            {
                return;
            }
            //If Drag-Drop Location are same
            if (toRowIndex == fromRowIndex || (toRowIndex == dg.Items.Count - 1 && fromRowIndex == dg.Items.Count - 2))
            {
                return;
            }

            DecisionModel          dm = DecisionModelVM.DecisionModel;
            LinkedList <Criterion> oc = dm.OrderedCriteria;

            //Fix up criterion orderings

            //First fix criterion ordering for criterion being moved

            LinkedListNode <Criterion> fromCriterionNode = oc.GetNodeAt <Criterion>(fromRowIndex);

            if (fromRowIndex == 0)
            {
                // moving first criterion somewhere else - delete its current ordering

                dm.DeleteCriterionOrdering(fromCriterionNode.Value.Name);
            }
            else
            {
                // moving criterion in body of orderings - delete the previous criterion's ordering to it

                CriterionOrdering previousCriterionOrdering = dm.CriterionOrderings[fromCriterionNode.Previous.Value.Name];

                dm.DeleteCriterionOrdering(fromCriterionNode.Previous.Value.Name);

                if (fromRowIndex != oc.Count - 1)
                {
                    // not moving the last criterion - so must create ordering between previous criterion and next criterion

                    CriterionOrdering fromCriterionOrdering = dm.CriterionOrderings[fromCriterionNode.Value.Name];

                    dm.DeleteCriterionOrdering(fromCriterionNode.Value.Name);

                    dm.CreateCriterionOrdering(
                        previousCriterionOrdering.Left.Name,
                        previousCriterionOrdering.Relation,
                        fromCriterionOrdering.Right.Name);
                }
            }

            fromCriterionNode.Remove();

            if (toRowIndex > fromRowIndex)
            {
                toRowIndex--;
            }

            //Now fix criterion ordering where criterion is being dropped

            LinkedListNode <Criterion> toCriterionNode = oc.GetNodeAt <Criterion>(toRowIndex);

            if (toRowIndex == 0)
            {
                // moving criterion to first position - just add a criterion ordering for the moved criterion to the first criterion

                dm.CreateCriterionOrdering(
                    fromCriterionNode.Value.Name,
                    CriterionOrdering.OrderingRelation.IsEqualTo,
                    toCriterionNode.Value.Name);
            }
            else
            {
                // not moving to first position

                if (toRowIndex < oc.Count)
                {
                    // Not moving below last criteria, so create ordering between previous criterion and moved criterion

                    CriterionOrdering previousCriterionOrdering = dm.CriterionOrderings[toCriterionNode.Previous.Value.Name];

                    dm.DeleteCriterionOrdering(toCriterionNode.Previous.Value.Name);

                    dm.CreateCriterionOrdering(
                        previousCriterionOrdering.Left.Name,
                        previousCriterionOrdering.Relation,
                        fromCriterionNode.Value.Name);

                    // Add ordering for the moved criterion

                    dm.CreateCriterionOrdering(
                        fromCriterionNode.Value.Name,
                        CriterionOrdering.OrderingRelation.IsEqualTo,
                        toCriterionNode.Value.Name);
                }
                else
                {
                    // Moving below last criteria, so just create ordering between last criteria and moved criteria

                    LinkedListNode <Criterion> lastCriterionNode = oc.Last;

                    dm.CreateCriterionOrdering(
                        lastCriterionNode.Value.Name,
                        CriterionOrdering.OrderingRelation.IsEqualTo,
                        fromCriterionNode.Value.Name);
                }
            }

            dm.NormalizeCriteria();
        }