protected static FR_L6SO_FPC_1548 Execute(DbConnection Connection, DbTransaction Transaction, P_L6SO_FPC_1548 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6SO_FPC_1548();
            returnValue.Result = new L6SO_FPC_1548();

            #region Validation

            var isAllowedParam = new P_L6SO_IPCA_1039()
            {
                LOG_SHP_Shipment_HeaderID = Parameter.LOG_SHP_Shipment_HeaderID
            };
            var validationResult = cls_Is_PickingControlAllowed.Invoke(Connection, Transaction, isAllowedParam, securityTicket).Result;

            if (!validationResult.IsPickingControlAllowed)
            {
                if (validationResult.IfPickingControlNotAllowed_ResetShipmentFlags)
                {
                    var updateHeaderParam = new P_L3SO_USHSaDARfSH_1054()
                    {
                        ShipmentHeaderID = Parameter.LOG_SHP_Shipment_HeaderID
                    };

                    var result = cls_Update_ShipmentHeaderStatus_and_DeleteActiveReservations_for_ShipmentHeaderID.Invoke(Connection, Transaction, updateHeaderParam, securityTicket).Result;

                    if (result)
                    {
                        returnValue.Result.Status = EPickingControlStatus.Error_InconsistentData;
                    }
                    else
                    {
                        returnValue.Result.Status = EPickingControlStatus.Error_AlreadyFinished;
                    }
                }
                else
                {
                    returnValue.Result.Status = EPickingControlStatus.Error_AlreadyFinished;
                }

                return(returnValue);
            }

            #endregion

            #region GetAllShippingorderPositions

            var positions = ORM_LOG_SHP_Shipment_Position.Query.Search(Connection, Transaction, new ORM_LOG_SHP_Shipment_Position.Query()
            {
                LOG_SHP_Shipment_Header_RefID = Parameter.LOG_SHP_Shipment_HeaderID,
                IsDeleted = false
            });

            #endregion

            foreach (var position in positions)
            {
                var reservations = ORM_LOG_RSV_Reservation.Query.Search(Connection, Transaction, new ORM_LOG_RSV_Reservation.Query()
                {
                    LOG_SHP_Shipment_Position_RefID = position.LOG_SHP_Shipment_PositionID,
                    IsReservationExecuted           = false,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });

                #region Update Contents and positions

                foreach (var reservation in reservations)
                {
                    reservation.IsReservationExecuted = true;
                    reservation.Save(Connection, Transaction);

                    #region Shelf Conent

                    var shelfContent = new ORM_LOG_WRH_Shelf_Content();
                    shelfContent.Load(Connection, Transaction, reservation.LOG_WRH_Shelf_Content_RefID);
                    shelfContent.Quantity_Current -= reservation.ReservedQuantity;
                    shelfContent.Save(Connection, Transaction);

                    #endregion

                    #region Shelf Content Adjustments

                    var contentAdjustment = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment();
                    contentAdjustment.LOG_WRH_Shelf_ContentAdjustmentID = Guid.NewGuid();
                    contentAdjustment.ShelfContent_RefID = shelfContent.LOG_WRH_Shelf_ContentID;

                    contentAdjustment.QuantityChangedAmount = -reservation.ReservedQuantity;;
                    contentAdjustment.QuantityChangedDate   = DateTime.Now;

                    contentAdjustment.IsInitialReceipt         = false;
                    contentAdjustment.IsInventoryJobCorrection = false;
                    contentAdjustment.IsShipmentWithdrawal     = false;
                    contentAdjustment.IsManualCorrection       = false;

                    contentAdjustment.IsShipmentWithdrawal = true;
                    contentAdjustment.IfShipmentWithdrawal_ShipmentPosition_RefID = reservation.LOG_SHP_Shipment_Position_RefID;

                    contentAdjustment.PerformedBy_Account_RefID = securityTicket.AccountID;
                    contentAdjustment.PerformedAt_Date          = DateTime.Now;

                    contentAdjustment.ContentAdjustmentComment = "Product is being moved from the shelf after picking control";

                    contentAdjustment.Tenant_RefID       = securityTicket.TenantID;
                    contentAdjustment.Creation_Timestamp = DateTime.Now;
                    contentAdjustment.Save(Connection, Transaction);

                    #endregion

                    #region Reservation TrackingInstance

                    var reservationTrackingInstance = ORM_LOG_RSV_Reservation_TrackingInstance.Query.Search(Connection, Transaction, new ORM_LOG_RSV_Reservation_TrackingInstance.Query()
                    {
                        LOG_RSV_Reservation_RefID = reservation.LOG_RSV_ReservationID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).SingleOrDefault();

                    if (reservationTrackingInstance != default(ORM_LOG_RSV_Reservation_TrackingInstance))
                    {
                        var trackingInstance = new ORM_LOG_ProductTrackingInstance();
                        trackingInstance.Load(Connection, Transaction, reservationTrackingInstance.LOG_ProductTrackingInstance_RefID);

                        trackingInstance.CurrentQuantityOnTrackingInstance -= reservationTrackingInstance.ReservedQuantityFromTrackingInstance;
                        trackingInstance.R_FreeQuantity     -= reservationTrackingInstance.ReservedQuantityFromTrackingInstance;
                        trackingInstance.R_ReservedQuantity -= reservationTrackingInstance.ReservedQuantityFromTrackingInstance;

                        trackingInstance.Save(Connection, Transaction);

                        #region ORM_LOG_ProductTrackingInstance_HistoryEntry

                        var trackingInstanceHistory = new CL1_LOG.ORM_LOG_ProductTrackingInstance_HistoryEntry();
                        trackingInstanceHistory.LOG_ProductTrackingInstance_HistoryEntryID = Guid.NewGuid();
                        trackingInstanceHistory.ProductTrackingInstance_RefID = trackingInstance.LOG_ProductTrackingInstanceID;
                        trackingInstanceHistory.HistoryEntry_Text             = "Products are being removed from the shelf after picking control finish";
                        trackingInstanceHistory.Creation_Timestamp            = DateTime.Now;
                        trackingInstanceHistory.Tenant_RefID = securityTicket.TenantID;
                        trackingInstanceHistory.Save(Connection, Transaction);

                        #endregion

                        #region ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance

                        var adjustment2tracking = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance();
                        adjustment2tracking.LOG_WRH_Shelf_ContentAdjustment_TrackingInstanceID = Guid.NewGuid();
                        adjustment2tracking.LOG_ProductTrackingInstance_RefID     = trackingInstance.LOG_ProductTrackingInstanceID;
                        adjustment2tracking.LOG_WRH_Shelf_ContentAdjustment_RefID = contentAdjustment.LOG_WRH_Shelf_ContentAdjustmentID;
                        adjustment2tracking.QuantityChangedAmount = -reservation.ReservedQuantity;
                        adjustment2tracking.Creation_Timestamp    = DateTime.Now;
                        adjustment2tracking.Tenant_RefID          = securityTicket.TenantID;
                        adjustment2tracking.Save(Connection, Transaction);

                        #endregion
                    }

                    #endregion
                }

                #endregion
            }

            #region Change ShipmentOrderStatus Status

            var parameter = new P_L5SO_CSOS_1148();
            parameter.LOG_SHP_Shipment_HeaderID = Parameter.LOG_SHP_Shipment_HeaderID;
            parameter.HasPickingFinished        = true;
            parameter.IsShipped = true;

            cls_Change_ShippigOrderHeader_Status.Invoke(Connection, Transaction, parameter, securityTicket);

            #endregion

            returnValue.Result.Status = EPickingControlStatus.Finished;
            return(returnValue);

            #endregion UserCode
        }
            private static List <ORM_LOG_WRH_Shelf_ContentAdjustment> Search(Query query, string connectionString, DbConnection connection, DbTransaction transaction)
            {
                CSV2Core.Core.Interfaces.IManagedConnection managedConnection = new CSV2Core_MySQL.MySQLManagedConnection();
                List <ORM_LOG_WRH_Shelf_ContentAdjustment>  items;

                try
                {
                    managedConnection.set(connectionString, connection, transaction);
                    var loader = new CSV2Core_MySQL.Dictionaries.MultiTable.Loader.DictionaryLoader(managedConnection.getConnection(), managedConnection.getTransaction());

                    DbCommand command = managedConnection.manage(query.CreateSelectQuery(TableName));
                    query.SetParameters(command);

                    items = new List <ORM_LOG_WRH_Shelf_ContentAdjustment>();

                    var reader = new CSV2Core_MySQL.Support.DBSQLReader(command.ExecuteReader());
                    reader.SetOrdinals(new string[] { "LOG_WRH_Shelf_ContentAdjustmentID", "ShelfContent_RefID", "QuantityChangedAmount", "QuantityChangedDate", "IsInitialReceipt", "IfInitialReceipt_ReceiptPosition_QualityControlItem_RefID", "IsInventoryJobCorrection", "IfInventoryJobCorrection_InvenoryJobProcess_RefID", "IsShipmentWithdrawal", "IfShipmentWithdrawal_ShipmentPosition_RefID", "IsManualCorrection", "IfManualCorrection_InventoryChangeReason_RefID", "PerformedBy_Account_RefID", "PerformedAt_Date", "ContentAdjustmentComment", "IsBatchNumberOrSerialKeyUpdate", "IfBatchNumberOrSerialKeyUpdate_CorrespondingAdjustment_RefID", "IsRelocation", "IfRelocation_CorrespondingAdjustment_RefID", "Creation_Timestamp", "Tenant_RefID", "IsDeleted" });
                    while (reader.Read())
                    {
                        ORM_LOG_WRH_Shelf_ContentAdjustment item = new ORM_LOG_WRH_Shelf_ContentAdjustment();
                        //0:Parameter LOG_WRH_Shelf_ContentAdjustmentID of type Guid
                        item.LOG_WRH_Shelf_ContentAdjustmentID = reader.GetGuid(0);
                        //1:Parameter ShelfContent_RefID of type Guid
                        item.ShelfContent_RefID = reader.GetGuid(1);
                        //2:Parameter QuantityChangedAmount of type double
                        item.QuantityChangedAmount = reader.GetDouble(2);
                        //3:Parameter QuantityChangedDate of type DateTime
                        item.QuantityChangedDate = reader.GetDate(3);
                        //4:Parameter IsInitialReceipt of type Boolean
                        item.IsInitialReceipt = reader.GetBoolean(4);
                        //5:Parameter IfInitialReceipt_ReceiptPosition_QualityControlItem_RefID of type Guid
                        item.IfInitialReceipt_ReceiptPosition_QualityControlItem_RefID = reader.GetGuid(5);
                        //6:Parameter IsInventoryJobCorrection of type Boolean
                        item.IsInventoryJobCorrection = reader.GetBoolean(6);
                        //7:Parameter IfInventoryJobCorrection_InvenoryJobProcess_RefID of type Guid
                        item.IfInventoryJobCorrection_InvenoryJobProcess_RefID = reader.GetGuid(7);
                        //8:Parameter IsShipmentWithdrawal of type Boolean
                        item.IsShipmentWithdrawal = reader.GetBoolean(8);
                        //9:Parameter IfShipmentWithdrawal_ShipmentPosition_RefID of type Guid
                        item.IfShipmentWithdrawal_ShipmentPosition_RefID = reader.GetGuid(9);
                        //10:Parameter IsManualCorrection of type Boolean
                        item.IsManualCorrection = reader.GetBoolean(10);
                        //11:Parameter IfManualCorrection_InventoryChangeReason_RefID of type Guid
                        item.IfManualCorrection_InventoryChangeReason_RefID = reader.GetGuid(11);
                        //12:Parameter PerformedBy_Account_RefID of type Guid
                        item.PerformedBy_Account_RefID = reader.GetGuid(12);
                        //13:Parameter PerformedAt_Date of type DateTime
                        item.PerformedAt_Date = reader.GetDate(13);
                        //14:Parameter ContentAdjustmentComment of type String
                        item.ContentAdjustmentComment = reader.GetString(14);
                        //15:Parameter IsBatchNumberOrSerialKeyUpdate of type Boolean
                        item.IsBatchNumberOrSerialKeyUpdate = reader.GetBoolean(15);
                        //16:Parameter IfBatchNumberOrSerialKeyUpdate_CorrespondingAdjustment_RefID of type Guid
                        item.IfBatchNumberOrSerialKeyUpdate_CorrespondingAdjustment_RefID = reader.GetGuid(16);
                        //17:Parameter IsRelocation of type Boolean
                        item.IsRelocation = reader.GetBoolean(17);
                        //18:Parameter IfRelocation_CorrespondingAdjustment_RefID of type Guid
                        item.IfRelocation_CorrespondingAdjustment_RefID = reader.GetGuid(18);
                        //19:Parameter Creation_Timestamp of type DateTime
                        item.Creation_Timestamp = reader.GetDate(19);
                        //20:Parameter Tenant_RefID of type Guid
                        item.Tenant_RefID = reader.GetGuid(20);
                        //21:Parameter IsDeleted of type Boolean
                        item.IsDeleted = reader.GetBoolean(21);


                        item.Status_IsAlreadySaved = true;
                        item.Status_IsDirty        = false;
                        items.Add(item);
                    }
                    reader.Close();
                    loader.Load();
                    managedConnection.commit();
                }
                catch (Exception ex)
                {
                    managedConnection.rollback();
                    throw;
                }
                return(items);
            }