コード例 #1
0
        /// <summary>
        /// Makes a shallow copy of the current DojoSeminarRegistrationOptionCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>DojoSeminarRegistrationOptionCollection</returns>
        public DojoSeminarRegistrationOptionCollection Clone()
        {
            DojoSeminarRegistrationOptionCollection clonedDojoSeminarRegistrationOption = new DojoSeminarRegistrationOptionCollection(count);

            lock (this)
            {
                foreach (DojoSeminarRegistrationOption item in this)
                {
                    clonedDojoSeminarRegistrationOption.Add(item);
                }
            }
            return(clonedDojoSeminarRegistrationOption);
        }
コード例 #2
0
        /// <summary>
        /// Makes a deep copy of the current DojoSeminarRegistrationOption.
        /// </summary>
        /// <param name="isolation">Placeholders are used to isolate the
        /// items in the DojoSeminarRegistrationOptionCollection from their children.</param>
        public DojoSeminarRegistrationOptionCollection Copy(bool isolated)
        {
            DojoSeminarRegistrationOptionCollection isolatedCollection = new DojoSeminarRegistrationOptionCollection(count);

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DojoSeminarRegistrationOptionArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DojoSeminarRegistrationOptionArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
コード例 #3
0
        private void cacheStoreCollection(int hashCode, DojoSeminarRegistrationOptionCollection dojoSeminarRegistrationOptionCollection)
        {
            CacheManager cache = CacheFactory.GetCacheManager();

            cache.Add(tableName + "_Collection_" + hashCode.ToString(), dojoSeminarRegistrationOptionCollection);
        }
コード例 #4
0
        public DojoSeminarRegistrationOptionCollection GetCollection(int topCount, string whereClause, string sortClause, params DojoSeminarRegistrationOptionFlags[] optionFlags)
        {
            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;
            DojoSeminarRegistrationOptionCollection dojoSeminarRegistrationOptionCollection;
            int hashcode;

            // Cache Handling

            hashcode = 0;

            if (cacheEnabled)
            {
                hashcode = topCount.GetHashCode() +
                           whereClause.GetHashCode() +
                           sortClause.GetHashCode() +
                           tableName.GetHashCode();

                DojoSeminarRegistrationOptionCollection collection = cacheFindCollection(hashcode);
                if (collection != null)
                {
                    return(collection);
                }
            }

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }

            foreach (string columnName in InnerJoinFields)
            {
                query.Append("DojoSeminarRegistrationOption.");
                query.Append(columnName);
                query.Append(",");
            }

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int parentOptionOffset       = -1;
            int parentOptionItemOffset   = -1;
            int parentRegistrationOffset = -1;
            int parentRegistrationParentSeminarOffset  = -1;
            int parentRegistrationContactOffset        = -1;
            int parentRegistrationInvoiceLineOffset    = -1;
            int parentRegistrationSalesOrderLineOffset = -1;
            int parentRegistrationCustomerOffset       = -1;

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DojoSeminarRegistrationOptionFlags.ParentOption:
                        for (int i = 0; i <= DojoSeminarOptionManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ParentOption.");
                            query.Append(DojoSeminarOptionManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentOptionOffset = innerJoinOffset;
                        innerJoinOffset    = parentOptionOffset + DojoSeminarOptionManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentOptionItem:
                        for (int i = 0; i <= RHItemManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ParentOption_Item.");
                            query.Append(RHItemManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentOptionItemOffset = innerJoinOffset;
                        innerJoinOffset        = parentOptionItemOffset + RHItemManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistration:
                        for (int i = 0; i <= DojoSeminarRegistrationManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ParentRegistration.");
                            query.Append(DojoSeminarRegistrationManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentRegistrationOffset = innerJoinOffset;
                        innerJoinOffset          = parentRegistrationOffset + DojoSeminarRegistrationManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationParentSeminar:
                        for (int i = 0; i <= DojoSeminarManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ParentRegistration_ParentSeminar.");
                            query.Append(DojoSeminarManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentRegistrationParentSeminarOffset = innerJoinOffset;
                        innerJoinOffset = parentRegistrationParentSeminarOffset + DojoSeminarManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationContact:
                        for (int i = 0; i <= GreyFoxContactManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ParentRegistration_Contact.");
                            query.Append(GreyFoxContactManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentRegistrationContactOffset = innerJoinOffset;
                        innerJoinOffset = parentRegistrationContactOffset + GreyFoxContactManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationInvoiceLine:
                        for (int i = 0; i <= RHInvoiceLineManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ParentRegistration_InvoiceLine.");
                            query.Append(RHInvoiceLineManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentRegistrationInvoiceLineOffset = innerJoinOffset;
                        innerJoinOffset = parentRegistrationInvoiceLineOffset + RHInvoiceLineManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationSalesOrderLine:
                        for (int i = 0; i <= RHSalesOrderLineManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ParentRegistration_SalesOrderLine.");
                            query.Append(RHSalesOrderLineManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentRegistrationSalesOrderLineOffset = innerJoinOffset;
                        innerJoinOffset = parentRegistrationSalesOrderLineOffset + RHSalesOrderLineManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationCustomer:
                        for (int i = 0; i <= RHCustomerManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ParentRegistration_Customer.");
                            query.Append(RHCustomerManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentRegistrationCustomerOffset = innerJoinOffset;
                        innerJoinOffset = parentRegistrationCustomerOffset + RHCustomerManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;
                    }
                }
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            if (optionFlags != null)
            {
                query.Append(" FROM ");

                //
                // Start INNER JOIN expressions
                //
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    query.Append("(");
                }

                query.Append("kitTessen_SeminarRegistrationOptions AS DojoSeminarRegistrationOption");
            }
            else
            {
                query.Append(" FROM kitTessen_SeminarRegistrationOptions AS DojoSeminarRegistrationOption");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DojoSeminarRegistrationOptionFlags.ParentOption:
                        query.Append(" LEFT JOIN kitTessen_SeminarOptions AS ParentOption ON DojoSeminarRegistrationOption.ParentOptionID = ParentOption.DojoSeminarOptionID)");
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentOptionItem:
                        query.Append(" LEFT JOIN RH_Items AS ParentOption_Item ON ParentOption.ItemID = ParentOption_Item.RHItemID)");
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistration:
                        query.Append(" LEFT JOIN kitTessen_SeminarRegistrations AS ParentRegistration ON DojoSeminarRegistrationOption.ParentRegistrationID = ParentRegistration.DojoSeminarRegistrationID)");
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationParentSeminar:
                        query.Append(" LEFT JOIN kitTessen_Seminars AS ParentRegistration_ParentSeminar ON ParentRegistration.ParentSeminarID = ParentRegistration_ParentSeminar.DojoSeminarID)");
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationContact:
                        query.Append(" LEFT JOIN kitTessen_SeminarRegistrations_Contacts AS ParentRegistration_Contact ON ParentRegistration.ContactID = ParentRegistration_Contact.GreyFoxContactID)");
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationInvoiceLine:
                        query.Append(" LEFT JOIN RH_InvoiceLines AS ParentRegistration_InvoiceLine ON ParentRegistration.InvoiceLineID = ParentRegistration_InvoiceLine.RHInvoiceLineID)");
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationSalesOrderLine:
                        query.Append(" LEFT JOIN RH_SalesOrderLines AS ParentRegistration_SalesOrderLine ON ParentRegistration.SalesOrderLineID = ParentRegistration_SalesOrderLine.RHSalesOrderLineID)");
                        break;

                    case DojoSeminarRegistrationOptionFlags.ParentRegistrationCustomer:
                        query.Append(" LEFT JOIN RH_Customers AS ParentRegistration_Customer ON ParentRegistration.CustomerID = ParentRegistration_Customer.RHCustomerID)");
                        break;
                    }
                }
            }

            //
            // Render where clause
            //
            if (whereClause != string.Empty)
            {
                query.Append(" WHERE ");
                query.Append(whereClause);
            }

            //
            // Render sort clause
            //
            if (sortClause != string.Empty)
            {
                query.Append(" ORDER BY ");
                query.Append(sortClause);
            }

            //
            // Render final semicolon
            //
            query.Append(";");
            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
                        #if DEBUG
            try
            {
                r = database.ExecuteReader(dbCommand);
            }
            catch (Exception e)
            {
                string msg = e.Message;
                throw(new Exception(msg + " --- Query: " + query.ToString()));
            }
                        #else
            r = database.ExecuteReader(dbCommand);
                        #endif

            dojoSeminarRegistrationOptionCollection = new DojoSeminarRegistrationOptionCollection();

            while (r.Read())
            {
                DojoSeminarRegistrationOption dojoSeminarRegistrationOption = ParseFromReader(r, 0, 1);

                // Fill ParentOption
                if (parentOptionOffset != -1 && !r.IsDBNull(parentOptionOffset))
                {
                    DojoSeminarOptionManager.FillFromReader(dojoSeminarRegistrationOption.parentOption, r, parentOptionOffset, parentOptionOffset + 1);

                    // Fill
                    if (parentOptionItemOffset != -1 && !r.IsDBNull(parentOptionItemOffset))
                    {
                        RHItemManager.FillFromReader(dojoSeminarRegistrationOption.parentOption.Item, r, parentOptionItemOffset, parentOptionItemOffset + 1);
                    }
                }

                // Fill ParentRegistration
                if (parentRegistrationOffset != -1 && !r.IsDBNull(parentRegistrationOffset))
                {
                    DojoSeminarRegistrationManager.FillFromReader(dojoSeminarRegistrationOption.parentRegistration, r, parentRegistrationOffset, parentRegistrationOffset + 1);

                    // Fill
                    if (parentRegistrationParentSeminarOffset != -1 && !r.IsDBNull(parentRegistrationParentSeminarOffset))
                    {
                        DojoSeminarManager.FillFromReader(dojoSeminarRegistrationOption.parentRegistration.ParentSeminar, r, parentRegistrationParentSeminarOffset, parentRegistrationParentSeminarOffset + 1);
                    }

                    // Fill
                    if (parentRegistrationContactOffset != -1 && !r.IsDBNull(parentRegistrationContactOffset))
                    {
                        GreyFoxContactManager.FillFromReader(dojoSeminarRegistrationOption.parentRegistration.Contact, "kitTessen_SeminarRegistrations_Contacts", r, parentRegistrationContactOffset, parentRegistrationContactOffset + 1);
                    }

                    // Fill Invoice Line
                    if (parentRegistrationInvoiceLineOffset != -1 && !r.IsDBNull(parentRegistrationInvoiceLineOffset))
                    {
                        RHInvoiceLineManager.FillFromReader(dojoSeminarRegistrationOption.parentRegistration.InvoiceLine, r, parentRegistrationInvoiceLineOffset, parentRegistrationInvoiceLineOffset + 1);
                    }

                    // Fill Sales Order Line
                    if (parentRegistrationSalesOrderLineOffset != -1 && !r.IsDBNull(parentRegistrationSalesOrderLineOffset))
                    {
                        RHSalesOrderLineManager.FillFromReader(dojoSeminarRegistrationOption.parentRegistration.SalesOrderLine, r, parentRegistrationSalesOrderLineOffset, parentRegistrationSalesOrderLineOffset + 1);
                    }

                    // Fill Registrant
                    if (parentRegistrationCustomerOffset != -1 && !r.IsDBNull(parentRegistrationCustomerOffset))
                    {
                        RHCustomerManager.FillFromReader(dojoSeminarRegistrationOption.parentRegistration.Customer, r, parentRegistrationCustomerOffset, parentRegistrationCustomerOffset + 1);
                    }
                }

                dojoSeminarRegistrationOptionCollection.Add(dojoSeminarRegistrationOption);
            }

            // Microsoft DAAB still needs to close readers.
            r.Close();

            if (cacheEnabled)
            {
                cacheStoreCollection(hashcode, dojoSeminarRegistrationOptionCollection);
            }

            return(dojoSeminarRegistrationOptionCollection);
        }
コード例 #5
0
ファイル: DojoSeminar.cs プロジェクト: rahodges/Tessen
        public DojoSeminarRegistration NewRegistration(DateTime registrationDate,
                                                       GreyFoxContact contact,
                                                       int classUnits, DojoSeminarRegistrationOptionCollection options)
        {
            DojoSeminarRegistration r = new DojoSeminarRegistration();

            r.isSynced      = false;
            r.isPlaceHolder = false;
            r.contact       = contact;
            r.classUnits    = classUnits;

            //
            // Calculate base registration calcSeminarFee and detect full registrations.
            //
            switch (ClassUnitType)
            {
            case DojoSeminarClassUnitType.Day:
                TimeSpan span = endDate.Subtract(startDate);
                if (classUnits == span.Days)
                {
                    r.totalFee = fullRegistrationFee;
                }
                else
                {
                    r.totalFee = baseRegistrationFee + (classUnitFee * classUnits);
                }
                break;

            case DojoSeminarClassUnitType.Class:
                if (classUnits == ClassCount)
                {
                    r.totalFee = fullRegistrationFee;
                }
                else
                {
                    r.totalFee = baseRegistrationFee + (classUnitFee * classUnits);
                }
                break;

            case DojoSeminarClassUnitType.None:
                if (classUnits == ClassCount)
                {
                    r.totalFee = fullRegistrationFee;
                }
                else
                {
                    r.totalFee = baseRegistrationFee + (classUnitFee * classUnits);
                }
                break;
            }

            //
            // Add up lineOption fees and set lineOption parent seminar.
            //
            for (int x = 0; x <= options.Count; x++)
            {
                options[x].parentRegistration = r;
                r.totalFee += options[x].totalFee;
            }

            return(r);
        }
コード例 #6
0
        /// <summary>
        /// Calculates the calcSeminarFee for the registration and sets the TotalFee to the amount due.
        /// </summary>
        /// <param name="ignore">Optionally ignores setting the TotalFee property.</param>
        /// <returns>The amount of the TotalFee.</returns>
        public decimal CalculateFee(DojoSeminarRegistrationOptionCollection options, bool ignore)
        {
            decimal     fullFee        = decimal.Zero;
            decimal     calcSeminarFee = decimal.Zero;
            decimal     calcTotalFee   = decimal.Zero;
            DojoSeminar seminar        = ParentSeminar;

            // Detect Early Bird
            if (registrationDate < seminar.EarlyEndDate)
            {
                fullFee = seminar.FullEarlyRegistrationFee;
            }
            else if (registrationDate < seminar.LateStartDate)
            {
                fullFee = seminar.FullRegistrationFee;
            }
            else
            {
                fullFee = seminar.FullLateRegistrationFee;
            }

            switch (seminar.ClassUnitType)
            {
            case DojoSeminarClassUnitType.Day:
                TimeSpan span = seminar.EndDate.Subtract(seminar.StartDate);
                if (ClassUnits == span.Days)
                {
                    calcSeminarFee = fullFee;
                }
                else
                {
                    calcSeminarFee = seminar.BaseRegistrationFee + (seminar.ClassUnitFee * ClassUnits);
                }
                break;

            case DojoSeminarClassUnitType.Class:
                if (ClassUnits == seminar.ClassCount)
                {
                    calcSeminarFee = fullFee;
                }
                else
                {
                    calcSeminarFee = seminar.BaseRegistrationFee + (seminar.ClassUnitFee * ClassUnits);
                }
                break;

            case DojoSeminarClassUnitType.None:
                calcSeminarFee = fullFee;
                break;

            default:
                throw (new Exception(string.Format("Illegal ClassUnitType '{0}'.", seminar.ClassUnitType)));
            }

            // Calculate Option Fees
            calcTotalFee = calcSeminarFee;
            foreach (DojoSeminarRegistrationOption option in options)
            {
                calcTotalFee += option.TotalFee;
            }

            if (!ignore)
            {
                SeminarFee = calcSeminarFee;
                TotalFee   = calcTotalFee;
            }

            return(calcSeminarFee);
        }
コード例 #7
0
 public decimal CalculateFee(DojoSeminarRegistrationOptionCollection options)
 {
     return(CalculateFee(options, false));
 }