public static void AddOrderItemComponentComponent(OrderItemComponentComponentModel component) { string line = "ADD_ORDERITEM_SUBCOMPONENT," + component.ParentId.ToString() + "," + component.ComponentId.ToString() + "," + component.Name + "," + component.DisplayName + "," + component.Portions; SendRecord(line); }
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 static void AddOrderItemComponentComponent(OrderItemComponentComponentModel subComponent) { string line = "ADD_ORDERITEM_SUBCOMPONENT," + subComponent.ParentId + "," + subComponent.ComponentId + "," + subComponent.Portions; StoreTransaction(line); }
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); } }