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);
        }
Beispiel #3
0
        public void UpdateStock(Session session, int itemID, int?inventoryID, float quantity, bool updateBOM, int locationID, string lot = "", int?LPNNumber = null, DateTime?ExpirationDate = null, bool IsNewInventory = true)
        {
            double scrapfactor = 0;

            //To do update the stock for the item and bom's associated with it
            if (updateBOM == true)
            {
                if (inventoryID.HasValue)
                {
                    //Dim inventoryBOMs As InventoryBOMsBLL = New InventoryBOMsBLL
                    //Dim inventoryItemBOM As SPG.InventoryBOMsDataTable = inventoryBOMs.GetInventoryBOMsBYInventoryID(inventoryID.Value)
                    XPCollection <InventoryBOMs> inventoryItemBOM = InventoryBOMsBLL.GetInventoryBOMsByInventoryID(session, inventoryID.Value);
                    //If inventoryItemBOM.Rows.Count <> 0 Then
                    if (inventoryItemBOM.Count != 0)
                    {
                        //Dim itemsBOM As SPG.InventoryBOMsRow
                        InventoryBOMs itemsBOM = null;
                        for (int i = 0; i < inventoryItemBOM.Count; i++)
                        {
                            //itemsBOM = CType(inventoryItemBOM.Rows(i), SPG.InventoryBOMsRow)
                            itemsBOM = inventoryItemBOM[i];
                            if (itemsBOM.IsDeleted == false)
                            {
                                //updates the raw material
                                if (itemsBOM.ScrapFactor > 0)
                                {
                                    scrapfactor = itemsBOM.InventoryBOMQuantity * itemsBOM.ScrapFactor;
                                }
                                else
                                {
                                    scrapfactor = 0;
                                }
                                UpdateStock(session, itemsBOM.InventoryBOMRawMatID.ItemID, (Convert.ToSingle(quantity * (itemsBOM.InventoryBOMQuantity + scrapfactor)) * -1), false, locationID);
                            }
                        }
                        updateBOM = false;
                    }
                }
            }

            if (updateBOM == true)
            {
                //The item has a bom attached to it
                BOMBLL boms = new BOMBLL();
                //Dim itemsBOMs As SPG.BOMDataTable = boms.GetBOMBYFGItemID(itemID)
                XPCollection <BOMs> itemsBOMs = BOMBLL.GetBOMByFGItemID(session, itemID);

                //If itemsBOMs.Rows.Count <> 0 Then
                if (itemsBOMs.Count != 0)
                {
                    //Dim itemsBOM As SPG.BOMRow
                    BOMs itemsBOM = null;
                    //For i As Integer = 0 To itemsBOMs.Rows.Count - 1
                    for (int i = 0; i < itemsBOMs.Count; i++)
                    {
                        //itemsBOM = CType(itemsBOMs.Rows(i), SPG.BOMRow)
                        itemsBOM = itemsBOMs[i];
                        //updates the raw material
                        if (itemsBOM.BOMRawMatID.ItemID != itemID)
                        {
                            if (itemsBOM.ScrapFactor > 0)
                            {
                                scrapfactor = itemsBOM.BOMQuantity * (itemsBOM.ScrapFactor / 100);
                            }
                            else
                            {
                                scrapfactor = 0;
                            }
                            UpdateStock(session, itemsBOM.BOMRawMatID.ItemID, (Convert.ToSingle(quantity * (itemsBOM.BOMQuantity + scrapfactor)) * -1), false, locationID);
                        }
                    }
                }
            }

            LocationInventoryBLL.UpdateStock(session, itemID, locationID, quantity, lot, LPNNumber, ExpirationDate, IsNewInventory);

            //Dim item As SPG.ItemsRow = CType(GetItemBYId(itemID).Rows(0), SPG.ItemsRow)
            //item.s ngQuantityOnHand += quantity
            //Adapter.Update(item)
        }