Compare commits

...

8 Commits

15 changed files with 272 additions and 41 deletions

View File

@ -141,6 +141,7 @@
</Compile>
<Compile Include="PlateDetector.cs" />
<Compile Include="PlateProcessor.cs" />
<Compile Include="Printer.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sidebar.cs">
@ -223,6 +224,9 @@
<Content Include="plateLong.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="PrinterForm.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">

View File

@ -29,23 +29,89 @@
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AIParkingApplicationForm));
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.toolStripMenuItemSwitchLane = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemSwitchLaneInIn = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemSwitchLaneInOut = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemSwitchLaneOutOut = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemSwitchLaneOutIn = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// menuStrip
//
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemSwitchLane});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1366, 24);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStrip1";
//
// toolStripMenuItemSwitchLane
//
this.toolStripMenuItemSwitchLane.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemSwitchLaneInIn,
this.toolStripMenuItemSwitchLaneInOut,
this.toolStripMenuItemSwitchLaneOutOut,
this.toolStripMenuItemSwitchLaneOutIn});
this.toolStripMenuItemSwitchLane.Name = "toolStripMenuItemSwitchLane";
this.toolStripMenuItemSwitchLane.Size = new System.Drawing.Size(59, 20);
this.toolStripMenuItemSwitchLane.Text = "Đảo làn";
//
// toolStripMenuItemSwitchLaneInIn
//
this.toolStripMenuItemSwitchLaneInIn.Name = "toolStripMenuItemSwitchLaneInIn";
this.toolStripMenuItemSwitchLaneInIn.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItemSwitchLaneInIn.Text = "Vào - Vào";
this.toolStripMenuItemSwitchLaneInIn.Click += new System.EventHandler(this.toolStripMenuItemSwitchLaneInIn_Click);
//
// toolStripMenuItemSwitchLaneInOut
//
this.toolStripMenuItemSwitchLaneInOut.Name = "toolStripMenuItemSwitchLaneInOut";
this.toolStripMenuItemSwitchLaneInOut.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItemSwitchLaneInOut.Text = "Vào - Ra";
//
// toolStripMenuItemSwitchLaneOutOut
//
this.toolStripMenuItemSwitchLaneOutOut.Name = "toolStripMenuItemSwitchLaneOutOut";
this.toolStripMenuItemSwitchLaneOutOut.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItemSwitchLaneOutOut.Text = "Ra - Ra";
//
// toolStripMenuItemSwitchLaneOutIn
//
this.toolStripMenuItemSwitchLaneOutIn.Name = "toolStripMenuItemSwitchLaneOutIn";
this.toolStripMenuItemSwitchLaneOutIn.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItemSwitchLaneOutIn.Text = "Ra - Vào";
//
// AIParkingApplicationForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1366, 737);
this.Controls.Add(this.menuStrip);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.menuStrip;
this.MinimumSize = new System.Drawing.Size(1382, 776);
this.Name = "AIParkingApplicationForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "AIParking - Phần mềm quản lý bãi đỗ xe";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AIParkingApplicationForm_FormClosing);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSwitchLane;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSwitchLaneInIn;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSwitchLaneInOut;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSwitchLaneOutOut;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSwitchLaneOutIn;
}
}

View File

