/// <summary> /// Function to fill ledgers as TreeMode /// </summary> /// <param name="tn"></param> public void FillTree(TreeNode tn) { try { DataTable dtb = new DataTable(); AccountGroupSP spAccountGroup = new AccountGroupSP(); dtb = spAccountGroup.AccountGroupViewAllByGroupUnder(Convert.ToDecimal(tn.Name)); AccountLedgerSP ledgerSP = new AccountLedgerSP(); if (dtb.Rows.Count > 0) { foreach (DataRow dr in dtb.Rows) { tn.Nodes.Add(dr["accountGroupId"].ToString(), dr["accountGroupName"].ToString()); tn.ExpandAll(); if (tn.LastNode != null) { tn.LastNode.ForeColor = Color.Red; } else { tn.LastNode.ForeColor = Color.Blue; } } foreach (TreeNode tn1 in tn.Nodes) { FillTree(tn1); DataTable dtb1 = ledgerSP.AccountLedgerViewAllByLedgerName(Convert.ToDecimal(tn1.Name)); foreach (DataRow dr in dtb1.Rows) { tn1.Nodes.Add(dr["ledgerId"].ToString(), dr["ledgerName"].ToString()); tn1.ExpandAll(); if (tn1.LastNode != null) { tn1.LastNode.ForeColor = Color.Blue; } else { tn.LastNode.ForeColor = Color.Red; } } } } } catch (Exception ex) { formMDI.infoError.ErrorString = "COA1:" + ex.Message; } }
/// <summary> /// Form Load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmChartOfAccount_Load(object sender, EventArgs e) { try { dtblItems.Columns.Add("name"); dtblItems.Columns.Add("type"); AccountGroupSP spAccountGroup = new AccountGroupSP(); DataTable dtbl = new DataTable(); dtbl = spAccountGroup.AccountGroupViewAllByGroupUnder(-1); foreach (DataRow dr in dtbl.Rows) { tvChartOfAccount.Nodes.Add(dr["accountGroupId"].ToString(), dr["accountGroupName"].ToString()); } foreach (TreeNode tn1 in tvChartOfAccount.Nodes) { FillTree(tn1); } } catch (Exception ex) { formMDI.infoError.ErrorString = "COA3:" + ex.Message; } }