Esempio n. 1
0
        private static DinningTable covertToDinningTable(string id, int guestAmount, DateTime arrivedTime, string note)
        {
            DinningTable table = new DinningTable();

            table.Id          = id.Trim();
            table.GuestAmount = guestAmount;
            table.ArrivedTime = arrivedTime;
            table.Note        = note.Trim();

            return(table);
        }
        public void GetDinningTableTest()
        {
            string       tableNumber = string.Empty;       // TODO: 初始化为适当的值
            DinningTable expected    = new DinningTable(); // TODO: 初始化为适当的值

            expected.Id          = "003";
            expected.GuestAmount = 5;
            expected.ArrivedTime = DateTime.Parse("2010-6-5 20:05:57");
            expected.Note        = string.Empty;

            DinningTable actual;

            actual = TableDao.GetDinningTable("003");

            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.GuestAmount, actual.GuestAmount);
            Assert.AreEqual(expected.ArrivedTime.ToString(), actual.ArrivedTime.ToString());
            Assert.AreEqual(expected.Note, actual.Note);
        }
Esempio n. 3
0
        public static void InsertDinningTable(string tableId, DinningTable dinning)
        {
            List <SqlCommand> commands = new List <SqlCommand>();

            SqlCommand comm = new SqlCommand(@"insert into DinningTable(Id, TableId, GuestAmount, ArrivedTime, Note)
                                                                             values(@Id, @TableId, @GuestAmount, @ArrivedTime, @Note)");


            comm.Parameters.Add("@Id", SqlDbType.Char, 10);
            comm.Parameters.Add("@TableId", SqlDbType.Char, 10);
            comm.Parameters.Add("@GuestAmount", SqlDbType.Int);
            comm.Parameters.Add("@ArrivedTime", SqlDbType.DateTime);
            comm.Parameters.Add("@Note", SqlDbType.Text);

            comm.Parameters["@Id"].Value          = dinning.Id;
            comm.Parameters["@TableId"].Value     = tableId;
            comm.Parameters["@GuestAmount"].Value = dinning.GuestAmount;
            comm.Parameters["@ArrivedTime"].Value = dinning.ArrivedTime;
            comm.Parameters["@Note"].Value        = dinning.Note;

            commands.Add(comm);

            try
            {
                using (SqlConnection conn = Utilities.GetConnection())
                {
                    Utilities.TransactionExecuteNonQuery(conn, commands);
                }
            }
            catch (SqlException ex)
            {
                if (ex.Number >= 50000)
                {
                    throw new HCSMSException(ex.Message);
                }
                else
                {
                    throw new HCSMSException("Transaction Errors !", ex);
                }
            }
        }
        public void OrderItem(string tableNumber, List <Item> itemList)
        {
            FrontDeskRequest frontdesk = null;

            try
            {
                HCSMSLog.OnWarningLog(this, new NotifyEventArgs("Recieve Order Request"));

                //check if this table is really in use
                DinningTable table = TableDao.GetDinningTable(tableNumber);
                if (table == null)
                {
                    throw  new HCSMSException("餐桌是空的 !");
                }

                // constructing order list
                List <RequestHandleInfo> requestList = new List <RequestHandleInfo>();
                foreach (Item ite in itemList)
                {
                    RequestHandleInfo info = new RequestHandleInfo();
                    info.EntityId    = tableNumber;
                    info.IsHandled   = false;
                    info.RequestType = RequestType.OrderItem;
                    info.SourceId    = ite.Id;

                    requestList.Add(info);
                }

                //check for response of cook at the kitchen
                KitchenRequest handler = KitchenRequestControl.GetService();
                if (handler == null)
                {
                    requestList.Clear();
                }
                else
                {
                    requestList = handler.OnOrderItem(requestList);
                }
                HCSMSLog.OnWarningLog(this, new NotifyEventArgs("Recieve Result order item"));

                List <RequestHandleInfo> denyList = new List <RequestHandleInfo>();
                foreach (RequestHandleInfo ite in requestList)
                {
                    if (!ite.IsHandled)
                    {
                        denyList.Add(ite);
                    }
                }
                if (denyList.Count == 0 && requestList.Count > 0)
                {
                    //save data to database
                    ItemDao.InsertItemOrder(table.Id, itemList);
                }
                else
                {
                    frontdesk = FrontDeskRequestControl.GetService(callBackId);
                    if (frontdesk != null)
                    {
                        //means kitchen service is not up
                        if (requestList.Count == 0)
                        {
                            frontdesk.InformationMessage(new NotifyEventArgs("不存在厨房处理服务!"));
                        }
                        // notify front desk, the request is not satisfied
                        else
                        {
                            frontdesk.RequestDeny(denyList);
                        }
                    }
                }
            }
            catch (HCSMSException ex)
            {
                raiseError(ex);
                if (frontdesk != null)
                {
                    frontdesk.ErrorMessage(new ErrorEventArgs("Order Item Not Success", ex));
                }
            }
            catch (Exception ex)
            {
                raiseError(ex);
            }
        }