Exemple #1
0
        public static void FillOptions(DojoSeminarCollection dojoSeminarCollection)
        {
            StringBuilder s;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;

            if (dojoSeminarCollection.Count > 0)
            {
                s = new StringBuilder("SELECT DojoSeminarID, DojoSeminarOptionID FROM kitTessen_SeminarsChildren_Options ORDER BY DojoSeminarID; ");

                // Clone and sort collection by ID first to fill children in one pass
                DojoSeminarCollection clonedCollection = dojoSeminarCollection.Clone();
                clonedCollection.Sort();

                database  = DatabaseFactory.CreateDatabase();
                dbCommand = database.GetSqlStringCommand(s.ToString());
                r         = database.ExecuteReader(dbCommand);

                bool more = r.Read();

                foreach (DojoSeminar dojoSeminar in clonedCollection)
                {
                    DojoSeminarOptionCollection options;
                    if (dojoSeminar.options != null)
                    {
                        options = dojoSeminar.options;
                        options.Clear();
                    }
                    else
                    {
                        options             = new DojoSeminarOptionCollection();
                        dojoSeminar.options = options;
                    }

                    while (more)
                    {
                        if (r.GetInt32(0) < dojoSeminar.iD)
                        {
                            more = r.Read();
                        }
                        else if (r.GetInt32(0) == dojoSeminar.iD)
                        {
                            options.Add(DojoSeminarOption.NewPlaceHolder(r.GetInt32(1)));
                            more = r.Read();
                        }
                        else
                        {
                            break;
                        }
                    }

                    // No need to continue if there are no more records
                    if (!more)
                    {
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Makes a shallow copy of the current DojoSeminarOptionCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>DojoSeminarOptionCollection</returns>
        public DojoSeminarOptionCollection Clone()
        {
            DojoSeminarOptionCollection clonedDojoSeminarOption = new DojoSeminarOptionCollection(count);

            lock (this)
            {
                foreach (DojoSeminarOption item in this)
                {
                    clonedDojoSeminarOption.Add(item);
                }
            }
            return(clonedDojoSeminarOption);
        }
Exemple #3
0
        public static void FillOptions(DojoSeminar dojoSeminar)
        {
            StringBuilder s;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;

            s = new StringBuilder("SELECT DojoSeminarOptionID FROM kitTessen_SeminarsChildren_Options ");
            s.Append("WHERE DojoSeminarID=");
            s.Append(dojoSeminar.iD);
            s.Append(";");

            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(s.ToString());
            r         = database.ExecuteReader(dbCommand);

            DojoSeminarOptionCollection options;

            if (dojoSeminar.options != null)
            {
                options = dojoSeminar.options;
                options.Clear();
            }
            else
            {
                options             = new DojoSeminarOptionCollection();
                dojoSeminar.options = options;
            }

            while (r.Read())
            {
                options.Add(DojoSeminarOption.NewPlaceHolder(r.GetInt32(0)));
            }

            dojoSeminar.Options = options;
            // Store DojoSeminar in cache.
            if (cacheEnabled)
            {
                cacheStore(dojoSeminar);
            }
        }
        /// <summary>
        /// Makes a deep copy of the current DojoSeminarOption.
        /// </summary>
        /// <param name="isolation">Placeholders are used to isolate the
        /// items in the DojoSeminarOptionCollection from their children.</param>
        public DojoSeminarOptionCollection Copy(bool isolated)
        {
            DojoSeminarOptionCollection isolatedCollection = new DojoSeminarOptionCollection(count);

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DojoSeminarOptionArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DojoSeminarOptionArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
Exemple #5
0
        private void cacheStoreCollection(int hashCode, DojoSeminarOptionCollection dojoSeminarOptionCollection)
        {
            CacheManager cache = CacheFactory.GetCacheManager();

            cache.Add(tableName + "_Collection_" + hashCode.ToString(), dojoSeminarOptionCollection);
        }
Exemple #6
0
        public DojoSeminarOptionCollection GetCollection(int topCount, string whereClause, string sortClause, params DojoSeminarOptionFlags[] optionFlags)
        {
            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;
            DojoSeminarOptionCollection dojoSeminarOptionCollection;
            int hashcode;

            // Cache Handling

            hashcode = 0;

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

                DojoSeminarOptionCollection 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("DojoSeminarOption.");
                query.Append(columnName);
                query.Append(",");
            }

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int itemOffset                   = -1;
            int itemParentItemOffset         = -1;
            int itemPurchaseVendorOffset     = -1;
            int itemPurchaseAccountOffset    = -1;
            int itemInventoryAccountOffset   = -1;
            int itemTaxOffset                = -1;
            int itemSalesIncomeAccountOffset = -1;

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

                    case DojoSeminarOptionFlags.ItemParentItem:
                        for (int i = 0; i <= RHItemManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Item_ParentItem.");
                            query.Append(RHItemManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        itemParentItemOffset = innerJoinOffset;
                        innerJoinOffset      = itemParentItemOffset + RHItemManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarOptionFlags.ItemPurchaseVendor:
                        for (int i = 0; i <= RHVendorManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Item_PurchaseVendor.");
                            query.Append(RHVendorManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        itemPurchaseVendorOffset = innerJoinOffset;
                        innerJoinOffset          = itemPurchaseVendorOffset + RHVendorManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarOptionFlags.ItemPurchaseAccount:
                        for (int i = 0; i <= RHAccountManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Item_PurchaseAccount.");
                            query.Append(RHAccountManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        itemPurchaseAccountOffset = innerJoinOffset;
                        innerJoinOffset           = itemPurchaseAccountOffset + RHAccountManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarOptionFlags.ItemInventoryAccount:
                        for (int i = 0; i <= RHAccountManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Item_InventoryAccount.");
                            query.Append(RHAccountManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        itemInventoryAccountOffset = innerJoinOffset;
                        innerJoinOffset            = itemInventoryAccountOffset + RHAccountManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarOptionFlags.ItemTax:
                        for (int i = 0; i <= RHTaxTypeManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Item_Tax.");
                            query.Append(RHTaxTypeManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        itemTaxOffset   = innerJoinOffset;
                        innerJoinOffset = itemTaxOffset + RHTaxTypeManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarOptionFlags.ItemSalesIncomeAccount:
                        for (int i = 0; i <= RHAccountManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Item_SalesIncomeAccount.");
                            query.Append(RHAccountManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        itemSalesIncomeAccountOffset = innerJoinOffset;
                        innerJoinOffset = itemSalesIncomeAccountOffset + RHAccountManager.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_SeminarOptions AS DojoSeminarOption");
            }
            else
            {
                query.Append(" FROM kitTessen_SeminarOptions AS DojoSeminarOption");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DojoSeminarOptionFlags.Item:
                        query.Append(" LEFT JOIN RH_Items AS Item ON DojoSeminarOption.ItemID = Item.RHItemID)");
                        break;

                    case DojoSeminarOptionFlags.ItemParentItem:
                        query.Append(" LEFT JOIN RH_Items AS Item_ParentItem ON Item.ParentItemID = Item_ParentItem.RHItemID)");
                        break;

                    case DojoSeminarOptionFlags.ItemPurchaseVendor:
                        query.Append(" LEFT JOIN RH_Vendors AS Item_PurchaseVendor ON Item.PurchaseVendorID = Item_PurchaseVendor.RHVendorID)");
                        break;

                    case DojoSeminarOptionFlags.ItemPurchaseAccount:
                        query.Append(" LEFT JOIN RH_Accounts AS Item_PurchaseAccount ON Item.PurchaseAccountID = Item_PurchaseAccount.RHAccountID)");
                        break;

                    case DojoSeminarOptionFlags.ItemInventoryAccount:
                        query.Append(" LEFT JOIN RH_Accounts AS Item_InventoryAccount ON Item.InventoryAccountID = Item_InventoryAccount.RHAccountID)");
                        break;

                    case DojoSeminarOptionFlags.ItemTax:
                        query.Append(" LEFT JOIN RH_TaxTypes AS Item_Tax ON Item.TaxID = Item_Tax.RHTaxTypeID)");
                        break;

                    case DojoSeminarOptionFlags.ItemSalesIncomeAccount:
                        query.Append(" LEFT JOIN RH_Accounts AS Item_SalesIncomeAccount ON Item.SalesIncomeAccountID = Item_SalesIncomeAccount.RHAccountID)");
                        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

            dojoSeminarOptionCollection = new DojoSeminarOptionCollection();

            while (r.Read())
            {
                DojoSeminarOption dojoSeminarOption = ParseFromReader(r, 0, 1);

                // Fill Item
                if (itemOffset != -1 && !r.IsDBNull(itemOffset))
                {
                    RHItemManager.FillFromReader(dojoSeminarOption.item, r, itemOffset, itemOffset + 1);

                    // Fill
                    if (itemParentItemOffset != -1 && !r.IsDBNull(itemParentItemOffset))
                    {
                        RHItemManager.FillFromReader(dojoSeminarOption.item.ParentItem, r, itemParentItemOffset, itemParentItemOffset + 1);
                    }

                    // Fill Vendor
                    if (itemPurchaseVendorOffset != -1 && !r.IsDBNull(itemPurchaseVendorOffset))
                    {
                        RHVendorManager.FillFromReader(dojoSeminarOption.item.PurchaseVendor, r, itemPurchaseVendorOffset, itemPurchaseVendorOffset + 1);
                    }

                    // Fill Purchase Account
                    if (itemPurchaseAccountOffset != -1 && !r.IsDBNull(itemPurchaseAccountOffset))
                    {
                        RHAccountManager.FillFromReader(dojoSeminarOption.item.PurchaseAccount, r, itemPurchaseAccountOffset, itemPurchaseAccountOffset + 1);
                    }

                    // Fill Asset Account
                    if (itemInventoryAccountOffset != -1 && !r.IsDBNull(itemInventoryAccountOffset))
                    {
                        RHAccountManager.FillFromReader(dojoSeminarOption.item.InventoryAccount, r, itemInventoryAccountOffset, itemInventoryAccountOffset + 1);
                    }

                    // Fill
                    if (itemTaxOffset != -1 && !r.IsDBNull(itemTaxOffset))
                    {
                        RHTaxTypeManager.FillFromReader(dojoSeminarOption.item.Tax, r, itemTaxOffset, itemTaxOffset + 1);
                    }

                    // Fill
                    if (itemSalesIncomeAccountOffset != -1 && !r.IsDBNull(itemSalesIncomeAccountOffset))
                    {
                        RHAccountManager.FillFromReader(dojoSeminarOption.item.SalesIncomeAccount, r, itemSalesIncomeAccountOffset, itemSalesIncomeAccountOffset + 1);
                    }
                }

                dojoSeminarOptionCollection.Add(dojoSeminarOption);
            }

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

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

            return(dojoSeminarOptionCollection);
        }