Example #1
0
 private void tsmIndependent_Click(object sender, EventArgs e)
 {
     if (trvAccount.SelectedNode != null)
     {
         TreeNode node            = trvAccount.SelectedNode;
         TreeNode parentNode      = node.Parent;
         TreeNode grandparentNode = node.Parent.Parent;
         TreeNode newNode         = (TreeNode)node.Clone();
         if (node.Parent != null && node.Parent.Parent != null)
         {
             string parentNodeName      = parentNode.Text;
             string grandparentNodeName = grandparentNode.Text;
             G.glb.lstSubAccount.RemoveAll(o => o.Account == parentNode.Text && o.SubAccount == node.Text);
             RSubAccount newSub = new RSubAccount();
             newSub.Account    = grandparentNode.Text;
             newSub.SubAccount = node.Text;
             newSub.index      = grandparentNode.Nodes.Count;
             G.glb.lstSubAccount.Add(newSub);
             grandparentNode.Nodes.Insert(parentNode.Index + 1, newNode);
             node.Remove();
             trvAccount.SelectedNode = newNode;
             ReIndex(grandparentNodeName);
             ReIndex(parentNodeName);
         }
     }
 }
Example #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool CanSaveFlag = true;

            if (G.glb.lstAccount.Exists(o => o.AccountName == txtAccount.Text))
            {
                CanSaveFlag = false;
                MessageBox.Show("Account exists!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (cbxAccountType.Text == "")
            {
                CanSaveFlag = false;
                MessageBox.Show("Choose The Account Type", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (txtCurrency.Text == "")
            {
                CanSaveFlag = false;
                MessageBox.Show("Choose The Currency", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (CanSaveFlag)
            {
                CAccount newAccount = new CAccount();
                newAccount.AccountName = txtAccount.Text;
                int iconIndex = 0;
                switch (cbxAccountType.Text)
                {
                case "Assets":
                    newAccount.AccountType = EAccountType.Assets;
                    iconIndex = 2;
                    break;

                case "Expense":
                    newAccount.AccountType = EAccountType.Expense;
                    iconIndex = 3;
                    break;

                case "Equity":
                    newAccount.AccountType = EAccountType.Equity;
                    iconIndex = 2;
                    break;

                case "Liability":
                    newAccount.AccountType = EAccountType.Liability;
                    iconIndex = 2;
                    break;

                case "Income":
                    newAccount.AccountType = EAccountType.Income;
                    iconIndex = 1;
                    break;

                default:
                    break;
                }
                newAccount.Currency = txtCurrency.Text;
                G.glb.lstAccount.Add(newAccount);
                RSubAccount newRSubAccount = new RSubAccount();
                int         maxIndex;
                if (G.glb.lstSubAccount.Exists(o => o.Account == UpperAccount))
                {
                    List <RSubAccount> sameLevel = G.glb.lstSubAccount.FindAll(o => o.Account == UpperAccount).ToList();
                    sameLevel = sameLevel.OrderByDescending(o => o.index).ToList();
                    maxIndex  = sameLevel[0].index + 1;
                }
                else
                {
                    maxIndex = 0;
                }
                newRSubAccount.Account    = UpperAccount;
                newRSubAccount.SubAccount = txtAccount.Text;
                newRSubAccount.index      = maxIndex;
                G.glb.lstSubAccount.Add(newRSubAccount);
                AddChildNode(txtAccount.Text, iconIndex);
                Dispose();
            }
        }