Esempio n. 1
0
        public static void AreEqual(XmlNode productNode, XmlNodeList productNodes, ProductMix productMix, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            if (productNode.GetXmlAttribute("A") == null || productNode.GetXmlAttribute("B") == null)
                return;

            UniqueIdAssert.AreEqual(linkList, productNode.GetXmlAttribute("A"), productMix.Id.UniqueIds);
            Assert.AreEqual(productNode.GetXmlAttribute("A"), productMix.Id.FindIsoId());
            Assert.AreEqual(productNode.GetXmlAttribute("B"), productMix.Description);

            var prnNodes = productNode.SelectNodes("PRN");
            ProductComponentAssert.AreEqual(prnNodes, productMix.ProductComponents, productNodes, catalog, linkList);
        }
Esempio n. 2
0
        private string WriteProductMix(XmlWriter writer, ProductMix productMix)
        {
            var productId = productMix.Id.FindIsoId() ?? GenerateId();
            TaskWriter.Ids.Add(productId, productMix.Id);

            writer.WriteStartElement(XmlPrefix);
            writer.WriteAttributeString("A", productId);
            writer.WriteAttributeString("B", productMix.Description);
            writer.WriteAttributeString("F", "2");

            WriteTotalQuantity(writer, productMix.TotalQuantity);
            WriteProductComponents(writer, productMix.ProductComponents);

            writer.WriteEndElement();

            return productId;
        }
Esempio n. 3
0
        private ProductMix GetProduct(XmlNode inputNode)
        {
            var product = new ProductMix { ProductType = ProductTypeEnum.Mix, Form = ProductFormEnum.Unknown };

            var groupId = inputNode.GetXmlNodeValue("@C");
            if (string.IsNullOrEmpty(groupId))
                return product;

            var groupNode = _taskDocument.RootNode.SelectSingleNode(
                string.Format(CultureInfo.InvariantCulture, "PGP[@A='{0}']", groupId));
            if (groupNode == null)
                return product;

            var groupType = groupNode.GetXmlNodeValue("@C");
            if (string.IsNullOrEmpty(groupType))
                return product;

            if (string.Equals(groupType, "2", StringComparison.OrdinalIgnoreCase))
                product.ProductType = ProductTypeEnum.Variety;

            return product;
        }
Esempio n. 4
0
        private void LoadTotalQuantity(XmlNode inputNode, ProductMix productMix)
        {
            var quantityValue = inputNode.GetXmlNodeValue("@G");

            double quantity;
            if (!double.TryParse(quantityValue, NumberStyles.Float, CultureInfo.InvariantCulture, out quantity))
                return;

            var unit = LoadUnit(inputNode);
            var userUnit = _taskDocument.Units.FindById(inputNode.GetXmlNodeValue("@D"));

            var numericValue = new NumericValue(unit.ToAdaptUnit(), unit.ConvertFromIsoUnit(quantity));
            productMix.TotalQuantity = new NumericRepresentationValue(null, userUnit.ToAdaptUnit(), numericValue);
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
        private bool LoadProductComponents(XmlNodeList inputNodes, ProductMix productMix)
        {
            List<Ingredient> components = new List<Ingredient>();
            foreach (XmlNode productRelationNode in inputNodes)
            {
                var component = LoadProductRelation(productRelationNode, productMix);
                if (component == null)
                    return false;
                components.Add(component);
            }

            _taskDocument.Ingredients.AddRange(components);
            return true;
        }