Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private static void cacheStore(DojoSeminarRegistrationOption dojoSeminarRegistrationOption)
        {
            CacheManager cache = CacheFactory.GetCacheManager();

            cache.Add("kitTessen_SeminarRegistrationOptions_" + dojoSeminarRegistrationOption.iD.ToString(), dojoSeminarRegistrationOption);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Inserts a DojoSeminarRegistrationOption into the database. All children should have been
        /// saved to the database before insertion. New children will not be
        /// related to this object in the database.
        /// </summary>
        /// <param name="_DojoSeminarRegistrationOption">The DojoSeminarRegistrationOption to insert into the database.</param>
        internal static int _insert(DojoSeminarRegistrationOption dojoSeminarRegistrationOption)
        {
            int       id;
            string    query;
            Database  database;
            DbCommand dbCommand;

            database = DatabaseFactory.CreateDatabase();

            query = "INSERT INTO kitTessen_SeminarRegistrationOptions " +
                    "(" +
                    "Quantity," +
                    "TotalFee," +
                    "CostPerItem," +
                    "ParentOptionID," +
                    "ParentRegistrationID) VALUES (" +
                    "@Quantity," +
                    "@TotalFee," +
                    "@CostPerItem," +
                    "@ParentOptionID," +
                    "@ParentRegistrationID);";

            if (database.ConnectionStringWithoutCredentials.StartsWith("provider=microsoft.jet.oledb.4.0"))
            {
                // Microsoft Access
                // Connection must remain open for IDENTITY to return correct value,
                // therefore use the dbCommand object's Connection directly to control
                // connection state.
                dbCommand = database.GetSqlStringCommand(query);
                fillParameters(database, dbCommand, dojoSeminarRegistrationOption);
                dbCommand.Connection = database.CreateConnection();
                dbCommand.Connection.Open();
                dbCommand.ExecuteNonQuery();
                dbCommand.CommandText = "SELECT @@IDENTITY AS LastID";
                id = (int)dbCommand.ExecuteScalar();
                dbCommand.Connection.Close();
            }
            else
            {
                //// Microsoft SQL Server
                dbCommand = database.GetSqlStringCommand(query + " SELECT @LastID = SCOPE_IDENTITY();");
                fillParameters(database, dbCommand, dojoSeminarRegistrationOption);
                database.AddOutParameter(dbCommand, "@LastID", DbType.Int32, 10);
                database.ExecuteNonQuery(dbCommand);
                id = (int)dbCommand.Parameters["@LastID"].Value;
            }
            // Store dojoSeminarRegistrationOption in cache.
            if (cacheEnabled)
            {
                cacheStore(dojoSeminarRegistrationOption);
            }
            // ************************* WARNING ****************************
            // Insert operations must invalidate the cached collections.
            // Invalidation MUST invalidate any foreign cached collections that
            // with children objects this manager provides or else the foreign
            // caches retain invalidated and potentially corrupt data!
            // NOTE:
            // NitroCast only allows collection caching on objects that do not
            // have any children objects to minimize potential corruption.
            invalidateCachedCollections();
            return(id);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Compares the object's ID to another object's ID.
 /// </summary>
 public int CompareTo(DojoSeminarRegistrationOption dojoSeminarRegistrationOption)
 {
     return(this.iD - dojoSeminarRegistrationOption.iD);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Compares the object's ID to another object's ID.
        /// </summary>
        int IComparable.CompareTo(object obj)
        {
            DojoSeminarRegistrationOption dojoSeminarRegistrationOption = (DojoSeminarRegistrationOption)obj;

            return(this.iD - dojoSeminarRegistrationOption.iD);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Deep copies the current DojoSeminarRegistrationOption to another instance of DojoSeminarRegistrationOption.
 /// This method does not provide isolated copies; use overriden method for this feature.
 /// </summary>
 /// <param name="DojoSeminarRegistrationOption">The DojoSeminarRegistrationOption to copy to.</param>
 public void CopyTo(DojoSeminarRegistrationOption dojoSeminarRegistrationOption)
 {
     CopyTo(dojoSeminarRegistrationOption, false);
 }
 public bool Contains(DojoSeminarRegistrationOption value)
 {
     return(IndexOf(value) != -1);
 }