@ -13,6 +13,7 @@ namespace AIParkingApplication
private StatusBar statusBar;
private Sidebar sidebar;
private Config configOnWeb;
private EngineApiController engineApiController;
public AIParkingApplicationForm(ApiController apiController, Config configOnWeb)
{
@ -25,7 +26,6 @@ namespace AIParkingApplication
Controls.Add(sidebar);
c3Device = new C3DeviceController("192.168.1.200");
EngineApiController engineApiController = null;
try
{
@ -38,12 +38,12 @@ namespace AIParkingApplication
}
laneIn = new LaneIn(1, this.configOnWeb.CameraData1.StreamUrl, this.configOnWeb.CameraData2.StreamUrl, c3Device, this.apiController, engineApiController, true, false, true);
laneIn.BorderStyle = BorderStyle.FixedSingle;
laneIn.Location = new System.Drawing.Point(sidebar.Location.X + sidebar.Width + 20, 0);
laneIn.Location = new System.Drawing.Point(sidebar.Location.X + sidebar.Width + 20, menuStrip.Height);
Controls.Add(laneIn);
laneOut = new LaneOut(2, this.configOnWeb.CameraData3.StreamUrl, this.configOnWeb.CameraData4.StreamUrl, c3Device, this.apiController, engineApiController, true, false, true);
laneOut.BorderStyle = BorderStyle.FixedSingle;
laneOut.Location = new System.Drawing.Point(laneIn.Location.X + laneIn.Width + 20, 0);
laneOut.Location = new System.Drawing.Point(laneIn.Location.X + laneIn.Width + 20, menuStrip.Height);
Controls.Add(laneOut);
statusBar = new StatusBar("192.168.1.122", "192.168.1.200", TimeSpan.FromSeconds(1));
@ -54,17 +54,38 @@ namespace AIParkingApplication
StartLanes();
}
~AIParkingApplicationForm()
{
laneIn.Stop();
laneOut.Stop();
Application.Exit();
}
private void StartLanes()
{
laneIn.Start();
laneOut.Start();
}
private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e)
{
laneIn.Stop();
laneOut.Stop();
laneIn.Hide();
laneOut.Hide();
LaneIn laneIn1, laneIn2;
laneIn1 = new LaneIn(1, this.configOnWeb.CameraData1.StreamUrl, this.configOnWeb.CameraData2.StreamUrl, c3Device, this.apiController, engineApiController, true, false, true);
laneIn1.BorderStyle = BorderStyle.FixedSingle;
laneIn1.Location = new System.Drawing.Point(sidebar.Location.X + sidebar.Width + 20, menuStrip.Height);
Controls.Add(laneIn1);
laneIn2 = new LaneIn(2, this.configOnWeb.CameraData1.StreamUrl, this.configOnWeb.CameraData2.StreamUrl, c3Device, this.apiController, engineApiController, true, false, true);
laneIn2.BorderStyle = BorderStyle.FixedSingle;
laneIn2.Location = new System.Drawing.Point(laneIn1.Location.X + laneIn1.Width + 20, menuStrip.Height);
Controls.Add(laneIn2);
laneIn1.Start();
laneIn2.Start();
this.MinimumSize = new System.Drawing.Size(500, 768);
this.Width = 500;
}
private void AIParkingApplicationForm_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
}
}

View File

@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

View File

@ -42,7 +42,8 @@ namespace AIParkingApplication
Console.WriteLine($"Login Exception:\t{DateTime.Now.GetTimeFormatted()} \t {ex.Message}");
return new LoginDataModel
{
IsLoginSuccess = false
IsLoginSuccess = false,
Exception = ex
};
}
}
@ -259,6 +260,8 @@ namespace AIParkingApplication
[JsonProperty("data")]
public Config LoginData { get; set; }
public Exception Exception { get; set; }
}
public class Config

View File

@ -42,14 +42,6 @@ namespace AIParkingApplication
plateCamera = new Camera(plateStream);
this.apiController = apiController;
this.doorControlAccess = doorControlAccess;
this.doorControlAccess.OnNewCardReceived += C3Device_OnNewCardReceived;
plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived;
plateCamera.OnOpenVideoStreamFailed += PlateCamera_OnOpenVideoStreamFailed;
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
plateProcessor = new PlateProcessor(engineApiController, this.isSupportSquarePlate, this.isSupportLongPlate);
}
@ -188,9 +180,9 @@ namespace AIParkingApplication
private void ConnectToDoorAccessControl()
{
if (!this.doorControlAccess.Connect().HasError)
if (!doorControlAccess.Connect().HasError)
{
_ = this.doorControlAccess.GetLogToReceiveNewCard();
_ = doorControlAccess.GetLogToReceiveNewCard();
}
else
{
@ -200,6 +192,12 @@ namespace AIParkingApplication
private void LaneIn_Load(object sender, EventArgs e)
{
doorControlAccess.OnNewCardReceived += C3Device_OnNewCardReceived;
plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived;
plateCamera.OnOpenVideoStreamFailed += PlateCamera_OnOpenVideoStreamFailed;
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
ConnectToDoorAccessControl();
}
}

View File

@ -267,6 +267,7 @@
this.Controls.Add(this.grbPlateRefernce);
this.Name = "LaneOut";
this.Size = new System.Drawing.Size(680, 692);
this.Load += new System.EventHandler(this.LaneOut_Load);
this.grbPlateRefernce.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxOverviewImageIn)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateImageIn)).EndInit();

