Beispiel #1
0
 /// <summary>Perform the command</summary>
 /// <param name="commandHistory">The command history.</param>
 public void Do(CommandHistory commandHistory)
 {
     if (!supplementsReset) // First call; store a copy of the original values
     {
         prevList = new List <SupplementItem>(this.suppList.Count);
         for (int i = 0; i < this.suppList.Count; i++)
         {
             SupplementItem newItem = new SupplementItem();
             newItem.Assign(suppList[i]);
             prevList.Add(newItem);
         }
     }
     foreach (SupplementItem supp in suppList)
     {
         int suppNo = SupplementLibrary.DefaultSuppConsts.IndexOf(supp.Name);
         if (suppNo >= 0)
         {
             string name   = supp.Name;
             double amount = supp.Amount;
             supp.Assign(SupplementLibrary.DefaultSuppConsts[suppNo]);
             supp.Name   = name;
             supp.Amount = amount;
         }
     }
     supplementsReset = true;
     if (this.parent.CurIndex > 0)
     {
         commandHistory.InvokeModelChanged(this.parent[this.parent.CurIndex]);
     }
 }
 /// <summary>Perform the command</summary>
 /// <param name="tree">A tree view to which the changes will be applied.</param>
 /// <param name="modelChanged">Action to be performed if/when a model is changed.</param>
 public void Do(ITreeView tree, Action <object> modelChanged)
 {
     if (parent.ReadOnly)
     {
         throw new ApsimXException(parent, string.Format("Unable to modify {0} - it is read-only.", parent.Name));
     }
     if (!supplementsReset) // First call; store a copy of the original values
     {
         prevList = new List <SupplementItem>(this.suppList.Count);
         for (int i = 0; i < this.suppList.Count; i++)
         {
             SupplementItem newItem = new SupplementItem();
             newItem.Assign(suppList[i]);
             prevList.Add(newItem);
         }
     }
     foreach (SupplementItem supp in suppList)
     {
         int suppNo = SupplementLibrary.DefaultSuppConsts.IndexOf(supp.Name);
         if (suppNo >= 0)
         {
             string name   = supp.Name;
             double amount = supp.Amount;
             supp.Assign(SupplementLibrary.DefaultSuppConsts[suppNo]);
             supp.Name   = name;
             supp.Amount = amount;
         }
     }
     supplementsReset = true;
     if (this.parent.CurIndex > 0)
     {
         modelChanged(this.parent[this.parent.CurIndex]);
     }
 }