Esempio n. 1
0
        public static bool TryParse(string xml, out CheckItemCollection item)
        {
            bool parsed = false;
            item = new CheckItemCollection();

            try
            {
                XElement element = XElement.Parse(xml);

                foreach (XElement xItem in element.Elements("item"))
                {
                    CheckItem cItem = new CheckItem();
                    cItem.Name = xItem.Attribute("name").Value;
                    cItem.Standard = xItem.Attribute("standard").Value;
                    cItem.Unit = xItem.Attribute("unit").Value;
                    cItem.Value = xItem.Attribute("value").Value;
                    cItem.ValueType = StringToCheckItemValueType(xItem.Attribute("type").Value);

                    item.Items.Add(cItem);
                }

                foreach (XElement xGroup in element.Elements("group"))
                {
                    CheckItemGroup cGroup = new CheckItemGroup();

                    cGroup.Name = xGroup.Attribute("name").Value;
                    cGroup.Unit = xGroup.Attribute("unit").Value;

                    foreach (XElement xItem in xGroup.Elements("item"))
                    {
                        CheckItem cItem = new CheckItem();
                        cItem.Name = xItem.Attribute("name").Value;
                        cItem.Standard = xItem.Attribute("standard").Value;
                        cItem.Unit = xItem.Attribute("unit").Value;
                        cItem.Value = xItem.Attribute("value").Value;
                        cItem.ValueType = StringToCheckItemValueType(xItem.Attribute("type").Value);

                        cGroup.Items.Add(cItem);
                    }

                    item.Groups.Add(cGroup);
                }

                parsed = true;
            }
            catch
            {
                parsed = false;
                item = null;
            }

            return parsed;
        }
Esempio n. 2
0
        public static bool TryParse(string xml, out CheckItemCollection item)
        {
            bool parsed = false;
            item = new CheckItemCollection();

            try
            {
                XElement element = XElement.Parse(xml);

                foreach (XElement xItem in element.Elements("item"))
                {
                    ICheckItemBase cItem = new CheckItem();
                    (cItem as CheckItem).Name = xItem.Attribute("name").Value;
                    (cItem as CheckItem).Standard = xItem.Attribute("standard").Value;
                    (cItem as CheckItem).Unit = xItem.Attribute("unit").Value;
                    (cItem as CheckItem).Value = xItem.Attribute("value").Value;
                    (cItem as CheckItem).ValueType = StringToCheckItemValueType(xItem.Attribute("type").Value);

                    item.Items.Add((cItem as CheckItem));

                    // 把item放到接口列表
                    int index;
                    Int32.TryParse(xItem.Attribute("index") == null ? "0" : xItem.Attribute("index").Value, out index);
                    cItem.Index = index;
                    item.CheckItems.Add(cItem);
                }

                foreach (XElement xGroup in element.Elements("group"))
                {
                    ICheckItemBase cGroup = new CheckItemGroup();

                    cGroup.Name = xGroup.Attribute("name").Value;
                    cGroup.Unit = xGroup.Attribute("unit").Value;

                    foreach (XElement xItem in xGroup.Elements("item"))
                    {
                        CheckItem cItem = new CheckItem();
                        cItem.Name = xItem.Attribute("name").Value;
                        cItem.Standard = xItem.Attribute("standard").Value;
                        cItem.Unit = xItem.Attribute("unit").Value;
                        cItem.Value = xItem.Attribute("value").Value;
                        cItem.ValueType = StringToCheckItemValueType(xItem.Attribute("type").Value);

                        (cGroup as CheckItemGroup).Items.Add(cItem);
                    }

                    item.Groups.Add((cGroup as CheckItemGroup));

                    // 把item放到接口列表
                    int index;
                    Int32.TryParse(xGroup.Attribute("index") == null ? "0" : xGroup.Attribute("index").Value, out index);
                    cGroup.Index = index;
                    item.CheckItems.Add(cGroup);
                }

                item.Sort();

                parsed = true;
            }
            catch (Exception ex)
            {
                throw ex;
                parsed = false;
                item = null;
            }

            return parsed;
        }