private void FrmInvoice_Load(object sender, EventArgs e) { try { dsDictionary.EnforceConstraints = false; BLOrder oBL = new BLOrder(); var table = oBL.GetDataByID(SAInvoiceID); if (table.Rows.Count <= 0) { BLSAInvoice oBLSAInvoice = new BLSAInvoice(); table = oBLSAInvoice.GetDataByID(SAInvoiceID); // Nếu tạo mới từ Order if (SAInvoiceID != Guid.Empty) { btnSave.Visible = true; dsDictionary.Clear(); dsDictionary.SAInvoice.Merge(oBLSAInvoice.GetDataByID(SAInvoiceID), false, MissingSchemaAction.Ignore); dsDictionary.SAInvoiceDetail.Merge(oBLSAInvoice.GetDataDetailByID(SAInvoiceID), false, MissingSchemaAction.Ignore); CreateSAInvoice(); } // Nếu không phải tạo mới thì load dữ liệu else { btnSave.Visible = false; LoadSAInvoice(); } } else { // Nếu tạo mới từ Order if (SAInvoiceID != Guid.Empty) { btnSave.Visible = true; dsDictionary.Clear(); dsDictionary.Order.Merge(oBLOrder.GetDataByID(SAInvoiceID), false, MissingSchemaAction.Ignore); dsDictionary.OrderDetail.Merge(oBLOrder.GetDataDetailByID(SAInvoiceID), false, MissingSchemaAction.Ignore); CreateSAInvoice(); } // Nếu không phải tạo mới thì load dữ liệu else { btnSave.Visible = false; LoadSAInvoice(); } } if (table != null && table.Rows.Count > 0) { SAInvoiceRow = dsDictionary.SAInvoice.FirstOrDefault(); dsDictionary.Customer.Merge(new BLCustomer().GetDataByID(Guid.Parse(table.Rows[0][5].ToString()))); CustomerRow = dsDictionary.Customer.FindByCustomerID(Guid.Parse(table.Rows[0][5].ToString())); } BindingData(table); } catch (Exception ex) { MessageBoxCommon.ShowException(ex); } }
/// <summary> /// Load thông tin hóa đơn /// </summary> private void LoadSAInvoice() { dsDictionary.Clear(); dsDictionary.SAInvoice.Merge(oBLSAInvoice.GetDataByID(SAInvoiceID), false, MissingSchemaAction.Ignore); dsDictionary.SAInvoiceDetail.Merge(oBLSAInvoice.GetDataDetailByID(SAInvoiceID), false, MissingSchemaAction.Ignore); BLInventoryItem oBLInventoryItem = new BLInventoryItem(); foreach (var item in dsDictionary.SAInvoiceDetail) { if (dsDictionary.InventoryItem.FindByInventoryItemID(item.ItemID) == null) { dsDictionary.InventoryItem.Merge(oBLInventoryItem.GetByID_SAInvoice(item.ItemID)); } } }