Example #1
0
        /// <summary>
        /// Makes a shallow copy of the current DojoSeminarCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>DojoSeminarCollection</returns>
        public DojoSeminarCollection Clone()
        {
            DojoSeminarCollection clonedDojoSeminar = new DojoSeminarCollection(count);

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

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DojoSeminarArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DojoSeminarArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
Example #3
0
        public DojoSeminarCollection GetCollection(int topCount, string whereClause, string sortClause, params DojoSeminarFlags[] optionFlags)
        {
            StringBuilder         query;
            Database              database;
            DbCommand             dbCommand;
            IDataReader           r;
            DojoSeminarCollection dojoSeminarCollection;

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

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

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

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int locationOffset               = -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 DojoSeminarFlags.Location:
                        for (int i = 0; i <= GreyFoxContactManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Location.");
                            query.Append(GreyFoxContactManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        locationOffset  = innerJoinOffset;
                        innerJoinOffset = locationOffset + GreyFoxContactManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoSeminarFlags.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 DojoSeminarFlags.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 DojoSeminarFlags.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 DojoSeminarFlags.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 DojoSeminarFlags.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 DojoSeminarFlags.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 DojoSeminarFlags.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_Seminars AS DojoSeminar");
            }
            else
            {
                query.Append(" FROM kitTessen_Seminars AS DojoSeminar");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DojoSeminarFlags.Location:
                        query.Append(" LEFT JOIN kitTessen_Locations AS Location ON DojoSeminar.LocationID = Location.GreyFoxContactID)");
                        break;

                    case DojoSeminarFlags.Item:
                        query.Append(" LEFT JOIN RH_Items AS Item ON DojoSeminar.ItemID = Item.RHItemID)");
                        break;

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

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

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

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

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

                    case DojoSeminarFlags.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

            dojoSeminarCollection = new DojoSeminarCollection();

            while (r.Read())
            {
                DojoSeminar dojoSeminar = ParseFromReader(r, 0, 1);

                // Fill Location
                if (locationOffset != -1 && !r.IsDBNull(locationOffset))
                {
                    GreyFoxContactManager.FillFromReader(dojoSeminar.location, "kitTessen_Locations", r, locationOffset, locationOffset + 1);
                }

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

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

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

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

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

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

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

                dojoSeminarCollection.Add(dojoSeminar);
            }

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

            return(dojoSeminarCollection);
        }