private void GetChildrenIntern(IList <String> help, string AAccountCode, int AChildLevel) { if (FAccountTable.Rows.Count > 0) { FAccountTable.DefaultView.Sort = AAccountHierarchyDetailTable.GetReportOrderDBName() + ", " + AAccountHierarchyDetailTable.GetReportingAccountCodeDBName(); foreach (DataRowView rv in FAccountTable.DefaultView) { accountRow = (AAccountHierarchyDetailRow)rv.Row; if (accountRow.AccountCodeToReportTo.Equals(AAccountCode)) { if (accountRow.AccountHierarchyCode.Equals(STANDARD)) { help.Add(accountRow.ReportingAccountCode); if (AChildLevel != 0) { GetChildrenIntern(help, accountRow.ReportingAccountCode, --AChildLevel); } } } } } }
private void AddNewAccount(Object sender, EventArgs e) { if (FCurrentAccount == null) { MessageBox.Show(Catalog.GetString("You can only add a new account after selecting a parent account")); return; } ValidateAllData(true, false); string newName = FNameForNewAccounts; Int32 countNewAccount = 0; if (FMainDS.AAccount.Rows.Find(new object[] { FLedgerNumber, newName }) != null) { while (FMainDS.AAccount.Rows.Find(new object[] { FLedgerNumber, newName + countNewAccount.ToString() }) != null) { countNewAccount++; } newName += countNewAccount.ToString(); } // ChangeAccountCodeValue() needs this value! strOldDetailAccountCode = newName; AAccountRow parentAccount = FCurrentAccount.AccountRow; GLSetupTDSAAccountRow newAccountRow = FMainDS.AAccount.NewRowTyped(); newAccountRow.AccountCode = newName; newAccountRow.LedgerNumber = FLedgerNumber; newAccountRow.AccountActiveFlag = true; newAccountRow.DebitCreditIndicator = parentAccount.DebitCreditIndicator; newAccountRow.AccountType = parentAccount.AccountType; newAccountRow.ValidCcCombo = parentAccount.ValidCcCombo; newAccountRow.PostingStatus = true; FMainDS.AAccount.Rows.Add(newAccountRow); AAccountHierarchyDetailRow hierarchyDetailRow = FMainDS.AAccountHierarchyDetail.NewRowTyped(); hierarchyDetailRow.LedgerNumber = FLedgerNumber; hierarchyDetailRow.AccountHierarchyCode = FSelectedHierarchy; hierarchyDetailRow.AccountCodeToReportTo = parentAccount.AccountCode; hierarchyDetailRow.ReportingAccountCode = newName; // change posting/summary flag of parent account if it was previously a leaf parentAccount.PostingStatus = false; // The parent is now a summary account! hierarchyDetailRow.ReportOrder = ucoAccountsTree.GetLastChildReportingOrder() + 1; FMainDS.AAccountHierarchyDetail.Rows.Add(hierarchyDetailRow); FIAmUpdating++; ShowDetails(newAccountRow); FIAmUpdating--; ucoAccountsTree.AddNewAccount(newAccountRow, hierarchyDetailRow); txtDetailAccountCode.Focus(); FPetraUtilsObject.SetChangedFlag(); }
/// <summary> /// Add this new account as child of the currently selected node /// </summary> public void AddNewAccount(GLSetupTDSAAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { trvAccounts.BeginUpdate(); TreeNode newNode = trvAccounts.SelectedNode.Nodes.Add(AccountRow.AccountCode); AccountNodeDetails NewAccount = AccountNodeDetails.AddNewAccount(newNode, AccountRow, HierarchyDetailRow); trvAccounts.EndUpdate(); FParentForm.SetSelectedAccount(NewAccount); }
private void GetChildrenIntern(IList <String> help, string AAccountCode, Boolean OnlyPosting, int AChildLevel) { if (FHierarchyDetailTable.Rows.Count > 0) { FHierarchyDetailTable.DefaultView.Sort = AAccountHierarchyDetailTable.GetReportOrderDBName() + ", " + AAccountHierarchyDetailTable.GetReportingAccountCodeDBName(); foreach (DataRowView rv in FHierarchyDetailTable.DefaultView) { AAccountHierarchyDetailRow Row = (AAccountHierarchyDetailRow)rv.Row; if (Row.AccountCodeToReportTo.Equals(AAccountCode)) { if (Row.AccountHierarchyCode.Equals(STANDARD)) { Boolean includeThis = true; if (OnlyPosting) { Int32 pos = FAccountTable.DefaultView.Find(Row.ReportingAccountCode); if (pos >= 0) { AAccountRow account = (AAccountRow)FAccountTable.DefaultView[pos].Row; if (!account.PostingStatus) { includeThis = false; } } } if (includeThis) { help.Add(Row.ReportingAccountCode); } if (AChildLevel != 0) { GetChildrenIntern(help, Row.ReportingAccountCode, OnlyPosting, --AChildLevel); } } } } } }
private void InsertNodeIntoTreeView(GLSetupTDS MainDS, Int32 LedgerNumber, TreeNode AParent, DataView view, AAccountHierarchyDetailRow ADetailRow) { GLSetupTDSAAccountRow AccountRow = (GLSetupTDSAAccountRow)MainDS.AAccount.Rows.Find( new object[] { LedgerNumber, ADetailRow.ReportingAccountCode }); TreeNode Child = new TreeNode(); AccountNodeDetails NodeTag = AccountNodeDetails.AddNewAccount(Child, AccountRow, ADetailRow); NodeTag.IsNew = (ADetailRow.RowState == DataRowState.Added); SetNodeLabel(AccountRow, Child); if (AParent == null) { trvAccounts.Nodes.Add(Child); } else { InsertInOrder(AParent, Child); } // Now add the children of this node: view.RowFilter = AAccountHierarchyDetailTable.GetAccountHierarchyCodeDBName() + " = '" + ADetailRow.AccountHierarchyCode + "' AND " + AAccountHierarchyDetailTable.GetAccountCodeToReportToDBName() + " = '" + ADetailRow.ReportingAccountCode + "'"; if (view.Count > 0) { // An account cannot be deleted if it has children. NodeTag.CanDelete = false; NodeTag.Msg = Catalog.GetString("Child accounts must be deleted first."); NodeTag.CanHaveChildren = true; foreach (DataRowView rowView in view) { AAccountHierarchyDetailRow accountDetail = (AAccountHierarchyDetailRow)rowView.Row; InsertNodeIntoTreeView(MainDS, LedgerNumber, Child, view, accountDetail); } } }
/// <summary> /// Gets the parent account of an inserted account ... /// </summary> /// <param name="AAccountCode"></param> /// <returns></returns> public string GetParentAccount(string AAccountCode) { if (FAccountTable.Rows.Count > 0) { for (int i = 0; i < FAccountTable.Rows.Count; ++i) { accountRow = (AAccountHierarchyDetailRow)FAccountTable.Rows[i]; if (accountRow.ReportingAccountCode.Equals(AAccountCode)) { if (accountRow.AccountHierarchyCode.Equals(STANDARD)) { return(accountRow.AccountCodeToReportTo); } } } } return(String.Empty); }
/// <summary> /// If you only want to know, that the account code has no children, you can avoid the /// handling of the list. /// </summary> /// <param name="AAccountCode"></param> /// <returns></returns> public bool HasNoChildren(string AAccountCode) { if (FAccountTable.Rows.Count > 0) { for (int i = 0; i < FAccountTable.Rows.Count; ++i) { accountRow = (AAccountHierarchyDetailRow)FAccountTable.Rows[i]; if (accountRow.AccountCodeToReportTo.Equals(AAccountCode)) { if (accountRow.AccountHierarchyCode.Equals(STANDARD)) { return(false); } } } } return(true); }
/// <summary>Helps to show what the the new child reporting order should be</summary> public Int32 GetLastChildReportingOrder() { TreeNodeCollection SelectedNodeChildren = FSelectedAccount.linkedTreeNode.Nodes; if (SelectedNodeChildren.Count == 0) { return(0); } else { AAccountHierarchyDetailRow siblingRow = ((AccountNodeDetails)SelectedNodeChildren[SelectedNodeChildren.Count - 1].Tag).DetailRow; if (siblingRow.IsReportOrderNull()) { siblingRow.ReportOrder = 1; } return(siblingRow.ReportOrder + 1); } }
/// <summary> /// Create an AccountNodeDetails object for this account /// </summary> public static AccountNodeDetails AddNewAccount(TreeNode NewTreeNode, AAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { AccountNodeDetails NodeDetails = new AccountNodeDetails(); NodeDetails.CanHaveChildren = true; if (AccountRow.PostingStatus) // A "Posting account" that's not been used may yet be promoted to a "Summary account". { NodeDetails.CanHaveChildren = null; } else // A "Summary account" can have children. { NodeDetails.CanHaveChildren = true; } NodeDetails.IsNew = true; NodeDetails.DetailRow = HierarchyDetailRow; NodeDetails.AccountRow = AccountRow; NewTreeNode.Tag = NodeDetails; NodeDetails.linkedTreeNode = NewTreeNode; return NodeDetails; }
/// <summary> /// helper function for ExportAccountHierarchy /// </summary> private static void InsertNodeIntoXmlDocument(GLSetupTDS AMainDS, XmlDocument ADoc, XmlNode AParentNode, AAccountHierarchyDetailRow ADetailRow) { AAccountRow account = (AAccountRow)AMainDS.AAccount.Rows.Find(new object[] { ADetailRow.LedgerNumber, ADetailRow.ReportingAccountCode }); XmlElement accountNode = ADoc.CreateElement(TYml2Xml.XMLELEMENT); // AccountCodeToReportTo and ReportOrder are encoded implicitly accountNode.SetAttribute("name", ADetailRow.ReportingAccountCode); accountNode.SetAttribute("active", account.AccountActiveFlag ? "True" : "False"); accountNode.SetAttribute("type", account.AccountType.ToString()); accountNode.SetAttribute("debitcredit", account.DebitCreditIndicator ? "debit" : "credit"); accountNode.SetAttribute("validcc", account.ValidCcCombo); accountNode.SetAttribute("shortdesc", account.EngAccountCodeShortDesc); if (account.EngAccountCodeLongDesc != account.EngAccountCodeShortDesc) { accountNode.SetAttribute("longdesc", account.EngAccountCodeLongDesc); } if (account.EngAccountCodeShortDesc != account.AccountCodeShortDesc) { accountNode.SetAttribute("localdesc", account.AccountCodeShortDesc); } if (account.EngAccountCodeLongDesc != account.AccountCodeLongDesc) { accountNode.SetAttribute("locallongdesc", account.AccountCodeLongDesc); } if (AMainDS.AAccountProperty.Rows.Find(new object[] { account.LedgerNumber, account.AccountCode, MFinanceConstants.ACCOUNT_PROPERTY_BANK_ACCOUNT, "true" }) != null) { accountNode.SetAttribute("bankaccount", "true"); } if (account.ForeignCurrencyFlag) { accountNode.SetAttribute("currency", account.ForeignCurrencyCode); } AParentNode.AppendChild(accountNode); AMainDS.AAccountHierarchyDetail.DefaultView.Sort = AAccountHierarchyDetailTable.GetReportOrderDBName(); AMainDS.AAccountHierarchyDetail.DefaultView.RowFilter = AAccountHierarchyDetailTable.GetAccountHierarchyCodeDBName() + " = '" + ADetailRow.AccountHierarchyCode + "' AND " + AAccountHierarchyDetailTable.GetAccountCodeToReportToDBName() + " = '" + ADetailRow.ReportingAccountCode + "'"; foreach (DataRowView rowView in AMainDS.AAccountHierarchyDetail.DefaultView) { AAccountHierarchyDetailRow accountDetail = (AAccountHierarchyDetailRow)rowView.Row; InsertNodeIntoXmlDocument(AMainDS, ADoc, accountNode, accountDetail); } }
/// <summary> /// Gets the parent account of an inserted account ... /// </summary> /// <param name="AAccountCode"></param> /// <returns></returns> public string GetParentAccount(string AAccountCode) { if (FAccountTable.Rows.Count > 0) { for (int i = 0; i < FAccountTable.Rows.Count; ++i) { accountRow = (AAccountHierarchyDetailRow)FAccountTable.Rows[i]; if (accountRow.ReportingAccountCode.Equals(AAccountCode)) { if (accountRow.AccountHierarchyCode.Equals(STANDARD)) { return accountRow.AccountCodeToReportTo; } } } } return String.Empty; }
/// <summary> /// If you only want to know, that the account code has no children, you can avoid the /// handling of the list. /// </summary> /// <param name="AAccountCode"></param> /// <returns></returns> public bool HasNoChildren(string AAccountCode) { if (FAccountTable.Rows.Count > 0) { for (int i = 0; i < FAccountTable.Rows.Count; ++i) { accountRow = (AAccountHierarchyDetailRow)FAccountTable.Rows[i]; if (accountRow.AccountCodeToReportTo.Equals(AAccountCode)) { if (accountRow.AccountHierarchyCode.Equals(STANDARD)) { return false; } } } } return true; }
private void GetChildrenIntern(IList <String>help, string AAccountCode, int AChildLevel) { if (FAccountTable.Rows.Count > 0) { FAccountTable.DefaultView.Sort = AAccountHierarchyDetailTable.GetReportOrderDBName() + ", " + AAccountHierarchyDetailTable.GetReportingAccountCodeDBName(); foreach (DataRowView rv in FAccountTable.DefaultView) { accountRow = (AAccountHierarchyDetailRow)rv.Row; if (accountRow.AccountCodeToReportTo.Equals(AAccountCode)) { if (accountRow.AccountHierarchyCode.Equals(STANDARD)) { help.Add(accountRow.ReportingAccountCode); if (AChildLevel != 0) { GetChildrenIntern(help, accountRow.ReportingAccountCode, --AChildLevel); } } } } } }
/// <summary> /// helper function for ExportAccountHierarchy /// </summary> private static void InsertNodeIntoXmlDocument(GLSetupTDS AMainDS, XmlDocument ADoc, XmlNode AParentNode, AAccountHierarchyDetailRow ADetailRow) { #region Validate Arguments if (AMainDS == null) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The GL Posting dataset is null!"), Utilities.GetMethodName(true))); } else if (AMainDS.AAccount == null) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The Account table does not exist in the dataset!"), Utilities.GetMethodName(true))); } else if (AMainDS.AAccountProperty == null) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The Account Property table does not exist in the dataset!"), Utilities.GetMethodName(true))); } else if (AMainDS.AAccountHierarchyDetail == null) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The Account Hierarchy Detail table does not exist in the dataset!"), Utilities.GetMethodName(true))); } #endregion Validate Arguments AAccountRow account = (AAccountRow)AMainDS.AAccount.Rows.Find(new object[] { ADetailRow.LedgerNumber, ADetailRow.ReportingAccountCode }); XmlElement accountNode = ADoc.CreateElement(TYml2Xml.XMLELEMENT); // AccountCodeToReportTo and ReportOrder are encoded implicitly accountNode.SetAttribute("name", ADetailRow.ReportingAccountCode); accountNode.SetAttribute("active", account.AccountActiveFlag ? "True" : "False"); accountNode.SetAttribute("type", account.AccountType.ToString()); accountNode.SetAttribute("debitcredit", account.DebitCreditIndicator ? "debit" : "credit"); accountNode.SetAttribute("validcc", account.ValidCcCombo); accountNode.SetAttribute("shortdesc", account.EngAccountCodeShortDesc); if (account.EngAccountCodeLongDesc != account.EngAccountCodeShortDesc) { accountNode.SetAttribute("longdesc", account.EngAccountCodeLongDesc); } if (account.EngAccountCodeShortDesc != account.AccountCodeShortDesc) { accountNode.SetAttribute("localdesc", account.AccountCodeShortDesc); } if (account.EngAccountCodeLongDesc != account.AccountCodeLongDesc) { accountNode.SetAttribute("locallongdesc", account.AccountCodeLongDesc); } if (AMainDS.AAccountProperty.Rows.Find(new object[] { account.LedgerNumber, account.AccountCode, MFinanceConstants.ACCOUNT_PROPERTY_BANK_ACCOUNT, "true" }) != null) { accountNode.SetAttribute("bankaccount", "true"); } if (account.ForeignCurrencyFlag) { accountNode.SetAttribute("currency", account.ForeignCurrencyCode); } AParentNode.AppendChild(accountNode); AMainDS.AAccountHierarchyDetail.DefaultView.Sort = AAccountHierarchyDetailTable.GetReportOrderDBName(); AMainDS.AAccountHierarchyDetail.DefaultView.RowFilter = AAccountHierarchyDetailTable.GetAccountHierarchyCodeDBName() + " = '" + ADetailRow.AccountHierarchyCode + "' AND " + AAccountHierarchyDetailTable.GetAccountCodeToReportToDBName() + " = '" + ADetailRow.ReportingAccountCode + "'"; foreach (DataRowView rowView in AMainDS.AAccountHierarchyDetail.DefaultView) { AAccountHierarchyDetailRow accountDetail = (AAccountHierarchyDetailRow)rowView.Row; InsertNodeIntoXmlDocument(AMainDS, ADoc, accountNode, accountDetail); } }
private static string InsertNodeIntoHTMLTreeView(GLSetupTDS AMainDS, Int32 ALedgerNumber, AAccountHierarchyDetailRow ADetailRow, bool AIsRootNode = false) { StringBuilder result = new StringBuilder(); AAccountRow AccountRow = (AAccountRow)AMainDS.AAccount.Rows.Find( new object[] { ALedgerNumber, ADetailRow.ReportingAccountCode }); string nodeLabel = ADetailRow.ReportingAccountCode; if (!AccountRow.IsAccountCodeShortDescNull()) { nodeLabel += " (" + AccountRow.AccountCodeShortDesc + ")"; } if (AIsRootNode) { result.Append("<ul><li id='acct" + AccountRow.AccountCode + "'><span><i class=\"icon-folder-open\"></i>" + nodeLabel + "</span><ul>"); } else if (!AccountRow.PostingStatus) { result.Append("<li id='acct" + AccountRow.AccountCode + "'><span><i class=\"icon-minus-sign\"></i>" + nodeLabel + "</span><ul>"); } else if (AccountRow.PostingStatus) { result.Append("<li id='acct" + AccountRow.AccountCode + "'><span><i class=\"icon-leaf\"></i>" + nodeLabel + "</span></<li>"); } // Now add the children of this node: DataView view = new DataView(AMainDS.AAccountHierarchyDetail); view.Sort = AAccountHierarchyDetailTable.GetReportOrderDBName() + ", " + AAccountHierarchyDetailTable.GetReportingAccountCodeDBName(); view.RowFilter = AAccountHierarchyDetailTable.GetAccountHierarchyCodeDBName() + " = '" + ADetailRow.AccountHierarchyCode + "' AND " + AAccountHierarchyDetailTable.GetAccountCodeToReportToDBName() + " = '" + ADetailRow.ReportingAccountCode + "'"; if (view.Count > 0) { foreach (DataRowView rowView in view) { AAccountHierarchyDetailRow accountDetail = (AAccountHierarchyDetailRow)rowView.Row; result.Append(InsertNodeIntoHTMLTreeView(AMainDS, ALedgerNumber, accountDetail)); } } if (AIsRootNode) { result.Append("</ul></li></ul>"); } else if (!AccountRow.PostingStatus) { result.Append("</ul></li>"); } return result.ToString(); }
private static Boolean AccountIsDescendantOf(DataView View, String ParentAccount, AAccountHierarchyDetailRow Row) { if (Row.AccountCodeToReportTo == ParentAccount) { return true; } Int32 Idx = View.Find(Row.AccountCodeToReportTo); if (Idx < 0) { return false; // This account has no parent } return AccountIsDescendantOf(View, ParentAccount, (AAccountHierarchyDetailRow)View[Idx].Row); }
/// <summary> /// Add this new account as child of the currently selected node /// </summary> public void AddNewAccount(AAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { trvAccounts.BeginUpdate(); TreeNode newNode = trvAccounts.SelectedNode.Nodes.Add(AccountRow.AccountCode); AccountNodeDetails NewAccount = AccountNodeDetails.AddNewAccount(newNode, AccountRow, HierarchyDetailRow); trvAccounts.EndUpdate(); FParentForm.SetSelectedAccount(NewAccount); }
/// <summary> /// Create an AccountNodeDetails object for this account /// </summary> public static AccountNodeDetails AddNewAccount(TreeNode NewTreeNode, AAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { AccountNodeDetails NodeDetails = new AccountNodeDetails(); NodeDetails.CanHaveChildren = true; if (AccountRow.PostingStatus) // A "Posting account" that's not been used may yet be promoted to a "Summary account". { NodeDetails.CanHaveChildren = null; } else // A "Summary account" can have children. { NodeDetails.CanHaveChildren = true; } NodeDetails.IsNew = true; NodeDetails.DetailRow = HierarchyDetailRow; NodeDetails.AccountRow = AccountRow; NewTreeNode.Tag = NodeDetails; NodeDetails.linkedTreeNode = NewTreeNode; return(NodeDetails); }
private void InsertNodeIntoTreeView(GLSetupTDS MainDS, Int32 LedgerNumber, TreeNode AParent, DataView view, AAccountHierarchyDetailRow ADetailRow) { AAccountRow AccountRow = (AAccountRow)MainDS.AAccount.Rows.Find( new object[] { LedgerNumber, ADetailRow.ReportingAccountCode }); TreeNode Child = new TreeNode(); AccountNodeDetails NodeTag = AccountNodeDetails.AddNewAccount(Child, AccountRow, ADetailRow); NodeTag.IsNew = false; SetNodeLabel(AccountRow, Child); if (AParent == null) { trvAccounts.Nodes.Add(Child); } else { InsertInOrder(AParent, Child); } // Now add the children of this node: view.RowFilter = AAccountHierarchyDetailTable.GetAccountHierarchyCodeDBName() + " = '" + ADetailRow.AccountHierarchyCode + "' AND " + AAccountHierarchyDetailTable.GetAccountCodeToReportToDBName() + " = '" + ADetailRow.ReportingAccountCode + "'"; if (view.Count > 0) { // An account cannot be deleted if it has children. NodeTag.CanDelete = false; NodeTag.Msg = Catalog.GetString("Child accounts must be deleted first."); NodeTag.CanHaveChildren = true; foreach (DataRowView rowView in view) { AAccountHierarchyDetailRow accountDetail = (AAccountHierarchyDetailRow)rowView.Row; InsertNodeIntoTreeView(MainDS, LedgerNumber, Child, view, accountDetail); } } }
private void DeleteAccount(Object sender, EventArgs ev) { string AccountCode = FCurrentAccount.DetailRow.ReportingAccountCode; if (!FCurrentAccount.CanDelete.HasValue) { MessageBox.Show(Catalog.GetString("Fault: CanDelete status is unknown."), Catalog.GetString( "Delete Account"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!FCurrentAccount.CanDelete.Value) { MessageBox.Show( String.Format(Catalog.GetString( "Account {0} cannot be deleted. You can deactivate the account, but not delete it."), AccountCode) + "\r\n" + FCurrentAccount.Msg, Catalog.GetString("Delete Account"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ucoAccountsTree.DeleteSelectedAccount(); // Calling this changes the current FCurrentAccount to the parent of the deleted account! // // If this account has analysis Attributes, // I need to remove them. if (FMainDS.AAnalysisAttribute != null) { DataView DeleteThese = new DataView(FMainDS.AAnalysisAttribute); DeleteThese.RowFilter = String.Format("a_ledger_number_i={0} AND a_account_code_c='{1}'", FLedgerNumber, AccountCode); foreach (DataRowView rv in DeleteThese) { DataRow TempRow = rv.Row; TempRow.Delete(); } } AAccountHierarchyDetailRow AccountHDetailToBeDeleted = (AAccountHierarchyDetailRow)FMainDS.AAccountHierarchyDetail.Rows.Find( new object[] { FLedgerNumber, FSelectedHierarchy, AccountCode }); AccountHDetailToBeDeleted.Delete(); // // I can delete this account if it no longer appears in any Hieararchy. DataView AHD_stillInUse = new DataView(FMainDS.AAccountHierarchyDetail); AHD_stillInUse.RowFilter = String.Format("a_ledger_number_i={0} AND a_reporting_account_code_c='{1}'", FLedgerNumber, AccountCode); if (AHD_stillInUse.Count == 0) { AAccountRow AccountToBeDeleted = (AAccountRow)FMainDS.AAccount.Rows.Find( new object[] { FLedgerNumber, AccountCode }); AccountToBeDeleted.Delete(); } else { MessageBox.Show(String.Format( Catalog.GetString( "The account {0} is removed from the {1} hierarchy, but not deleted, since it remains part of another heirarchy."), AccountCode, FSelectedHierarchy), Catalog.GetString("Delete Account"), MessageBoxButtons.OK, MessageBoxIcon.Information); } // FCurrentAccount is now the parent of the account that was just deleted. // If the parent account now has no accounts reporting to it (in any hierarchies), mark it as posting account. FCurrentAccount.GetAttrributes(); tbbDeleteAccount.Enabled = (FCurrentAccount.CanDelete.HasValue ? FCurrentAccount.CanDelete.Value : false); AAccountRow ParentAccountRow = FCurrentAccount.AccountRow; AHD_stillInUse.RowFilter = String.Format("a_ledger_number_i={0} AND a_account_code_to_report_to_c='{1}'", FLedgerNumber, ParentAccountRow.AccountCode); if (AHD_stillInUse.Count == 0) // No-one now reports to this account, so I can mark it as "Posting" { // Note that since the "Posting" status is now editable, this is unneccessary and may be inappropriate. ParentAccountRow.PostingStatus = true; chkDetailForeignCurrencyFlag.Enabled = (!ParentAccountRow.SystemAccountFlag); cmbDetailForeignCurrencyCode.Enabled = (!ParentAccountRow.SystemAccountFlag && ParentAccountRow.ForeignCurrencyFlag); // It's possible this account could now be deleted, but the user would need to save and re-load first, // if the server still has it down as a summary account. } FPetraUtilsObject.SetChangedFlag(); }
/// <summary> /// Process the account code parent codes /// </summary> private static void ProcessAccountParent( int ALedgerNumber, string CurrAccountCode, bool ADebitCreditIndicator, string ACostCentreList, ABudgetRow ABudgetRow, List <ABudgetPeriodRow> ABudgetPeriods) { AAccountRow AccountRow = (AAccountRow)GLPostingDS.AAccount.Rows.Find(new object[] { ALedgerNumber, CurrAccountCode }); AAccountHierarchyDetailRow AccountHierarchyDetailRow = (AAccountHierarchyDetailRow)GLPostingDS.AAccountHierarchyDetail.Rows.Find( new object[] { ALedgerNumber, MFinanceConstants.ACCOUNT_HIERARCHY_STANDARD, CurrAccountCode }); if (AccountHierarchyDetailRow != null) { string AccountCodeToReportTo = AccountHierarchyDetailRow.AccountCodeToReportTo; if ((AccountCodeToReportTo != null) && (AccountCodeToReportTo != string.Empty)) { /* Recursively call this procedure. */ ProcessAccountParent( ALedgerNumber, AccountCodeToReportTo, ADebitCreditIndicator, ACostCentreList, ABudgetRow, ABudgetPeriods); } } int DebitCreditMultiply = 1; /* needed if the debit credit indicator is not the same */ /* If the account has the same db/cr indicator as the original * account for which the budget was created, add the budget amount. * Otherwise, subtract. */ if (AccountRow.DebitCreditIndicator != ADebitCreditIndicator) { DebitCreditMultiply = -1; } string[] CostCentres = ACostCentreList.Split(':'); string AccCode = AccountRow.AccountCode; /* For each associated Cost Centre, update the General Ledger Master. */ foreach (string CostCentreCode in CostCentres) { int glmRowIndex = GLPostingDS.AGeneralLedgerMaster.DefaultView.Find(new object[] { ALedgerNumber, ABudgetRow.Year, AccCode, CostCentreCode }); if (glmRowIndex == -1) { TGLPosting.CreateGLMYear(ref GLPostingDS, ALedgerNumber, ABudgetRow.Year, AccCode, CostCentreCode); glmRowIndex = GLPostingDS.AGeneralLedgerMaster.DefaultView.Find(new object[] { ALedgerNumber, ABudgetRow.Year, AccCode, CostCentreCode }); } int GLMSequence = ((AGeneralLedgerMasterRow)GLPostingDS.AGeneralLedgerMaster.DefaultView[glmRowIndex].Row).GlmSequence; /* Update totals for the General Ledger Master period record. */ foreach (ABudgetPeriodRow BPR in ABudgetPeriods) { AddBudgetValue(GLMSequence, BPR.PeriodNumber, DebitCreditMultiply * BPR.BudgetBase); } } }