Пример #1
0
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L5AR_FPfDS_1324_Array Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5AR_FPfDS_1324 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L5AR_FPfDS_1324_Array functionReturn = new FR_L5AR_FPfDS_1324_Array();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw new Exception("Exception occured in method cls_Filter_ProductIDs_for_DefaultSupplierID", ex);
            }
            return(functionReturn);
        }
Пример #2
0
        protected static FR_L5AR_FPfDS_1324_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5AR_FPfDS_1324 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5AR_FPfDS_1324_Array();

            /*  Explanation:
             *      There are three levels of priority to retrieve a supplier for a product:
             *          1. A supplier is assigned to a product in CMN_PRO_Product_Suppliers with CMN_PRO_Product_Suppliers.SupplierPriority = 1
             *          2. A product is assigned to a LOG_WRH_QuantityLevels -> the supplier is retrieved by the default supplier of the corresponding storage level e.g. LOG_WRH_Rack_DefaultSuppliers
             *          3. A product has neither 1. or 2. In that case retrieve the LOG_WRH_Area_DefaultSuppliers from the area with LOG_WRH_Areas.IsDefaultIntakeArea
             * */

            var result          = new List <L5AR_FPfDS_1324>();
            var includeProducts = new List <Guid>();
            var excludeProducts = new List <Guid>();

            #region The first priority

            var productsSuppliersWithHighestPriority = ORM_CMN_PRO_Product_Supplier.Query.Search(Connection, Transaction,
                                                                                                 new ORM_CMN_PRO_Product_Supplier.Query()
            {
                SupplierPriority = 1,
                Tenant_RefID     = securityTicket.TenantID,
                IsDeleted        = false
            });

            if (Parameter.SupplierID != null)
            {
                includeProducts = productsSuppliersWithHighestPriority.Where(i => i.CMN_BPT_Supplier_RefID == Parameter.SupplierID).Select(i => i.CMN_PRO_Product_RefID).Intersect(Parameter.ProductIDList).ToList();
                excludeProducts = productsSuppliersWithHighestPriority.Where(i => i.CMN_BPT_Supplier_RefID != Parameter.SupplierID).Select(i => i.CMN_PRO_Product_RefID).Intersect(Parameter.ProductIDList).ToList();
            }
            else
            {
                includeProducts = productsSuppliersWithHighestPriority.Select(i => i.CMN_PRO_Product_RefID).Intersect(Parameter.ProductIDList).ToList();
            }

            result = productsSuppliersWithHighestPriority.Where(i => includeProducts.Contains(i.CMN_PRO_Product_RefID)).Select(i => new L5AR_FPfDS_1324()
            {
                ProductID     = i.CMN_PRO_Product_RefID,
                SupplierID    = i.CMN_BPT_Supplier_RefID,
                SupplierName  = String.Empty,
                PriorityLevel = 1
            }).ToList();

            //exclude already procesed elements
            Parameter.ProductIDList = Parameter.ProductIDList.Except(excludeProducts).ToArray();
            Parameter.ProductIDList = Parameter.ProductIDList.Except(includeProducts).ToArray();

            #endregion

            #region The second priority

            var param2 = new P_L5AR_FPfDSoQL_1410()
            {
                ProductIDList = Parameter.ProductIDList,
            };

            var defaultSuppliersOfQuantityLevels = cls_Filter_ProductIDs_for_DefaultSupplierOfQuantityLevels.Invoke(Connection, Transaction, param2, securityTicket).Result;

            if (defaultSuppliersOfQuantityLevels != null)
            {
                if (Parameter.SupplierID != null)
                {
                    includeProducts = defaultSuppliersOfQuantityLevels.Where(i => i.CMN_BPT_Supplier_RefID == Parameter.SupplierID).Select(i => i.Product_RefID).Intersect(Parameter.ProductIDList).ToList();
                    excludeProducts = defaultSuppliersOfQuantityLevels.Where(i => i.CMN_BPT_Supplier_RefID != Parameter.SupplierID).Select(i => i.Product_RefID).Intersect(Parameter.ProductIDList).ToList();
                }
                else
                {
                    includeProducts = defaultSuppliersOfQuantityLevels.Select(i => i.Product_RefID).Intersect(Parameter.ProductIDList).ToList();
                }

                result.AddRange(defaultSuppliersOfQuantityLevels.Where(i => includeProducts.Contains(i.Product_RefID)).Select(i => new L5AR_FPfDS_1324()
                {
                    ProductID     = i.Product_RefID,
                    SupplierID    = i.CMN_BPT_Supplier_RefID,
                    SupplierName  = String.Empty,
                    PriorityLevel = 2
                }));

                //exclude already procesed elements
                Parameter.ProductIDList = Parameter.ProductIDList.Except(excludeProducts).ToArray();
                Parameter.ProductIDList = Parameter.ProductIDList.Except(includeProducts).ToArray();
            }

            #endregion

            #region The third priority

            var defaultIntakeArea = ORM_LOG_WRH_Area.Query.Search(Connection, Transaction, new ORM_LOG_WRH_Area.Query()
            {
                IsDefaultIntakeArea = true,
                Tenant_RefID        = securityTicket.TenantID,
                IsDeleted           = false
            }).SingleOrDefault();

            if (defaultIntakeArea != null)
            {
                var defaultSupplierForIntakeArea = ORM_LOG_WRH_Area_DefaultSupplier.Query.Search(Connection, Transaction, new ORM_LOG_WRH_Area_DefaultSupplier.Query()
                {
                    Area_RefID             = defaultIntakeArea.LOG_WRH_AreaID,
                    IsDeleted              = false,
                    CMN_BPT_Supplier_RefID = Parameter.SupplierID
                }).SingleOrDefault();

                if (defaultSupplierForIntakeArea != null)
                {
                    includeProducts.AddRange(Parameter.ProductIDList);

                    result.AddRange(Parameter.ProductIDList.Select(i => new L5AR_FPfDS_1324()
                    {
                        ProductID     = i,
                        SupplierID    = defaultSupplierForIntakeArea.CMN_BPT_Supplier_RefID,
                        SupplierName  = String.Empty,
                        PriorityLevel = 3
                    }));
                }
            }


            #endregion

            var suppliers = cls_Get_SuppliersDisplayNames_with_ID_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;

            foreach (var item in result)
            {
                item.SupplierName = suppliers.Where(i => i.CMN_BPT_SupplierID == item.SupplierID).Select(i => i.DisplayName).SingleOrDefault();
            }

            returnValue.Result = result.ToArray();
            return(returnValue);

            #endregion UserCode
        }