private Unit GetUnit(string UnitName) { if (dictUnit == null) { dictUnit = new Dictionary<string, Unit>(); XPCollection<Unit> units = new XPCollection<Unit>(session); foreach (Unit unit in units) { dictUnit.Add(unit.UnitName.ToUpper(), unit); } } if (dictUnit.ContainsKey(UnitName.ToUpper())) { return dictUnit[UnitName.ToUpper()]; } else { Unit unit = new Unit(session); unit.UnitName = UnitName; unit.Type = Unit.UnitType.Dimension; unit.Decimal = 0; unit.Save(); dictUnit.Add(UnitName.ToUpper(), unit); return unit; } }
protected void UpdateWHQty(WHTotal whTotal) { if (whTotal.Unit != null) { _WHUnit = whTotal.Unit; OnChanged("WHUnit"); } if (_OriginalUnit == null) return; if (_OriginalUnit == _WHUnit) { _WHQty = _OriginalQty; _ExchangeRate = 1; } else if (_OriginalUnit.Type == Unit.UnitType.Qty) { _ExchangeRate = _OriginalUnit.GetExchangeRate(_WHUnit); _WHQty = _OriginalQty / _ExchangeRate; } else if (_OriginalUnit.Type == Unit.UnitType.Dimension) { _WHQty = _OriginalQty; // Cannot Calculate the WHQty _ExchangeRate = 1; } else if (_OriginalUnit.Type == Unit.UnitType.Weight) { _ExchangeRate = Item.NetWeight; _WHQty = _OriginalQty / _ExchangeRate; } OnChanged("WHQty"); OnChanged("ExchangeRate"); }
public float GetExchangeRate(Unit ToUnit) { float ExchangeRate = 1; foreach (UnitConvert unitConvert in ToUnits) { if (unitConvert.ToUnit == ToUnit) { ExchangeRate = unitConvert.ExchangeRate; break; } } return ExchangeRate; }