private void gridSalesItem_Deleted(object sender, Telerik.Windows.Controls.GridViewDeletedEventArgs e) { UISolution.DataSource.HanSungLinqDataContext lDataContext = new DataSource.HanSungLinqDataContext(); foreach (HSOrderItem l in e.Items) { DataSource.OrderItem ldeletedItem = lDataContext.OrderItems.SingleOrDefault(p => p.Id == l.Id); try { lDataContext.OrderItems.DeleteOnSubmit(ldeletedItem); lDataContext.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void gridOrderItem_Deleted(object sender, Telerik.Windows.Controls.GridViewDeletedEventArgs e) { JSDataContext lDataContext = new CommonFunction().JSDataContext(); foreach (HSOrderItem l in e.Items) { if (l.Id < 0) { continue; } try { DataSource.OrderItem lItem = lDataContext.OrderItems.SingleOrDefault <DataSource.OrderItem>(p => p.Id == l.Id); lDataContext.OrderItems.DeleteOnSubmit(lItem); 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); }