예제 #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]);
     }
 }
예제 #2
0
 /// <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]);
     }
 }
예제 #3
0
 public DeleteSupplementCommand(Supplement parent, SupplementItem supplementItem)
 {
     if (parent.ReadOnly)
     {
         throw new ApsimXException(parent, string.Format("Unable to delete {0} - it is read-only.", parent.Name));
     }
     this.parent             = parent;
     this.supplementToDelete = supplementItem;
 }
예제 #4
0
        /// <summary>Perform the command</summary>
        /// <param name="commandHistory">The command history.</param>
        public void Do(CommandHistory commandHistory)
        {
            int iSuppNo = SupplementLibrary.DefaultSuppConsts.IndexOf(this.supplementName);

            if (iSuppNo >= 0)
            {
                this.supplementToAdd = SupplementLibrary.DefaultSuppConsts[iSuppNo];
                this.prevSuppIdx     = this.parent.CurIndex;
                this.parent.CurIndex = this.parent.Add(this.supplementName);
                this.supplementAdded = true;
                commandHistory.InvokeModelChanged(this.parent);
            }
        }
예제 #5
0
        /// <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)
        {
            int suppNo = SupplementLibrary.DefaultSuppConsts.IndexOf(this.supplementName);

            if (suppNo >= 0)
            {
                this.supplementToAdd = SupplementLibrary.DefaultSuppConsts[suppNo];
                this.prevSuppIdx     = this.parent.CurIndex;
                this.parent.CurIndex = this.parent.Add(this.supplementName);
                this.supplementAdded = true;
                modelChanged(parent);
            }
        }
예제 #6
0
 public DeleteSupplementCommand(Supplement parent, SupplementItem supplementItem)
 {
     this.parent             = parent;
     this.supplementToDelete = supplementItem;
 }
예제 #7
0
 /// <summary>
 /// Returns the index of FoodSupplement in the array of supplements
 /// </summary>
 /// <param name="item">The supplement item</param>
 /// <returns>The array index, or -1 if not found</returns>
 public int IndexOf(SupplementItem item)
 {
     return(theModel.IndexOf(item));
 }