private void scanInvoiceNo(string invoiceNo) { if (saveInvoiceStatus(invoiceNo) < 0) { return; } DataSource.Invoice findInvoice = invoiceSet.SingleOrDefault <DataSource.Invoice>(p => p.InvoiceNo == invoiceNo); if (findInvoice != null) { MessageBox.Show("Already Scanned [" + invoiceNo + "]"); return; } DataSource.Invoice lInvoice = lDataContext.Invoices.SingleOrDefault(p => p.InvoiceNo == invoiceNo); if (lInvoice == null) { MessageBox.Show("Scan : Can not find Invoice No [" + invoiceNo + "]"); return; } DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.InvoiceId == lInvoice.Id); invoiceSet.Add(new DataSource.Invoice { Id = lInvoice.Id, InvoiceNo = lInvoice.InvoiceNo, DeliveryDate = lInvoice.DeliveryDate, Description = lOrder.Description, Status = lInvoice.Status }); }
private void RadGridView1_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e) { SunSeven.Models.HSOrderHistory lOrderHistory = e.EditedItem as SunSeven.Models.HSOrderHistory; DataSource.Order lOrder = lDataContext.Orders.FirstOrDefault(p => p.Id == lOrderHistory.OrderId); if (lOrder != null) { try { lOrder.EmpDeliveryId = lOrderHistory.DeliveryPersonId; lOrder.EmployeeId = lOrderHistory.SalesPersonId; DataSource.Invoice lInvoice = lDataContext.Invoices.Single(p => p.Id == lOrder.InvoiceId); if (lInvoice != null) { lInvoice.DeliveryDate = lOrderHistory.DeliveryDate; lInvoice.EmpDeliveryId = lOrderHistory.DeliveryPersonId; lInvoice.Description = lOrderHistory.Description; lDataContext.SubmitChanges(); } if (lOrder != null) { lOrder.Description = lOrderHistory.InternalComment; lDataContext.SubmitChanges(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void GridContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e) { RadContextMenu menu = (RadContextMenu)sender; RadMenuItem clickedItem = e.OriginalSource as RadMenuItem; GridViewRow row = menu.GetClickedElement <GridViewRow>(); if (clickedItem != null && row != null) { string header = Convert.ToString(clickedItem.Header); switch (header) { case "Add": break; case "Edit": DataSource.Invoice lSelectedInvoice = row.Item as DataSource.Invoice; if (lSelectedInvoice != null) { DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.InvoiceId == lSelectedInvoice.Id); if (lOrder == null) { MessageBox.Show("Failed to find Order Id [" + lSelectedInvoice.Id + "]"); return; } scannedOrderCommand?.Invoke(lOrder.Id); } break; case "Delete": break; default: break; } } }
private int saveInvoiceStatus(string invoiceNo) { DataSource.Invoice lInvoice = lDataContext.Invoices.SingleOrDefault(p => p.InvoiceNo == invoiceNo); try { lInvoice.Status = 3; // Returned lDataContext.SubmitChanges(); return(0); } catch (Exception ex) { MessageBox.Show("Save Status : Can not find Invoice No [" + invoiceNo + "]"); //MessageBox.Show(ex.Message); return(-1); } }
void OnGridMouseDoubleClick(object sender, MouseButtonEventArgs e) { FrameworkElement originalSender = e.OriginalSource as FrameworkElement; if (originalSender != null) { DataSource.Invoice lSelectedInvoice = originalSender.DataContext as DataSource.Invoice; if (lSelectedInvoice != null) { DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.InvoiceId == lSelectedInvoice.Id); if (lOrder == null) { MessageBox.Show("Failed to find Order Id [" + lSelectedInvoice.Id + "]"); return; } scannedOrderCommand?.Invoke(lOrder.Id); } } }
private void RadGridView1_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e) { DataSource.Invoice gridInvoice = e.NewData as DataSource.Invoice; DataSource.Order orgOrder = lDataContext.Orders.Single(p => p.InvoiceId == gridInvoice.Id); DataSource.Invoice orgInvoice = lDataContext.Invoices.Single(p => p.Id == gridInvoice.Id); if (orgOrder != null) { orgOrder.Description = gridInvoice.Description; orgInvoice.Status = gridInvoice.Status; try { lDataContext.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private Boolean SavingEnded() { //System.Threading.Thread.Sleep(2000); DataSource.Invoice lInvoice = lDataContext.Invoices.SingleOrDefault(p => p.Id == this.Invoice.Id); if (lInvoice == null) { this.Invoice.InvoiceNo = GetInvoiceNo(); DataSource.Invoice newInvoice = new DataSource.Invoice { CustomerId = this.CustomerId, InvoiceNo = this.Invoice.InvoiceNo, InvoiceDate = this.Invoice.InvoiceDate, DeliveryDate = this.Invoice.DeliveryDate, Description = this.Invoice.Description, Status = this.Invoice.InvoiceStatusId, EmpDeliveryId = this.DelivererId }; lDataContext.Invoices.InsertOnSubmit(newInvoice); try { lDataContext.SubmitChanges(); this.Invoice.Id = newInvoice.Id; } catch (SqlException ex) { if (ex.Number == 2627) { MessageBox.Show("Cannot insert duplicate Invoice No [" + this.Invoice.InvoiceNo + "] Please save again."); } else { MessageBox.Show("SqlException : " + ex.Message); } ChangeSet pendingChanges = lDataContext.GetChangeSet(); foreach (object obj in pendingChanges.Inserts) { var tableToDeleteFrom = lDataContext.GetTable(obj.GetType()); //(tableToDeleteFrom as DataSource.Invoice).InvoiceNo = GetInvoiceNo(); //lDataContext.SubmitChanges(); //this.Invoice.Id = newInvoice.Id; tableToDeleteFrom.DeleteOnSubmit(obj); } return(false); } catch (Exception ex) { this.Message = "Faled to Save - Invoice Detail"; return(false); } } else { lInvoice.CustomerId = this.CustomerId; lInvoice.InvoiceNo = this.Invoice.InvoiceNo; lInvoice.InvoiceDate = this.Invoice.InvoiceDate; lInvoice.DeliveryDate = this.Invoice.DeliveryDate; lInvoice.Description = this.Invoice.Description; lInvoice.EmpDeliveryId = this.DelivererId; lInvoice.Status = this.Invoice.InvoiceStatusId; try { lDataContext.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Message = "Faled to Update - Invoice Detail"; return(false); } } DataSource.Order lOrder = lDataContext.Orders.SingleOrDefault(p => p.Id == this.Id); if (lOrder == null) { DataSource.Order lnewOrder = new DataSource.Order { CustomerId = this.CustomerId, OrderDate = this.OrderDate.Value, InvoiceId = (this.Invoice == null) ? null : this.Invoice.Id, EmpDeliveryId = this.DelivererId, EmployeeId = this.SellerId, RequiredDate = DateTime.Now, ShippedDate = DateTime.Now, Description = this.Description }; lDataContext.Orders.InsertOnSubmit(lnewOrder); try { lDataContext.SubmitChanges(); this.Id = lnewOrder.Id; } catch (Exception ex) { MessageBox.Show(ex.Message); this.Message = "Faled to Save - Order Detail"; return(false); } } else { lOrder.CustomerId = this.CustomerId; lOrder.OrderDate = this.OrderDate.Value; lOrder.InvoiceId = this.Invoice.Id; lOrder.EmpDeliveryId = this.DelivererId; lOrder.EmployeeId = this.SellerId; lOrder.RequiredDate = DateTime.Now; lOrder.ShippedDate = DateTime.Now; lOrder.Description = this.Description; try { lDataContext.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Message = "Faled to Update - Order Detail"; return(false); } } foreach (HSSupplyItem l in this.SupplyItems) { if (l.Id == -1 || l.Id == null) { DataSource.OrderItem lDSOrderItem = new OrderItem(); lDSOrderItem.OrderId = this.Id.Value; lDSOrderItem.SalesStatusId = l.SalesStatusId; lDSOrderItem.ProductId = l.ProductId; lDSOrderItem.VatId = l.VatId; lDSOrderItem.UnitPrice = l.UnitPrice; lDSOrderItem.Quantity = l.Quantity; lDSOrderItem.SellingUnitId = (l.SellingUnitId == null) ? 0 : l.SellingUnitId; lDSOrderItem.Description = l.Description; lDataContext.OrderItems.InsertOnSubmit(lDSOrderItem); try { lDataContext.SubmitChanges(); l.Id = lDSOrderItem.Id; } catch (Exception ex) { MessageBox.Show(ex.Message); this.Message = "Faled to Save - OrderItem Detail"; return(false); } } else { DataSource.OrderItem lItem = lDataContext.OrderItems.SingleOrDefault(p => p.Id == l.Id); lItem.OrderId = this.Id.Value; lItem.SalesStatusId = l.SalesStatusId; lItem.ProductId = l.ProductId; lItem.VatId = l.VatId; lItem.UnitPrice = l.UnitPrice; lItem.Quantity = l.Quantity; lItem.SellingUnitId = (l.SellingUnitId == null) ? 0 : l.SellingUnitId; lItem.Description = l.Description; try { lDataContext.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Message = "Faled to Update - OrderItem Detail"; return(false); } } } this.Message = "Saved Successfully..."; return(false); }