diff --git a/AIParkingApplication/Statistic.cs b/AIParkingApplication/Statistic.cs index ffaac09..7c2a752 100644 --- a/AIParkingApplication/Statistic.cs +++ b/AIParkingApplication/Statistic.cs @@ -14,6 +14,7 @@ namespace AIParkingApplication public partial class Statistic : UserControl { private const string AIPARKING_CLIENT_HTTP_API_REQUEST = "http://{0}:{1}{2}"; + private readonly HttpClient client = new HttpClient { BaseAddress = new Uri("http://192.168.1.123:80/"), Timeout = TimeSpan.FromMilliseconds(5000) }; Label lblLoaiXe; Label lblXeMay; @@ -43,28 +44,26 @@ namespace AIParkingApplication { try { - using (var client = new HttpClient { BaseAddress = new Uri("http://192.168.1.123:80/"), Timeout = TimeSpan.FromMilliseconds(5000) }) + HttpResponseMessage response = await client.GetAsync("/api/statistics"); + response.EnsureSuccessStatusCode(); + var vehicle = await response.Content.ReadAsAsync(); + lblSoLuongXeMay?.Invoke(new Action(() => { - HttpResponseMessage response = await client.GetAsync("/api/statistics"); - response.EnsureSuccessStatusCode(); - var vehicle = await response.Content.ReadAsAsync(); - lblSoLuongXeMay?.Invoke(new Action(() => - { - lblSoLuongXeMay.Text = vehicle.NumberOfMoto.ToString(); - })); - lblSoLuongOto?.Invoke(new Action(() => - { - lblSoLuongOto.Text = vehicle.NumberOfCar.ToString(); - })); - lblVehicleTotalIn?.Invoke(new Action(() => - { - lblVehicleTotalIn.Text = vehicle.TotalIn; - })); - lblVehicleTotalOut?.Invoke(new Action(() => - { - lblVehicleTotalOut.Text = vehicle.TotelOut; - })); - } + lblSoLuongXeMay.Text = vehicle.NumberOfMoto.ToString(); + })); + lblSoLuongOto?.Invoke(new Action(() => + { + lblSoLuongOto.Text = vehicle.NumberOfCar.ToString(); + })); + lblVehicleTotalIn?.Invoke(new Action(() => + { + lblVehicleTotalIn.Text = vehicle.TotalIn; + })); + lblVehicleTotalOut?.Invoke(new Action(() => + { + lblVehicleTotalOut.Text = vehicle.TotelOut; + })); + } catch (Exception ex) { @@ -102,7 +101,7 @@ namespace AIParkingApplication [JsonProperty("moto")] public int NumberOfMoto { get; set; } - + [JsonProperty("total_in")] public string TotalIn { get; set; }