/// <summary>
        /// This is recomended method to load items
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public DataItem GetDataItemNode(int Id, string NodeName)
        {
            JdSuite.Common.ApplicationWindowUtil.ShowStatusBarMessage($"Output Module: Loading Record {Id}");
            XElement xnode = GetXMLNode(Id, NodeName);

            if (xnode == null)
            {
                return(null);
            }

            var item = new DataItem();

            item.Id = Id;
            int maxlevel = 0;
            //item.Load(xnode, this.RootSchemaNode, ref maxlevel);TODO:Revert

            XElement topElement = new XElement(this.RootSchemaNode.Name, xnode);

            item.Load(topElement, this.RootSchemaNode, ref maxlevel);
            item.IsProperty = false;
            item.Value      = "";

            if (this.Maxlevel < maxlevel)
            {
                this.Maxlevel = maxlevel;
            }

            logger.Trace("Loaded_node {0}", item.ToString());

            JdSuite.Common.ApplicationWindowUtil.ShowStatusBarMessage($"Output Module: Loaded Record {Id}");
            return(item);
        }
示例#2
0
        public void Load(XElement xElement, Field schema, ref int maxLevel)
        {
            this.Schema   = schema;
            this.Name     = schema.Name;
            this.Type     = schema.Type;
            this.DataType = schema.DataType;


            logger.Trace("Processing_Schema [{0}]", schema.ToString());

            foreach (var schemaChild in schema.ChildNodes)
            {
                var xDataChildren = xElement.Elements().Where(x => string.Compare(x.Name.LocalName, schemaChild.Name, true) == 0);

                logger.Trace("Processing_Child_Schema [{0}] DataCount [{1}]", schemaChild.ToString(), xDataChildren.Count());

                if (xDataChildren.Count() == 0)
                {
                    DataItem child = AddChild(new DataItem(schemaChild.Name, schemaChild.Optionality, schemaChild.Type, schemaChild.DataType, "N/A"));

                    child.Load(new XElement(schemaChild.Name), schemaChild, ref maxLevel);
                    child.IsDataNodeMissing = true;
                    child.IsProperty        = !schemaChild.HasChildNodes();
                    child.Value             = "";
                    child.TotalRecordCount  = 0;
                    logger.Trace("Added_Child_DataItem Schema: [{0}] DataItem: [{1}]", schemaChild.ToString(), child.ToString());
                }
                else
                {
                    bool isFirst = true;

                    foreach (var xDataNode in xDataChildren)
                    {
                        DataItem child = AddChild(new DataItem(schemaChild.Name, schemaChild.Optionality, schemaChild.Type, schemaChild.DataType, ""));
                        if (isFirst)
                        {
                            child.TotalRecordCount = xDataChildren.Count();
                            isFirst = false;
                        }
                        child.Load(xDataNode, schemaChild, ref maxLevel);
                        child.IsDataNodeMissing = false;
                        child.IsProperty        = !schemaChild.HasChildNodes();
                        if (child.IsProperty)
                        {
                            child.Value = xDataNode.Value;
                        }
                        logger.Trace("Added_Child_DataItem2 Schema: [{0}] DataItem: [{1}]", schemaChild.ToString(), child.ToString());
                    }
                }
            }
        }