AIParkingApplicationForm - hardcoded to const CURRENT_LANE_SETTING_KEY. Util - Add extensition method: DisableSelected

This commit is contained in:
DucDangAnh 2020-07-14 11:07:53 +07:00
parent 0375eac88d
commit 740858693e
2 changed files with 26 additions and 7 deletions

View File

@ -8,6 +8,8 @@ namespace AIParkingApplication
{ {
public partial class AIParkingApplicationForm : Form public partial class AIParkingApplicationForm : Form
{ {
private const string CURRENT_LANE_SETTING_KEY = "CURRENT_LANE_SETTING";
private ApiController apiController; private ApiController apiController;
private IDoorControlAccess c3Device; private IDoorControlAccess c3Device;
private LaneIn laneIn12; private LaneIn laneIn12;
@ -92,6 +94,8 @@ namespace AIParkingApplication
laneOut34.Location = new Point(laneIn12.Location.X + laneIn12.Width + 20, menuStrip.Height); laneOut34.Location = new Point(laneIn12.Location.X + laneIn12.Width + 20, menuStrip.Height);
laneOut34.Show(); laneOut34.Show();
laneOut34.Start(); laneOut34.Start();
toolStripMenuItemSwitchLaneInOut.DisableSelected();
} }
private void UpdateLaneInIn() private void UpdateLaneInIn()
@ -105,6 +109,8 @@ namespace AIParkingApplication
laneIn56.Location = new Point(laneIn12.Location.X + laneIn12.Width + 20, menuStrip.Height); laneIn56.Location = new Point(laneIn12.Location.X + laneIn12.Width + 20, menuStrip.Height);
laneIn56.Show(); laneIn56.Show();
laneIn56.Start(); laneIn56.Start();
toolStripMenuItemSwitchLaneInIn.DisableSelected();
} }
private void UpdateLaneOutIn() private void UpdateLaneOutIn()
@ -118,6 +124,8 @@ namespace AIParkingApplication
laneIn56.Location = new Point(laneOut78.Location.X + laneOut78.Width + 20, menuStrip.Height); laneIn56.Location = new Point(laneOut78.Location.X + laneOut78.Width + 20, menuStrip.Height);
laneIn56.Show(); laneIn56.Show();
laneIn56.Start(); laneIn56.Start();
toolStripMenuItemSwitchLaneOutIn.DisableSelected();
} }
private void UpdateLaneOutOut() private void UpdateLaneOutOut()
@ -131,11 +139,13 @@ namespace AIParkingApplication
laneOut34.Location = new Point(laneOut78.Location.X + laneOut78.Width + 20, menuStrip.Height); laneOut34.Location = new Point(laneOut78.Location.X + laneOut78.Width + 20, menuStrip.Height);
laneOut34.Show(); laneOut34.Show();
laneOut34.Start(); laneOut34.Start();
toolStripMenuItemSwitchLaneOutOut.DisableSelected();
} }
private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e)
{ {
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-IN"); Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-IN");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInIn(); UpdateLaneInIn();
@ -143,7 +153,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"); Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInOut(); UpdateLaneInOut();
@ -151,7 +161,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"); Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "OUT-IN");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutIn(); UpdateLaneOutIn();
@ -159,7 +169,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"); Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "OUT-OUT");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutOut(); UpdateLaneOutOut();
@ -204,7 +214,7 @@ namespace AIParkingApplication
{ {
try try
{ {
string lanesConfig = ConfigurationManager.AppSettings["CURRENT_LANE_SETTING"]; string lanesConfig = ConfigurationManager.AppSettings[CURRENT_LANE_SETTING_KEY];
if (!string.IsNullOrEmpty(lanesConfig)) if (!string.IsNullOrEmpty(lanesConfig))
{ {
string[] lanes = lanesConfig.Split('-'); string[] lanes = lanesConfig.Split('-');
@ -215,14 +225,17 @@ namespace AIParkingApplication
if (lane0 == "in" && lane1 == "in") if (lane0 == "in" && lane1 == "in")
{ {
UpdateLaneInIn(); UpdateLaneInIn();
} }
if (lane0 == "in" && lane1 == "out") if (lane0 == "in" && lane1 == "out")
{ {
UpdateLaneInOut(); UpdateLaneInOut();
} }
if (lane0 == "out" && lane1 == "in") if (lane0 == "out" && lane1 == "in")
{ {
UpdateLaneOutIn(); UpdateLaneOutIn();
} }
if (lane0 == "out" && lane1 == "out") if (lane0 == "out" && lane1 == "out")
{ {
@ -231,14 +244,14 @@ namespace AIParkingApplication
} }
else else
{ {
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-OUT"); Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut(); UpdateLaneInOut();
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-OUT"); Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut(); UpdateLaneInOut();
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadLaneSettingFromConfigurationFile\t{ex.Message}"); Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadLaneSettingFromConfigurationFile\t{ex.Message}");
} }

View File

@ -198,6 +198,12 @@ namespace AIParkingApplication
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tAddOrUpdateAppSettings\t{ex.Message}"); Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tAddOrUpdateAppSettings\t{ex.Message}");
} }
} }
public static void DisableSelected(this ToolStripMenuItem toolStripMenuItem)
{
toolStripMenuItem.Checked = true;
toolStripMenuItem.Enabled = false;
}
} }
public class PlateRequestEngineModel public class PlateRequestEngineModel