private void PopulateDummyData()
        {
            OrderModel model = new Application.OrderModel();

            model.Id   = 1;
            model.Name = "Ben";
            OrderItemModel itemModel = new Application.OrderItemModel(1, 1, 4, "Sandwich", 0, 0, State.None);

            OrderItemComponentModel itemComponent = new OrderItemComponentModel(1, "Brie", "Brie", 1, 1, 1, 1);

            itemModel.AddComponentModel(itemComponent);

            itemComponent = new OrderItemComponentModel(2, "Something", "Something", 1, 2, 1, 2);
            itemModel.AddComponentModel(itemComponent);

            model.AddOrderItemModel(itemModel);

            itemModel = new Application.OrderItemModel(2, 1, 5, "Coffee - Americano", 0, 0, State.None);
            model.AddOrderItemModel(itemModel);

            itemModel = new Application.OrderItemModel(3, 1, 6, "Coffee - Flat White", 0, 0, State.None);
            model.AddOrderItemModel(itemModel);

            ((AllItemsLayout)currentLayout).AddOrder(model);

            svc.SaveOrder(model);
        }
        private void AddComponent(int id, int portions, int position)
        {
            ComponentModel component = svc.GetComponentModel(id);

            OrderItemComponentModel componentModel = null;

            if (currentOrderItemId == 0)
            {
                componentModel = new OrderItemComponentModel(newOrderItemComponentId, newOrderItemId, id, component.Name, component.DisplayName, component.Cost, component.Price, portions, position);
            }
            else
            {
                componentModel = new OrderItemComponentModel(newOrderItemComponentId, currentOrderItemId, id, component.Name, component.DisplayName, component.Cost, component.Price, portions, position);
            }

            if (editedComponents.Where(ec => ec.Id == id).Count() == 0)
            {
                foreach (ComponentModel model in component.Components.Values)
                {
                    if (model.IsDefault)
                    {
                        componentModel.AddComponent(new OrderItemComponentComponentModel(newOrderItemComponentId, model.Id, model.Name, model.DisplayName, model.Cost, model.Price, model.Portions, model.IsDefault));
                    }
                }
            }

            components.Add(id, componentModel);

            newOrderItemComponentId++;
        }
        public void Reset()
        {
            currentOrderItemId = 0;
            currentDiscountId  = 1;
            currentQuantity    = 1;

            quantityButton.Enabled = true;

            discountText.Text = "No Discount";
            quantityText.Text = "1";

            positions.Clear();
            components.Clear();
            editedComponents.Clear();

            currentComponent = null;

            thisPosition = 0;

            orderItemOverriden = false;

            positions.Add(new VariationPosition()
            {
                PosType = PositionType.Variations, Id = 1
            });
            DisplayVariations(1);
        }
Ejemplo n.º 4
0
        public static void AddOrderItemComponent(OrderItemComponentModel component)
        {
            //ComponentModel model = Database.GetComponentModel(component.ComponentId);

            string line = "ADD_ORDERITEM_COMPONENT," + component.Id.ToString() + "," + component.OrderItemId.ToString() + "," + component.ComponentId.ToString() + "," + component.DisplayName + "," + component.Portions + "," + component.Position;

            SendRecord(line);
        }
        private void ComponentsAdapter_ArrowClicked(object sender, Events.ArrowClickedEventArgs e)
        {
            currentComponent = components[e.Arrow.ComponentId];

            DisplayComponents(e.Arrow.ComponentId, true, ComponentListMode.Component);

            if (!editedComponents.Contains(currentComponent))
            {
                editedComponents.Add(currentComponent);
            }

            confirmButton.Visibility = ViewStates.Invisible;
        }
        private void BackButton_Click(object sender, EventArgs e)
        {
            if (currentComponent != null)
            {
                currentComponent = null;

                DisplayComponents(positions[thisPosition].Id, true, ComponentListMode.Variation);
                Show();

                return;
            }

            --thisPosition;
            DisplayVariations(positions[thisPosition].Id);

            confirmButton.Visibility = ViewStates.Invisible;

            Show();
        }
Ejemplo n.º 7
0
        public static void AddOrderItemComponent(OrderItemComponentModel component)
        {
            string line = "ADD_ORDERITEM_COMPONENT," + component.Id.ToString() + "," + component.OrderItemId.ToString() + "," + component.ComponentId.ToString() + "," + component.Portions;

            StoreTransaction(line);
        }
