bool ConvertToSuitableChild(Unit iterator, decimal value, out decimal result) { result = value; var query = from child in iterator.Children where child == _toUnit select child; var unit = query.FirstOrDefault(); if (unit != null) { result = result*unit.FactorToParent; return true; } foreach (var child in iterator.Children) { if (child.FactorToParent == 0m) { result = -1m; return true; } decimal subresult; if (ConvertToSuitableChild(child, result * child.FactorToParent, out subresult)) { result = subresult; return true; } } return false; }
public EditStockMovementItem(RecipeableItem itemToBook, Unit unitToBook) { ItemToBook = itemToBook; UnitToBook = unitToBook; QuantityToBook = 0.0m; QuantityLeft = 0.0m; }
public StockItem BookItemOutOfStock(Stock stock, decimal quantity, Unit unit, RecipeableItem recipeableItem) { if (stock == null) throw new ArgumentNullException("stock"); var stockItem = FindStockItem(stock, unit, recipeableItem, stock.IsMainStock); var bookQuantity = _unitConverter.Convert(quantity, unit, stockItem.Unit); stockItem.Quantity -= bookQuantity; return stockItem; }
internal StockItem FindStockItem(Stock stock, Unit unit, RecipeableItem recipeableItem, bool createIfNotExists) { if (recipeableItem == null) throw new ArgumentNullException("recipeableItem"); if (unit == null) throw new ArgumentNullException("unit"); var stockItem = stock.StockItems.Where(x => x.RecipeableItem == recipeableItem).FirstOrDefault(); if (stockItem == null) { if( !createIfNotExists ) throw new InvalidOperationException(); stockItem = new StockItem { RecipeableItem = recipeableItem, Unit = unit }; stock.AddStockItem(stockItem); } return stockItem; }
public decimal Convert(decimal value, Unit from, Unit to) { if( from==to ) return value; if( from==null || to==null ) throw new InvalidUnitException(); _fromUnit = from; _toUnit = to; _value = value; decimal result; if (ConvertToParent(out result)) return result; if (ConvertToChild(out result)) return result; throw new UnitNotConvertableException(); }
void OnUnitChanged(Unit unit) { var viewmodel = (from vm in AllUnits where vm.Id == unit.Id select vm).FirstOrDefault(); if (viewmodel == null) { viewmodel = new SingleUnitViewModel(unit); AllUnits.Add(viewmodel); } else { viewmodel.ExchangeData(unit); } OnPropertyChanged("ItemSelected"); OnPropertyChanged("ItemsSelected"); }
public new StockItem FindStockItem(Stock stock, Unit unit, RecipeableItem recipeableItem, bool createIfNotExists) { return base.FindStockItem(stock, unit, recipeableItem, createIfNotExists); }
public SingleUnitViewModel(Unit unit) { _unit = unit; base.DisplayName = unit.Name; }
public void ExchangeData(Unit unit) { _unit = unit; }
public EditUnit(Unit unit) { Unit = unit; FactorToParentString = FactorToParent; }
public virtual void RemoveChild(Unit unit) { _children.Remove(unit); }
public virtual void AddChild(Unit unit) { _children.Add(unit); }