public Guid Add(Order entity) { if (entity.BillNo <= 0) throw new ArgumentException("Order No cannot be empty!"); if (entity.CustomerId == Guid.Empty) throw new ArgumentException("Order Customer cannot be empty!"); if (entity.EmployeeId == Guid.Empty) throw new ArgumentException("Order Employee cannot be empty!"); if (CheckDuplicateBillNo(entity.Id, entity.BillNo)) throw new ArgumentException("Duplicate Order No found!"); using (OpenPOSDbEntities ctx = new OpenPOSDbEntities()) { try { ctx.Orders.MergeOption = MergeOption.NoTracking; ctx.Orders.AddObject(entity); ctx.SaveChanges(); var id = entity.Id; ctx.Detach(entity); return id; } catch (Exception ex) { LogService.Error("Error while adding order", ex); throw new ArgumentException("Error while adding new order!", ex); } } }
public static FlowDocument GetPrintDocument(string templateXml, Order order) { var doc = new XmlDocument(); doc.LoadXml(templateXml); PopulateTemplate(doc, order); var xml = doc.OuterXml; var flowDocument = (FlowDocument)XamlReader.Load(new XmlTextReader(new StringReader(xml))); flowDocument.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.IetfLanguageTag); flowDocument.DataContext = order; flowDocument.PageHeight = order.OrderDetails.Count * Properties.Settings.Default.LineHeight + Properties.Settings.Default.ExtraHeight; flowDocument.PageWidth = Properties.Settings.Default.TicketWidth; // we need to give the binding infrastructure a push as we // are operating outside of the intended use of WPF var dispatcher = Dispatcher.CurrentDispatcher; dispatcher.Invoke(DispatcherPriority.SystemIdle, new DispatcherOperationCallback((arg) => { return null; }), order); return flowDocument; }
public void UpdateOrderCustomer(Order entity) { if (entity.Id.Equals(Guid.Empty)) throw new ArgumentException("Order Id cannot be empty!"); if (entity.BillNo <= 0) throw new ArgumentException("Order No cannot be empty!"); if (entity.CustomerId == Guid.Empty || entity.Customer == null) throw new ArgumentException("Order Customer cannot be empty!"); try { using (OpenPOSDbEntities ctx = new OpenPOSDbEntities()) { ctx.ExecuteStoreCommand("UPDATE Orders SET CustomerId = {0} WHERE Id = {1};", entity.CustomerId, entity.Id); } } catch (Exception ex) { LogService.Error("Error while updating order customer", ex); throw new ArgumentException("Error while updating order customer!", ex); } }
public void Update(Order entity) { if (entity.Id.Equals(Guid.Empty)) throw new ArgumentException("Order Id cannot be empty!"); if (entity.BillNo <= 0) throw new ArgumentException("Order No cannot be empty!"); if (entity.CustomerId == Guid.Empty) throw new ArgumentException("Order Customer cannot be empty!"); if (entity.EmployeeId == Guid.Empty) throw new ArgumentException("Order Employee cannot be empty!"); if (CheckDuplicateBillNo(entity.Id, entity.BillNo)) throw new ArgumentException("Duplicate Order No found!"); using (OpenPOSDbEntities ctx = new OpenPOSDbEntities()) { try { using (var scope = new TransactionScope(TransactionScopeOption.Required)) { ctx.ExecuteStoreCommand("DELETE FROM OrderDetails WHERE OrderId = {0};", entity.Id); ctx.ExecuteStoreCommand("DELETE FROM Payments WHERE OrderId = {0};", entity.Id); foreach (var od in entity.OrderDetails) { ctx.AttachTo("OrderDetails", od); ctx.ObjectStateManager.ChangeObjectState(od, System.Data.EntityState.Added); } foreach (var payment in entity.Payments) { ctx.AttachTo("Payments", payment); ctx.ObjectStateManager.ChangeObjectState(payment, System.Data.EntityState.Added); } ctx.AttachTo("Orders", entity); ctx.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified); ctx.SaveChanges(); scope.Complete(); } } catch (Exception ex) { LogService.Error("Error while updating order", ex); throw new ArgumentException("Error while updating order!", ex); } } }
public Order NewOrder(Guid customerId, Guid employeeId) { using (var scope = new TransactionScope(TransactionScopeOption.Required)) { var entity = new Order(); entity.OrderDate = DateTime.Now; entity.SystemId = Environment.MachineName; entity.Status = true; using (var ctx = new OpenPOSDbEntities()) { entity.BillNo = ctx.Orders.Max(x => x.BillNo) + 1; } entity.CustomerId = customerId; entity.EmployeeId = employeeId; Add(entity); entity = GetOrderById(entity.Id); scope.Complete(); return entity; } }
/// <summary> /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToOrders(Order order) { base.AddObject("Orders", order); }
/// <summary> /// Create a new Order object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="billNo">Initial value of the BillNo property.</param> /// <param name="billAmount">Initial value of the BillAmount property.</param> /// <param name="status">Initial value of the Status property.</param> /// <param name="orderDate">Initial value of the OrderDate property.</param> /// <param name="customerId">Initial value of the CustomerId property.</param> /// <param name="employeeId">Initial value of the EmployeeId property.</param> /// <param name="systemId">Initial value of the SystemId property.</param> public static Order CreateOrder(global::System.Guid id, global::System.Int32 billNo, global::System.Double billAmount, global::System.Boolean status, global::System.DateTime orderDate, global::System.Guid customerId, global::System.Guid employeeId, global::System.String systemId) { Order order = new Order(); order.Id = id; order.BillNo = billNo; order.BillAmount = billAmount; order.Status = status; order.OrderDate = orderDate; order.CustomerId = customerId; order.EmployeeId = employeeId; order.SystemId = systemId; return order; }
private static void PopulateTemplate(XmlDocument doc, Order order) { var tableRows = doc.GetElementsByTagName("TableRow"); XmlElement itemRow = null; XmlElement specialItemRow = null; foreach (XmlElement row in tableRows) { if (row.HasAttribute("Name") && !string.IsNullOrEmpty(row.Attributes["Name"].Value)) { if (row.Attributes["Name"].Value.Equals("itemrow", StringComparison.OrdinalIgnoreCase)) { itemRow = row; } else if (row.Attributes["Name"].Value.Equals("specialitemrow", StringComparison.OrdinalIgnoreCase)) { specialItemRow = row; } } } if (itemRow != null && itemRow.ParentNode != null) { XmlElement rowGroup = (XmlElement)itemRow.ParentNode; XmlElement rowTemplate = (XmlElement)itemRow.CloneNode(true); rowGroup.RemoveChild(itemRow); foreach (var orderItem in order.OrderDetails.Where(x => string.IsNullOrEmpty(x.Barcode) || !x.Barcode.StartsWith("."))) { XmlElement newRow = GetItemRow(rowTemplate, orderItem); rowGroup.PrependChild(newRow); } } var specialItems = order.OrderDetails.Where(x => !string.IsNullOrEmpty(x.Barcode) && x.Barcode.StartsWith(".")).ToList(); if (specialItemRow != null && specialItemRow.ParentNode != null) { var rowGroup = (XmlElement)specialItemRow.ParentNode; var rowTemplate = (XmlElement)specialItemRow.CloneNode(true); rowGroup.RemoveChild(specialItemRow); if (specialItems.Count > 0) { foreach (var orderItem in specialItems) { XmlElement newRow = GetSpecialItemRow(rowTemplate, orderItem); rowGroup.PrependChild(newRow); } } else { var spTables = doc.GetElementsByTagName("Table"); foreach (XmlElement tb in spTables) { if (tb.HasAttribute("Name") && tb.Attributes["Name"].Value == "SpecialItemsTable") { tb.ParentNode.RemoveChild(tb); break; } } } } if (specialItemRow == null && specialItems.Count > 0) { LogService.Info("Print Template does not have valid Special Items TableRow!"); } if (itemRow == null) { LogService.Info("Print Template does not have valid TableRow for including line items!"); } }