Ejemplo n.º 1
0
        public bool UpdateShippingDetails(Session session, int?detailID, int shippingID, int?itemID, string lot, int?quantity, float?pallets, string note, DateTime?expirationDate, string fullLPNNumber)
        {
            if (!itemID.HasValue)
            {
                throw new ApplicationException("You must provide shipping item.");
            }

            if (!quantity.HasValue)
            {
                throw new ApplicationException("You must provide the Quantity shipped.");
            }

            SPG.ShippingDetailsDataTable details = Adapter.GetDetailsByDetailID(detailID.Value);

            if (details.Count() == 0)
            {
                //It is a new Detail
                return(InsertDetails(session, shippingID, itemID, lot, quantity, pallets, note, expirationDate, fullLPNNumber));
            }

            SPG.ShippingDetailsRow shippingDetail = details[0];
            int  originalItem     = 0;
            int  originalQuantity = 0;
            int  newQuantity      = 0;
            bool itemChanged      = false;

            object[] originalRecord = shippingDetail.ItemArray;

            SPG.ShippingDetailsRow originalDetail = details.NewShippingDetailsRow();
            originalDetail.ItemArray = (object[])originalRecord.Clone();

            originalItem = shippingDetail.ShipDetItemID;
            if (itemID.HasValue && originalItem != itemID.Value)
            {
                itemChanged = true;
            }
            shippingDetail.ShipDetItemID = itemID.Value;
            if (string.IsNullOrEmpty(lot))
            {
                shippingDetail.SetShipDetLotNull();
            }
            else
            {
                shippingDetail.ShipDetLot = lot;
            }
            originalQuantity             = shippingDetail.ShipDetDetQty;
            newQuantity                  = quantity.Value - shippingDetail.ShipDetDetQty;
            shippingDetail.ShipDetDetQty = quantity.Value;
            shippingDetail.SetsngPackagesNull();
            if (!pallets.HasValue)
            {
                shippingDetail.SetsngPalletsNull();
            }
            else
            {
                shippingDetail.sngPallets = pallets.Value;
            }
            if (string.IsNullOrEmpty(note))
            {
                shippingDetail.SetNoteNull();
            }
            else
            {
                shippingDetail.Note = note;
            }
            if (expirationDate.HasValue)
            {
                shippingDetail.ExpirationDate = expirationDate.Value;
            }
            else
            {
                shippingDetail.SetExpirationDateNull();
            }
            if (string.IsNullOrEmpty(fullLPNNumber))
            {
                shippingDetail.SetFullLPNNumberNull();
            }
            else
            {
                shippingDetail.FullLPNNumber = fullLPNNumber;
            }

            if (!(originalRecord == null))
            {
                UpdateAuditTrail(shippingDetail, originalRecord);
            }

            int rowsAffected = Adapter.Update(shippingDetail);

            if (rowsAffected == 1)
            {
                ItemsBLL items      = new ItemsBLL();
                int      locationID = session.GetObjectByKey <Shipping>(shippingID).ShippingLocation.Oid;
                //If itemChanged = True Then
                if (originalDetail.FullLPNNumber.StartsWith(CustomersBLL.GetLPNPrefix(7)))
                {
                    items.UpdateStock(session, originalItem, originalQuantity, false, locationID, originalDetail.ShipDetLot, int.Parse(originalDetail.FullLPNNumber.Replace(CustomersBLL.GetLPNPrefix(7), "")));
                }
                else
                {
                    items.UpdateStock(session, originalItem, originalQuantity, false, locationID);
                }
                if (fullLPNNumber.StartsWith(CustomersBLL.GetLPNPrefix(7)))
                {
                    items.UpdateStock(session, itemID.Value, quantity.Value * -1, false, locationID, lot, int.Parse(fullLPNNumber.Replace(CustomersBLL.GetLPNPrefix(7), "")));
                }
                else
                {
                    items.UpdateStock(session, itemID.Value, quantity.Value * -1, false, locationID);
                }
                //Else
                //    If newQuantity <> 0 Then
                //        items.UpdateStock(session, itemID.Value, newQuantity * -1, False, locationID)
                //    End If
                //End If
            }

            return(rowsAffected == 1);
        }
Ejemplo n.º 2
0
        public bool InsertDetails(Session session, int shippingID, int?itemID, string lot, int?quantity, float?pallets, string note, DateTime?expirationDate, string fullLPNNumber)
        {
            SPG.ShippingDetailsDataTable details        = new SPG.ShippingDetailsDataTable();
            SPG.ShippingDetailsRow       shippingDetail = details.NewShippingDetailsRow();

            shippingDetail.ShipDetMainID = shippingID;
            shippingDetail.ShipDetItemID = itemID.Value;
            if (string.IsNullOrEmpty(lot))
            {
                shippingDetail.SetShipDetLotNull();
            }
            else
            {
                shippingDetail.ShipDetLot = lot;
            }
            shippingDetail.ShipDetDetQty = quantity.Value;
            shippingDetail.SetsngPackagesNull();
            if (!pallets.HasValue)
            {
                shippingDetail.SetsngPalletsNull();
            }
            else
            {
                shippingDetail.sngPallets = pallets.Value;
            }
            if (string.IsNullOrEmpty(note))
            {
                shippingDetail.SetNoteNull();
            }
            else
            {
                shippingDetail.Note = note;
            }
            if (expirationDate.HasValue)
            {
                shippingDetail.ExpirationDate = expirationDate.Value;
            }
            else
            {
                shippingDetail.SetExpirationDateNull();
            }
            if (string.IsNullOrEmpty(fullLPNNumber))
            {
                shippingDetail.SetFullLPNNumberNull();
            }
            else
            {
                shippingDetail.FullLPNNumber = fullLPNNumber;
            }

            details.AddShippingDetailsRow(shippingDetail);
            int rowsAffected = Adapter.Update(details);

            if (rowsAffected == 1)
            {
                ItemsBLL items = new ItemsBLL();
                if (fullLPNNumber.StartsWith(CustomersBLL.GetLPNPrefix(7)))
                {
                    items.UpdateStock(session, itemID.Value, quantity.Value * -1, false, session.GetObjectByKey <Shipping>(shippingID).ShippingLocation.Oid, lot, int.Parse(fullLPNNumber.Replace(CustomersBLL.GetLPNPrefix(7), "")));
                }
                else
                {
                    items.UpdateStock(session, itemID.Value, quantity.Value * -1, false, session.GetObjectByKey <Shipping>(shippingID).ShippingLocation.Oid);
                }
            }

            return(rowsAffected == 1);
        }