private static void DoDmjson(List <Dm> listDm, JObject jObjectData) { if (jObjectData.ContainsKey("dm")) //处理dm { JArray jObjectDm = (JArray)jObjectData["dm"]; foreach (JToken jToken in jObjectDm.Children()) { Dm dm = new Dm(); dm.advertisement_id = long.Parse(jToken["advertisement_id"].ToString()); dm.store_name = jToken["store_name"].ToString(); dm.display_time = int.Parse(jToken["display_time"].ToString()); dm.puton_time = DateTime.Parse(jToken["puton_time"].ToString()); dm.putoff_time = DateTime.Parse(jToken["putoff_time"].ToString()); dm.Title = jToken["title"].ToString(); dm.image_url = jToken["image_url"].ToString(); dm.category_id = int.Parse(jToken["category_id"].ToString()); dm.date_modified = DateTime.Parse(jToken["date_modified"].ToString()); dm.img_path = Config.adImgRoot + "\\" + Ad.GetImgName(dm.image_url); DateTime dt = DateTime.Now; if (dm.puton_time <= dt && dt <= dm.putoff_time) //在上线时间范围内 { Dm oldDm = DmDao.GetDmById(dm.advertisement_id); if (oldDm == null)//数据库中不存在 { if (HttpUtil.DownloadImg(dm.image_url, dm.img_path)) { DmDao.InsertDm(dm); listDm.Add(dm); } } else //数据库中存在 { if (oldDm.date_modified != dm.date_modified)//如果需要修改 { FileInfo fileInfo = new FileInfo(dm.img_path); if (fileInfo.Exists == false || fileInfo.Length <= 0) { if (HttpUtil.DownloadImg(dm.image_url, dm.img_path)) { dm.id = oldDm.id; DmDao.UpdateDm(dm); listDm.Add(dm); } } } } } } DmWindow.listDm = DmDao.GetDms(); } }
private static void DoAdjson(List <Ad> listAD, JObject jObjectData) { if (jObjectData.ContainsKey("ad")) //处理ad { JArray jObjectAd = (JArray)jObjectData["ad"]; foreach (JToken jToken in jObjectAd.Children()) { Ad ad = new Ad(); ad.advertisement_id = long.Parse(jToken["advertisement_id"].ToString()); ad.advertiser_name = jToken["advertiser_name"].ToString(); ad.date_modified = DateTime.Parse(jToken["date_modified"].ToString()); ad.display_time = int.Parse(jToken["display_time"].ToString()); ad.image_url = jToken["image_url"].ToString(); ad.sub_image_url = jToken["sub_image_url"].ToString(); ad.Title = jToken["title"].ToString(); ad.puton_time = DateTime.Parse(jToken["puton_time"].ToString()); ad.putoff_time = DateTime.Parse(jToken["putoff_time"].ToString()); ad.show_type = int.Parse(jToken["show_type"].ToString()); ad.img_path = Config.adImgRoot + "\\" + Ad.GetImgName(ad.image_url); DateTime dt = DateTime.Now; if (ad.puton_time <= dt && dt <= ad.putoff_time) //在上线时间范围内 { Ad oldad = AdDao.GetAdById(ad.advertisement_id); if (oldad == null) //数据库中不存在 { bool url1 = true, url2 = true; url1 = HttpUtil.DownloadImg(ad.image_url, ad.img_path); if ((ad.show_type == 2 || ad.show_type == 3) && String.IsNullOrEmpty(ad.sub_image_url) == false) { ad.sub_img_path = Config.adImgRoot + "\\" + Ad.GetImgName(ad.sub_image_url); url2 = HttpUtil.DownloadImg(ad.sub_image_url, ad.sub_img_path); } else { ad.sub_img_path = ""; } if (url1 && url2) { AdDao.InsertAd(ad); listAD.Add(ad); } } else //数据库中存在 { if (oldad.date_modified != ad.date_modified)//需要更新 { FileInfo fileInfo = new FileInfo(ad.img_path); //if (fileInfo.Directory.Exists == false) { // fileInfo.Directory.Create(); //} bool url1 = true, url2 = true; if (fileInfo.Exists == false || fileInfo.Length <= 0) { url1 = HttpUtil.DownloadImg(ad.image_url, ad.img_path); } if ((ad.show_type == 2 || ad.show_type == 3) && String.IsNullOrEmpty(ad.sub_image_url) == false) { ad.sub_img_path = Config.adImgRoot + "\\" + Ad.GetImgName(ad.sub_image_url); url2 = HttpUtil.DownloadImg(ad.sub_image_url, ad.sub_img_path); } else { ad.sub_img_path = ""; } if (url1 && url2) { ad.id = oldad.id; //ad.sub_image_url = oldad.sub_image_url; AdDao.UpdateAd(ad); listAD.Add(ad); } } } } } MainWindow.listAd = AdDao.GetAds(); } }