AIParkingApplicationForm - Add Func. UpdateMenuStripItemStatus

This commit is contained in:
DucDangAnh 2020-07-09 15:09:52 +07:00
parent b46d79e101
commit 0cc0400b05

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
namespace AIParkingApplication namespace AIParkingApplication
@ -124,28 +125,49 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e)
{ {
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInIn(); UpdateLaneInIn();
} }
private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e)
{ {
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInOut(); UpdateLaneInOut();
} }
private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e)
{ {
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutIn(); UpdateLaneOutIn();
} }
private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e)
{ {
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutOut(); 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() private void StopAllLanes()
{ {
laneIn12.DoorId = 10; laneIn12.DoorId = 10;