private void deleteRepositoryItemButtonEdit_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to remove this transfer detail, this can`t be undone?", "Delete Transfer Detail", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.No) { return; } LocationTransferDetails detail = m_TransfersSession.GetObjectByKey <LocationTransferDetails>(transferDetailsGridView.GetFocusedRowCellValue(colOid)); if (detail != null) { int item = Convert.ToInt32(transferDetailsGridView.GetFocusedRowCellValue(transferItemGridColumn)); if (detail.TransferQuantity > ItemsBLL.GetQtyOnHandByID(m_TransfersSession, item, Convert.ToInt32(toLocationLookUpEdit.EditValue), detail.TransferLot, detail.FullLpnNumber)) { MessageBox.Show("You can't delete this transfer detail, it will create a negative stock at the location", "Insufficient Inventory", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } detail.Delete(); if (detail.IsDeleted == false) { MessageBox.Show("The transfer detail was not removed."); } else { LocationInventoryBLL.UpdateStock(m_TransfersSession, item, Convert.ToInt32(fromLocationLookUpEdit.EditValue), detail.TransferQuantity, detail.TransferLot, detail.FullLpnNumber); LocationInventoryBLL.UpdateStock(m_TransfersSession, item, Convert.ToInt32(toLocationLookUpEdit.EditValue), detail.TransferQuantity * -1, detail.TransferLot, detail.FullLpnNumber); } } else { transferDetailsGridView.DeleteRow(transferDetailsGridView.FocusedRowHandle); } }
private bool SaveChanges() { int selectedID = 0; //make sure that the record gets validated before saving by moving off the record being edited transferDetailsGridView.CloseEditor(); transferDetailsGridView.MoveNext(); if (m_CanSaveDetails == false || ValidateAvailability() == false) { return(false); } if (m_CurrentTransfer.Oid != -1) { selectedID = transferSearchGridView.FocusedRowHandle; } if (LocationTransfersBLL.ValidateRecord((int?)transferNumberTextEdit.EditValue, (int?)fromLocationLookUpEdit.EditValue, (int?)toLocationLookUpEdit.EditValue, (int?)carrierLookUpEdit.EditValue, m_CurrentTransfer, m_TransfersSession)) { m_CurrentTransfer.FromLocation = m_TransfersSession.GetObjectByKey <Locations>(Convert.ToInt32(fromLocationLookUpEdit.EditValue)); m_CurrentTransfer.ToLocation = m_TransfersSession.GetObjectByKey <Locations>(Convert.ToInt32(toLocationLookUpEdit.EditValue)); m_CurrentTransfer.TransferDate = Convert.ToDateTime(transferDateDateEdit.DateTime); m_CurrentTransfer.TransferCarrier = m_TransfersSession.GetObjectByKey <Carriers>(Convert.ToInt32(carrierLookUpEdit.EditValue)); m_CurrentTransfer.Trailer = (trailerTextEdit.EditValue == null) ? null : (trailerTextEdit.EditValue == null ? null : Convert.ToString(trailerTextEdit.EditValue)); //m_CurrentTransfer.TransferNumber = CInt(transferNumberTextEdit.EditValue) m_CurrentTransfer.LoadedBy = (loadedByLookUpEdit.EditValue == null) ? null : m_TransfersSession.GetObjectByKey <Employees>(Convert.ToInt32(loadedByLookUpEdit.EditValue)); m_CurrentTransfer.UnloadedBy = (unloadedByLookUpEdit.EditValue == null) ? null : m_TransfersSession.GetObjectByKey <Employees>(Convert.ToInt32(unloadedByLookUpEdit.EditValue)); m_CurrentTransfer.CheckedBy = (checkedByLookUpEdit.EditValue == null) ? null : m_TransfersSession.GetObjectByKey <Employees>(Convert.ToInt32(checkedByLookUpEdit.EditValue)); } else { MessageBox.Show("You must provide a From location; To location and Carrier before saving the record."); return(false); } try { int newQuantity = 0; LocationTransferDetails originalRecord = null; foreach (LocationTransferDetails transferDetail in transferDetailsXpCollection) { if (transferDetail.Transfer == null || transferDetail.Transfer.Oid == -1) { transferDetail.Transfer = m_CurrentTransfer; LocationInventoryBLL.UpdateStock(m_TransfersSession, transferDetail.TransferItem.ItemID, Convert.ToInt32(fromLocationLookUpEdit.EditValue), transferDetail.TransferQuantity * -1, transferDetail.TransferLot, transferDetail.FullLpnNumber); LocationInventoryBLL.UpdateStock(m_TransfersSession, transferDetail.TransferItem.ItemID, Convert.ToInt32(toLocationLookUpEdit.EditValue), transferDetail.TransferQuantity, transferDetail.TransferLot, transferDetail.FullLpnNumber); } else { originalRecord = Session.DefaultSession.GetObjectByKey <LocationTransferDetails>(transferDetail.Oid, true); if (originalRecord == null) { newQuantity = transferDetail.TransferQuantity; } else { newQuantity = transferDetail.TransferQuantity - originalRecord.TransferQuantity; } LocationInventoryBLL.UpdateStock(m_TransfersSession, transferDetail.TransferItem.ItemID, Convert.ToInt32(fromLocationLookUpEdit.EditValue), newQuantity * -1, transferDetail.TransferLot, transferDetail.FullLpnNumber); LocationInventoryBLL.UpdateStock(m_TransfersSession, transferDetail.TransferItem.ItemID, Convert.ToInt32(toLocationLookUpEdit.EditValue), newQuantity, transferDetail.TransferLot, transferDetail.FullLpnNumber); } } m_CurrentTransfer.Save(); } catch (ApplicationException ex) { MessageBox.Show(ex.Message, "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } BindTransferSearch(); BindTransferControls(m_CurrentTransfer.Oid); transferSearchGridView.FocusedRowHandle = selectedID; return(true); }