using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace SklAnalysis.TemplateXml
{
    public partial class DataDs
    {
        private System.String _SourceName;
        public System.String SourceName
        {
            get { return _SourceName; }
            set { _SourceName = value; }
        }

        /// <summary>
        /// Filters
        /// <summary>
        private Filters _Filters = new Filters();
        public Filters Filters
        {
            get { return _Filters; }
            set { _Filters = value; }
        }

        private System.String _FieldName;
        public System.String FieldName
        {
            get { return _FieldName; }
            set { _FieldName = value; }
        }

        private bool _IsColumnToRow;

        /// <summary>
        /// 是否行转列  
        /// </summary>
        public bool IsColumnToRow
        {
            get { return _IsColumnToRow; }
            set { _IsColumnToRow = value; }
        }

        private System.String _FilterGroupName;
        public System.String FilterGroupName
        {
            get { return _FilterGroupName; }
            set { _FilterGroupName = value; }
        }

        #region 对象序列化,反序列化
        public static DataDs MappingFromNode(XmlNode node)
        {
            if (node != null)
            {
                DataDs rtnO = new DataDs();
                try
                {
                    XmlNode xNode0 = node.SelectSingleNode("child::Filters");
                    if (xNode0 != null)
                    {
                        Filters xSEdiu0 = Filters.MappingFromNode(xNode0);
                        if (xSEdiu0 != null)
                        {
                            rtnO.Filters = xSEdiu0;
                        }
                    }

                    string tmpStr = "";
                    tmpStr = Common.GetNodeAttributes(node, "SourceName");
                    rtnO.SourceName = tmpStr;

                    tmpStr = Common.GetNodeAttributes(node, "FieldName");
                    rtnO.FieldName = tmpStr;

                    tmpStr = Common.GetNodeAttributes(node, "IsColumnToRow");
                    rtnO.IsColumnToRow = string.IsNullOrEmpty(tmpStr) ? false : Convert.ToBoolean(tmpStr);

                    tmpStr = Common.GetNodeAttributes(node, "FilterGroupName");
                    rtnO.FilterGroupName = tmpStr;

                }
                catch (Exception ex)
                {
                    return null;
                }
                return rtnO;
            }
            else
            {
                return null;
            }
        }
        public XmlNode MappingToNode(XmlDocument xmlDoc)
        {
            if (xmlDoc != null)
            {
                XmlNode rtnNode = xmlDoc.CreateElement("DataDs");
                try
                {
                    if (this.Filters.FilterS.Count > 0)
                    {
                        XmlElement xFiltersEle = xmlDoc.CreateElement("Filters");
                        xFiltersEle = (XmlElement)this.Filters.MappingToNode(xmlDoc);
                        rtnNode.AppendChild(xFiltersEle);
                    }

                    XmlAttribute xNameAtt = xmlDoc.CreateAttribute("SourceName");
                    xNameAtt.Value = this.SourceName == null ? "" : Convert.ToString(this.SourceName);
                    rtnNode.Attributes.Append(xNameAtt);

                    XmlAttribute xFieldNameAtt = xmlDoc.CreateAttribute("FieldName");
                    xFieldNameAtt.Value = this.FieldName == null ? "" : Convert.ToString(this.FieldName);
                    rtnNode.Attributes.Append(xFieldNameAtt);

                    XmlAttribute xHave = xmlDoc.CreateAttribute("IsColumnToRow");
                    xHave.Value = this.IsColumnToRow == null ? "False" : Convert.ToString(this.IsColumnToRow);
                    if (this.IsColumnToRow)
                        rtnNode.Attributes.Append(xHave);

                    XmlAttribute xFilterNameAtt = xmlDoc.CreateAttribute("FilterGroupName");
                    xFilterNameAtt.Value = this.FilterGroupName == null ? "" : Convert.ToString(this.FilterGroupName);
                    if (xFilterNameAtt.Value.Length > 0)
                        rtnNode.Attributes.Append(xFilterNameAtt);
                }
                catch (Exception ex)
                {
                    return null;
                }
                return rtnNode;
            }
            else
            {
                return null;
            }
        }
        #endregion
    }


    public partial class DataDsCollection : Collection<DataDs>
    {
        public void Remove(DataDs ds)
        {
            for (int i = 0; i < List.Count; i++)
            {
                if (List[i].Equals(ds))
                {
                    List.RemoveAt(i);
                    break;
                }
            }

        }
    }

}