Ejemplo n.º 8
0
        private static void ProcessOrdersTransactionFile(string fileName)
        {
            FileStream   fs     = new FileStream(fileName, FileMode.Open);
            StreamReader reader = new StreamReader(fs);

            OrderModel              model          = null;
            OrderItemModel          itemModel      = null;
            OrderItemComponentModel componentModel = null;

            bool onFirstOrder = true;

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                if (line.StartsWith("SAVE_ORDER"))
                {
                    if (!onFirstOrder)
                    {
                        Database.SaveOrder(model, false, false);
                    }

                    onFirstOrder = false;

                    model = new OrderModel();
                    int firstComma  = line.IndexOf(",");
                    int secondComma = line.IndexOf(",", firstComma + 1);
                    model.Id = Int32.Parse(line.Substring(firstComma + 1, secondComma - firstComma - 1));

                    int thirdComma = line.IndexOf(",", secondComma + 1);
                    model.Name = line.Substring(secondComma + 1, thirdComma - secondComma - 1);

                    int fourthComma = line.IndexOf(",", thirdComma + 1);
                    model.CustomerType = Int32.Parse(line.Substring(thirdComma + 1, fourthComma - thirdComma - 1));

                    model.Date = DateTime.Parse(line.Substring(fourthComma + 1, line.Length - fourthComma - 1));
                }
                else if (line.StartsWith("ADD_ORDER_ITEM"))
                {
                    int firstComma  = line.IndexOf(",");
                    int secondComma = line.IndexOf(",", firstComma + 1);
                    int id          = Int32.Parse(line.Substring(firstComma + 1, secondComma - firstComma - 1));

                    int thirdComma = line.IndexOf(",", secondComma + 1);
                    int orderId    = Int32.Parse(line.Substring(secondComma + 1, thirdComma - secondComma - 1));

                    int fourthComma = line.IndexOf(",", thirdComma + 1);
                    int variationId = Int32.Parse(line.Substring(thirdComma + 1, fourthComma - thirdComma - 1));

                    int fifthComma  = line.IndexOf(",", fourthComma + 1);
                    int inOutStatus = Int32.Parse(line.Substring(fourthComma + 1, fifthComma - fourthComma - 1));

                    int sixthComma = line.IndexOf(",", fifthComma + 1);
                    int discountId = Int32.Parse(line.Substring(fifthComma + 1, sixthComma - fifthComma - 1));

                    State state = (State)Int32.Parse(line.Substring(sixthComma + 1, line.Length - sixthComma - 1));

                    itemModel = new OrderItemModel(id, orderId, variationId, inOutStatus, discountId, state);
                    model.OrderItems.Add(itemModel);
                }
                else if (line.StartsWith("ADD_ORDERITEM_COMPONENT"))
                {
                    int firstComma  = line.IndexOf(",");
                    int secondComma = line.IndexOf(",", firstComma + 1);
                    int id          = Int32.Parse(line.Substring(firstComma + 1, secondComma - firstComma - 1));

                    int thirdComma  = line.IndexOf(",", secondComma + 1);
                    int orderItemId = Int32.Parse(line.Substring(secondComma + 1, thirdComma - secondComma - 1));

                    int fourthComma = line.IndexOf(",", thirdComma + 1);
                    int componentId = Int32.Parse(line.Substring(thirdComma + 1, fourthComma - thirdComma - 1));
                    int portions    = Int32.Parse(line.Substring(fourthComma + 1, line.Length - fourthComma - 1));

                    ComponentModel component = Database.GetComponentModel(componentId);
                    component.Portions = portions;

                    componentModel = new OrderItemComponentModel(id, orderItemId, componentId, component.Name, component.DisplayName, component.Cost, component.Price, portions, 0);
                    itemModel.ComponentModels.Add(componentModel);
                }
                else if (line.StartsWith("ADD_ORDERITEM_SUBCOMPONENT"))
                {
                    int firstComma  = line.IndexOf(",");
                    int secondComma = line.IndexOf(",", firstComma + 1);
                    int parentId    = Int32.Parse(line.Substring(firstComma + 1, secondComma - firstComma - 1));

                    int thirdComma  = line.IndexOf(",", secondComma + 1);
                    int componentId = Int32.Parse(line.Substring(secondComma + 1, thirdComma - secondComma - 1));

                    int portions = Int32.Parse(line.Substring(thirdComma + 1, line.Length - thirdComma - 1));

                    ComponentModel component = Database.GetComponentModel(componentId);
                    component.Portions = portions;

                    OrderItemComponentComponentModel subComponentModel = new OrderItemComponentComponentModel(parentId, componentId, component.Name, component.DisplayName, component.Cost, component.Price, portions, component.IsDefault);
                    componentModel.AddComponent(subComponentModel);
                }
                else if (line.StartsWith("SET_CURRENT_ORDER"))
                {
                    if (!onFirstOrder)
                    {
                        Database.SaveOrder(model, false, false);
                        onFirstOrder = true;
                    }

                    int firstComma = line.IndexOf(",");
                    int orderId    = Int32.Parse(line.Substring(firstComma + 1, line.Length - firstComma - 1));

                    Database.SetCurrentOrder(orderId, false);
                }
                else if (line.StartsWith("CLEAR_CURRENT_ORDER"))
                {
                    if (!onFirstOrder)
                    {
                        Database.SaveOrder(model, false, false);
                        onFirstOrder = true;
                    }

                    Database.ClearCurrentOrder(false);
                }
                else if (line.StartsWith("PAY_ORDER"))
                {
                    int firstComma = line.IndexOf(",");
                    int orderId    = Int32.Parse(line.Substring(firstComma + 1, line.Length - firstComma - 1));

                    Database.SaveOrder(model, false, false);

                    onFirstOrder = true;

                    Database.PayOrder(model, false);
                }
                else if (line.StartsWith("DELETE_ORDER"))
                {
                    int firstComma = line.IndexOf(",");
                    int orderId    = Int32.Parse(line.Substring(firstComma + 1, line.Length - firstComma - 1));

                    if (!onFirstOrder)
                    {
                        Database.SaveOrder(model, false, false);
                        onFirstOrder = true;
                    }

                    OrderModel orderModel = new OrderModel(orderId);
                    Database.DeleteOrder(orderModel, false, false);
                }
                else if (line.StartsWith("ORDER_UPLOADED"))
                {
                    int firstComma = line.IndexOf(",");
                    int orderId    = Int32.Parse(line.Substring(firstComma + 1, line.Length - firstComma - 1));

                    if (!onFirstOrder)
                    {
                        Database.SaveOrder(model, false, false);
                        onFirstOrder = true;
                    }

                    Database.OrderUploaded(orderId, false);
                }
            }

            if (!onFirstOrder)
            {
                Database.SaveOrder(model, false, false);
            }

            reader.Close();
            fs.Close();
        }
        public void RecieveRecord(string record)
        {
            if (record.StartsWith("SAVE_ORDER"))
            {
                model = new OrderModel();
                int firstComma  = record.IndexOf(",");
                int secondComma = record.IndexOf(",", firstComma + 1);
                model.Id = Int32.Parse(record.Substring(firstComma + 1, secondComma - firstComma - 1));

                int thirdComma = record.IndexOf(",", secondComma + 1);
                model.Name = record.Substring(secondComma + 1, thirdComma - secondComma - 1);

                int fourthComma = record.IndexOf(",", thirdComma + 1);
                model.CustomerType = Int32.Parse(record.Substring(thirdComma + 1, fourthComma - thirdComma - 1));

                int fifthComma = record.IndexOf(",", fourthComma + 1);
                model.Date = DateTime.Parse(record.Substring(fourthComma + 1, fifthComma - fourthComma - 1));

                model.OrderNumber = int.Parse(record.Substring(fifthComma + 1, record.Length - fifthComma - 1));
            }
            else if (record.StartsWith("ADD_ORDER_ITEM"))
            {
                int firstComma  = record.IndexOf(",");
                int secondComma = record.IndexOf(",", firstComma + 1);
                int id          = Int32.Parse(record.Substring(firstComma + 1, secondComma - firstComma - 1));

                int thirdComma = record.IndexOf(",", secondComma + 1);
                int orderId    = Int32.Parse(record.Substring(secondComma + 1, thirdComma - secondComma - 1));

                int fourthComma = record.IndexOf(",", thirdComma + 1);
                int variationId = Int32.Parse(record.Substring(thirdComma + 1, fourthComma - thirdComma - 1));

                int    fifthComma           = record.IndexOf(",", fourthComma + 1);
                string variationDisplayName = record.Substring(fourthComma + 1, fifthComma - fourthComma - 1);

                int sixthComma  = record.IndexOf(",", fifthComma + 1);
                int inOutStatus = Int32.Parse(record.Substring(fifthComma + 1, sixthComma - fifthComma - 1));

                int   seventhComma = record.IndexOf(",", sixthComma + 1);
                int   discountId   = Int32.Parse(record.Substring(sixthComma + 1, seventhComma - sixthComma - 1));
                State state        = (State)Int32.Parse(record.Substring(seventhComma + 1, record.Length - seventhComma - 1));

                itemModel = new OrderItemModel(id, orderId, variationId, variationDisplayName, inOutStatus, discountId, state);
                model.OrderItems.Add(id, itemModel);
            }
            else if (record.StartsWith("ADD_ORDERITEM_COMPONENT"))
            {
                int firstComma  = record.IndexOf(",");
                int secondComma = record.IndexOf(",", firstComma + 1);
                int id          = Int32.Parse(record.Substring(firstComma + 1, secondComma - firstComma - 1));

                int thirdComma  = record.IndexOf(",", secondComma + 1);
                int orderItemId = Int32.Parse(record.Substring(secondComma + 1, thirdComma - secondComma - 1));

                int fourthComma = record.IndexOf(",", thirdComma + 1);
                int componentId = Int32.Parse(record.Substring(thirdComma + 1, fourthComma - thirdComma - 1));

                int    fifthComma           = record.IndexOf(",", fourthComma + 1);
                string componentDisplayName = record.Substring(fourthComma + 1, fifthComma - fourthComma - 1);

                int sixthComma = record.IndexOf(",", fifthComma + 1);
                int portions   = Int32.Parse(record.Substring(fifthComma + 1, sixthComma - fifthComma - 1));

                int position = Int32.Parse(record.Substring(sixthComma + 1, record.Length - sixthComma - 1));

                componentModel = new OrderItemComponentModel(id, "", componentDisplayName, orderItemId, componentId, portions, position);

                itemModel.ComponentModels.Add(componentModel);
            }
            else if (record.StartsWith("ADD_ORDERITEM_SUBCOMPONENT"))
            {
                int firstComma  = record.IndexOf(",");
                int secondComma = record.IndexOf(",", firstComma + 1);
                int parentId    = Int32.Parse(record.Substring(firstComma + 1, secondComma - firstComma - 1));

                int thirdComma  = record.IndexOf(",", secondComma + 1);
                int componentId = Int32.Parse(record.Substring(secondComma + 1, thirdComma - secondComma - 1));

                int    fourthComma = record.IndexOf(",", thirdComma + 1);
                string name        = record.Substring(thirdComma + 1, fourthComma - thirdComma - 1);

                int    fifthComma  = record.IndexOf(",", fourthComma + 1);
                string displayName = record.Substring(fourthComma + 1, fifthComma - fourthComma - 1);
                int    portions    = Int32.Parse(record.Substring(fifthComma + 1, record.Length - fifthComma - 1));

                OrderItemComponentComponentModel subComponentModel = new OrderItemComponentComponentModel(parentId, componentId, name, displayName, portions);

                componentModel.AddComponent(subComponentModel);
            }
            else if (record.StartsWith("END_OF_ORDER"))
            {
                if (currentLayout is SpecificItemLayout)
                {
                    SpecificItemLayout thisLayout = (SpecificItemLayout)currentLayout;
                    if (model.OrderItems.ContainsKey(thisLayout.OrderItemId))
                    {
                        thisLayout.UpdateView(model.OrderItems[thisLayout.OrderItemId]);
                    }
                }
                else if (currentLayout is AllItemsLayout)
                {
                    AllItemsLayout thisLayout = (AllItemsLayout)currentLayout;
                    thisLayout.AddOrder(model);
                }

                svc.SaveOrder(model);
                model = null;
            }
            else if (record.StartsWith("LOCK_ORDER_ITEM"))
            {
                if (currentLayout is AllItemsLayout)
                {
                    AllItemsLayout thisLayout = (AllItemsLayout)currentLayout;

                    int firstComma = record.IndexOf(",");
                    int id         = Int32.Parse(record.Substring(firstComma + 1, record.Length - firstComma - 1));

                    thisLayout.LockOrderItem(id);
                }
            }
            else if (record.StartsWith("UNLOCK_ORDER_ITEM"))
            {
                if (currentLayout is AllItemsLayout)
                {
                    AllItemsLayout thisLayout = (AllItemsLayout)currentLayout;

                    int firstComma = record.IndexOf(",");
                    int id         = Int32.Parse(record.Substring(firstComma + 1, record.Length - firstComma - 1));

                    thisLayout.UnlockOrderItem(id);
                }
            }
            else if (record.StartsWith("DELETE_ORDER"))
            {
                int firstComma = record.IndexOf(",");
                int id         = Int32.Parse(record.Substring(firstComma + 1, record.Length - firstComma - 1));

                if (currentLayout is AllItemsLayout)
                {
                    AllItemsLayout thisLayout = (AllItemsLayout)currentLayout;
                    thisLayout.DeleteOrder(id);
                }
                else
                {
                    SpecificItemLayout thisLayout = (SpecificItemLayout)currentLayout;
                    thisLayout.DeleteOrder(id);
                }
            }
            else if (record.StartsWith("ADD_VARIATION,"))
            {
                AddVariation(record);
            }
            else if (record.StartsWith("UPDATE_VARIATION,"))
            {
                UpdateVariation(record);
            }
            else if (record.StartsWith("ADD_COMPONENT,"))
            {
                AddComponent(record);
            }
            else if (record.StartsWith("UPDATE_COMPONENT,"))
            {
                UpdateComponent(record);
            }
        }