/// <summary>
        /// 添加一个 外部的命令.
        /// </summary>
        /// <param name="cmd"></param>
        public void AddNewOutsideCommand(CommandOutside cmd)
        {
            if (logger.IsInfoEnabled)
            {
                logger.InfoFormat("电梯外部的人,在{0}层,按了一下{1}的按钮!", cmd.FromFloorNum, cmd.CommandType);
            }


            // 如果外部命令是 “前往指定的楼层”
            // 那么判断, 该楼层是否已经在列表中了.
            var query =
                from data in todoList
                where data.StopAtFloorNum == cmd.FromFloorNum
                select data;

            if (cmd.CommandType == CommandOutside.CommandOutsideType.Up)
            {
                // 指定楼层上面,按了 向上按钮.
                query = query.Where(p => p.StopWhen == ElevatorRunningStatus.Up);
            }
            else
            {
                // 指定楼层上面,按了 向下按钮.
                query = query.Where(p => p.StopWhen == ElevatorRunningStatus.Down);
            }

            if (query.Count() == 0)
            {
                // todoList 数据列表中没有数据.
                // 那么 新增命令.

                // 停在哪层楼
                ElevatorCommand newCmd = new ElevatorCommand()
                {
                    StopAtFloorNum = cmd.FromFloorNum,
                };


                // 向上停? 向下停?
                if (cmd.CommandType == CommandOutside.CommandOutsideType.Up)
                {
                    newCmd.StopWhen = ElevatorRunningStatus.Up;
                }
                else
                {
                    newCmd.StopWhen = ElevatorRunningStatus.Down;
                }

                // 加入列表.
                todoList.Add(newCmd);
            }

            // 基本状态切换.
            SwitchRunningStatus();
        }
        /// <summary>
        /// 添加一个 外部的命令.
        /// </summary>
        /// <param name="cmd"></param>
        public void AddNewOutsideCommand(CommandOutside cmd)
        {
            if (logger.IsInfoEnabled )
            {
                logger.InfoFormat ("电梯外部的人,在{0}层,按了一下{1}的按钮!", cmd.FromFloorNum,  cmd.CommandType);
            }

            // 如果外部命令是 “前往指定的楼层”
            // 那么判断, 该楼层是否已经在列表中了.
            var query =
                from data in todoList
                where data.StopAtFloorNum == cmd.FromFloorNum
                select data;

            if (cmd.CommandType == CommandOutside.CommandOutsideType.Up)
            {
                // 指定楼层上面,按了 向上按钮.
                query = query.Where(p => p.StopWhen == ElevatorRunningStatus.Up);
            }
            else
            {
                // 指定楼层上面,按了 向下按钮.
                query = query.Where(p => p.StopWhen == ElevatorRunningStatus.Down);
            }

            if (query.Count() == 0)
            {
                // todoList 数据列表中没有数据.
                // 那么 新增命令.

                // 停在哪层楼
                ElevatorCommand newCmd = new ElevatorCommand()
                {
                    StopAtFloorNum = cmd.FromFloorNum,
                };

                // 向上停? 向下停?
                if (cmd.CommandType == CommandOutside.CommandOutsideType.Up)
                {
                    newCmd.StopWhen = ElevatorRunningStatus.Up;
                }
                else
                {
                    newCmd.StopWhen = ElevatorRunningStatus.Down;
                }

                // 加入列表.
                todoList.Add(newCmd);
            }

            // 基本状态切换.
            SwitchRunningStatus();
        }
 /// <summary>
 /// 楼层上面 按了 上/下的按钮.
 /// </summary>
 /// <param name="cmd"></param>
 public void AddNewOutsideCommand(CommandOutside cmd)
 {
     this.myElevator.AddNewOutsideCommand(cmd);
 }
        /// <summary>
        /// 向上.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUp_Click(object sender, EventArgs e)
        {
            btnUp.BackColor = Color.Orange;
            this.Refresh();

            // 外部命令.
            CommandOutside cmd = new CommandOutside() {
                // 本楼层按的按钮.
                FromFloorNum = this.FloorNo,
                // 方向:向上
                CommandType  = CommandOutside.CommandOutsideType.Up,
            };
            this.myElevatorManager.AddNewOutsideCommand(cmd);
        }
Exemple #5
0
 /// <summary>
 /// 楼层上面 按了 上/下的按钮.
 /// </summary>
 /// <param name="cmd"></param>
 public void AddNewOutsideCommand(CommandOutside cmd)
 {
     this.myElevator.AddNewOutsideCommand(cmd);
 }