Example #1
0
        public DbBase findRecId(string recIdSearch)
        {
            XmlNode foundRecord = null;
            DbBase  retObject   = null;

            foundRecord = CoOpGlobal.XML.findNodeWithAttribute(xmlDatabase, this.DBRootNode(), "RecId", $"{recIdSearch}", "Record");
            if (foundRecord != null)
            {
                // Initilaise record object
                retObject = this.createNewInstance();
                // Set Rec Id separately because it isn't a property, just a variable
                retObject.recId = recIdSearch;
                IEnumerator fieldEnumerator = foundRecord.GetEnumerator();

                // Assign field values to object properties
                while (fieldEnumerator.MoveNext())
                {
                    XmlNode curField = fieldEnumerator.Current as XmlNode;

                    retObject.GetType().GetProperty(curField.Name).SetValue(retObject, curField.InnerText);
                }
            }

            return(retObject);
        }
Example #2
0
        public DbBase findFieldValue(string fieldName, string value)
        {
            DbBase      retObject        = null;
            Boolean     recordExists     = false;
            XmlNode     dbRoot           = this.DBRootNode();
            IEnumerator recordEnumerator = dbRoot.GetEnumerator();


            while (recordEnumerator.MoveNext() && !recordExists)
            {
                XmlNode curRecord = recordEnumerator.Current as XmlNode;

                IEnumerator fieldEnumerator       = curRecord.GetEnumerator();
                IEnumerator fieldEnumeratorAssign = curRecord.GetEnumerator();
                while (fieldEnumerator.MoveNext() && !recordExists)
                {
                    XmlNode curField = fieldEnumerator.Current as XmlNode;

                    if (curField.Name == fieldName)
                    {
                        if (curField.InnerText == value)
                        {
                            recordExists = true;
                        }
                    }
                }

                if (recordExists)
                {
                    // Initilaise record object
                    retObject = this.createNewInstance();
                    // Set Rec Id separately because it isn't a property, just a variable
                    retObject.recId = curRecord.Attributes.GetNamedItem("RecId").Value;

                    // Assign field values to object properties
                    while (fieldEnumeratorAssign.MoveNext())
                    {
                        XmlNode       curField  = fieldEnumeratorAssign.Current as XmlNode;
                        TypeConverter converter = TypeDescriptor.GetConverter(retObject.GetType().GetProperty(curField.Name).PropertyType);


                        retObject.GetType().GetProperty(curField.Name).SetValue(retObject, converter.ConvertFromString(curField.InnerText));
                    }
                }
            }

            return(retObject);
        }