private void Model_New_Name_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Return) { string name = (sender as TextBox).Text; Model_New_Popup.IsOpen = false; DecisionModel dm = new DecisionModel(name); dm.CreateCriterion("C1", "Color", new ChoiceScorer( 10, new[] { new ChoiceScorer.Selection("Red", 10), new ChoiceScorer.Selection("Green", 5), new ChoiceScorer.Selection("Other", 3) })); dm.CreateCriterion("C2", "MPG", new RangeScorer(10.0, 40.0)); dm.CreateCriterion("C3", "Warranty Period Years", new RangeScorer(1.0, 5.0)); dm.CreateCriterion("C4", "Price", new RangeScorer(30000.0, 150000.0)); dm.CreateCriterion("C5", "Backup Camera", new BooleanScorer()); dm.CreateCriterion("C6", "Craftsmanship", new DiscreteRangeScorer(1, 10)); dm.CreateCriterion("C7", "Distance to Dealer", new RangeScorer(4.0, 50.0, higherIsBetter: false)); dm.CreateCriterion("C8", "Horsepower", new RangeScorer(200.0, 900.0)); dm.CreateCriterion("C9", "Manufacturer", new ChoiceScorer( 10, new[] { new ChoiceScorer.Selection("Porsche", 10), new ChoiceScorer.Selection("Audi", 8), new ChoiceScorer.Selection("BMW", 6), new ChoiceScorer.Selection("Lexus", 4), new ChoiceScorer.Selection("Nissan", 3), new ChoiceScorer.Selection("Ford", 2), new ChoiceScorer.Selection("Other", 0), })); dm.CreateCriterionOrdering("C8", CriterionOrdering.OrderingRelation.IsEqualTo, "C7"); dm.CreateCriterionOrdering("C7", CriterionOrdering.OrderingRelation.IsSignificantlyBetterThan, "C6"); dm.CreateCriterionOrdering("C6", CriterionOrdering.OrderingRelation.IsModeratelyBetterThan, "C9"); dm.CreateCriterionOrdering("C9", CriterionOrdering.OrderingRelation.IsSlightlyBetterThan, "C5"); dm.CreateCriterionOrdering("C5", CriterionOrdering.OrderingRelation.IsSlightlyBetterThan, "C4"); dm.CreateCriterionOrdering("C4", CriterionOrdering.OrderingRelation.IsSlightlyBetterThan, "C3"); dm.CreateCriterionOrdering("C3", CriterionOrdering.OrderingRelation.IsEqualTo, "C2"); dm.CreateCriterionOrdering("C2", CriterionOrdering.OrderingRelation.IsEqualTo, "C1"); dm.NormalizeCriteria(); DecisionModelVM.DecisionModel = dm; e.Handled = true; } }
public void EditableCriterion_PropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case "Criterion": { EditableCriterion ec = sender as EditableCriterion; int index = orderedCriteria.IndexOf(ec); if (index == -1 || !ec.IsNewEditableCriterion) { return; } // Finished editing a new Criterion - need to add it to the DecisionModel DecisionModel dm = DecisionModel; dm.CreateCriterion( ec.Name, ec.Description, ec.Scorer); if (orderedCriteria.Count != 1) { Criterion lastCriterion = dm.OrderedCriteria.Last.Value; Criterion newCriterion = dm.Criteria[ec.Name]; dm.CreateCriterionOrdering( lastCriterion.Name, CriterionOrdering.OrderingRelation.IsEqualTo, newCriterion.Name); } dm.NormalizeCriteria(); break; } case "Scorer": { EditableCriterion ec = sender as EditableCriterion; Scorer = ec.Scorer; break; } } }
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(); }