예제 #1
0
        void QueryTicket()
        {
            #region--参数检测
            rtbTip.Text = string.Empty;
            ResourceManager rm = Lang.ResourceManager;
            List<string> nullItem = new List<string>();
            if (string.IsNullOrEmpty(ticketParam.from_station))
            {
                nullItem.Add(rm.GetString(langTipFix + cmbBeginStation.Tag));
            }
            if (string.IsNullOrEmpty(ticketParam.to_station))
            {
                nullItem.Add(rm.GetString(langTipFix + cmbToStation.Tag));
            }
            if (nullItem.Count > 0)
            {
                List<string> requireItem = new List<string>();
                requireItem.Add(rm.GetString(langTipFix + cmbBeginStation.Tag));
                requireItem.Add(rm.GetString(langTipFix + cmbToStation.Tag));
                rtbTip.Text = string.Format(Lang.Tip_12306_QueryTicketIsRequired, string.Join(",", requireItem), string.Join(",", nullItem));
                return;
            }
            #endregion
            string url = InitQueryTicketParam(ticketParam);
            string json = HttpClientExtend.HttpClientGet(url);
            LoggerWriter.CreateLogFile(json, LogDir, ELogType.DataLog, DateTime.Now.ToString(CommonFormat.DateTimeIntFormat) + ".txt");
            leftTicketDTOResponse response = json.ConvertObject<leftTicketDTOResponse>();//不能序列化字典
            JObject jr = JObject.Parse(json);
            JObject jd = (JObject)jr["data"];//字典为data下数据  map
            //由于json序列化时不能将节点下的字典型json串进行逆序列化,次出使用中转形式先读取取字典内容,在填充到对象
            JObject jdic = (JObject)jd["map"];
            Dictionary<string, string> _Data = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(jdic.ToString());
            if (response != null && response.data != null)
            {
                response.data.map = _Data;
            }
            //leftTicketDTOResponse responseNew= Newtonsoft.Json.JsonConvert.DeserializeObject<leftTicketDTOResponse>(json);
            /*
             * Newtonsoft
             其他信息: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.String[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
             */
            foreach (var item in response.data.result)
            {
                GetCarTicket(item, response);
            }
            //存储列车座位信息
            //反射时构造函数没有提供参数可以进行创建
            ISyncTicketDataManage sync = IocHelper.CreateObjectCtorWithParam<ISyncTicketDataManage>(
                new object[]{AppCategory.WinApp,"Conn" },
                typeof(SyncTicketDataManage).Name,
                "TicketData.Manage",
                "CaptureManage.AppWin",//此为程序集,而不是命名空间
                NowAppDirHelper.GetNowAppDir(AppCategory.WinApp));
             
            //由于实现类中对于构造函数存在参数限定,此处需要特殊参数的传递
            sync.SaveCarWithSeatData(response);
            //读取列车过站信息
            //存储列车过站信息,绘制运动轨迹图

        }