Exemple #1
0
        public static bool DeleteInventory(Session session, int id)
        {
            //Dim inventory As SPG.InventoryDataTable = Adapter.GetInventoryByID(id)
            //Dim rowsAffected As Integer = 0
            //Dim inventorySession As Session = session
            session.DropIdentityMap();

            int       item       = 0;
            int       quantity   = 0;
            int       locationID = 0;
            Inventory production = session.GetObjectByKey <Inventory>(id);

            //If inventory.Count = 1 Then
            if (production == null)
            {
                return(false);
            }
            else if (production.Shipment != null)
            {
                MessageBox.Show("The selected record can't be deleted, it was already shipped.");
                return(true);
            }

            //Dim inventoryRecord As SPG.InventoryRow = CType(Inventory.Rows(0), SPG.InventoryRow)
            InventoryBOMsBLL inventoryBOM = new InventoryBOMsBLL();

            item       = production.InventoryItemID.ItemID;
            quantity   = production.InventoryQuantity;
            locationID = production.ProductionLocation.Oid;
            InventoryBOMsBLL.DeleteInventoryBOMByInventoryID(session, id);
            DeleteInventoryConsumption(production, session);
            DeleteProductionProjectDetails(session, production);
            //rowsAffected = Adapter.Delete(id, inventoryRecord.ts)
            try
            {
                production.Delete();

                //If rowsAffected = 1 Then
                //If production.IsDeleted Then
                ItemsBLL items = new ItemsBLL();
                items.UpdateStock(session, item, quantity * -1, true, locationID);
                //End If

                //Return true if precisely one row was deleted, otherwise return false.
                //Return rowsAffected = 1

                //Return production.IsDeleted
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #2
0
        public Inventory UpdateInventory(Session session, int inventoryID, DateTime inventoryDate, int item, int quantity, float?pallets, string po, string lot, int?shift, int?pallet, DateTime?expirationDate, int locationID, string note)
        {
            //Dim inventory As SPG.InventoryDataTable = Adapter.GetInventoryByID(inventoryID)

            //If inventory.Count = 0 Then
            Change    change     = new Change();
            Inventory production = session.GetObjectByKey <Inventory>(inventoryID);

            if (production == null)
            {
                //It is a new Production Record
                change = new Change()
                {
                    PropertyName = Inventory.Fields.InventoryID.PropertyName,
                    PrevValue    = "<NULL>",
                    NewValue     = inventoryID.ToString()
                };
                changes.Add(change);
                return(InsertInventory(session, inventoryID, inventoryDate, item, quantity, pallets, po, lot, shift, pallet, expirationDate, locationID, note));
            }

            //Dim inventoryRecord As SPG.InventoryRow = inventory(0)
            int  originalQuantity = 0;
            int  newQuantity      = 0;
            bool itemChanged      = false;

            //Dim originalRecord As Object() = inventoryRecord.ItemArray

            //inventoryRecord.InventoryDate = CDate(Format(inventoryDate, "D"))
            int originalItem = production.InventoryItemID.ItemID;

            if (originalItem != item)
            {
                itemChanged = true;
            }
            else
            {
                itemChanged = false;
            }
            //inventoryRecord.InventoryItemID = item
            originalQuantity = production.InventoryQuantity;
            newQuantity      = production.InventoryQuantity - quantity;
            //inventoryRecord.InventoryQuantity = quantity
            //inventoryRecord.InventoryPallets = pallets.Value
            //inventoryRecord.PO = po
            //inventoryRecord.Lot = lot
            //If shift.HasValue AndAlso shift.Value > 0 Then
            //    inventoryRecord.Shift = shift.Value
            //Else
            //    inventoryRecord.SetShiftNull()
            //End If
            //If pallet.HasValue AndAlso pallet.Value > 0 Then
            //    inventoryRecord.Pallet = pallet.Value
            //Else
            //    inventoryRecord.SetPalletNull()
            //End If
            //If expirationDate.HasValue Then
            //    inventoryRecord.ExpirationDate = expirationDate.Value
            //Else
            //    inventoryRecord.SetExpirationDateNull()
            //End If

            change = new Change()
            {
                PropertyName = Inventory.Fields.InventoryID.PropertyName,
                PrevValue    = production.InventoryID.ToString(),
                NewValue     = production.InventoryID.ToString()
            };
            changes.Add(change);
            SetInventoryFields(session, inventoryDate, item, quantity, pallets, po, lot, shift, pallet, expirationDate, locationID, note, production);

            //If Not IsNothing(originalRecord) Then
            //    Me.UpdateAuditTrail(inventoryRecord, originalRecord)
            //End If

            try
            {
                production.Save();
            }
            catch (Exception ex)
            {
                return(null);
            }

            UpdateAuditTrail();

            //Dim rowsAffected As Integer = Adapter.Update(inventoryRecord)

            //If rowsAffected = 1 Then
            ItemsBLL items = new ItemsBLL();

            //Dim inventoryBOM As InventoryBOMsBLL = New InventoryBOMsBLL
            if (itemChanged == true)
            {
                items.UpdateStock(session, originalItem, inventoryID, originalQuantity * -1, true, locationID);
                InventoryBOMsBLL.DeleteInventoryBOMByInventoryID(session, inventoryID);
                InventoryBOMsBLL.AddInventoryBOMByItemID(session, item, production);
                items.UpdateStock(session, item, quantity, true, locationID);
            }
            else
            {
                if (newQuantity != 0)                 //there was a change in the quantity
                {
                    items.UpdateStock(session, item, inventoryID, newQuantity * -1, true, locationID);
                }
            }
            //End If

            //Return rowsAffected = 1
            return(production);
        }