/// <summary> /// Saves the DojoRank object state to the database. /// </summary> public int Save() { if (promotionRank != null) { promotionRank.Save(); } if (isSynced) { return(iD); } if (iD == -1) { throw (new Exception("Invalid record; cannot be saved.")); } if (iD == 0) { iD = DojoRankManager._insert(this); } else { DojoRankManager._update(this); } isSynced = iD != -1; return(iD); }
/// <summary> /// Duplicates DojoRank object into a database; may or may not be the same database /// as the parent object. /// </summary> /// <returns> A new DojoRank object reflecting the replicated DojoRank object.</returns> public DojoRank Duplicate() { DojoRank clonedDojoRank = this.Clone(); // Insert must be called after children are replicated! clonedDojoRank.iD = DojoRankManager._insert(clonedDojoRank); clonedDojoRank.isSynced = true; return(clonedDojoRank); }
/// <summary> /// Ensures that the object's fields and children are /// pre-loaded before any updates or reads. /// </summary> public void EnsurePreLoad() { if (!isPlaceHolder) { return; } DojoRankManager._fill(this); isPlaceHolder = false; }
/// <summary> /// Overwrites and existing DojoRank object in the database. /// </summary> public void Overwrite(int id) { iD = id; DojoRankManager._update(this); isSynced = true; }
public void Delete() { DojoRankManager._delete(this.iD); this.iD = 0; isSynced = false; }
public DojoRank(int id) { this.iD = id; isSynced = DojoRankManager._fill(this); }
public DojoRankCollection GetCollection(int topCount, string whereClause, string sortClause, params DojoRankFlags[] optionFlags) { StringBuilder query; Database database; DbCommand dbCommand; IDataReader r; DojoRankCollection dojoRankCollection; int innerJoinOffset; query = new StringBuilder("SELECT "); if (topCount > 0) { query.Append("TOP "); query.Append(topCount); query.Append(" "); } foreach (string columnName in InnerJoinFields) { query.Append("DojoRank."); query.Append(columnName); query.Append(","); } innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1; int promotionRankOffset = -1; int promotionRankPromotionRankOffset = -1; int promotionRankItemOffset = -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 DojoRankFlags.PromotionRank: for (int i = 0; i <= DojoRankManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("PromotionRank."); query.Append(DojoRankManager.InnerJoinFields[i]); query.Append(","); } promotionRankOffset = innerJoinOffset; innerJoinOffset = promotionRankOffset + DojoRankManager.InnerJoinFields.GetUpperBound(0) + 1; break; case DojoRankFlags.PromotionRankPromotionRank: for (int i = 0; i <= DojoRankManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("PromotionRank_PromotionRank."); query.Append(DojoRankManager.InnerJoinFields[i]); query.Append(","); } promotionRankPromotionRankOffset = innerJoinOffset; innerJoinOffset = promotionRankPromotionRankOffset + DojoRankManager.InnerJoinFields.GetUpperBound(0) + 1; break; case DojoRankFlags.PromotionRankItem: for (int i = 0; i <= RHItemManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("PromotionRank_Item."); query.Append(RHItemManager.InnerJoinFields[i]); query.Append(","); } promotionRankItemOffset = innerJoinOffset; innerJoinOffset = promotionRankItemOffset + RHItemManager.InnerJoinFields.GetUpperBound(0) + 1; break; case DojoRankFlags.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 DojoRankFlags.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 DojoRankFlags.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 DojoRankFlags.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 DojoRankFlags.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 DojoRankFlags.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 DojoRankFlags.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_Ranks AS DojoRank"); } else { query.Append(" FROM kitTessen_Ranks AS DojoRank"); } // // Finish INNER JOIN expressions // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case DojoRankFlags.PromotionRank: query.Append(" LEFT JOIN kitTessen_Ranks AS PromotionRank ON DojoRank.PromotionRankID = PromotionRank.DojoRankID)"); break; case DojoRankFlags.PromotionRankPromotionRank: query.Append(" LEFT JOIN kitTessen_Ranks AS PromotionRank_PromotionRank ON PromotionRank.PromotionRankID = PromotionRank_PromotionRank.DojoRankID)"); break; case DojoRankFlags.PromotionRankItem: query.Append(" LEFT JOIN RH_Items AS PromotionRank_Item ON PromotionRank.ItemID = PromotionRank_Item.RHItemID)"); break; case DojoRankFlags.Item: query.Append(" LEFT JOIN RH_Items AS Item ON DojoRank.ItemID = Item.RHItemID)"); break; case DojoRankFlags.ItemParentItem: query.Append(" LEFT JOIN RH_Items AS Item_ParentItem ON Item.ParentItemID = Item_ParentItem.RHItemID)"); break; case DojoRankFlags.ItemPurchaseVendor: query.Append(" LEFT JOIN RH_Vendors AS Item_PurchaseVendor ON Item.PurchaseVendorID = Item_PurchaseVendor.RHVendorID)"); break; case DojoRankFlags.ItemPurchaseAccount: query.Append(" LEFT JOIN RH_Accounts AS Item_PurchaseAccount ON Item.PurchaseAccountID = Item_PurchaseAccount.RHAccountID)"); break; case DojoRankFlags.ItemInventoryAccount: query.Append(" LEFT JOIN RH_Accounts AS Item_InventoryAccount ON Item.InventoryAccountID = Item_InventoryAccount.RHAccountID)"); break; case DojoRankFlags.ItemTax: query.Append(" LEFT JOIN RH_TaxTypes AS Item_Tax ON Item.TaxID = Item_Tax.RHTaxTypeID)"); break; case DojoRankFlags.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 dojoRankCollection = new DojoRankCollection(); while (r.Read()) { DojoRank dojoRank = ParseFromReader(r, 0, 1); // Fill PromotionRank if (promotionRankOffset != -1 && !r.IsDBNull(promotionRankOffset)) { DojoRankManager.FillFromReader(dojoRank.promotionRank, r, promotionRankOffset, promotionRankOffset + 1); // Fill if (promotionRankPromotionRankOffset != -1 && !r.IsDBNull(promotionRankPromotionRankOffset)) { DojoRankManager.FillFromReader(dojoRank.promotionRank.PromotionRank, r, promotionRankPromotionRankOffset, promotionRankPromotionRankOffset + 1); } // Fill if (promotionRankItemOffset != -1 && !r.IsDBNull(promotionRankItemOffset)) { RHItemManager.FillFromReader(dojoRank.promotionRank.Item, r, promotionRankItemOffset, promotionRankItemOffset + 1); } } // Fill Item if (itemOffset != -1 && !r.IsDBNull(itemOffset)) { RHItemManager.FillFromReader(dojoRank.item, r, itemOffset, itemOffset + 1); // Fill if (itemParentItemOffset != -1 && !r.IsDBNull(itemParentItemOffset)) { RHItemManager.FillFromReader(dojoRank.item.ParentItem, r, itemParentItemOffset, itemParentItemOffset + 1); } // Fill Vendor if (itemPurchaseVendorOffset != -1 && !r.IsDBNull(itemPurchaseVendorOffset)) { RHVendorManager.FillFromReader(dojoRank.item.PurchaseVendor, r, itemPurchaseVendorOffset, itemPurchaseVendorOffset + 1); } // Fill Purchase Account if (itemPurchaseAccountOffset != -1 && !r.IsDBNull(itemPurchaseAccountOffset)) { RHAccountManager.FillFromReader(dojoRank.item.PurchaseAccount, r, itemPurchaseAccountOffset, itemPurchaseAccountOffset + 1); } // Fill Asset Account if (itemInventoryAccountOffset != -1 && !r.IsDBNull(itemInventoryAccountOffset)) { RHAccountManager.FillFromReader(dojoRank.item.InventoryAccount, r, itemInventoryAccountOffset, itemInventoryAccountOffset + 1); } // Fill if (itemTaxOffset != -1 && !r.IsDBNull(itemTaxOffset)) { RHTaxTypeManager.FillFromReader(dojoRank.item.Tax, r, itemTaxOffset, itemTaxOffset + 1); } // Fill if (itemSalesIncomeAccountOffset != -1 && !r.IsDBNull(itemSalesIncomeAccountOffset)) { RHAccountManager.FillFromReader(dojoRank.item.SalesIncomeAccount, r, itemSalesIncomeAccountOffset, itemSalesIncomeAccountOffset + 1); } } dojoRankCollection.Add(dojoRank); } // Microsoft DAAB still needs to close readers. r.Close(); return(dojoRankCollection); }