View File

@ -20,6 +20,7 @@ namespace AIParkingApplication
private bool isRetryMode;
private IDoorControlAccess doorControlAccess;
private ApiController apiController;
private Printer printer;
public LaneOut(int doorId,
string plateStream,
@ -42,14 +43,7 @@ namespace AIParkingApplication
plateCamera = new Camera(plateStream);
this.apiController = apiController;
this.doorControlAccess = doorControlAccess;
this.doorControlAccess.OnNewCardReceived += C3Device_OnNewCardReceived;
plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived;
plateCamera.OnOpenVideoStreamFailed += PlateCamera_OnOpenVideoStreamFailed;
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
printer = new Printer();
plateProcessor = new PlateProcessor(engineApiController, this.isSupportSquarePlate, this.isSupportLongPlate);
}
@ -103,6 +97,14 @@ namespace AIParkingApplication
{
OpenDoor(doorId);
}
PrinterData printerData = new PrinterData
{
PlateString = result.PlateString,
MoneyAmount = saveLogResult.Cost,
TimeParkingIn = cardInformation.TimeIn,
TimeParkingOut = DateTime.Now.GetTimeFormatted()
};
printer.DoPrint(printerData);
}
else
{
@ -234,9 +236,9 @@ namespace AIParkingApplication
private void ConnectToDoorAccessControl()
{
if (!this.doorControlAccess.Connect().HasError)
if (!doorControlAccess.Connect().HasError)
{
_ = this.doorControlAccess.GetLogToReceiveNewCard();
_ = doorControlAccess.GetLogToReceiveNewCard();
}
else
{
@ -248,5 +250,15 @@ namespace AIParkingApplication
{
ConnectToDoorAccessControl();
}
private void LaneOut_Load(object sender, EventArgs e)
{
doorControlAccess.OnNewCardReceived += C3Device_OnNewCardReceived;
plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived;
plateCamera.OnOpenVideoStreamFailed += PlateCamera_OnOpenVideoStreamFailed;
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
}
}
}

View File

@ -55,15 +55,26 @@ namespace AIParkingApplication
}
var loginResult = await apiController.Login(new LoginModel { Username = username, Password = password });
if (loginResult.Exception != null)
{
var execeptioMessage = loginResult.Exception.Message;
if (execeptioMessage.Contains("Error converting value"))
{
lblLoginStatus.UpdateLabel("Tên tài khoản hoặc mật khẩu không đúng!", Color.Red);
}
if (execeptioMessage.Contains("An error occurred while sending the request"))
{
lblLoginStatus.UpdateLabel("Không có kết nối tới server!\r\nKiểm tra lại kết nối tới server!", Color.Red, Color.White);
}
return;
}
if (loginResult.IsLoginSuccess)
{
new AIParkingApplicationForm(apiController, loginResult.LoginData).Show();
Hide();
}
else
{
lblLoginStatus.Text = "Tên tài khoản hoặc mật khẩu không đúng!";
}
}
private void btnLogin_Click(object sender, System.EventArgs e)

View File

