代码改变世界

将数据库中的数据取出然后转换成为Xml形式的解析2.详情

2011-03-25 14:44  闫妍  阅读(205)  评论(0编辑  收藏  举报

接口

image

协议

Request的body部分

image

Response的Body部分

image

image

示例部分

image

image

转换后的Xml

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Adapter.WebUI.Interface;
using Common.Utils;
using System.Xml.Linq;
using Adapter.DataProvider.Interface;
using Adapter.DataProvider.Common;
using System.Reflection;
using Common.Utils.Helper;

namespace Adapter.Impl
{
    public class WorkCardInfoDetailViewProcess : IProcess
    {
        /// <summary>
        /// 根据上岗证ID获取上岗证详情
        /// </summary>
        /// <param name="header"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public Result<string> Process(string header, XElement body)
        {
            try
            {
                IWorkCardInfoDataProvider provider = DataProviderFactory.CreateWorkCardInfoDataProvider();
                string workCardID = body.Element("WorkCardID").Value;
                WorkCardInfo obj = provider.GetWorkCardInfoByWorkCardId(workCardID);

                XElement xeBody = new XElement("Body",
                    new XElement("MultipleDetailPage",
                    new XElement("Title", ""),
                    new XElement("Uri", ""),
                    new XElement("ListType", ""),
                    new XElement("ActionState", ""),
                    new XElement("GroupList", new XElement("GroupItem", ""))));

                if (obj == null) return new Result<string> { Code = 200, Message = "", State = xeBody.ToString() };

                List<string> lstField = new List<string> { "NET_EMPLOYEE_INFO_ID", "WORK_CARD_INFO_ID", "DESCC", "WORK_CARD_LEVEL", "WORK_CARD_LEVEL", "REDUCE_NUM",
                                                            "REMAIN_NUM","END_TIME"};

                lstField.ForEach(h =>
                {
                    PropertyInfo propertyInfo = obj.GetType().GetProperty(h);
                    if (propertyInfo != null)
                    {
                        object o = propertyInfo.GetValue(obj, null);
                        xeBody.Element("MultipleDetailPage").Element("GroupList").Element("GroupItem").Add(new XElement(propertyInfo.Name, o.ToString()));
                    }
                });

                return new Result<string> { Code = 200, Message = "", State = xeBody.ToString() };

            }
            catch (Exception ex)
            {
                LogHelper.Error("WorkCardInfoDetailViewProcess $ Process", ex);
                return new Result<string> { Code = (ushort)StatusCode._523, Message = "获取数据失败", State = string.Empty };
            }
        }
    }
}