Ejemplo n.º 1
0
        private void createCashBookItemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int transactionNo  = (int)transactionsDataGridView.SelectedRows[0].Cells[AccountTransaction.fNo].Value;
            int verificationNo = (int)transactionsDataGridView.SelectedRows[0].Cells[AccountTransaction.fVerificationNo].Value;

            CashBookTransactionForm form = new CashBookTransactionForm(DataCache, MainForm.Guesser, verificationNo: verificationNo);

            using (var core = new StandardBusinessLayer(DataCache)) {
                core.Connect();
                //AccountTransaction accountTransaction = core.GetAccountTransaction(transactionNo);
                AccountTransaction accountTransaction = DataCache.GetAccountTransaction(transactionNo);

                if (accountTransaction != null)
                {
                    CashBookTransactionCollection cashBookTransactions = core.GetCashBookTransactionsByVerificationNo(verificationNo);
                    AccountTransactionCollection  accountTransactions  = core.GetAccountTransactionsByVerificationNo(verificationNo);

                    decimal sum = accountTransactions.Sum(t => t.Amount) - cashBookTransactions.Sum(t => t.Amount);
                    form.Amount = sum;
                }
            }

            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                using (var core = new StandardBusinessLayer(DataCache)) {
                    core.Connect();

                    core.AddCashBookTransaction(form.VerificationNo, form.VerificationDate, form.AccountingDate, form.UserNo,
                                                form.CategoryNo, form.Amount, form.Note);
                }

                LoadTransactionGrid();
                SelectGridTransaction(transactionNo);
            }
        }
Ejemplo n.º 2
0
        private void newCashBookItemButton_Click(object sender, EventArgs e)
        {
            CashBookTransactionForm form = new CashBookTransactionForm(DataCache, MainForm.Guesser);

            using (var core = new StandardBusinessLayer(DataCache)) {
                core.Connect();

                int          accountingYear = core.GetCashBoxSettings(CashBoxSettingsNo.CurrentApplicationNo).AccountingYear;
                Verification verification   = core.GetFirstUnbalancedVerification(accountingYear);

                if (verification != null)
                {
                    decimal sum = core.GetVerificationBalance(verification.No);

                    form.Amount = sum;
                }
            }

            // Show dialog
            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                CashBookTransaction transaction;

                using (var core = new StandardBusinessLayer(DataCache)) {
                    core.Connect();

                    transaction = core.AddCashBookTransaction(form.VerificationNo, form.VerificationDate, form.AccountingDate, form.UserNo,
                                                              form.CategoryNo, form.Amount, form.Note);
                }

                LoadTransactionGrid();
                SelectGridTransaction(transaction.No);
            }
        }