using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TellerSystem.Library.Ext.Function;
using System.Windows;
using TellerSystem.Communication;
using System.Windows.Controls;
using Platform.Presentation.Interfaces;
using Platform.Controls.ControlsHelper;

namespace TellerSystem.Contract.Function
{
    /// <summary>
    /// 复核岗复核元素和回显元素的数据项集合
    /// </summary>
    public class CheckElements
    {
        private System.Xml.XmlDocument document = null;
        private System.Xml.XmlElement root = null;
        private List<System.Xml.XmlNode> nodeList = null;

        public CheckElements()
        {
            //
            this.document = new System.Xml.XmlDocument();
            System.Xml.XmlDeclaration dec = this.document.CreateXmlDeclaration("1.0", "GB2312", null);
            this.document.AppendChild(dec);

            //
            this.root = this.document.CreateElement("root");
            this.document.AppendChild(this.root);

            //
            this.nodeList = new List<System.Xml.XmlNode>();
        }

        /// <summary>
        /// 增加要复核或显示给复核岗看的项
        /// </summary>
        /// <param name="label"></param>
        /// <param name="text"></param>
        /// <param name="checkLabel">是否需要复核柜员复核的数据项</param>
        /// <param name="inputType">此数据的数据类型</param>
        public void AddElement(string label, string text, string checkLabel, Platform.Controls.ControlsHelper.InputType inputType, bool IsToSbc = false, ItemCollection dict = null)
        {
            System.Xml.XmlElement element = this.document.CreateElement("Element");

            //
            System.Xml.XmlAttribute attribute1 = this.document.CreateAttribute("Label");
            attribute1.Value = label;
            element.Attributes.Append(attribute1);

            //
            System.Xml.XmlAttribute attribute2 = this.document.CreateAttribute("CheckLabel");
            attribute2.Value = checkLabel;
            element.Attributes.Append(attribute2);

            //
            System.Xml.XmlAttribute attribute3 = this.document.CreateAttribute("InputType");
            attribute3.Value = ((int)inputType).ToString();
            element.Attributes.Append(attribute3);


            //
            System.Xml.XmlAttribute attribute4 = this.document.CreateAttribute("IsToSbc");
            attribute4.Value = IsToSbc.ToString();
            element.Attributes.Append(attribute4);


            //
            System.Xml.XmlAttribute attribute5 = this.document.CreateAttribute("dict");
            var val = new StringBuilder();
            if (dict != null)
                foreach (KeyValuePair<string, string> item in dict)
                {
                    val.AppendLine(string.Format("{0}|{1}", item.Key, item.Value));
                }
            attribute5.Value = val.ToString();
            element.Attributes.Append(attribute5);

            //
            element.InnerText = text;

            this.nodeList.Add(element);
            this.root.AppendChild(element);
        }



        /// <summary>
        /// 获得所有待复合对象集合
        /// </summary>
        public System.Xml.XmlNode[] Xelement
        {
            get
            {
                return this.nodeList.ToArray();
            }
        }

        /// <summary>
        /// 获取用string表示的xml文档，在拼到总线上用
        /// </summary>
        public string XmlString
        {
            get
            {
                return this.document.OuterXml;
            }
        }
    }
}
