private async Task Json_Paring_Destination(string json) { try { JObject obj = JObject.Parse(json); if (total_number == 0) { //Console.WriteLine(obj["total"].ToString()); total_number = int.Parse(obj["total"].ToString()); } JArray hotel_destination = JArray.Parse(obj["destinations"].ToString()); foreach (JObject itemObj in hotel_destination) { if (itemObj.ContainsKey("zones") == true) { JArray hotel_zones = JArray.Parse(itemObj["zones"].ToString()); foreach (JObject itemObj2 in hotel_zones) { DestinationDesc contents = new DestinationDesc(); contents.destinatin_code = itemObj["code"].ToString(); if (itemObj.ContainsKey("name") == true) { contents.destinatin_name = itemObj["name"]["content"].ToString(); } contents.destinatin_countryCode = itemObj["countryCode"].ToString(); contents.destinatin_zonecode = itemObj2["zoneCode"].ToString(); contents.destinatin_zonecode_name = itemObj2["name"].ToString(); HBDestinationDescList.Add(contents); } } else { DestinationDesc contents = new DestinationDesc(); contents.destinatin_code = itemObj["code"].ToString(); contents.destinatin_name = itemObj["name"]["content"].ToString(); contents.destinatin_countryCode = itemObj["countryCode"].ToString(); HBDestinationDescList.Add(contents); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private async void GetHotel_btn_Click(object sender, RoutedEventArgs e) { DestinationDescMomoryDB = File.ReadAllLines(@"..\..\CSVfiles\DestinationDesc.csv") .Skip(1) .Select(v => DestinationDesc.FromCsv(v)) .ToList(); RoomDescMomoryDB = File.ReadAllLines(@"..\..\CSVfiles\RoomDesc.csv") .Skip(1) .Select(v => RoomDesc.FromCsv(v)) .ToList(); change_button_status(); string status_barTxt = ""; hotelContentsList = new List <HotelInformation>(); HBRoomImageList = new List <RoomImage>(); HBWildCardsList = new List <HotelWildCards>(); HBHTRoomTypeList = new List <HotelRoomTypeInfo>(); from = 1; to = 1000; total_number = 0; current_from = from; current_to = to; string getApiUrl = ApiUrl_TB.Text + setField4HotelContents(GL_target_Data); //Console.WriteLine(getApiUrl); HttpConnects h_Conn = new HttpConnects(getApiUrl, mainWindow.ApiKey_TB.Text, mainWindow.Security_TB.Text); do { statusBar.Content = "Please wait for a Second.... Now We are Communicating with HB API ... -> Get Hotel from " + current_from + " to " + current_to; RSResult rsResult = await h_Conn.GetHotelContents(current_from, current_to); //Console.WriteLine(rsResult.result); if (rsResult.rq_status == true) { await Json_Paring(GL_target_Data, rsResult.result); Console.WriteLine(GL_target_Data + " -- " + rsResult.result); status_barTxt = "Done: Successfully, Get Hotel from 1 to " + current_to;; } else { status_barTxt = "Error: " + rsResult.result; MessageBoxResult result = MessageBox.Show(rsResult.result); break; } current_from = current_to + 1; current_to = current_from + 999; } while (total_number > current_from); switch (GL_target_Data) { case "HT": //** THIS "hotelContentsList" Cooming from Json_Paring() function as a Global parameter hbHotelRoom_Grid.ItemsSource = hotelContentsList; break; case "IMG": //** THIS "hotelContentsList" Cooming from Json_Paring() function as a Global parameter HBRoomImageList = (from x in HBRoomImageList orderby x.hotel_code, x.imageOrder ascending select x).ToList(); hbHotelRoom_Grid.ItemsSource = HBRoomImageList; break; case "WILD": hbHotelRoom_Grid.ItemsSource = HBWildCardsList; break; case "HTROOM": hbHotelRoom_Grid.ItemsSource = HBHTRoomTypeList; break; default: hbHotelRoom_Grid.ItemsSource = hotelContentsList; break; } statusBar.Content = status_barTxt; MessageBox.Show(status_barTxt); change_button_status(); }