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); } }
private void AddComponentComponent(int componentId) { ComponentModel model = svc.GetComponentModel(componentId); currentComponent.AddComponent(new OrderItemComponentComponentModel(currentComponent.Id, model.Id, model.Name, model.DisplayName, model.Cost, model.Price, model.Portions, model.IsDefault)); }