AIParkingApplicationForm - Add method: InitLaneFirstTime, save lanes configuration.

This commit is contained in:
DucDangAnh 2020-07-13 16:02:50 +07:00
parent 92d95236c8
commit daf755949a
2 changed files with 52 additions and 2 deletions

View File

@ -26,7 +26,7 @@ namespace AIParkingApplication
this.apiController = apiController; this.apiController = apiController;
this.configOnWeb = configOnWeb; this.configOnWeb = configOnWeb;
ReadAccessControlDeviceIPConfiguration(); ReadAccessControlDeviceIPConfigurationFile();
if (string.IsNullOrEmpty(doorAccessControlDeviceIP) || !Util.IsValidIPAddress(doorAccessControlDeviceIP)) if (string.IsNullOrEmpty(doorAccessControlDeviceIP) || !Util.IsValidIPAddress(doorAccessControlDeviceIP))
{ {
MessageBox.Show("Kiểm tra lại cấu hình IP thiết bị mở cửa! (C3200)", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Kiểm tra lại cấu hình IP thiết bị mở cửa! (C3200)", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -135,6 +135,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e)
{ {
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-IN");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInIn(); UpdateLaneInIn();
@ -142,6 +143,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e)
{ {
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-OUT");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInOut(); UpdateLaneInOut();
@ -149,6 +151,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e)
{ {
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "OUT-IN");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutIn(); UpdateLaneOutIn();
@ -156,6 +159,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e)
{ {
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "OUT-OUT");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutOut(); UpdateLaneOutOut();
@ -196,7 +200,51 @@ namespace AIParkingApplication
laneOut78?.Hide(); laneOut78?.Hide();
} }
private void ReadAccessControlDeviceIPConfiguration() private void InitLaneFirstTime()
{
try
{
string lanesConfig = ConfigurationManager.AppSettings["CURRENT_LANE_SETTING"];
if (!string.IsNullOrEmpty(lanesConfig))
{
string[] lanes = lanesConfig.Split('-');
if (lanes.Length == 2)
{
string lane0 = lanes[0].ToLower();
string lane1 = lanes[1].ToLower();
if (lane0 == "in" && lane1 == "in")
{
UpdateLaneInIn();
}
if (lane0 == "in" && lane1 == "out")
{
UpdateLaneInOut();
}
if (lane0 == "out" && lane1 == "in")
{
UpdateLaneOutIn();
}
if (lane0 == "out" && lane1 == "out")
{
UpdateLaneOutOut();
}
}
else
{
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-OUT");
UpdateLaneInOut();
}
}
}
catch (Exception ex)
{
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-OUT");
UpdateLaneInOut();
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadLaneSettingFromConfigurationFile\t{ex.Message}");
}
}
private void ReadAccessControlDeviceIPConfigurationFile()
{ {
try try
{ {
@ -212,6 +260,7 @@ namespace AIParkingApplication
private void AIParkingApplicationForm_Load(object sender, EventArgs e) private void AIParkingApplicationForm_Load(object sender, EventArgs e)
{ {
InitAllLanes(); InitAllLanes();
InitLaneFirstTime();
} }
private void AIParkingApplicationForm_FormClosing(object sender, FormClosingEventArgs e) private void AIParkingApplicationForm_FormClosing(object sender, FormClosingEventArgs e)

View File

@ -4,6 +4,7 @@
<add key="DOOR_ACCESS_DEVICE_CONTROL_IP" value="192.168.1.200" /> <add key="DOOR_ACCESS_DEVICE_CONTROL_IP" value="192.168.1.200" />
<add key="DEFAULT_USERNAME" value="congvao1" /> <add key="DEFAULT_USERNAME" value="congvao1" />
<add key="DEFAULT_PASSWORD" value="123456a@" /> <add key="DEFAULT_PASSWORD" value="123456a@" />
<add key="CURRENT_LANE_SETTING" value="OUT-OUT" />
</appSettings> </appSettings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />