Beispiel #1
0
        private void deleteAccountButton_Click(object sender, EventArgs e)
        {
            int  accountNo      = (int)accountComboBox.SelectedValue;
            bool accountDeleted = false;

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

                int accountTransactionsCount = core.CountAccountTransactionsByAccountNo(accountNo);
                if (accountTransactionsCount > 0)
                {
                    MessageBox.Show("Kontot kan inte tas bort eftersom den har registrerade kontotransaktioner.", CurrentApplication.Name, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                Account account = core.GetAccount(accountNo);

                DialogResult result = MessageBox.Show("Är du säker på att du vill ta bort kontot '" + account.Name + "'?", CurrentApplication.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (result == DialogResult.Yes)
                {
                    core.DeleteAccount(accountNo);
                    accountDeleted = true;
                }
            }

            if (accountDeleted)
            {
                ReloadForm();
            }
        }
Beispiel #2
0
        private void Save()
        {
            if (ValidateForm())
            {
                using (var core = new StandardBusinessLayer(DataCache)) {
                    core.Connect();
                    Account account;

                    string      name          = nameTextBox.Text.Trim();
                    int         userNo        = (int)userComboBox.SelectedValue;
                    bool        showInDiagram = showInDiagramCheckBox.Checked;
                    bool        isArchived    = isArchivedCheckBox.Checked;
                    AccountType accountType   = typeDebtRadioButton.Checked ? AccountType.Debt : AccountType.Asset;

                    if (NewAccount)
                    {
                        account = new Account(userNo, accountType, name, decimal.Parse(balanceBroughtForwardAmountTextBox.Text), isArchived, CurrentApplication.DateTimeNow, true);
                    }
                    else
                    {
                        account               = core.GetAccount((int)accountComboBox.SelectedValue);
                        account.Name          = name;
                        account.UserNo        = userNo;
                        account.Type          = accountType;
                        account.ShowInDiagram = showInDiagram;
                        account.IsArchived    = isArchived;

                        if (balanceBroughtForwardAmountTextBox.Text.Trim() == "")
                        {
                            account.BalanceBroughtForwardAmount = 0;
                        }
                        else
                        {
                            account.BalanceBroughtForwardAmount = decimal.Parse(balanceBroughtForwardAmountTextBox.Text);
                        }
                    }

                    core.Save(account);
                    NewAccount     = false;
                    CurrentAccount = account;
                }

                ReloadForm();
            }
        }
Beispiel #3
0
        private void accountComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!IgnoreAccountDropDownChange)
            {
                int accountNo = (int)accountComboBox.SelectedValue;

                if (accountNo == 0)
                {
                    CurrentAccount = null;
                    UpdateFormFromProperty();
                }
                else
                {
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        core.Connect();
                        CurrentAccount = core.GetAccount(accountNo);
                        UpdateFormFromProperty();
                    }
                }
            }

            EnableDisableControls();
        }
Beispiel #4
0
        private void ReloadForm()
        {
            using (var core = new StandardBusinessLayer(DataCache))
            {
                core.Connect();

                int currentAccountNo = CurrentAccount != null ? CurrentAccount.No : 0;

                IgnoreAccountDropDownChange = true;

                var accounts = (from a in core.GetAccountsByIsArchived(false, new EasyBase.Classes.SortOrder(Account.fName, OrderDirection.Ascending))
                                select new DictionaryItem <int, string>()
                {
                    Key = a.No,
                    Value = a.Name
                }).ToList();

                accountComboBox.DataSource = null;
                accounts.Insert(0, new DictionaryItem <int, string>()
                {
                    Key = 0, Value = "*** Välj ett konto ***"
                });

                var archivedAccounts = (from a in core.GetAccountsByIsArchived(true, new EasyBase.Classes.SortOrder(Account.fName, OrderDirection.Ascending))
                                        select new DictionaryItem <int, string>()
                {
                    Key = a.No,
                    Value = a.Name
                }).ToList();

                if (archivedAccounts.Count > 0)
                {
                    accounts.Add(new DictionaryItem <int, string>()
                    {
                        Key = -1, Value = "*** Arkiverade konton ***"
                    });
                    accounts.AddRange(archivedAccounts);
                }

                accountComboBox.DisplayMember = "Value";
                accountComboBox.ValueMember   = "Key";
                accountComboBox.DataSource    = accounts;
                accountComboBox.SelectedValue = 0;

                userComboBox.DataSource    = null;
                userComboBox.ValueMember   = User.fNo;
                userComboBox.DisplayMember = User.fName;
                userComboBox.DataSource    = core.GetUsers();
                userComboBox.SelectedValue = 0;

                CurrentAccount = core.GetAccount(currentAccountNo);
                UpdateFormFromProperty();

                if (CurrentAccount != null)
                {
                    accountComboBox.SelectedValue = CurrentAccount.No;
                    userComboBox.SelectedValue    = CurrentAccount.UserNo;
                }

                IgnoreAccountDropDownChange = false;
            }

            IsDirty = false;
        }
