/// <summary>
        /// 获取医保中心日期
        /// </summary>
        /// <returns></returns>
        public static bool GetYBCenterDate(out DateTime dateTime, out string msg)
        {
            dateTime = DateTime.MinValue;

            DealModel deal = new DealModel("52");

            deal.CallName = "获取医保中心时间";

            deal.CallDeal();

            msg = deal.Msg;

            if (deal.IsYanHaiSuccess)
            {
                Dictionary <string, string> dicAll = XMLHelper.GetDicFromXML(deal.astr_jysc_xml, DealModel.xPathSubRow);
                if (dicAll.TryGetValue("prm_sysdate", out string value))
                {
                    if (DateTime.TryParse(value, out dateTime))
                    {
                        return(true);
                    }
                    else
                    {
                        msg = "格式转换失败";
                    }
                }
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Dic 转Result Model
        /// </summary>
        /// <param name="dealModel"></param>
        private static void ParseXMLToModel(DealModel dealModel)
        {
            //如果xml是顶层
            if (!dealModel.IsRows)
            {
                Dictionary <string, string> dic = XMLHelper.GetDicFromXML(dealModel.astr_jysc_xml, dealModel.ResultXmlXpath);
                Type type          = dealModel.ReslutModel.GetType();
                var  allProperties = type.GetFields();

                for (int i = 0; i < allProperties.Length; i++)
                {
                    YinHaiAttribute atturn = allProperties[i].GetCustomAttribute(typeof(YinHaiAttribute), false) as YinHaiAttribute;
                    if (atturn != null)
                    {
                        if (dic.TryGetValue(atturn.XmlAttName.ToLower().Trim(), out string value))
                        {
                            allProperties[i].SetValue(dealModel.ReslutModel, value);
                        }
                    }
                }
            }
            else
            {
                //根据xml rows获取多个Dic,然后转换为model的items
                Dictionary <string, string>[] dicArray = XMLHelper.GetDicArrayFromXML(dealModel.astr_jysc_xml, dealModel.ResultXmlXpath);

                //拿到对象的Items List属性
                var itemsField = dealModel.ReslutModel.GetType().GetFields().Where(P => P.Name.ToLower() == "items").FirstOrDefault();
                if (itemsField == null)
                {
                    dealModel.Msg += "--当前对象没有Items 属性";
                    return;
                }
                //创建 List 对象
                var entityList = Activator.CreateInstance(itemsField.FieldType);

                //绑定List对象到model类
                itemsField.SetValue(dealModel.ReslutModel, entityList);

                //所有到数据
                for (int i = 0; i < dicArray.Length; i++)
                {
                    try
                    {
                        //创建List 泛型里的类实例
                        var subItem = itemsField.DeclaringType.Assembly.CreateInstance(itemsField.FieldType.GenericTypeArguments[0].FullName);

                        foreach (var item in dicArray[i].Keys)
                        {
                            //获取子类所有属性并赋值
                            var properties = subItem.GetType().GetFields().Where(P => (P.GetCustomAttribute(typeof(YinHaiAttribute), false) as YinHaiAttribute)?.XmlAttName.ToLower() == item).FirstOrDefault();

                            if (properties != null)
                            {
                                properties.SetValue(subItem, dicArray[i][item]);
                            }
                            else
                            {
                                //Model 里忘了封装 属性了。。。
                                dealModel.Msg = "--当前对象没找到标记为此的属性" + item;
                            }
                        }

                        //讲子类添加到List 里
                        BindingFlags flag       = BindingFlags.Instance | BindingFlags.Public;
                        MethodInfo   methodInfo = entityList.GetType().GetMethod("Add", flag);
                        methodInfo.Invoke(entityList, new object[] { subItem });//相当于List<T>调用Add方法
                    }
                    catch (Exception ex)
                    {
                        dealModel.Msg = "--异常" + ex.Message;
                    }
                }
            }
        }
Example #3
0
        ///// <summary>
        ///// 从返回的XML里,根据xpath,创建json返回
        ///// </summary>
        ///// <returns></returns>
        //public string GetJsonResultFromXML()
        //{
        //    Dictionary<string,string> dicResult = XMLHelper.GetDicFromXML(this.astr_jysc_xml, ResultXmlXpath);

        //    if (IsSuccess)
        //    {
        //        dicResult.Add("status", "success");
        //    }
        //    else
        //    {

        //    }

        //    return JsonHelper.ConvertDicToJson(dicResult, DealName);

        //}Z


        public Dictionary <string, string> GetDicResult()
        {
            return(XMLHelper.GetDicFromXML(this.astr_jysc_xml, ResultXmlXpath));
        }