Example #1
0
        public Transaction(Docket docket, List<Order> orders)
        {
            this.docket = docket;
            this.orders = orders;

            payTime = DateTime.Now;
        }
Example #2
0
        //add a new docket by splitting into partial docket and calling addPartialDocket
        private void addDocket(Docket docketToAdd)
        {
            //check if docket already exist;
            Docket existingDocket = null;

            foreach (Docket docket in this.dockets) {
                if (docketToAdd.DocketNumber == docket.DocketNumber) {
                    existingDocket = docket;
                    break;
                }
            }

            if (existingDocket != null) {
                this.removeExistingDocket(existingDocket);
            }

            this.dockets.Add(docketToAdd);

            List<BindingList<object>> partialDocketsToAdd = this.extractPartialDocketsToAdd(docketToAdd);

            //clasifying partialDocket to add to corresponding partialDocket list;
            foreach (BindingList<object> partialDocket in partialDocketsToAdd) {
                //check if partialDocket is done
                bool done = getPartialDocketState(partialDocket);

                if (done) this.addPartialDocket(partialDocket, true);
                else this.addPartialDocket(partialDocket, false);
            }

            this.refreshPage();
            this.refreshListDataSource();
            this.receiveDone.Set();
        }
Example #3
0
        public SelectPayForm(Docket docket, BindingList<Order> orders, NgopiPrinter ngopiPrinter, BindingList<Transaction> transactions)
        {
            InitializeComponent();
            this.orders = orders;
            this.docket = docket;
            this.ngopiPrinter = ngopiPrinter;
            this.transactions = transactions;

            foreach (Order order in orders) {
                if (!order.Paid) {
                    orderListBox.Items.Add(order);
                }
            }
        }
Example #4
0
        //toggle done state of an order and inform the server.
        private void toggleOrderDone(Order order, Docket ownerDocket, BindingList<object> partialDocket)
        {
            bool curState = getPartialDocketState(partialDocket);

            order.ToggleDone();
            this.sendDoneCommand(ownerDocket, order);

            bool newState = getPartialDocketState(partialDocket);

            if (curState != newState) {
                setPartialDocketState(newState, partialDocket);

                this.refreshPage();
                this.refreshListDataSource();
            }
        }
Example #5
0
        //send done command of an order
        private void sendDoneCommand(Docket docket, Order order)
        {
            List<byte> data = new List<byte>();

            int docketNumber = docket.DocketNumber;
            int index = docket.Orders.IndexOf(order);

            DoneCommand command = new DoneCommand(docketNumber, index);

            IFormatter formatter = new BinaryFormatter();
            Stream stream = new MemoryStream();
            formatter.Serialize(stream, command);

            byte[] res = ((MemoryStream)stream).ToArray();
            int sendLength = res.Length;

            byte[] length = BitConverter.GetBytes(sendLength);
            data.AddRange(length);
            data.AddRange(res);

            this.state.WorkSocket.Send(data.ToArray());
        }
Example #6
0
        //remove the existing docket and corresponding partialDocket
        private void removeExistingDocket(Docket existingDocket)
        {
            this.dockets.Remove(existingDocket);
            List<int> indexToRemove = new List<int>();

            //finding corresponding partialDocket
            foreach (BindingList<object> partialDocket in this.partialDocketsOngoing) {
                Docket selectedDocket = (Docket)partialDocket[0];
                if (selectedDocket == existingDocket) indexToRemove.Add(this.partialDocketsOngoing.IndexOf(partialDocket));
            }

            //and removing it
            foreach (int index in indexToRemove) {
                this.partialDocketsOngoing.RemoveAt(index);
            }

            //do the same thing to partialDocketsHistory
            indexToRemove.Clear();

            foreach (BindingList<object> partialDocket in this.partialDocketsHistory) {
                Docket selectedDocket = (Docket)partialDocket[0];
                if (selectedDocket == existingDocket) indexToRemove.Add(this.partialDocketsHistory.IndexOf(partialDocket));
            }

            foreach (int index in indexToRemove) {
                this.partialDocketsHistory.RemoveAt(index);
            }
        }