Beispiel #5
0
        private void AccountTransactionForm_Load(object sender, EventArgs e)
        {
            suggestion1CheckBox.Visible = false;
            suggestion2CheckBox.Visible = false;
            suggestion3CheckBox.Visible = false;

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

                CurrentAccount      = core.GetAccount(_initialAccountNo);
                tagComboBox.Visible = CurrentAccount.Type == AccountType.Asset;
                tagLabel.Visible    = tagComboBox.Visible;
                int accountingYear = DataCache.Settings.AccountingYear;

                //var verifications = (from v in core.GetUnbalancedAndEmptyVerifications(accountingYear)
                //                     orderby v.No descending
                //                     select new
                //                                {
                //                                    No = v.No,
                //                                    Name = v.Year.ToString() + "-" + v.SerialNo.ToString()
                //                                }).ToList();

                var verifications = (from v in DataCache.GetUnbalancedAndEmptyVerifications()
                                     orderby v.No descending
                                     select new
                {
                    No = v.No,
                    Name = v.Year.ToString() + "-" + v.SerialNo.ToString()
                }).ToList();

                if (!verifications.Any())
                {
                    verifications.Insert(0, new { No = 0, Name = "Ny affärshändelse" });
                }

                if (_initialVerificationNo > 0 && verifications.All(x => x.No != _initialVerificationNo))
                {
                    Verification verification = DataCache.GetVerification(_initialVerificationNo);
                    //Verification verification = core.GetVerification(_initialVerificationNo);
                    verifications.Add(new { No = verification.No, Name = verification.Date.Year.ToString() + "-" + verification.SerialNo.ToString() });
                }

                verificationComboBox.ValueMember   = "No";
                verificationComboBox.DisplayMember = "Name";
                verificationComboBox.DataSource    = verifications;

                if (_initialAccountTransactionNo > 0)
                {
                    AccountTransaction transaction = DataCache.GetAccountTransaction(_initialAccountTransactionNo);

                    verificationComboBox.SelectedValue = _initialVerificationNo;

                    dateTimePicker.Value           = transaction.TransactionTime;
                    accountingDateTimePicker.Value = transaction.AccountingDate;
                    amountTextBox.Text             = transaction.Amount.ToString(CurrentApplication.MoneyEditFormat);
                    noteTextBox.Text = transaction.Note;
                }
                else
                {
                    verificationComboBox.SelectedIndex = verifications.Count() - 1;
                }

                _tagHandler = new TagHandler(DataCache, _initialAccountNo);

                tagComboBox.DataSource   = _tagHandler.ComboBoxItems;
                tagComboBox.SelectedItem = _tagHandler.GetDefaultComboBoxItem();
            }

            _accountingDateSameAsTransactionTime = false;
            if (dateTimePicker.Value == accountingDateTimePicker.Value)
            {
                _accountingDateSameAsTransactionTime = true;
            }

            EnableDisableControls();
        }