Пример #1
0
 /// <summary>
 /// 将订单添加到订单队列中
 /// </summary>
 /// <param name="order"></param>
 public void AddToOderQueue(Order order)
 {
     //队列是否为空
     if (_orderQueue==null)
     {
         _orderQueue=new Queue<Order>();
     }
     else
     {
         _orderQueue.Enqueue(order);//将菜品添加进订单队列
         _orderNum++;
     }
 }
Пример #2
0
        /// <summary>
        /// 纠正订单剩余制作时间
        /// 订单信息更新后,调用本函数
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static int ReviseOrderTimeToTable(Order order)
        {
            //判断串口是否打开
            if (SerialPortConfig.TablePort.IsOpen)
            {
                char[] data = DataProtocol.ReviseOrderTimeToTable(order, order.TableId);//将订单转换为char数组
                try
                {
                    SerialPortConfig.TablePort.Write(data, 0, data.Length);//发送数据
                    return 0;//数据发送成功
                }
                //捕捉异常,不知道怎么处理,哈哈
                catch (TimeoutException)
                {
                    return 1;
                }
            }

            //如果串口尚未打开,则自动打开串口
            TimeSpan waitTime = new TimeSpan(0, 0, 0, 0, 50);
            Thread.Sleep(waitTime);
            SerialPortConfig.TablePort.Open();//重新打开串口
            return 1;//串口未打开,提示重新发送数据
        }
Пример #3
0
        /// <summary>
        /// 后台定时查询来自点餐端的新订单信息
        /// 将新订单加入到全局 _orderQueue中
        /// </summary>
        private void BackGroundQueryNewOrder()
        {
            List<Order> sendToTabelList=new List<Order>();//发送到餐桌的订单
            var timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(10);//设定timer间隔,每隔10s查询一次
            timer.Tick+=new EventHandler(delegate(object s, EventArgs a)
            {
                var connection = DataBaseOperation.CreateConnection();//获取数据库连接
                connection.Open();//打开连接
                string cmdText = "select * from FoodOrder where OrderState=0";//查询新订单
                var adapter = DataBaseOperation.GetSqlDataAdapter(cmdText, connection);//获取adapter
                var dataSet = DataBaseOperation.GetDataSet(adapter);//获取dataSet
                SqlCommandBuilder commandBuilder=new SqlCommandBuilder(adapter);
                if (dataSet != null)
                {
                    var num = dataSet.Tables[0].Rows.Count;//获取新订单的数量
                    //将数据库订单存储到订单队列中,并更新数据库OrderStae状态
                    for (int i = 0; i < num; i++)
                    {
                        Order tempOrder = new Order
                        {
                            Id = int.Parse((dataSet.Tables[0].Rows[i]["Id"]).ToString()),//设置订单菜品号
                            SeqId = int.Parse((dataSet.Tables[0].Rows[i]["SeqId"]).ToString()),//设置订单队列序号
                            TableId = int.Parse((dataSet.Tables[0].Rows[i]["TableId"]).ToString()),//设置订单餐桌号
                            OrderState = (char)OrderState.Waiting,//设置订单状态
                            ReceiveFromDbTime = DateTime.Now, //设置从数据库读取到的时间
                        };

                        dataSet.Tables[0].Rows [i]["OrderState"] = (int)OrderState.Waiting;//将工作状态设置为“等待”,下次不再读取
                        //加锁(不解释了....)
                        lock (_orderQueue)
                        {
                            _orderQueue.AddToOderQueue(tempOrder);//将订单添加到订单队列
                            sendToTabelList.Add(tempOrder);//将订单添加到sendToTabelList队列,缺少预测时间
                        }
                    }
                    //将修改后的信息重新写入数据库
                    if (dataSet.HasChanges())
                    {
                        adapter.Update(dataSet);
                    }
                    connection.Close();//关闭连接
                }

                connection.Open();//打开数据连接

                //完善sendToTabelList队列中订单的预测时间
                for (int i=0;i<sendToTabelList.Count;i++)
                {
                    cmdText = "select * from Food where Id='" + sendToTabelList[i].Id + "' ";
                    adapter = DataBaseOperation.GetSqlDataAdapter(cmdText, connection);//获取adapter
                    dataSet = DataBaseOperation.GetDataSet(adapter);//获取dataSet
                    //设置order的预测时间ForcastTime
                    sendToTabelList[i].ForcastTime =
                        int.Parse((dataSet.Tables[0].Rows[0]["waitSendToKitchenTime"]).ToString()) +
                        int.Parse((dataSet.Tables[0].Rows[0]["waitToMakeTime"]).ToString()) +
                        int.Parse((dataSet.Tables[0].Rows[0]["makingTime"]).ToString());

                }

                //---------------------------------------------------------------//
                //这里方法有问题,不保所有的订单都是同一个餐桌的,后期需要进行改进
                //DataSendAndRecv.SendOrderToTabel(sendToTabelList,sendToTabelList[0].TableId);
                //---------------------------------------------------------------//
                //---------------------------------------------------------------//
            });
            timer.Start();//启动定时器
        }