public void DeleteReceiptInvoiceDetail(int receiptInvoiceDetailID) { var receiptInvoiceDetail = new ReceiptInvoiceDetail(); receiptInvoiceDetail.LoadByPrimaryKey(receiptInvoiceDetailID); receiptInvoiceDetail.MarkAsDeleted(); var transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr(); transaction.BeginTransaction(); try { receiptInvoiceDetail.Save(); transaction.CommitTransaction(); } catch (Exception exception) { transaction.RollbackTransaction(); } }
private void BindInvoiceDetail(ReceiptInvoice receiptInvoice) { _dtReceiptInvoiceDetail.Rows.Clear(); var receiptInvoiceDetail = new ReceiptInvoiceDetail(); receiptInvoiceDetail.LoadByReceiptInvoice(receiptInvoice.ID); if (receiptInvoiceDetail.DefaultView.Count == 0) { BindInvoiceDetailByPO(receiptInvoice.POID); } else { receiptInvoiceDetail.LoadMergedPOAndInvoiceDetails(receiptInvoice.ID); foreach (DataRowView rowView in receiptInvoiceDetail.DefaultView) { var newrow = _dtReceiptInvoiceDetail.NewRow(); newrow["FullItemName"] = rowView["FullItemName"]; newrow["Unit"] = rowView["Unit"]; newrow["Manufacturer"] = rowView["Manufacturer"]; newrow["OrderedQuantity"] = rowView["OrderedQuantity"]; newrow["OrderedAmount"] = rowView["Amount"]; newrow["ItemID"] = Convert.ToInt32(rowView["ItemID"]); newrow["UnitOfIssueID"] = Convert.ToInt32(rowView["UnitOfIssueID"]); newrow["ManufacturerID"] = Convert.ToInt32(rowView["ManufacturerID"]); if (rowView["ExpiryDate"] != DBNull.Value) { newrow["ExpiryDate"] = Convert.ToDateTime(rowView["ExpiryDate"]); } newrow["IsSaved"] = false; newrow["GUID"] = Guid.NewGuid(); if (rowView["InvoicedQuantity"] != DBNull.Value) { newrow["ReceiptInvoiceDetailID"] = Convert.ToInt32(rowView["ReceiptInvoiceDetailID"]); newrow["ReceiptInvoiceID"] = Convert.ToInt32(rowView["ReceiptInvoiceID"]); newrow["BatchNumber"] = rowView["BatchNumber"]; newrow["InvoicedQty"] = Convert.ToDecimal(rowView["InvoicedQuantity"]); newrow["UnitPrice"] = Convert.ToDecimal(rowView["UnitPrice"]); newrow["Margin"] = Convert.ToDecimal(rowView["Margin"]); newrow["IsSaved"] = true; } else { newrow["UnitPrice"] = 0; newrow["Margin"] = 0; } _dtReceiptInvoiceDetail.Rows.Add(newrow); } MergeReceiptInvoiceDetailGUID(); _dtReceiptInvoiceDetail.DefaultView.Sort = "FullItemName, Unit, Manufacturer, ExpiryDate DESC, BatchNumber DESC"; gridInvoiceDetail.DataSource = _dtReceiptInvoiceDetail; if (receiptInvoice.CheckIfThisInvoiceHasBeenReceived()) { gridInvoiceDetail.Enabled = btnSave.Enabled = false; tabInvoice.SelectedTabPageIndex = 0; XtraMessageBox.Show("This Invoice has a related Receive!,You can't edit in this case!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void plusMinusButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Plus) { DataRow dr = gridViewInvoiceDetail.GetDataRow(gridViewInvoiceDetail.GetSelectedRows()[0]); DataRow drNew = _dtReceiptInvoiceDetail.NewRow(); drNew.ItemArray = dr.ItemArray; drNew["GUID"] = dr["GUID"]; drNew["IsSaved"] = false; drNew["ReceiptInvoiceDetailID"] = DBNull.Value; drNew["BatchNumber"] = DBNull.Value; drNew["InvoicedQty"] = DBNull.Value; _dtReceiptInvoiceDetail.Rows.Add(drNew); _dtReceiptInvoiceDetail.DefaultView.Sort = "FullItemName, Unit, Manufacturer, ExpiryDate DESC, BatchNumber DESC"; } else { DataRow dr = gridViewInvoiceDetail.GetDataRow(gridViewInvoiceDetail.GetSelectedRows()[0]); if (Convert.ToBoolean(dr["IsSaved"])) { if ( XtraMessageBox.Show(@"Are you sure you want to delete the detail from the database?", @"Confirmation", MessageBoxButtons.OKCancel) == DialogResult.OK) { var receiptInvoiceDetail = new ReceiptInvoiceDetail(); receiptInvoiceDetail.DeleteReceiptInvoiceDetail(Convert.ToInt32(dr["ReceiptInvoiceDetailID"])); _dtReceiptInvoiceDetail.Rows.Remove(dr); } } else { _dtReceiptInvoiceDetail.Rows.Remove(dr); } } }
private void btnSave_Click(object sender, EventArgs e) { bool isSaved = false; if (_receiptInvoiceID != 0) { if (!ValidateReceiptInvoiceDetails()) { return; } _dtReceiptInvoiceDetail = gridInvoiceDetail.DataSource as DataTable; var invoiceDetail = new ReceiptInvoiceDetail(); foreach (DataRow dr in _dtReceiptInvoiceDetail.Rows) { if (dr["InvoicedQty"] == DBNull.Value) { continue; } var itemID = Convert.ToInt32(dr["ItemID"]); if (dr["ReceiptInvoiceDetailID"] == DBNull.Value) { invoiceDetail.AddNew(); } else { invoiceDetail.LoadByPrimaryKey(Convert.ToInt32(dr["ReceiptInvoiceDetailID"])); } invoiceDetail.ItemID = itemID; invoiceDetail.UnitOfIssueID = Convert.ToInt32(dr["UnitOfIssueID"]); invoiceDetail.ManufacturerID = Convert.ToInt32(dr["ManufacturerID"]); invoiceDetail.ReceiptInvoiceID = _receiptInvoiceID; if (dr["ExpiryDate"] != DBNull.Value) { invoiceDetail.ExpiryDate = Convert.ToDateTime(dr["ExpiryDate"]); } invoiceDetail.BatchNumber = Convert.ToString(dr["BatchNumber"]); invoiceDetail.UnitPrice = dr["UnitPrice"] == DBNull.Value ? 0 : Convert.ToDecimal(dr["UnitPrice"]); invoiceDetail.Quantity = Convert.ToDecimal(dr["InvoicedQty"]); invoiceDetail.Margin = dr["Margin"] == DBNull.Value ? 0 : Convert.ToDecimal(dr["Margin"]); invoiceDetail.Rowguid = Guid.NewGuid(); invoiceDetail.Save(); dr["IsSaved"] = isSaved = true; } if (isSaved) { MessageBox.Show("Invoice details saved!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show(@"The invoice details are not attached to any invoice. Please first save the invoice.", @"No Invoice", MessageBoxButtons.OK, MessageBoxIcon.Error); } }