public CostBatch(CostBatch cb) { this.typeDictionary = new Dictionary <CostType, CostObject>(); foreach (KeyValuePair <CostType, CostObject> cost in cb.typeDictionary) { this.typeDictionary.Add(cost.Key, cost.Value); } }
public static CostBatch operator *(CostBatch left, double right) { CostBatch newCostBatch = new CostBatch(); foreach (KeyValuePair <CostType, CostObject> type in left.typeDictionary) { newCostBatch.typeDictionary[type.Key] = (type.Value * right); } return(newCostBatch); }
public static CostBatch operator -(CostBatch costBatch) { CostBatch negativeCostBatch = new CostBatch(); foreach (KeyValuePair <CostType, CostObject> type in costBatch.typeDictionary) { negativeCostBatch.typeDictionary[type.Key] = (-type.Value); } return(negativeCostBatch); }
public bool CostsEqual(CostBatch other) { foreach (var pair in typeDictionary) { if (!other.typeDictionary.ContainsKey(pair.Key)) { return(false); } else if (pair.Value != other.typeDictionary[pair.Key]) { return(false); } } return(true); }
public static CostBatch operator -(CostBatch left, CostBatch right) { CostBatch newCostBatch = new CostBatch(left); foreach (KeyValuePair <CostType, CostObject> type in right.typeDictionary) { if (newCostBatch.typeDictionary.ContainsKey(type.Key)) { newCostBatch.typeDictionary[type.Key] -= right.typeDictionary[type.Key]; } else { newCostBatch.typeDictionary.Add(type.Key, -type.Value); } } return(newCostBatch); }
private void raiseCostChanged(ITECObject sender, CostBatch obj) { CostChanged?.Invoke(obj); }
public static void CollectionChangedHandler(object sender, NotifyCollectionChangedEventArgs e, string propertyName, ITECObject parent, Action <Change, string, ITECObject, object, object> notifyChanged = null, Action <CostBatch> notifyCost = null, Action <int> notifyPoint = null, Action <object> onAdd = null, Action <object> onRemove = null, bool setTypical = true, bool notifyReorder = true) { CostBatch costs = new CostBatch(); int pointNumber = 0; bool costChanged = false; if (e.Action == NotifyCollectionChangedAction.Add) { foreach (ITECObject item in e.NewItems) { if (setTypical && parent is ITypicalable parentTypical && parentTypical.IsTypical && item is ITypicalable typ) { typ.MakeTypical(); } onAdd?.Invoke(item); if (item is ITypicalable typItem && typItem.IsTypical) { notifyCost = null; notifyPoint = null; } if (item is INotifyCostChanged cost) { costs += cost.CostBatch; costChanged = true; } pointNumber += (item as INotifyPointChanged)?.PointNumber ?? 0; notifyChanged?.Invoke(Change.Add, propertyName, parent, item, null); } if (costChanged) { notifyCost?.Invoke(costs); } if (pointNumber != 0) { notifyPoint?.Invoke(pointNumber); } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (ITECObject item in e.OldItems) { onRemove?.Invoke(item); if (item is ITypicalable typItem && typItem.IsTypical) { notifyCost = null; } if (item is INotifyCostChanged cost) { costs += cost.CostBatch; costChanged = true; } pointNumber += (item as INotifyPointChanged)?.PointNumber ?? 0; notifyChanged?.Invoke(Change.Remove, propertyName, parent, item, null); } if (costChanged) { notifyCost?.Invoke(costs * -1); } if (pointNumber != 0) { notifyPoint?.Invoke(pointNumber * -1); } } else if (e.Action == NotifyCollectionChangedAction.Move && notifyReorder) { notifyChanged?.Invoke(Change.Edit, propertyName, parent, sender, sender); } }