Beispiel #1
0
        private void WriteProductComponent(XmlWriter writer, ProductComponent productComponent)
        {
            var productId = TaskWriter.Products.FindById(productComponent.IngredientId);
            if (string.IsNullOrEmpty(productId) ||
                productComponent.Quantity == null ||
                productComponent.Quantity.Value == null)
                return;

            writer.WriteStartElement("PLN");
            writer.WriteAttributeString("A", productId);
            writer.WriteAttributeString("B", productComponent.Quantity.Value.Value.ToString("F0", CultureInfo.InvariantCulture));
            writer.WriteEndElement();
        }
        private static void AreEqual(XmlNode prnNode, ProductComponent productComponent, XmlNodeList productNodes, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            var productNode = FindMatchingProductNode(prnNode.GetXmlAttribute("A"), productNodes);
            if (productNode == null)
                return;

            var quantityDdi = Int32.Parse(productNode.GetXmlAttribute("E"));
            var uom = new RepresentationMapper().GetUnitForDdi(quantityDdi);
            Assert.AreEqual(uom, productComponent.Quantity.Value.UnitOfMeasure);
            Assert.AreEqual(prnNode.GetXmlAttribute("B"), productComponent.Quantity.Value.Value);

            var ingredient = catalog.Ingredients.Single(x => x.Id.ReferenceId == productComponent.IngredientId);
            Assert.AreEqual(productNode.GetXmlAttribute("B"), ingredient.Description);
        }
Beispiel #3
0
        private Ingredient LoadProductRelation(XmlNode productRelationNode, ProductMix productMix)
        {
            var productId = productRelationNode.GetXmlNodeValue("@A");
            var productQuantity = productRelationNode.GetXmlNodeValue("@B");

            if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(productQuantity))
                return null;

            long quantity;
            if (!long.TryParse(productQuantity, NumberStyles.Integer, CultureInfo.InvariantCulture, out quantity) ||
                quantity < 0)
                return null;

            Product product;
            if (_taskDocument.Products.TryGetValue(productId, out product) == false)
                return null;

            var unit = _taskDocument.UnitsByItemId.FindById(productId);
            var numericValue = new NumericValue(unit.ToAdaptUnit(), unit.ConvertFromIsoUnit(quantity));

            var ingredient = new ActiveIngredient
            {
                Description = product.Description,
            };

            var productComponent = new ProductComponent
            {
                IngredientId = product.Id.ReferenceId,
                Quantity = new NumericRepresentationValue(null, numericValue.UnitOfMeasure, numericValue)
            };

            if (productMix.ProductComponents == null)
                productMix.ProductComponents = new List<ProductComponent>();
            productMix.ProductComponents.Add(productComponent);

            return ingredient;
        }