@ -0,0 +1,71 @@
using Microsoft.Win32;
using System;
using System.IO;
using System.Windows.Forms;
namespace AIParkingApplication
{
public class Printer
{
public Printer()
{
SetupPrinterPageSetting();
}
public void DoPrint(PrinterData printData)
{
WebBrowser webBrowser = new WebBrowser();
webBrowser.Left = 0;
string documentText = ProcessingString("PrinterForm.html", printData);
if (!string.IsNullOrEmpty(documentText))
{
webBrowser.DocumentText = documentText;
webBrowser.DocumentCompleted += WebBrowser_DocumentCompleted;
}
}
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
((WebBrowser)sender).Print();
}
private string ProcessingString(string path, PrinterData printerField)
{
try
{
string htmlStr = File.ReadAllText(path);
htmlStr = htmlStr.Replace("{PLATE_STRING}", printerField.PlateString)
.Replace("{TIME_PARKING_IN}", printerField.TimeParkingIn)
.Replace("{TIME_PARKING_OUT}", printerField.TimeParkingOut)
.Replace("{MONEY_AMOUNT}", printerField.MoneyAmount);
return htmlStr;
}
catch (Exception ex)
{
Console.WriteLine($"ProcessingString\texMessage:{ex.Message}");
return string.Empty;
}
}
private void SetupPrinterPageSetting()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\PageSetup", RegistryKeyPermissionCheck.ReadWriteSubTree);
key.SetValue("footer", string.Empty, RegistryValueKind.String);
key.SetValue("header", string.Empty, RegistryValueKind.String);
key.SetValue("margin_top", 0);
key.SetValue("margin_right", 0.2);
key.SetValue("margin_bottom", 0.5);
key.SetValue("margin_left", 0.2);
key.Close();
}
}
public class PrinterData
{
public string PlateString { get; set; }
public string TimeParkingIn { get; set; }
public string TimeParkingOut { get; set; }
public string MoneyAmount { get; set; }
}
}

View File

@ -256,6 +256,7 @@
this.Controls.Add(this.grbVehicleStatistics);
this.Name = "Statistic";
this.Size = new System.Drawing.Size(192, 292);
this.Load += new System.EventHandler(this.Statistic_Load);
this.grbVehicleStatistics.ResumeLayout(false);
this.tlpStatisticTable.ResumeLayout(false);
this.tlpStatisticTable.PerformLayout();

View File

@ -17,7 +17,6 @@ namespace AIParkingApplication
this.apiController = apiController;
this.updateInterval = updateInterval;
statisticsThread = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true };
statisticsThread.Start();
}
private void GetStatistic()
@ -55,5 +54,10 @@ namespace AIParkingApplication
[JsonProperty("total_out")]
public string TotalOut { get; set; }
}
private void Statistic_Load(object sender, EventArgs e)
{
statisticsThread.Start();
}
}
}

View File

@ -136,6 +136,7 @@
this.MinimumSize = new System.Drawing.Size(1366, 24);
this.Name = "StatusBar";
this.Size = new System.Drawing.Size(1366, 24);
this.Load += new System.EventHandler(this.StatusBar_Load);
this.ResumeLayout(false);
}

View File

@ -13,6 +13,7 @@ namespace AIParkingApplication
private string doorAccessControlDeviceIP;
private TimeSpan updateInterval;
private const string engineFilePath = @"\engine.bat";
private Thread updateInfoThread;
public StatusBar(string webServerIP, string doorAccessControlDeviceIP, TimeSpan updateInterval)
{
@ -20,9 +21,7 @@ namespace AIParkingApplication
this.webServerIP = webServerIP;
this.doorAccessControlDeviceIP = doorAccessControlDeviceIP;
this.updateInterval = updateInterval;
Thread thrStatus = new Thread(new ThreadStart(UpdateStatus));
thrStatus.IsBackground = true;
thrStatus.Start();
updateInfoThread = new Thread(new ThreadStart(UpdateStatus)) { IsBackground = true };
}
private void UpdateStatus()
@ -98,6 +97,11 @@ namespace AIParkingApplication
public Color BackColor { get; set; }
public Color ForeColor { get; set; }
}
private void StatusBar_Load(object sender, EventArgs e)
{
updateInfoThread.Start();
}
}
}

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
@media only print {
@page {
margin: 0;
}
body {
margin: 0 20px;
height: 100px;
}
}
</style>
</head>
<body style="">
<h3 style="text-align: center;"><em>BỆNH VIỆN BẠCH MAI</em></h3>
<h2 style="text-align: center;"><strong>Biên lai thu tiền</strong></h2>
<p>Biển số xe: <em><strong>{PLATE_STRING}</strong></em></p>
<p>Thời gian vào: <em><strong>{TIME_PARKING_IN}</strong></em></p>
<p>Thời gian ra: <strong><em>{TIME_PARKING_OUT}</em></strong></p>
<p>Số tiền: <strong><em>{MONEY_AMOUNT}</em></strong></p>
</body>
</html>