Example #7
0
        //process header
        private void processResponseHeader()
        {
            this.response = null;
            byte[] byteSize = new byte[4];
            this.responseType = this.tempBuffer[0];
            for (int i = 1; i < 5; i++) byteSize[i - 1] = this.tempBuffer[i];

            this.totalSize = BitConverter.ToInt32(byteSize, 0);
            this.tempBuffer.RemoveRange(0, 5); //removing the header
        }
Example #8
0
        //process the content of response
        private void processResponse(Socket handler)
        {
            Stream stream = new MemoryStream();
            stream.Write(this.tempBuffer.ToArray(), 0, this.totalSize);
            stream.Position = 0;

            IFormatter formatter = new BinaryFormatter();
            //process response
            if (this.responseType == 0) { //if it's a docket
                this.Invoke((ThreadStart)delegate {
                    this.response = (Docket)formatter.Deserialize(stream);
                    stream.Close();
                    this.addDocket(this.response);
                    this.receiveDone.WaitOne();
                });
                SoundPlayer notificationSound = new SoundPlayer("notification.wav");
                notificationSound.Play();
            } else if (this.responseType == 1) { //if it's a string message
                this.message = (string)formatter.Deserialize(stream);
                stream.Close();
                this.BeginInvoke((ThreadStart)delegate {
                    this.messageListBox.Items.Add(this.message);
                    this.messageListBox.SelectedIndex = this.messageListBox.Items.Count - 1;
                    this.notificationTimer.Start();
                    this.notificationButton.Visible = true;
                });
                SoundPlayer notificationSound = new SoundPlayer("notification.wav");
                notificationSound.Play();
            } else if (this.responseType == 2) { //close command
                handler.Shutdown(SocketShutdown.Both);
                handler.Close();
                this.FormClosing -= MainForm_FormClosing;
                this.BeginInvoke((ThreadStart)delegate {
                    this.Close();
                });
            } else {
                this.BeginInvoke((ThreadStart)delegate {
                    MessageBox.Show("Error: Unknow type of response");
                });
            }
        }
Example #9
0
        //split docket into partialdockets;
        private List<BindingList<object>> extractPartialDocketsToAdd(Docket docketToAdd)
        {
            List<BindingList<object>> partialDocketsToAdd = new List<BindingList<object>>();

            //adding partialDockets of non take away order;
            int numberOfLines = 3;
            BindingList<object> newPartialDocket = new BindingList<object>();
            newPartialDocket.Add(docketToAdd);

            foreach (Order order in docketToAdd.Orders) {
                if (!order.TakeAway && order.ItemOrder.SendTo == Item.Destination.Kitchen) {
                    numberOfLines += order.Length;
                    if (numberOfLines > this.countMaxLine()) {
                        partialDocketsToAdd.Add(newPartialDocket);
                        numberOfLines = 3 + order.Length;
                        newPartialDocket = new BindingList<object>();
                        newPartialDocket.Add(docketToAdd);
                    }

                    newPartialDocket.Add(order);
                }
            }

            if (newPartialDocket.Count > 1)
                partialDocketsToAdd.Add(newPartialDocket);

            //do the same for take away order
            numberOfLines = 3;
            newPartialDocket = new BindingList<object>();
            newPartialDocket.Add(docketToAdd);

            foreach (Order order in docketToAdd.Orders) {
                if (order.TakeAway && order.ItemOrder.SendTo == Item.Destination.Kitchen) {
                    numberOfLines += order.Length;
                    if (numberOfLines > this.countMaxLine()) {
                        partialDocketsToAdd.Add(newPartialDocket);
                        numberOfLines = 3 + order.Length;
                        newPartialDocket = new BindingList<object>();
                        newPartialDocket.Add(docketToAdd);
                    }

                    newPartialDocket.Add(order);
                }
            }

            if (newPartialDocket.Count > 1)
                partialDocketsToAdd.Add(newPartialDocket);

            return partialDocketsToAdd;
        }