Compare commits
6 Commits
a61195ca03
...
c909ce2cc1
Author | SHA1 | Date | |
---|---|---|---|
c909ce2cc1 | |||
444b58721f | |||
b877a1493e | |||
a5932bebef | |||
88e1fb82ef | |||
853c49969d |
|
@ -1,10 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Web.Script.Serialization;
|
|
||||||
using System.Diagnostics.SymbolStore;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
@ -13,20 +8,22 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
public partial class Statistic : UserControl
|
public partial class Statistic : UserControl
|
||||||
{
|
{
|
||||||
private const string AIPARKING_CLIENT_HTTP_API_REQUEST = "http://{0}:{1}{2}";
|
private readonly HttpClient client;
|
||||||
|
private readonly Thread thrStatistics;
|
||||||
|
|
||||||
Label lblLoaiXe;
|
Label lblLoaiXe;
|
||||||
Label lblXeMay;
|
Label lblXeMay;
|
||||||
Label lblOto;
|
Label lblOto;
|
||||||
Label lblSoLuong;
|
Label lblSoLuong;
|
||||||
Label lblTT;
|
|
||||||
Label lblSoLuongXeMay;
|
Label lblSoLuongXeMay;
|
||||||
Label lblSoLuongOto;
|
Label lblSoLuongOto;
|
||||||
|
|
||||||
public Statistic()
|
public Statistic(string apiUrl)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Thread thrStatistics = new Thread(new ThreadStart(GetStatistic));
|
client = new HttpClient { BaseAddress = new Uri(apiUrl), Timeout = TimeSpan.FromMilliseconds(5000) };
|
||||||
|
thrStatistics = new Thread(new ThreadStart(GetStatistic));
|
||||||
|
thrStatistics.IsBackground = true;
|
||||||
thrStatistics.Start();
|
thrStatistics.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,28 +40,26 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
try
|
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<Vehicle>();
|
||||||
|
lblSoLuongXeMay?.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
HttpResponseMessage response = await client.GetAsync("/api/statistics");
|
lblSoLuongXeMay.Text = vehicle.NumberOfMoto.ToString();
|
||||||
response.EnsureSuccessStatusCode();
|
}));
|
||||||
var vehicle = await response.Content.ReadAsAsync<Vehicle>();
|
lblSoLuongOto?.Invoke(new Action(() =>
|
||||||
lblSoLuongXeMay?.Invoke(new Action(() =>
|
{
|
||||||
{
|
lblSoLuongOto.Text = vehicle.NumberOfCar.ToString();
|
||||||
lblSoLuongXeMay.Text = vehicle.NumberOfMoto.ToString();
|
}));
|
||||||
}));
|
lblVehicleTotalIn?.Invoke(new Action(() =>
|
||||||
lblSoLuongOto?.Invoke(new Action(() =>
|
{
|
||||||
{
|
lblVehicleTotalIn.Text = vehicle.TotalIn;
|
||||||
lblSoLuongOto.Text = vehicle.NumberOfCar.ToString();
|
}));
|
||||||
}));
|
lblVehicleTotalOut?.Invoke(new Action(() =>
|
||||||
lblVehicleTotalIn?.Invoke(new Action(() =>
|
{
|
||||||
{
|
lblVehicleTotalOut.Text = vehicle.TotelOut;
|
||||||
lblVehicleTotalIn.Text = vehicle.TotalIn;
|
}));
|
||||||
}));
|
|
||||||
lblVehicleTotalOut?.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
lblVehicleTotalOut.Text = vehicle.TotelOut;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -77,14 +72,13 @@ namespace AIParkingApplication
|
||||||
tlpStatisticTable.BorderStyle = BorderStyle.FixedSingle;
|
tlpStatisticTable.BorderStyle = BorderStyle.FixedSingle;
|
||||||
tlpStatisticTable.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
|
tlpStatisticTable.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
|
||||||
|
|
||||||
|
System.Drawing.Font labelFont = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
|
||||||
lblLoaiXe = new Label() { Text = "Loại xe", Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) };
|
lblLoaiXe = new Label() { Text = "Loại xe", Font = labelFont };
|
||||||
lblXeMay = new Label() { Text = "Xe máy", Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) };
|
lblXeMay = new Label() { Text = "Xe máy", Font = labelFont };
|
||||||
lblOto = new Label() { Text = "Ô tô", Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) };
|
lblOto = new Label() { Text = "Ô tô", Font = labelFont };
|
||||||
lblSoLuong = new Label() { Text = "Số Lượng", Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) };
|
lblSoLuong = new Label() { Text = "Số Lượng", Font = labelFont };
|
||||||
lblTT = new Label() { Text = "TT", Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) };
|
lblSoLuongXeMay = new Label() { Text = "0", Font = labelFont };
|
||||||
lblSoLuongXeMay = new Label() { Text = "0", Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) };
|
lblSoLuongOto = new Label() { Text = "0", Font = labelFont };
|
||||||
lblSoLuongOto = new Label() { Text = "0", Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) };
|
|
||||||
|
|
||||||
//Fill to StaticTable
|
//Fill to StaticTable
|
||||||
tlpStatisticTable.Controls.Add(lblLoaiXe, 0, 0);
|
tlpStatisticTable.Controls.Add(lblLoaiXe, 0, 0);
|
||||||
|
@ -102,7 +96,7 @@ namespace AIParkingApplication
|
||||||
|
|
||||||
[JsonProperty("moto")]
|
[JsonProperty("moto")]
|
||||||
public int NumberOfMoto { get; set; }
|
public int NumberOfMoto { get; set; }
|
||||||
|
|
||||||
[JsonProperty("total_in")]
|
[JsonProperty("total_in")]
|
||||||
public string TotalIn { get; set; }
|
public string TotalIn { get; set; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user