Пример #1
0
        public void AddChildAccountInDatabase()
        {
            Assert.Ignore();
            AccountManager accountManager = (AccountManager)container["AccountManager"];
            SqlTransaction sqlTransac = null;//ConnectionManager.GetInstance().GetSqlTransaction("");

            AccountCategory accountCategory = new AccountCategory {Name = "test"};
            int idCategory = accountManager.InsertAccountCategory(accountCategory, sqlTransac);

            Account account = new Account
            {
                Balance = 20,
                DebitPlus = true,
                AccountCategory = (OAccountCategories) idCategory,
                Label = "Child of CASH",
                Number = "10111",
                StockBalance = 10,
                TypeCode = "1111",
                CurrencyId = 1,
                ParentAccountId = 100
            };

            try
            {
                accountManager.Insert(account, sqlTransac);
                Assert.Fail("The account can be added in DB, the parent account id doesn't exist");
            }
            catch { }

            account.ParentAccountId = 2;
            accountManager.Update(account);

            List<Account> accounts = accountManager.SelectAllAccounts();
            Assert.AreEqual(1, accounts.Count);
        }
Пример #2
0
        private void DeleteAccount()
        {
            Account account = (Account)tlvAccounts.SelectedObject;
            if (account != null && account.Id != -1)
            {

                if (MessageBox.Show(MultiLanguageStrings.GetString(Ressource.ChartOfAccountsForm, "DeleteAccountMessage.Text"),
                        MultiLanguageStrings.GetString(Ressource.ChartOfAccountsForm, "DeleteAccountTitle.Text"),
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {

                        ServicesProvider.GetInstance().GetChartOfAccountsServices().DeleteAccount(account);
                        IntializeTreeViewChartOfAccounts();
                        MessageBox.Show(MultiLanguageStrings.GetString(Ressource.ChartOfAccountsForm, "AccountDeletedSuccessfully.Text"), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
                    }
                }
            }
            else if (account != null && account.Id == -1)
            {
                AccountCategory accountCategory = new AccountCategory() { Id = (int)account.AccountCategory, Name = account.Number };

                if (MessageBox.Show(MultiLanguageStrings.GetString(Ressource.ChartOfAccountsForm, "DeleteAccountCategoryMessage.Text"),
                        MultiLanguageStrings.GetString(Ressource.ChartOfAccountsForm, "DeleteAccountCategoryTitle.Text"),
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        ServicesProvider.GetInstance().GetChartOfAccountsServices().DeleteAccountCategory(accountCategory);
                        IntializeTreeViewChartOfAccounts();
                        MessageBox.Show(MultiLanguageStrings.GetString(Ressource.ChartOfAccountsForm, "AccountDeletedSuccessfully.Text"), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
                    }
                }
            }
        }
Пример #3
0
        public List<Account> SelectAccountByCategory(AccountCategory accountCategory)
        {
            const string sqlText = @"SELECT id,
                                       account_number,
                                       label,
                                       debit_plus,
                                       type_code,
                                       account_category_id,
                                       type,
                                       parent_account_id, lft, rgt
                                     FROM ChartOfAccounts
                                     WHERE account_category_id = @account_category_id";
            List<Account> accounts = new List<Account>();
            using (SqlConnection conn = GetConnection())
            {
                using (OpenCbsCommand select = new OpenCbsCommand(sqlText, conn))
                {
                    select.AddParam("@account_category_id", accountCategory.Id);
                    using (OpenCbsReader reader = select.ExecuteReader())
                    {
                        if (reader == null || reader.Empty) return null;

                        reader.Read();
                        while (reader.Read())
                        {
                            accounts.Add(GetAccount(reader));
                        }
                        return accounts;
                    }
                }
            }
        }
Пример #4
0
        public int InsertAccountCategory(AccountCategory accountCategory, SqlTransaction pSqlTransac)
        {
            const string sqlText = @"INSERT INTO AccountsCategory (name) VALUES (@name) SELECT SCOPE_IDENTITY()";

            using (OpenCbsCommand insert = new OpenCbsCommand(sqlText, pSqlTransac.Connection, pSqlTransac))
            {
                insert.AddParam("@name",  accountCategory.Name);

                return int.Parse(insert.ExecuteScalar().ToString());
            }
        }
Пример #5
0
 public void DeleteAccountCategory(AccountCategory accountCategory)
 {
     const string sqlText = @"DELETE FROM AccountsCategory WHERE id = @id";
     using (SqlConnection conn = GetConnection())
     {
         using (OpenCbsCommand delete = new OpenCbsCommand(sqlText, conn))
         {
             delete.AddParam("@id", accountCategory.Id);
             delete.ExecuteNonQuery();
         }
     }
 }
Пример #6
0
        public void InsertAccountCategory(AccountCategory accountCategory)
        {
            using (SqlConnection conn = _accountManagement.GetConnection())
            using (SqlTransaction sqlTransac = conn.BeginTransaction())
            {

                try
                {
                    _accountManagement.InsertAccountCategory(accountCategory, sqlTransac);

                    sqlTransac.Commit();
                }
                catch (Exception)
                {
                    sqlTransac.Rollback();
                    throw;
                }
            }
        }
Пример #7
0
 public void DeleteAccountCategory(AccountCategory accountCategory)
 {
     CheckAccountCategory(accountCategory);
     _accountManagement.DeleteAccountCategory(accountCategory);
 }
Пример #8
0
 public void CheckAccountCategory(AccountCategory accountCategory)
 {
     List<Account> accounts = _accountManagement.SelectAccountByCategory(accountCategory);
         if (accounts != null)
             throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.AccountCannotBeDeleted);
 }
Пример #9
0
 private void SetAccountCategory(AccountCategory accountCategory)
 {
     tbAccountCategory.Text = accountCategory.Name;
 }