Exemplo n.º 1
0
        private void verificationComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int verificationNo = (int)verificationComboBox.SelectedValue;

            if (verificationNo > 0)
            {
                using (var core = new StandardBusinessLayer(DataCache))
                {
                    core.Connect();
                    var verification = DataCache.GetVerification(verificationNo);

                    dateTimePicker.Value           = verification.Date;
                    accountingDateTimePicker.Value = verification.AccountingDate;
                    amountTextBox.Text             = verification.Balance.ToString(CurrentApplication.MoneyEditFormat);
                    noteTextBox.Text = "";
                }
            }
            else
            {
                dateTimePicker.Value           = CurrentApplication.DateNow;
                accountingDateTimePicker.Value = CurrentApplication.DateNow;
                amountTextBox.Text             = "";
                noteTextBox.Text = "";
            }
        }
Exemplo n.º 2
0
        private void transactionsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                int no             = (int)transactionsDataGridView.Rows[e.RowIndex].Cells[CashBookTransaction.fNo].Value;
                int userNo         = (int)transactionsDataGridView.Rows[e.RowIndex].Cells[CashBookTransaction.fUserNo].Value;
                int categoryNo     = (int)transactionsDataGridView.Rows[e.RowIndex].Cells[CashBookTransaction.fCategoryNo].Value;
                int verificationNo = (int)transactionsDataGridView.Rows[e.RowIndex].Cells[CashBookTransaction.fVerificationNo].Value;

                var          form   = new CashBookTransactionForm(DataCache, MainForm.Guesser, no, verificationNo);
                DialogResult result = form.ShowDialog();

                if (result == DialogResult.OK)
                {
                    CashBookTransaction transaction;
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        core.Connect();
                        transaction = core.UpdateCashBookTransaction(no, form.VerificationDate, form.AccountingDate, form.UserNo, form.CategoryNo, form.Amount, form.Note);
                    }

                    LoadTransactionGrid();
                    SelectGridTransaction(no);

                    ApplicationEvents.OnCashBookTransactionUpdated(no, transaction.VerificationNo);
                }
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
0
        private void createUsersButton_Click(object sender, EventArgs e)
        {
            if (ValidateForm())
            {
                using (var core = new StandardBusinessLayer())
                {
                    core.Connect();

                    User user = new User(user1TextBox.Text.Trim(), user1TextBox.Text.Trim().ToLower() + "@cashbox.se", "", CurrentApplication.DateTimeNow);
                    core.Save(user);

                    string  genitiveName = user.Name + (user.Name.ToLower().EndsWith("s") ? "" : "s");
                    Account account      = new Account(user.No, AccountType.Asset, genitiveName + " lönekonto", 0, false, CurrentApplication.DateTimeNow, true);
                    core.Save(account);

                    if (user2TextBox.Text.Trim() != "")
                    {
                        user = new User(user2TextBox.Text.Trim(), user2TextBox.Text.Trim().ToLower() + "@cashbox.se", "", CurrentApplication.DateTimeNow);
                        core.Save(user);

                        genitiveName = user.Name + (user.Name.ToLower().EndsWith("s") ? "" : "s");
                        account      = new Account(user.No, AccountType.Asset, genitiveName + " lönekonto", 0, false, CurrentApplication.DateTimeNow, true);
                        core.Save(account);
                    }
                }

                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
Exemplo n.º 5
0
        private bool ValidateIsArchivedCheckBox()
        {
            CheckBox ctrl         = isArchivedCheckBox;
            string   errorMessage = "";

            if (ctrl.Checked)
            {
                using (var core = new StandardBusinessLayer(DataCache))
                {
                    core.Connect();
                    //decimal amount = core.CalculateAccountBalance((int)accountComboBox.SelectedValue);
                    decimal amount = DataCache.CalculateAccountBalance((int)accountComboBox.SelectedValue);
                    if (decimal.Compare(amount, 0) != 0)
                    {
                        errorMessage = "Ett konto kan bara arkiveras om dess saldo är noll.";
                    }
                }
            }

            if (errorMessage == "")
            {
                errorProvider.SetError(ctrl, "");
                return(true);
            }
            else
            {
                errorProvider.SetError(ctrl, errorMessage);
                return(false);
            }
        }
Exemplo n.º 6
0
        private void restoreBackupBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            using (var core = new StandardBusinessLayer()) {
                core.Connect(true);

                core.Progress += new ProgressEventHandler(core_Progress);
                core.RestoreBackup(FullPath);
            }
        }
Exemplo n.º 7
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            using (var core = new StandardBusinessLayer(DataCache))
            {
                core.Connect();

                int currentAccountingYear = 0;
                currentAccountingYear = core.GetCashBoxSettings(CashBoxSettingsNo.CurrentApplicationNo).AccountingYear;
                DataCache.Load(currentAccountingYear);
                CalculateBalance();

                Text = CurrentApplication.Name;
                if (Environment.CommandLine.Contains(" /developer"))
                {
                    Text += " - Developer";
                }

                AccountForm form = new AccountForm(DataCache);
                form.MdiParent     = this;
                form.StartPosition = FormStartPosition.Manual;
                form.Location      = new Point(0, 0);
                form.Size          = new Size(ClientArea.Width / 2, ClientArea.Height);
                form.Show();

                CashBookForm cashBookForm = new CashBookForm(DataCache);
                cashBookForm.MdiParent     = this;
                cashBookForm.StartPosition = FormStartPosition.Manual;
                cashBookForm.Location      = new Point(ClientArea.Width / 2, 0);
                cashBookForm.Size          = new Size(ClientArea.Width / 2, ClientArea.Height);
                cashBookForm.Show();

                Verification verification = DataCache.GetLastVerification();

                if (verification == null)
                {
                    verification = core.CreateNewVerification(currentAccountingYear);
                }
                else
                {
                    verification = DataCache.GetVerification(verification.No);
                }

                decimal a = verification.AccountTransactions.Sum(x => x.Amount);
                decimal c = verification.CashBookTransactions.Sum(x => x.Amount);

                CurrentApplication.CurrentVerification = verification;

                if (currentAccountingYear != CurrentApplication.DateTimeNow.Year)
                {
                    MessageBox.Show("Varning!\n\nSystemets bokföringsår står inställt på " + currentAccountingYear +
                                    ", vilket inte stämmer överrens med nuvarande år på din lokala klocka som står inställd på år " +
                                    CurrentApplication.DateTimeNow.Year +
                                    ".\n\nOm det precis har blivit ett nytt år, var noga med att avsluta det föregående året, och gå sedan in i Inställningar (under menyn Inställningar) och ändra aktuellt bokföringsår till aktuellt år, så att du får en ny nummerserie för det här årets affärshändelser.", "Varning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Exemplo n.º 8
0
        private void ReloadForm()
        {
            using (var core = new StandardBusinessLayer(DataCache))
            {
                core.Connect();

                int currentCategoryNo = CurrentCategory != null ? CurrentCategory.No : 0;

                IgnoreCategoryDropDownChange = true;

                var categories = core.GetCategoriesHierarchical();
                categoryComboBox.DataSource = null;
                categories.Insert(0, new DictionaryItem <int, string>()
                {
                    Key = 0, Value = "*** Välj en kategori ***"
                });

                var archivedCategories = core.GetCategoriesHierarchicalArchived();
                if (archivedCategories.Count > 0)
                {
                    categories.Add(new DictionaryItem <int, string>()
                    {
                        Key = -1, Value = "*** Arkiverade kategorier ***"
                    });
                    categories.AddRange(archivedCategories);
                }

                categoryComboBox.DisplayMember = "Value";
                categoryComboBox.ValueMember   = "Key";
                categoryComboBox.DataSource    = categories;
                categoryComboBox.SelectedValue = 0;

                var parents = core.GetCategoriesHierarchical();
                parentComboBox.DataSource = null;
                parents.Insert(0, new DictionaryItem <int, string>()
                {
                    Key = 0, Value = ""
                });
                parentComboBox.DisplayMember = "Value";
                parentComboBox.ValueMember   = "Key";
                parentComboBox.DataSource    = parents;
                parentComboBox.SelectedValue = 0;

                CurrentCategory = core.GetCategory(currentCategoryNo);

                if (CurrentCategory != null)
                {
                    categoryComboBox.SelectedValue = CurrentCategory.No;
                    parentComboBox.SelectedValue   = CurrentCategory.ParentCategoryNo != null ? CurrentCategory.ParentCategoryNo : 0;
                }

                IgnoreCategoryDropDownChange = false;
            }

            IsDirty = false;
        }
Exemplo n.º 9
0
        private void CalculateBalance()
        {
            using (var core = new StandardBusinessLayer(DataCache)) {
                core.Connect();

                //decimal balance = core.CalculateAccountBalance((int)accountComboBox.ComboBox.SelectedValue);
                decimal balance = DataCache.CalculateAccountBalance((int)accountComboBox.ComboBox.SelectedValue);
                balanceToolStripStatusLabel.Text = "Saldo: " + balance.ToString(CurrentApplication.MoneyDisplayFormat) + " kr";
            }
        }
Exemplo n.º 10
0
        private void SettingsForm_Load(object sender, EventArgs e)
        {
            using (var core = new StandardBusinessLayer(DataCache))
            {
                core.Connect();

                _fromAccountingYear        = core.GetCashBoxSettings(CashBoxSettingsNo.CurrentApplicationNo).AccountingYear;
                accountingYearTextBox.Text = _fromAccountingYear.ToString();
            }
        }
Exemplo n.º 11
0
        private void DeleteSelectedTransaction()
        {
            DialogResult result = MessageBox.Show("Du kommer att ta bort den markerade kontotransaktionen. Vill du även ta bort den aktuella affärshändelsen med alla associerade konto- och kassabokstransaktioner?\n\nJa: Alla assicierade transaktioner kommer att tas bort.\nNej: Endast den markerade transaktionen kommer att tas bort.", CurrentApplication.Name, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3);

            int transactionNo  = (int)transactionsDataGridView.SelectedRows[0].Cells[AccountTransaction.fNo].Value;
            int verificationNo = (int)transactionsDataGridView.SelectedRows[0].Cells[AccountTransaction.fVerificationNo].Value;

            try
            {
                if (result == DialogResult.Yes)
                {
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        core.Connect();
                        core.DeleteVerificationAndAssociatedTransactions(verificationNo);
                    }

                    ApplicationEvents.OnVerificationDeleted(verificationNo);
                }
                else if (result == DialogResult.No)
                {
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        core.Connect();

                        int noOfTransactions = core.CountAccountTransactionsByVerificationNo(verificationNo) +
                                               core.CountCashBookTransactionsByVerificationNo(verificationNo);

                        if (noOfTransactions > 1)
                        {
                            //var accountTransaction = core.GetAccountTransaction(transactionNo);
                            var  accountTransaction = DataCache.GetAccountTransaction(transactionNo);
                            bool accountHasTags     = core.CountAccountTagsByAccountNo(accountTransaction.AccountNo) > 0;

                            if (accountTransaction.Amount != 0 && accountHasTags)
                            {
                                throw new VerificationException("Du försöker ta bort en kontotransaktion från ett konto som har kontomärkningar och vars belopp inte är 0. Detta är inte tillåtet eftersom befintliga kontomärkningar kan bli felaktiga. Sätt transaktionsbeloppet för transaktionen till 0 och försök igen.");
                            }

                            DataCache.DeleteAccountTransaction(transactionNo);
                            ApplicationEvents.OnAccountTransactionDeleted(transactionNo, verificationNo);
                        }
                        else
                        {
                            core.DeleteVerificationAndAssociatedTransactions(verificationNo);
                            ApplicationEvents.OnVerificationDeleted(verificationNo);
                        }
                    }
                }
            }
            catch (VerificationException ex)
            {
                MessageBox.Show(ex.Message, CurrentApplication.Name, MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Exemplo n.º 12
0
 private void newVerificationButton_Click(object sender, EventArgs e)
 {
     try {
         using (var core = new StandardBusinessLayer(DataCache)) {
             core.Connect();
             core.CreateNewVerification(core.GetCashBoxSettings(CashBoxSettingsNo.CurrentApplicationNo).AccountingYear);
         }
     }
     catch (VerificationException ex) {
         MessageBox.Show(ex.Message, CurrentApplication.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 13
0
        private void LoadMonthlyBalance()
        {
            monthlyBalanceChart.Series.Clear();
            monthlyBalanceChart.ResetAutoValues();

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

                monthlyBalanceChart.Series.Add("Inkomster");
                monthlyBalanceChart.Series["Inkomster"].ChartType = SeriesChartType.Column;

                monthlyBalanceChart.Series.Add("Utgifter");
                monthlyBalanceChart.Series["Utgifter"].ChartType = SeriesChartType.Column;

                DateTime year = (DateTime)monthlyBalanceYearToolStripComboBox.ComboBox.SelectedValue;

                DataTable yearBalanceIncomeDataTable  = core.GetMonthlyBalance(year, CategoryType.Income);
                DataTable yearBalanceExpenseDataTable = core.GetMonthlyBalance(year, CategoryType.Expense);

                DateTime startDate  = DateTime.MinValue;
                int      incomeRow  = 0;
                int      expenseRow = 0;

                for (int month = 1; month <= 12; month++)
                {
                    decimal monthIncome  = 0;
                    decimal monthExpense = 0;

                    if (yearBalanceIncomeDataTable.Rows.Count > 0 && incomeRow < yearBalanceIncomeDataTable.Rows.Count)
                    {
                        if ((string)yearBalanceIncomeDataTable.Rows[incomeRow]["Month"] == year.ToString("yyyy") + "-" + month.ToString("00"))
                        {
                            monthIncome = (decimal)yearBalanceIncomeDataTable.Rows[incomeRow]["Amount"];
                            incomeRow++;
                        }
                    }

                    if (yearBalanceExpenseDataTable.Rows.Count > 0 && expenseRow < yearBalanceExpenseDataTable.Rows.Count)
                    {
                        if ((string)yearBalanceExpenseDataTable.Rows[expenseRow]["Month"] == year.ToString("yyyy") + "-" + month.ToString("00"))
                        {
                            monthExpense = -(decimal)yearBalanceExpenseDataTable.Rows[expenseRow]["Amount"];
                            expenseRow++;
                        }
                    }

                    monthlyBalanceChart.Series["Inkomster"].Points.AddXY(month, monthIncome);
                    monthlyBalanceChart.Series["Utgifter"].Points.AddXY(month, monthExpense);
                }
            }
        }
Exemplo n.º 14
0
        private void UpdateRowHighlights(CashBookTransactionEventArgs e)
        {
            foreach (DataGridViewRow row in transactionsDataGridView.Rows)
            {
                if ((int)row.Cells[AccountTransaction.fVerificationNo].Value == e.VerificationNo)
                {
                    using (var core = new StandardBusinessLayer(DataCache)) {
                        core.Connect();
                        UnbalancedVerificationNumbers = DataCache.GetUnbalancedAndEmptyVerifications().Select(v => v.No).ToArray(); //core.GetUnbalancedVerificationNumbers();
                    }

                    UpdateRowHighlightsNoDatabase(ApplicationEvents.LastCashBookTransactionSelectionChangedEventArgs);
                }
            }
        }
Exemplo n.º 15
0
        private bool ValidateParentComboBox()
        {
            ComboBox ctrl = parentComboBox;

            if (ctrl.SelectedValue == null || (int)ctrl.SelectedValue == 0)
            {
                errorProvider.SetError(ctrl, "");
                return(true);
            }

            if (CurrentCategory != null)
            {
                bool isCircleReference = (int)ctrl.SelectedValue == CurrentCategory.No;

                if (!isCircleReference && (int)parentComboBox.SelectedValue > 0)
                {
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        core.Connect();

                        Category category = core.GetCategory((int)parentComboBox.SelectedValue);
                        while (category.ParentCategoryNo != null && (int)category.ParentCategoryNo > 0)
                        {
                            if (category.ParentCategoryNo != null &&
                                (int)category.ParentCategoryNo == CurrentCategory.No)
                            {
                                isCircleReference = true;
                                break;
                            }

                            category = core.GetCategory((int)category.ParentCategoryNo);
                        }
                    }
                }

                if (isCircleReference)
                {
                    errorProvider.SetError(ctrl,
                                           "Nuvarande inställning får föräldrakategorin att orsaka en cirkelreferens.");
                }
                else
                {
                    errorProvider.SetError(ctrl, "");
                }
            }

            return(errorProvider.GetError(ctrl) == "");
        }
Exemplo n.º 16
0
        private void LoadMonthlyOverview()
        {
            monthlyOverviewChart.Series.Clear();
            monthlyOverviewChart.ResetAutoValues();

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

                DataTable categorySpendingDataTable = core.GetSpendingsPerCategory(CategoryType.Expense, (DateTime)monthlyOverviewMonthToolStripComboBox.ComboBox.SelectedValue, true);
                List <DictionaryItem <string, decimal> > archivedCategories = new List <DictionaryItem <string, decimal> >();

                int serieNo = 0;

                foreach (DataRow accountDataRow in categorySpendingDataTable.Rows)
                {
                    if (accountDataRow["ParentCategoryNo"] is DBNull)
                    {
                        int     categoryNo = (int)accountDataRow["No"];
                        string  name       = (string)accountDataRow["Name"];
                        decimal amount     = (decimal)accountDataRow["Amount"];
                        bool    isArchived = (bool)accountDataRow["IsArchived"];

                        if (!isArchived)
                        {
                            amount = decimal.Add(amount, GetSubCategoriesAmount(categoryNo, categorySpendingDataTable));
                            monthlyOverviewChart.Series.Add(name).Points.Add((double)-amount);
                            serieNo++;
                        }
                        else if (decimal.Compare(amount, 0) != 0)   // Om kategorin är arkiverad men innehåller pengar
                        {
                            amount = decimal.Add(amount, GetSubCategoriesAmount(categoryNo, categorySpendingDataTable));
                            archivedCategories.Add(new DictionaryItem <string, decimal>()
                            {
                                Key = name, Value = amount
                            });
                        }
                    }
                }

                // Add archived categories at the end
                foreach (var archivedCategory in archivedCategories)
                {
                    monthlyOverviewChart.Series.Add(archivedCategory.Key).Points.Add((double)-archivedCategory.Value);
                    serieNo++;
                }
            }
        }
Exemplo n.º 17
0
        private void Load()
        {
            using (StandardBusinessLayer core = new StandardBusinessLayer(DataCache))
            {
                core.Connect();

                SortOrder byDate = new SortOrder(Verification.fDate, OrderDirection.Ascending);
                _verifications = core.GetVerifications(byDate);

                byDate = new SortOrder(AccountTransaction.fTransactionTime, OrderDirection.Ascending);
                _accountTransactions = core.GetAccountTransactions();

                byDate = new SortOrder(CashBookTransaction.fTransactionTime, OrderDirection.Ascending);
                _cashBookTransactions = core.GetCashBookTransactions();
            }
        }
Exemplo n.º 18
0
        private void DeleteSelectedTransaction()
        {
            DialogResult result = MessageBox.Show("Du kommer att ta bort den markerade kassabokstransaktionen. Vill du även ta bort den aktuella affärshändelsen med alla associerade konto- och kassabokstransaktioner?\n\nJa: Alla assicierade transaktioner kommer att tas bort.\nNej: Endast den markerade transaktionen kommer att tas bort.", CurrentApplication.Name, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3);

            int transactionNo  = (int)transactionsDataGridView.SelectedRows[0].Cells[CashBookTransaction.fNo].Value;
            int verificationNo = (int)transactionsDataGridView.SelectedRows[0].Cells[CashBookTransaction.fVerificationNo].Value;

            try
            {
                if (result == DialogResult.Yes)
                {
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        core.Connect();
                        core.DeleteVerificationAndAssociatedTransactions(verificationNo);
                    }

                    ApplicationEvents.OnVerificationDeleted(verificationNo);
                }
                else if (result == DialogResult.No)
                {
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        core.Connect();

                        int noOfTransactions = core.CountAccountTransactionsByVerificationNo(verificationNo) +
                                               core.CountCashBookTransactionsByVerificationNo(verificationNo);

                        if (noOfTransactions > 1)
                        {
                            DataCache.DeleteCashBookTransaction(transactionNo);
                            ApplicationEvents.OnCashBookTransactionDeleted(transactionNo, verificationNo);
                        }
                        else
                        {
                            core.DeleteVerificationAndAssociatedTransactions(verificationNo);
                            ApplicationEvents.OnVerificationDeleted(verificationNo);
                        }
                    }
                }
            }
            catch (VerificationException ex)
            {
                MessageBox.Show(ex.Message, CurrentApplication.Name, MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Exemplo n.º 19
0
        private void LoadMonthComboBoxItems()
        {
            using (var core = new StandardBusinessLayer(DataCache))
            {
                core.Connect();

                CashBoxDateType dateType = (CashBoxDateType)dateTypeComboBox.ComboBox.SelectedValue;

                DateTime?firstAccountTransactionDate = core.GetEarliestVerificationDate(dateType);
                Date     firstDate = CurrentApplication.DateNow;

                if (firstAccountTransactionDate != null)
                {
                    firstDate = new Date((DateTime)firstAccountTransactionDate);
                }

                // Fix so that the date is the first in its month
                firstDate = new Date(firstDate.Year, firstDate.Month, 1);

                // Month
                var monthList = new List <DictionaryItem <Date, string> >();

                DateTime?lastDate = core.GetLatestVerificationDate(dateType);
                Date     date     = CurrentApplication.DateNow;

                if (lastDate != null)
                {
                    date = (DateTime)lastDate;
                    date = new Date(date.Year, date.Month, 1);
                }

                while ((Date)date >= firstDate)
                {
                    monthList.Add(new DictionaryItem <Date, string>()
                    {
                        Key = date, Value = date.ToString("yyyy-MM")
                    });
                    date = date.AddMonths(-1);
                }

                monthToolStripComboBox.ComboBox.ValueMember   = "Key";
                monthToolStripComboBox.ComboBox.DisplayMember = "Value";
                monthToolStripComboBox.ComboBox.DataSource    = monthList;
            }
        }
Exemplo n.º 20
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();
            }
        }
Exemplo n.º 21
0
        private void LoginForm_Load(object sender, EventArgs e)
        {
            Text = CurrentApplication.Name;

            if (Environment.CommandLine.Contains(" /developer"))
            {
                Text += " - Debug";
            }

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

                userComboBox.ValueMember   = User.fNo;
                userComboBox.DisplayMember = User.fName;
                userComboBox.DataSource    = core.GetUsers();
                userComboBox.SelectedValue = 0;
            }
        }
Exemplo n.º 22
0
        private bool ValidateDateDimtePicker()
        {
            DateTimePicker ctrl = dateTimePicker;

            errorProvider.SetError(ctrl, "");

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

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

                if (ctrl.Value.Year != accountingYear)
                {
                    errorProvider.SetError(ctrl, "Du kan bara registrera transaktioner för systemets bokföringsår (" + accountingYear + ").");
                }
            }

            return(errorProvider.GetError(ctrl) == "");
        }
Exemplo n.º 23
0
        private void LoadTagAccountBalance()
        {
            tagAccountChart.Series.Clear();

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

                DataTable tagAccountDataTable = core.GetTagAccountBalances();

                foreach (DataRow accountDataRow in tagAccountDataTable.Rows)
                {
                    string  name    = (string)accountDataRow[Account.fName];
                    decimal balance = (decimal)accountDataRow["Balance"];

                    tagAccountChart.Series.Add(name).Points.Add((double)balance);
                }
            }
        }
Exemplo n.º 24
0
        private void skapaBackupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var fileDialog = new SaveFileDialog();

            fileDialog.Filter     = CurrentApplication.Name + "-backupfiler|*.backup|Alla filer|*.txt";
            fileDialog.DefaultExt = ".backup";
            fileDialog.FileName   = CurrentApplication.DateTimeNow.ToString("yyyyMMdd_HHmm") + " " + CurrentApplication.Name + ".backup";

            DialogResult result = fileDialog.ShowDialog();

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

                MessageBox.Show("Backupen skapades.", CurrentApplication.Name, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 25
0
        private void AccountForm_Load(object sender, EventArgs e)
        {
            balanceToolStripStatusLabel.Text = "";

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

                Condition notArchived             = new Condition(Account.fIsArchived, CompareOperator.NotEqualTo, true);
                EasyBase.Classes.SortOrder byName = new EasyBase.Classes.SortOrder(Account.fName, OrderDirection.Ascending);

                DataTable accountDataTable = core.GetAccountsTable(notArchived, byName, Account.fNo, Account.fName);

                accountComboBox.ComboBox.ValueMember   = Account.fNo;
                accountComboBox.ComboBox.DisplayMember = Account.fName;
                accountComboBox.ComboBox.DataSource    = accountDataTable;
                accountComboBox.ComboBox.SelectedValue = 0;
            }

            FormLoading = false;
            EnableDisableControls();
        }
Exemplo n.º 26
0
        public void CalculateBalance()
        {
            using (var core = new StandardBusinessLayer(DataCache)) {
                core.Connect();

                decimal balanceAmount = core.CalculateBalance();
                balanceToolStripStatusLabel.Text = "Balans: " + balanceAmount.ToString("#,##0.00") + " kr";
                if (balanceAmount.CompareTo(0m) == 0)
                {
                    balanceToolStripStatusLabel.ForeColor = System.Drawing.Color.Black;
                    Guesser.ClearGuess();
                }
                else
                {
                    balanceToolStripStatusLabel.ForeColor = System.Drawing.Color.Red;
                }

                decimal totalWealth = core.CalculateTotalWealth();
                TotalWealthToolStripStatusLabel.Text = "Total förmögenhet: " + totalWealth.ToString("#,##0.00") + " kr";
            }
        }
Exemplo n.º 27
0
        private void Save()
        {
            if (ValidateForm())
            {
                using (var core = new StandardBusinessLayer(DataCache)) {
                    core.Connect();
                    Category category;

                    string name             = nameTextBox.Text.Trim();
                    int?   parentCategoryNo = null;
                    if (parentComboBox.SelectedValue != null && (int)parentComboBox.SelectedValue > 0)
                    {
                        parentCategoryNo = (int)parentComboBox.SelectedValue;
                    }
                    CategoryType categoryType  = typeExpenseRadioButton.Checked ? CategoryType.Expense : CategoryType.Income;
                    bool         showInDiagram = showInDiagramCheckBox.Checked;
                    bool         isArchived    = isArchivedCheckBox.Checked;

                    if (NewCategory)
                    {
                        category = new Category(parentCategoryNo, categoryType, name, isArchived, CurrentApplication.DateTimeNow, showInDiagram);
                    }
                    else
                    {
                        category                  = core.GetCategory((int)categoryComboBox.SelectedValue);
                        category.Name             = name;
                        category.ParentCategoryNo = parentCategoryNo;
                        category.Type             = categoryType;
                        category.ShowInDiagram    = showInDiagram;
                        category.IsArchived       = isArchived;
                    }

                    core.Save(category);
                    NewCategory     = false;
                    CurrentCategory = category;
                }

                ReloadForm();
            }
        }
Exemplo n.º 28
0
        private void transactionsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                int no             = (int)transactionsDataGridView.Rows[e.RowIndex].Cells[AccountTransaction.fNo].Value;
                int verificationNo = (int)transactionsDataGridView.Rows[e.RowIndex].Cells[AccountTransaction.fVerificationNo].Value;
                int userNo         = (int)transactionsDataGridView.Rows[e.RowIndex].Cells[AccountTransaction.fUserNo].Value;
                int accountNo      = (int)transactionsDataGridView.Rows[e.RowIndex].Cells[AccountTransaction.fAccountNo].Value;

                var          form   = new DepositWithdrawalForm(DataCache, MainForm.Guesser, accountComboBox.Text, (int)accountComboBox.ComboBox.SelectedValue, no, verificationNo);
                DialogResult result = form.ShowDialog();

                if (result == DialogResult.OK)
                {
                    AccountTransaction transaction = null;
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        try
                        {
                            core.Connect();
                            transaction = core.UpdateAccountTransaction(no, form.VerificationDate, form.AccountingDate, userNo, accountNo,
                                                                        form.Amount, form.Note, form.GetTagComboBoxItem.Action,
                                                                        form.GetTagComboBoxItem.AccountTag != null ? form.GetTagComboBoxItem.AccountTag.No : 0);
                        }
                        catch (MoneyTagException ex)
                        {
                            MessageBox.Show(ex.Message, "Felaktig transaktion", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    LoadTransactionGrid();
                    SelectGridTransaction(no);

                    if (transaction != null)
                    {
                        ApplicationEvents.OnAccountTransactionUpdated(no, transaction.VerificationNo);
                    }
                }
            }
        }
Exemplo n.º 29
0
        private void categoryComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!IgnoreCategoryDropDownChange)
            {
                int categoryNo = (int)categoryComboBox.SelectedValue;

                if (categoryNo == 0)
                {
                    CurrentCategory = null;
                }
                else
                {
                    using (var core = new StandardBusinessLayer(DataCache))
                    {
                        core.Connect();
                        CurrentCategory = core.GetCategory(categoryNo);
                    }
                }

                EnableDisableControls();
            }
        }
Exemplo n.º 30
0
        private void deleteCategoryButton_Click(object sender, EventArgs e)
        {
            int  categoryNo      = (int)categoryComboBox.SelectedValue;
            bool categoryDeleted = false;

            // Category cannot be deleted if it has sub categories
            using (var core = new StandardBusinessLayer(DataCache)) {
                core.Connect();

                int subCategoriesCount = core.CountCategoriesByParentCategoryNo(categoryNo);

                if (subCategoriesCount > 0)
                {
                    MessageBox.Show("Kategorin kan inte tas bort eftersom den har underkategorier.", CurrentApplication.Name, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                int cashBookTransactionsCount = core.CountCashBookTransactionsByCategoryNo(categoryNo);
                if (cashBookTransactionsCount > 0)
                {
                    MessageBox.Show("Kategorin kan inte tas bort eftersom den har registrerade kassabokshändelser.", CurrentApplication.Name, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                Category category = core.GetCategory(categoryNo);

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

            if (categoryDeleted)
            {
                ReloadForm();
            }
        }