198 lines
7.1 KiB
C#
198 lines
7.1 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AIParkingApplication
|
|
{
|
|
public partial class AIParkingApplicationForm : Form
|
|
{
|
|
private ApiController apiController;
|
|
private IDoorControlAccess c3Device;
|
|
private LaneIn laneIn12;
|
|
private LaneIn laneIn56;
|
|
private LaneOut laneOut34;
|
|
private LaneOut laneOut78;
|
|
private StatusBar statusBar;
|
|
private Sidebar sidebar;
|
|
private Config configOnWeb;
|
|
private EngineApiController engineApiController;
|
|
|
|
public AIParkingApplicationForm(ApiController apiController, Config configOnWeb)
|
|
{
|
|
InitializeComponent();
|
|
this.apiController = apiController;
|
|
this.configOnWeb = configOnWeb;
|
|
c3Device = new C3DeviceController("192.168.1.200");
|
|
|
|
sidebar = new Sidebar(apiController)
|
|
{
|
|
Location = new Point(0, 0)
|
|
};
|
|
Controls.Add(sidebar);
|
|
|
|
statusBar = new StatusBar("192.168.1.122", "192.168.1.200", TimeSpan.FromSeconds(1))
|
|
{
|
|
Location = new Point(0, sidebar.Location.Y + sidebar.Height + 26),
|
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Left
|
|
};
|
|
Controls.Add(statusBar);
|
|
|
|
try
|
|
{
|
|
engineApiController = new EngineApiController($"http://{this.configOnWeb.APIPath.ApiPlateRecognize.IP}:{this.configOnWeb.APIPath.ApiPlateRecognize.Port}");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show("Cấu hình API Plate Recognize lỗi!", "Cấu hình API Engine lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
InitAllLanes();
|
|
}
|
|
|
|
private void InitAllLanes()
|
|
{
|
|
laneIn12 = new LaneIn(10, configOnWeb.CameraData1.Id.ToString(), configOnWeb.CameraData1.StreamUrl, configOnWeb.CameraData2.StreamUrl, c3Device, apiController, engineApiController, true, false, true);
|
|
laneIn12.BorderStyle = BorderStyle.FixedSingle;
|
|
laneIn12.Hide();
|
|
Controls.Add(laneIn12);
|
|
|
|
laneOut34 = new LaneOut(20, configOnWeb.CameraData3.Id.ToString(), configOnWeb.CameraData3.StreamUrl, configOnWeb.CameraData4.StreamUrl, c3Device, apiController, engineApiController, true, false, true);
|
|
laneOut34.BorderStyle = BorderStyle.FixedSingle;
|
|
laneOut34.Hide();
|
|
Controls.Add(laneOut34);
|
|
|
|
laneIn56 = new LaneIn(10, configOnWeb.CameraData5.Id.ToString(), configOnWeb.CameraData5.StreamUrl, configOnWeb.CameraData6.StreamUrl, c3Device, apiController, engineApiController, true, false, true);
|
|
laneIn56.BorderStyle = BorderStyle.FixedSingle;
|
|
laneIn56.Hide();
|
|
Controls.Add(laneIn56);
|
|
|
|
laneOut78 = new LaneOut(20, configOnWeb.CameraData7.Id.ToString(), configOnWeb.CameraData7.StreamUrl, configOnWeb.CameraData8.StreamUrl, c3Device, apiController, engineApiController, true, false, true);
|
|
laneOut78.BorderStyle = BorderStyle.FixedSingle;
|
|
laneOut78.Hide();
|
|
Controls.Add(laneOut78);
|
|
}
|
|
|
|
private void UpdateLaneInOut()
|
|
{
|
|
laneIn12.DoorId = 1;
|
|
laneIn12.Location = new Point(sidebar.Location.X + sidebar.Width + 20, menuStrip.Height);
|
|
laneIn12.Show();
|
|
laneIn12.Start();
|
|
|
|
laneOut34.DoorId = 2;
|
|
laneOut34.Location = new Point(laneIn12.Location.X + laneIn12.Width + 20, menuStrip.Height);
|
|
laneOut34.Show();
|
|
laneOut34.Start();
|
|
}
|
|
|
|
private void UpdateLaneInIn()
|
|
{
|
|
laneIn12.DoorId = 1;
|
|
laneIn12.Location = new Point(sidebar.Location.X + sidebar.Width + 20, menuStrip.Height);
|
|
laneIn12.Show();
|
|
laneIn12.Start();
|
|
|
|
laneIn56.DoorId = 2;
|
|
laneIn56.Location = new Point(laneIn12.Location.X + laneIn12.Width + 20, menuStrip.Height);
|
|
laneIn56.Show();
|
|
laneIn56.Start();
|
|
}
|
|
|
|
private void UpdateLaneOutIn()
|
|
{
|
|
laneOut78.DoorId = 1;
|
|
laneOut78.Location = new Point(sidebar.Location.X + sidebar.Width + 20, menuStrip.Height);
|
|
laneOut78.Show();
|
|
laneOut78.Start();
|
|
|
|
laneIn56.DoorId = 2;
|
|
laneIn56.Location = new Point(laneOut78.Location.X + laneOut78.Width + 20, menuStrip.Height);
|
|
laneIn56.Show();
|
|
laneIn56.Start();
|
|
}
|
|
|
|
private void UpdateLaneOutOut()
|
|
{
|
|
laneOut78.DoorId = 1;
|
|
laneOut78.Location = new Point(sidebar.Location.X + sidebar.Width + 20, menuStrip.Height);
|
|
laneOut78.Show();
|
|
laneOut78.Start();
|
|
|
|
laneOut34.DoorId = 2;
|
|
laneOut34.Location = new Point(laneOut78.Location.X + laneOut78.Width + 20, menuStrip.Height);
|
|
laneOut34.Show();
|
|
laneOut34.Start();
|
|
}
|
|
|
|
private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e)
|
|
{
|
|
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
|
|
StopAllLanes();
|
|
UpdateLaneInIn();
|
|
}
|
|
|
|
private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e)
|
|
{
|
|
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
|
|
StopAllLanes();
|
|
UpdateLaneInOut();
|
|
}
|
|
|
|
private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e)
|
|
{
|
|
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
|
|
StopAllLanes();
|
|
UpdateLaneOutIn();
|
|
}
|
|
|
|
private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e)
|
|
{
|
|
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
|
|
StopAllLanes();
|
|
UpdateLaneOutOut();
|
|
}
|
|
|
|
private void UpdateMenuStripItemStatus(ToolStripMenuItem selectedToolStripMenuItem)
|
|
{
|
|
if (selectedToolStripMenuItem != null)
|
|
{
|
|
((ToolStripMenuItem)selectedToolStripMenuItem.OwnerItem).DropDownItems
|
|
.OfType<ToolStripMenuItem>().ToList()
|
|
.ForEach(item =>
|
|
{
|
|
item.Checked = false;
|
|
item.Enabled = true;
|
|
});
|
|
|
|
selectedToolStripMenuItem.Checked = true;
|
|
selectedToolStripMenuItem.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void StopAllLanes()
|
|
{
|
|
laneIn12.DoorId = 10;
|
|
laneIn56.DoorId = 10;
|
|
laneOut34.DoorId = 10;
|
|
laneOut78.DoorId = 10;
|
|
|
|
laneIn12?.Stop();
|
|
laneIn56?.Stop();
|
|
laneOut34?.Stop();
|
|
laneOut78?.Stop();
|
|
|
|
laneIn12?.Hide();
|
|
laneIn56?.Hide();
|
|
laneOut34?.Hide();
|
|
laneOut78?.Hide();
|
|
}
|
|
|
|
private void AIParkingApplicationForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
}
|
|
}
|