Example #1
0
        private void LoadTransactionGrid()
        {
            if (accountComboBox.ComboBox.SelectedValue == null)
            {
                return;
            }

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

                //int accountingYear = core.GetCashBoxSettings(CashBoxSettingsNo.CurrentApplicationNo).AccountingYear;
                int accountingYear = DataCache.Settings.AccountingYear;

                var sortOrder = EasyBase.Classes.SortOrder.Create(AccountTransaction.fTransactionTime, OrderDirection.Descending,
                                                                  new EasyBase.Classes.SortOrder(AccountTransaction.fNo, OrderDirection.Descending));

                Condition belongsToAccount          = new Condition(AccountTransaction.fAccountNo, CompareOperator.EqualTo, (int)accountComboBox.ComboBox.SelectedValue);
                Condition laterThanOrEqualToMonth   = new Condition(AccountTransaction.fTransactionTime, CompareOperator.GreaterThanOrEqualTo, new DateTime(accountingYear, 1, 1), DateTimeResolution.Month);
                Condition earlierThanOrEqualToMonth = new Condition(AccountTransaction.fTransactionTime, CompareOperator.LessThanOrEqualTo, new DateTime(accountingYear, 12, 31), DateTimeResolution.Month);

                var accountTransactionsTable = core.GetAccountTransactionsTable(belongsToAccount & laterThanOrEqualToMonth & earlierThanOrEqualToMonth, sortOrder,
                                                                                AccountTransaction.fNo, AccountTransaction.fVerificationNo, AccountTransaction.fVerificationSerialNo, AccountTransaction.fTransactionTime, AccountTransaction.fAccountingDate, AccountTransaction.fNote, AccountTransaction.fAmount,
                                                                                AccountTransaction.fUserNo, AccountTransaction.fAccountNo);

                accountTransactionsTable.Columns.Add("AccountBalance", typeof(decimal));

                //var accountTransactions = core.GetAccountTransactionsByAccountNo((int)accountComboBox.ComboBox.SelectedValue, sortOrder);

                transactionsDataGridView.DataSource = accountTransactionsTable;

                //BalanceBroughtForward = core.GetAccount((int)accountComboBox.ComboBox.SelectedValue).BalanceBroughtForwardAmount;
                BalanceBroughtForward =
                    core.GetAccountBalanceBroughtForward((int)accountComboBox.ComboBox.SelectedValue, accountingYear);
                UpdateAccountBalanceColumn();

                // Hide all columns
                foreach (DataGridViewColumn column in transactionsDataGridView.Columns)
                {
                    column.Visible = false;
                    //column.SortMode = DataGridViewColumnSortMode.NotSortable;
                }

                // Show selected columns
                transactionsDataGridView.Columns[AccountTransaction.fVerificationSerialNo].Visible    = true;
                transactionsDataGridView.Columns[AccountTransaction.fVerificationSerialNo].Width      = 75;
                transactionsDataGridView.Columns[AccountTransaction.fVerificationSerialNo].HeaderText = "Nr";

                transactionsDataGridView.Columns[AccountTransaction.fTransactionTime].Visible    = true;
                transactionsDataGridView.Columns[AccountTransaction.fTransactionTime].Width      = 70;
                transactionsDataGridView.Columns[AccountTransaction.fTransactionTime].HeaderText = "Kassadatum";

                transactionsDataGridView.Columns[AccountTransaction.fAccountingDate].Visible    = true;
                transactionsDataGridView.Columns[AccountTransaction.fAccountingDate].Width      = 70;
                transactionsDataGridView.Columns[AccountTransaction.fAccountingDate].HeaderText = "Bokf.datum";

                transactionsDataGridView.Columns[AccountTransaction.fAmount].Width   = CurrentApplication.GridColumnAmountWidth;
                transactionsDataGridView.Columns[AccountTransaction.fAmount].Visible = true;
                transactionsDataGridView.Columns[AccountTransaction.fAmount].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                transactionsDataGridView.Columns[AccountTransaction.fAmount].HeaderText = "Belopp";

                transactionsDataGridView.Columns[AccountTransaction.fNote].Visible      = true;
                transactionsDataGridView.Columns[AccountTransaction.fNote].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                transactionsDataGridView.Columns[AccountTransaction.fNote].HeaderText   = "Notering";

                transactionsDataGridView.Columns["AccountBalance"].Width   = CurrentApplication.GridColumnAmountWidth;
                transactionsDataGridView.Columns["AccountBalance"].Visible = true;
                transactionsDataGridView.Columns["AccountBalance"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                transactionsDataGridView.Columns["AccountBalance"].HeaderText = "Balans";

                CalculateBalance();
                ((MainForm)ParentForm).CalculateBalance();
                EnableDisableControls();

                if (transactionsDataGridView.Rows.Count > 0)
                {
                    transactionsDataGridView.Rows[0].Selected = false;
                }

                UnbalancedVerificationNumbers = DataCache.GetUnbalancedAndEmptyVerifications().Select(v => v.No).ToArray(); //core.GetUnbalancedVerificationNumbers();

                UpdateRowHighlightsNoDatabase(ApplicationEvents.LastCashBookTransactionSelectionChangedEventArgs);
            }
        }