using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using WOSBusineSupporter;

namespace HySoft.BaseCallCenter.Web.workordermanage.workorder
{
    /// <summary>
    ///AssembleWorkFlowTask 的摘要说明
    /// </summary>
    public class AssembleWorkFlowTask
    {
        public AssembleWorkFlowTask()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        #region 组装指派参与者

        /// <summary>
        /// 组装
        /// </summary>
        /// <returns></returns>
        public XmlDocument AssembleParticipator(ParticipatorInfo participatorInfo)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                //定义XML文档头文件
                XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                xmlDoc.AppendChild(xmlDeclaration);

                //创建根
                XmlElement xeRoot = xmlDoc.CreateElement("ParticipatorInfo");
                xmlDoc.AppendChild(xeRoot);

                //装配GatewayInfo节点
                int i = 0;

                if (participatorInfo != null)
                {
                    if (participatorInfo.DeptList != null)
                    {
                        if (participatorInfo.DeptList.Length > 0)
                        {
                            XmlElement xeList = xmlDoc.CreateElement("DeptList");
                            xeRoot.AppendChild(xeList);
                            foreach (DeptInfo model in participatorInfo.DeptList)
                            {
                                XmlElement xeInfo = xmlDoc.CreateElement("DeptInfo");
                                xeList.AppendChild(xeInfo);
                                xeInfo.SetAttribute("ID", model.ID.ToString());
                                xeInfo.SetAttribute("Name", model.Name.ToString());
                                i++;
                            }
                        }
                    }

                    if (participatorInfo.RoleList != null)
                    {
                        if (participatorInfo.RoleList.Length > 0)
                        {
                            XmlElement xeList = xmlDoc.CreateElement("RoleList");
                            xeRoot.AppendChild(xeList);
                            foreach (RoleInfo model in participatorInfo.RoleList)
                            {
                                XmlElement xeInfo = xmlDoc.CreateElement("RoleInfo");
                                xeList.AppendChild(xeInfo);
                                xeInfo.SetAttribute("ID", model.ID.ToString());
                                xeInfo.SetAttribute("Name", model.Name.ToString());
                                i++;
                            }
                        }
                    }

                    if (participatorInfo.PostList != null)
                    {
                        if (participatorInfo.PostList.Length > 0)
                        {
                            XmlElement xeList = xmlDoc.CreateElement("PostList");
                            xeRoot.AppendChild(xeList);
                            foreach (PostInfo model in participatorInfo.PostList)
                            {
                                XmlElement xeInfo = xmlDoc.CreateElement("PostInfo");
                                xeList.AppendChild(xeInfo);
                                xeInfo.SetAttribute("ID", model.ID.ToString());
                                xeInfo.SetAttribute("Name", model.Name.ToString());
                                i++;
                            }
                        }
                    }

                    if (participatorInfo.UserList != null)
                    {
                        if (participatorInfo.UserList.Length > 0)
                        {
                            XmlElement xeList = xmlDoc.CreateElement("UserList");
                            xeRoot.AppendChild(xeList);
                            foreach (UserInfo model in participatorInfo.UserList)
                            {
                                XmlElement xeInfo = xmlDoc.CreateElement("UserInfo");
                                xeList.AppendChild(xeInfo);
                                xeInfo.SetAttribute("ID", model.ID.ToString());
                                xeInfo.SetAttribute("Name", model.Name.ToString());
                                i++;
                            }
                        }
                    }

                }

                if (i == 0)
                {
                    return null;
                }

                return xmlDoc;
            }
            catch
            {
                return null;
            }
        }

        #endregion

    }
}
