public void find() { //fungerande kolli id 91997792724SE Console.WriteLine("********************************************************"); Console.WriteLine(" PostNord Kolli sök"); Console.WriteLine("********************************************************"); Console.Write("\nSkriv in Kolli id: "); string kolliId = Console.ReadLine(); TrackingData tData = new TrackingData(); tData = Tracking.identyfier(kolliId); Console.WriteLine("\n--------------------------------------------------------"); Console.WriteLine("Avsändare:\n{0}\n{1} {2}\n{3}\n", tData.senderName, tData.receiverPostCode, tData.senderCity, tData.senderCountry); Console.WriteLine("Tjänst:\n** {0} **", tData.serviceName); Console.WriteLine("Status:\n** {0} **", tData.ShipmentStatus); Console.WriteLine("--------------------------------------------------------"); bool loop = true; do { Console.WriteLine("1. Se historik för det här kollit"); Console.WriteLine("2. Huvud meny"); int menu = int.Parse(Console.ReadLine()); switch (menu) { case 1: Console.Clear(); loop = false; dispalyHistory(kolliId); break; case 2: Console.Clear(); loop = false; start(); break; default: Console.WriteLine("Oj något gick fel"); Console.Clear(); continue; } } while (loop); }
public static TrackingData identyfier(string identyfier) { TrackingData tData = new TrackingData(); XmlDocument xmlTrackingData = new XmlDocument(); xmlTrackingData.Load(string.Format("https://api2.postnord.com/rest/shipment/v1/trackandtrace/findByIdentifier.xml?id=" + identyfier + "&locale=sv&apikey=" + apiKey)); try { tData.senderName = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignor/name").InnerText; } catch { tData.senderName = "Okänd"; } if (tData.senderName == "Okänd") { tData.receiverCity = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignee/address/city").InnerText; tData.receiverPostCode = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignee/address/postCode").InnerText; tData.receiverCountry = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignee/address/country").InnerText; } else { tData.senderCity = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignor/address/city").InnerText; tData.senderPostCode = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignor/address/postCode").InnerText; tData.senderCountry = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignor/address/country").InnerText; tData.receiverCity = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignee/address/city").InnerText; tData.receiverPostCode = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignee/address/postCode").InnerText; tData.receiverCountry = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/consignee/address/country").InnerText; } tData.serviceName = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/service/name").InnerText; tData.ShipmentStatus = xmlTrackingData.SelectSingleNode("TrackingInformationResponse/shipments/Shipment/statusText/header").InnerText; return(tData); }