From 61d2563923bb482eeb5a1419866ceb5f6c0e5dc1 Mon Sep 17 00:00:00 2001 From: Le Chau Date: Wed, 24 Jun 2020 16:20:36 +0700 Subject: [PATCH] =?UTF-8?q?Th=C3=AAm=20{Statistic}=20UserControl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AIParkingApplication.csproj | 10 + AIParkingApplication/Statistic.Designer.cs | 201 ++++++++++++++++++ AIParkingApplication/Statistic.cs | 118 ++++++++++ AIParkingApplication/Statistic.resx | 120 +++++++++++ 4 files changed, 449 insertions(+) create mode 100644 AIParkingApplication/Statistic.Designer.cs create mode 100644 AIParkingApplication/Statistic.cs create mode 100644 AIParkingApplication/Statistic.resx diff --git a/AIParkingApplication/AIParkingApplication.csproj b/AIParkingApplication/AIParkingApplication.csproj index 29788a1..94dbfc7 100644 --- a/AIParkingApplication/AIParkingApplication.csproj +++ b/AIParkingApplication/AIParkingApplication.csproj @@ -57,6 +57,7 @@ ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + @@ -95,6 +96,12 @@ + + UserControl + + + Statistic.cs + UserControl @@ -121,6 +128,9 @@ Resources.resx True + + Statistic.cs + StatusBar.cs diff --git a/AIParkingApplication/Statistic.Designer.cs b/AIParkingApplication/Statistic.Designer.cs new file mode 100644 index 0000000..7f3f56a --- /dev/null +++ b/AIParkingApplication/Statistic.Designer.cs @@ -0,0 +1,201 @@ +namespace AIParkingApplication +{ + partial class Statistic + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.grbVehicleStatistics = new System.Windows.Forms.GroupBox(); + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.lblVehicleTotalOut = new System.Windows.Forms.Label(); + this.lblVehicleTotalIn = new System.Windows.Forms.Label(); + this.tlpStatisticTable = new System.Windows.Forms.TableLayoutPanel(); + this.grbLoginInfo = new System.Windows.Forms.GroupBox(); + this.lblAuthorization = new System.Windows.Forms.Label(); + this.lblUsername = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.grbVehicleStatistics.SuspendLayout(); + this.grbLoginInfo.SuspendLayout(); + this.SuspendLayout(); + // + // grbVehicleStatistics + // + this.grbVehicleStatistics.Controls.Add(this.label4); + this.grbVehicleStatistics.Controls.Add(this.label3); + this.grbVehicleStatistics.Controls.Add(this.lblVehicleTotalOut); + this.grbVehicleStatistics.Controls.Add(this.lblVehicleTotalIn); + this.grbVehicleStatistics.Controls.Add(this.tlpStatisticTable); + this.grbVehicleStatistics.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.grbVehicleStatistics.Location = new System.Drawing.Point(1, 1); + this.grbVehicleStatistics.Name = "grbVehicleStatistics"; + this.grbVehicleStatistics.Size = new System.Drawing.Size(290, 189); + this.grbVehicleStatistics.TabIndex = 0; + this.grbVehicleStatistics.TabStop = false; + this.grbVehicleStatistics.Text = "Thống kê xe"; + // + // label4 + // + this.label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.label4.Location = new System.Drawing.Point(183, 133); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(60, 20); + this.label4.TabIndex = 2; + this.label4.Text = "Xe ra"; + this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label3 + // + this.label3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.label3.Location = new System.Drawing.Point(42, 133); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(60, 20); + this.label3.TabIndex = 2; + this.label3.Text = "Xe vào"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // lblVehicleTotalOut + // + this.lblVehicleTotalOut.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.lblVehicleTotalOut.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblVehicleTotalOut.Location = new System.Drawing.Point(183, 161); + this.lblVehicleTotalOut.Name = "lblVehicleTotalOut"; + this.lblVehicleTotalOut.Size = new System.Drawing.Size(60, 20); + this.lblVehicleTotalOut.TabIndex = 1; + this.lblVehicleTotalOut.Text = "0"; + this.lblVehicleTotalOut.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // lblVehicleTotalIn + // + this.lblVehicleTotalIn.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.lblVehicleTotalIn.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblVehicleTotalIn.Location = new System.Drawing.Point(42, 161); + this.lblVehicleTotalIn.Name = "lblVehicleTotalIn"; + this.lblVehicleTotalIn.Size = new System.Drawing.Size(60, 20); + this.lblVehicleTotalIn.TabIndex = 1; + this.lblVehicleTotalIn.Text = "0"; + this.lblVehicleTotalIn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // tlpStatisticTable + // + this.tlpStatisticTable.ColumnCount = 2; + this.tlpStatisticTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tlpStatisticTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tlpStatisticTable.Location = new System.Drawing.Point(6, 22); + this.tlpStatisticTable.Name = "tlpStatisticTable"; + this.tlpStatisticTable.RowCount = 3; + this.tlpStatisticTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.tlpStatisticTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.tlpStatisticTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.tlpStatisticTable.Size = new System.Drawing.Size(278, 100); + this.tlpStatisticTable.TabIndex = 0; + // + // grbLoginInfo + // + this.grbLoginInfo.Controls.Add(this.lblAuthorization); + this.grbLoginInfo.Controls.Add(this.lblUsername); + this.grbLoginInfo.Controls.Add(this.label2); + this.grbLoginInfo.Controls.Add(this.label1); + this.grbLoginInfo.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.grbLoginInfo.Location = new System.Drawing.Point(1, 198); + this.grbLoginInfo.Name = "grbLoginInfo"; + this.grbLoginInfo.Size = new System.Drawing.Size(290, 93); + this.grbLoginInfo.TabIndex = 1; + this.grbLoginInfo.TabStop = false; + this.grbLoginInfo.Text = "Thông tin đăng nhập"; + // + // lblAuthorization + // + this.lblAuthorization.AutoSize = true; + this.lblAuthorization.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblAuthorization.Location = new System.Drawing.Point(109, 60); + this.lblAuthorization.Name = "lblAuthorization"; + this.lblAuthorization.Size = new System.Drawing.Size(127, 18); + this.lblAuthorization.TabIndex = 0; + this.lblAuthorization.Text = "Nhân Viên Bảo Vệ"; + // + // lblUsername + // + this.lblUsername.AutoSize = true; + this.lblUsername.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblUsername.Location = new System.Drawing.Point(109, 27); + this.lblUsername.Name = "lblUsername"; + this.lblUsername.Size = new System.Drawing.Size(48, 18); + this.lblUsername.TabIndex = 0; + this.lblUsername.Text = "baove"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.Location = new System.Drawing.Point(16, 60); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(85, 18); + this.label2.TabIndex = 0; + this.label2.Text = "Phân quyền"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(16, 27); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(73, 18); + this.label1.TabIndex = 0; + this.label1.Text = "Tài khoản"; + // + // Statistic + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.grbLoginInfo); + this.Controls.Add(this.grbVehicleStatistics); + this.Name = "Statistic"; + this.Size = new System.Drawing.Size(292, 292); + this.Load += new System.EventHandler(this.Statistic_Load); + this.grbVehicleStatistics.ResumeLayout(false); + this.grbLoginInfo.ResumeLayout(false); + this.grbLoginInfo.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox grbVehicleStatistics; + private System.Windows.Forms.TableLayoutPanel tlpStatisticTable; + private System.Windows.Forms.GroupBox grbLoginInfo; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label lblAuthorization; + private System.Windows.Forms.Label lblUsername; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label lblVehicleTotalOut; + private System.Windows.Forms.Label lblVehicleTotalIn; + } +} diff --git a/AIParkingApplication/Statistic.cs b/AIParkingApplication/Statistic.cs new file mode 100644 index 0000000..79cd852 --- /dev/null +++ b/AIParkingApplication/Statistic.cs @@ -0,0 +1,118 @@ +using System; +using System.Text; +using System.Windows.Forms; +using System.IO; +using System.Net; +using System.Web.Script.Serialization; +using System.Diagnostics.SymbolStore; +using System.Threading; + +namespace AIParkingApplication +{ + public partial class Statistic : UserControl + { + private const string AIPARKING_CLIENT_HTTP_API_REQUEST = "http://{0}:{1}{2}"; + + Label lblLoaiXe; + Label lblXeMay; + Label lblOto; + Label lblSoLuong; + Label lblTT; + Label lblSoLuongXeMay; + Label lblSoLuongOto; + + public Statistic() + { + InitializeComponent(); + Thread thrStatistics = new Thread(new ThreadStart(GetStatistic)); + thrStatistics.Start(); + + } + + private void GetStatistic() + { + while (true) + { + string strGETRequest = GETDataFromServer("192.168.1.123", "80", "/api/statistics"); + JavaScriptSerializer js = new JavaScriptSerializer(); + var obj = js.Deserialize(strGETRequest); + Vehicle.NumberOfCar = obj["oto"]; + Vehicle.NumberOfMoto = obj["moto"]; + Vehicle.TotalIn = obj["total_in"]; + Vehicle.TotelOut = obj["total_out"]; + 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; + })); + Thread.Sleep(1000); + } + } + + private string GETDataFromServer(string serverUrl, string apiPort, string apiPath) + { + string responseString = ""; + string requestUriString = string.Format(AIPARKING_CLIENT_HTTP_API_REQUEST, serverUrl, apiPort, apiPath); + var request = (HttpWebRequest)WebRequest.Create(requestUriString); + string postData = $""; + byte[] data = Encoding.ASCII.GetBytes(postData); + + request.Method = "GET"; + request.ContentType = "application/x-www-form-urlencoded"; + request.ContentLength = data.Length; + + try + { + var response = (HttpWebResponse)request.GetResponse(); + responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); + Console.WriteLine(responseString); + } + catch (Exception ex) + { + } + return responseString; + } + + private void Statistic_Load(object sender, EventArgs e) + { + tlpStatisticTable.BorderStyle = BorderStyle.FixedSingle; + tlpStatisticTable.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single; + + + 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) }; + 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) }; + lblOto = new Label() { Text = "Ô tô", 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 = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) }; + 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 = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0) }; + 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 + tlpStatisticTable.Controls.Add(lblLoaiXe, 0, 0); + tlpStatisticTable.Controls.Add(lblXeMay, 0, 1); + tlpStatisticTable.Controls.Add(lblOto, 0, 2); + tlpStatisticTable.Controls.Add(lblSoLuong, 1, 0); + tlpStatisticTable.Controls.Add(lblSoLuongXeMay, 1, 1); + tlpStatisticTable.Controls.Add(lblSoLuongOto, 1, 2); + + } + static class Vehicle + { + public static int NumberOfCar { get; set; } + public static int NumberOfMoto { get; set; } + public static string TotalIn { get; set; } + public static string TotelOut { get; set; } + } + } +} diff --git a/AIParkingApplication/Statistic.resx b/AIParkingApplication/Statistic.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AIParkingApplication/Statistic.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file