64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using System.Threading;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace AIParkingApplication
|
|
{
|
|
public partial class Statistic : UserControl
|
|
{
|
|
private readonly Thread statisticsThread;
|
|
private readonly TimeSpan updateInterval;
|
|
private ApiController apiController;
|
|
|
|
public Statistic(ApiController apiController, TimeSpan updateInterval)
|
|
{
|
|
InitializeComponent();
|
|
this.apiController = apiController;
|
|
this.updateInterval = updateInterval;
|
|
statisticsThread = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true };
|
|
}
|
|
|
|
private void GetStatistic()
|
|
{
|
|
while (true)
|
|
{
|
|
GetDataUpdate();
|
|
Thread.Sleep(updateInterval);
|
|
}
|
|
}
|
|
|
|
private async void GetDataUpdate()
|
|
{
|
|
ParkInfo parkInfo = await apiController.GetStatisticInfo();
|
|
if (parkInfo != null && IsHandleCreated)
|
|
{
|
|
lblSoLuongXeMay.UpdateLabel(parkInfo.NumberOfMoto.ToString());
|
|
lblSoLuongOto.UpdateLabel(parkInfo.NumberOfCar.ToString());
|
|
lblVehicleTotalIn.UpdateLabel(parkInfo.TotalIn);
|
|
lblVehicleTotalOut.UpdateLabel(parkInfo.TotalOut);
|
|
}
|
|
}
|
|
|
|
public class ParkInfo
|
|
{
|
|
[JsonProperty("oto")]
|
|
public int NumberOfCar { get; set; }
|
|
|
|
[JsonProperty("moto")]
|
|
public int NumberOfMoto { get; set; }
|
|
|
|
[JsonProperty("total_in")]
|
|
public string TotalIn { get; set; }
|
|
|
|
[JsonProperty("total_out")]
|
|
public string TotalOut { get; set; }
|
|
}
|
|
|
|
private void Statistic_Load(object sender, EventArgs e)
|
|
{
|
|
statisticsThread.Start();
|
|
}
|
|
}
|
|
}
|