Наследование: DomainEntity
Пример #1
0
        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;
        }
Пример #2
0
 public EditStockMovementItem(RecipeableItem itemToBook, Unit unitToBook)
 {
     ItemToBook = itemToBook;
     UnitToBook = unitToBook;
     QuantityToBook = 0.0m;
     QuantityLeft = 0.0m;
 }
Пример #3
0
        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;
        }
Пример #4
0
        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;
        }
Пример #5
0
        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();
        }
Пример #6
0
 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");
 }
Пример #7
0
 public new StockItem FindStockItem(Stock stock, Unit unit, RecipeableItem recipeableItem, bool createIfNotExists)
 {
     return base.FindStockItem(stock, unit, recipeableItem, createIfNotExists);
 }
Пример #8
0
 public SingleUnitViewModel(Unit unit)
 {
     _unit = unit;
     base.DisplayName = unit.Name;
 }
Пример #9
0
 public void ExchangeData(Unit unit)
 {
     _unit = unit;
 }
Пример #10
0
 public EditUnit(Unit unit)
 {
     Unit = unit;
     FactorToParentString = FactorToParent;
 }
Пример #11
0
 public virtual void RemoveChild(Unit unit)
 {
     _children.Remove(unit);
 }
Пример #12
0
 public virtual void AddChild(Unit unit)
 {
     _children.Add(unit);
 }