示例#1
0
        private void Loans_listView_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get selected item value
            Loan loan = Loans_listView.SelectedItems.Count > 0 ? (Loan)Loans_listView.SelectedItems[0].Tag : null;

            if (loan == null)
            {
                return;
            }                             // to handle listView idiot 2 step item selection process

            // search DB for loan and update textBoxes
            var rdr = DB_API.SelectLoan(account_id, loan.Name);

            while (rdr.Read())
            {
                Name_textBox.Text               = rdr[DB_API.LoanEnt.name.ToString()].ToString();
                Name_textBox.ForeColor          = Color.Black;
                InitialAmount_textBox.Text      = DB_API.Moneyfy(rdr[DB_API.LoanEnt.initial_amount.ToString()].ToString());
                InitialAmount_textBox.ForeColor = Color.Black;
                CurrentDebt_textBox.Text        = DB_API.Moneyfy(rdr[DB_API.LoanEnt.current_debt.ToString()].ToString());
                CurrentDebt_textBox.ForeColor   = Color.Black;
                Enddate_dateTimePicker.Value    = DateTime.Parse(rdr[DB_API.LoanEnt.term.ToString()].ToString());
                Interest_textBox.Text           = Double.Parse(rdr[DB_API.LoanEnt.interest.ToString()].ToString()).ToString() + "%";
                Interest_textBox.ForeColor      = Color.Black;
            }
        }
        private void SellAll_btn_Click(object sender, EventArgs e)
        {
            // get selected item value
            Stock stock = MyStocks_listView.SelectedItems.Count > 0 ?
                          (Stock)MyStocks_listView.SelectedItems[0].Tag : null;

            if (stock == null)
            {
                return;
            }                              // to handle listView idiot 2 step item selection process

            // get the current price
            double askPrice = 0.0;

            for (int i = 0; i < StockMarket_listView.Items.Count; i++)
            {
                Stock s = (Stock)StockMarket_listView.Items[i].Tag;
                if (s.Company.Equals(stock.Company))
                {
                    askPrice = (double)s.AskPrice;
                    break;
                }
            }

            // make the sell
            Console.WriteLine(stock.PurchasePrice + ", " + askPrice);
            DB_API.DeleteStocksByCompany(account_id, stock.Company, (double)stock.PurchasePrice, askPrice);

            // update MyStocks listView
            PopulateMyStocksListView();
        }
        private void PopulateCategoriesListBox()
        {
            // get categories from DB
            var rdr = DB_API.SelectAccountCategories(account_id);

            // verify if account has no categories
            if (!rdr.HasRows)
            {
                ErrorMessenger.Warning("Account has no categories!");
                Categories_listbox.DataSource = new List <String>();
                return;
            }

            // extract category names for listBox
            this.categories = new Dictionary <string, int>();
            var res = new Dictionary <string, int>();

            while (rdr.Read())
            {
                string cat_name = rdr[DB_API.CategoryEnt.name.ToString()].ToString();
                int    cat_id   = (int)rdr[DB_API.CategoryEnt.category_id.ToString()];
                categories[cat_name] = cat_id;
                if (cat_id % 100 > 0)
                {
                    cat_name = "  -> " + cat_name;
                }
                res[cat_name] = cat_id;
            }
            Categories_listbox.DataSource = new List <string>(res.Keys);
        }
示例#4
0
        // -------------------------------------------------------------------
        // BUTTONS -----------------------------------------------------------
        // -------------------------------------------------------------------

        private void Findme_btn_Click(object sender, EventArgs e)
        {
            // read value from textbox
            string email = userfindme_textbox.ForeColor == Color.Black ? userfindme_textbox.Text : "";

            CURRENT_USER = email;

            // verify an email was given
            if (email.Equals(""))
            {
                ErrorMessenger.EmptyField("Email");
                return;
            }

            // verify if user exists
            var exists = DB_API.ExistsUser(email);

            if (!exists)
            {
                ErrorMessenger.Error("User does not exist!");
                return;
            }

            // populate account_listBox
            Populate_moneyAccounts_listBox(email);
        }
示例#5
0
        private void Deleteaccount_btn_Click(object sender, EventArgs e)
        {
            // get textbox value
            string account_name = account_textbox.ForeColor == Color.Black ? account_textbox.Text : "";
            int    account_id   = CURRENT_USER_ACCOUNTS[account_name];

            // verify if account exists before trying to delete
            var exists = DB_API.ExistsMoneyAccount(account_id);

            if (!exists)
            {
                ErrorMessenger.Error("Account does not exist!");
                return;
            }

            // delete money account
            bool sure = ErrorMessenger.OKCancel("Deleting a Money Account will permanently" +
                                                "delete all its transaction, categories," +
                                                "loans, goals and stock. Are you sure you want to delete?");

            if (sure)
            {
                DB_API.DeleteMoneyAccount(account_id);
                CURRENT_USER_ACCOUNTS.Remove(account_name);
            }
            else
            {
                return;
            }

            // repopulate accounts_listbox
            Populate_moneyAccounts_listBox(CURRENT_USER);
        }
示例#6
0
        private void Newaccount_btn_Click(object sender, EventArgs e)
        {
            // get textbox value
            string account_name = account_textbox.ForeColor == Color.Black ? account_textbox.Text : "";

            // verify that a name is given
            if ("".Equals(account_name))
            {
                ErrorMessenger.EmptyField("Account name");
                return;
            }

            // verify that a user is selected
            if (CURRENT_USER.Equals(""))
            {
                ErrorMessenger.Error("User must be selected to attribute account to!");
                return;
            }

            // verify if user already has same name account
            if (new List <String>(CURRENT_USER_ACCOUNTS.Keys).Contains(account_name))
            {
                ErrorMessenger.Error("User already has an account with the same name!");
                return;
            }

            // insert new account into 'money_accounts' and 'users_money_accounts' tables
            DB_API.InsertMoneyAccount(CURRENT_USER, account_name);

            Populate_moneyAccounts_listBox(CURRENT_USER);
        }
示例#7
0
        private void Accounts_listbox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get selected item value
            string account_name = (string)accounts_listbox.SelectedItem;
            int    account_id   = CURRENT_USER_ACCOUNTS[account_name];

            // set account_name label
            account_textbox.Text      = account_name;
            account_textbox.ForeColor = Color.Black;

            // get account complete info
            var rdr = DB_API.SelectMoneyAccountById(account_id);

            while (rdr.Read())
            {
                balance_textbox.Text   = DB_API.Moneyfy(Double.Parse(rdr[DB_API.MoneyAccountEnt.balance.ToString()].ToString()));
                patrimony_textbox.Text = DB_API.Moneyfy(Double.Parse(rdr[DB_API.MoneyAccountEnt.patrimony.ToString()].ToString()));
            }

            // get associated user of selected account
            rdr = DB_API.SelectMoneyAccountUsers(account_id);
            List <String> res = new List <string>();

            while (rdr.Read())
            {
                res.Add(rdr["user_email"].ToString());
            }
            associatedusers_listbox.DataSource = res;
        }
        private void Transactions_listView_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get selected item value
            Transaction tr = Transactions_listView.SelectedItems.Count > 0 ?
                             (Transaction)Transactions_listView.SelectedItems[0].Tag : null;

            if (tr == null)
            {
                return;
            }                           // to handle listView idiot 2 step item selection process

            // update TextBoxes
            // category and subcategory
            int category_id = (int)tr.CategoryID;

            if (category_id % 100 == 0) // is category
            {
                category_comboBox.Text    = categoriesIntStr[category_id];
                subcategory_comboBox.Text = this.none;
            }
            else
            {
                category_comboBox.Text    = categoriesIntStr[category_id / 100 * 100];
                subcategory_comboBox.Text = categoriesIntStr[category_id];
            }

            // transaction type
            type_comboBox.Text = DB_API.SelectTransactionTypeNameById((int)tr.TransactionTypeID);

            // wallet
            var rdr = DB_API.SelectWallet((int)tr.WalletID);

            while (rdr.Read())
            {
                wallet_comboBox.Text = rdr[DB_API.WalletEnt.name.ToString()].ToString();
                break;
            }
            if ((int)tr.TransactionTypeID == 0)
            {
                rdr = DB_API.SelectWallet((int)tr.RecipientWalletID);
                while (rdr.Read())
                {
                    wallet2_comboBox.Text = rdr[DB_API.WalletEnt.name.ToString()].ToString();
                    break;
                }
            }


            // amount
            amount_textBox.Text      = DB_API.Moneyfy(tr.Amount);
            amount_textBox.ForeColor = Color.Black;
            // date
            dateTimePicker.Value = (DateTime)tr.Date;
            // notes and location
            notes_textBox.Text         = tr.Notes;
            notes_textBox.ForeColor    = Color.Black;
            location_textBox.Text      = tr.Location;
            location_textBox.ForeColor = Color.Black;
        }
        // -------------------------------------------------------------------
        // LIST BOXES --------------------------------------------------------
        // -------------------------------------------------------------------

        private void PopulateTransactionsListView()
        {
            // get categories from DB
            DataTableReader rdr = null;

            rdr = DB_API.SelectAccountTransactions(account_id);
            PrivatePopulateTransactionsListView(rdr);
        }
        public void PopulateTransactionsListView(int account_id, int?cat_id, int?wallet_id, int?transaction_type_id,
                                                 double?minamount, double?maxamount, DateTime?start_date, DateTime?end_date)
        {
            // get categories from DB
            DataTableReader rdr = null;

            rdr = DB_API.SelectFilteredTransactions(account_id, cat_id, wallet_id, null, transaction_type_id,
                                                    minamount, maxamount, start_date, end_date, null);
            PrivatePopulateTransactionsListView(rdr);
        }
        private void Goalamount_textBox_Leave(object sender, EventArgs e)
        {
            goalamount_textBox.Text = DB_API.Moneyfy(goalamount_textBox.Text);

            if (goalamount_textBox.Text.Equals(""))
            {
                goalamount_textBox.Text      = "goal value";
                goalamount_textBox.ForeColor = Color.Gray;
            }
        }
示例#12
0
        private void Pay_textBox_Leave(object sender, EventArgs e)
        {
            Pay_textBox.Text = DB_API.Moneyfy(Pay_textBox.Text);

            if (Pay_textBox.Text.Equals(""))
            {
                Pay_textBox.Text      = "payment";
                Pay_textBox.ForeColor = Color.Gray;
            }
        }
        private void Amount_textBox_Leave(object sender, EventArgs e)
        {
            amount_textBox.Text = DB_API.Moneyfy(amount_textBox.Text);

            if (amount_textBox.Text.Equals(""))
            {
                amount_textBox.Text      = "amount";
                amount_textBox.ForeColor = Color.Gray;
            }
        }
示例#14
0
        private void CurrentDebt_textBox_Leave(object sender, EventArgs e)
        {
            CurrentDebt_textBox.Text = DB_API.Moneyfy(CurrentDebt_textBox.Text);

            if (CurrentDebt_textBox.Text.Equals(""))
            {
                CurrentDebt_textBox.Text      = "current debt";
                CurrentDebt_textBox.ForeColor = Color.Gray;
            }
        }
        private void Filtermaxamount_textBox_Leave(object sender, EventArgs e)
        {
            filtermaxamount_textBox.Text = DB_API.Moneyfy(filtermaxamount_textBox.Text);

            if (filtermaxamount_textBox.Text.Equals(""))
            {
                filtermaxamount_textBox.Text      = "max amount";
                filtermaxamount_textBox.ForeColor = Color.Gray;
            }
        }
示例#16
0
        private void Adduser_btn_Click(object sender, EventArgs e)
        {
            // get textbox value
            string new_user     = user_textbox.ForeColor == Color.Black ? user_textbox.Text : "";
            string account_name = account_textbox.ForeColor == Color.Black ? account_textbox.Text : "";
            int    account_id   = CURRENT_USER_ACCOUNTS[account_name];

            // verify if account field is filled
            if ("".Equals(account_name))
            {
                ErrorMessenger.EmptyField("Acount name");
                return;
            }

            // verify if account exists
            var exists = DB_API.ExistsMoneyAccount(account_id);

            if (!exists)
            {
                ErrorMessenger.Error("Account does not exist!");
                return;
            }

            // verify that a user is selected
            if (new_user.Equals(""))
            {
                ErrorMessenger.Error("User must be selected to attribute account to!");
                return;
            }

            // verify if user exists
            exists = DB_API.ExistsUser(new_user);
            if (!exists)
            {
                ErrorMessenger.Error("User does not exist!");
                return;
            }

            // verify if user already is associated with account
            var rdr = DB_API.SelectMoneyAccountUsers(account_id);

            while (rdr.Read())
            {
                if (rdr[DB_API.MoneyAccountEnt.user_email.ToString()].Equals(new_user))
                {
                    ErrorMessenger.Error("User already participates in account");
                    return;
                }
            }

            // insert new account into 'users_money_accounts table
            DB_API.MoneyAccountAddUser(account_id, new_user);

            Populate_associatedUsers_listBox(account_id);
        }
        // -------------------------------------------------------------------
        // BUTTONS -----------------------------------------------------------
        // -------------------------------------------------------------------

        private void Save_btn_Click(object sender, EventArgs e)
        {
            // get categories fields info
            int category_id    = categoriesStrInt[category_comboBox.SelectedItem.ToString()];
            int subcategory_id = subcategory_comboBox.SelectedItem.ToString().Equals(this.none) ||
                                 subcategory_comboBox.SelectedItem.ToString().Equals("") ?
                                 -1 : categoriesStrInt[subcategory_comboBox.SelectedItem.ToString()];
            // get amount
            string amt = amount_textBox.ForeColor == Color.Black ? amount_textBox.Text.Substring(1) : "";

            if (amt.Equals(""))
            {
                ErrorMessenger.EmptyField("Amount");
                return;
            }
            double amount = DB_API.UnMoneyfy(amount_textBox.Text);
            // get date
            DateTime date = dateTimePicker.Value;
            // get notes and location
            string notes    = notes_textBox.ForeColor == Color.Black ? notes_textBox.Text : "";
            string location = location_textBox.ForeColor == Color.Black ? location_textBox.Text : "";
            // get transaction type
            int transaction_type_id = -1;

            transaction_type_id = DB_API.SelectTransactionTypeIdByName(type_comboBox.SelectedItem.ToString());

            // get wallet
            string from_wallet_name = wallet_comboBox.SelectedItem.ToString();
            string to_wallet_name   = wallet2_comboBox.SelectedItem.ToString();
            int    from_wallet_id   = -1;
            int    to_wallet_id     = -1;
            var    rdr = DB_API.SelectWalletByName(account_id, from_wallet_name);

            while (rdr.Read())
            {
                from_wallet_id = (int)rdr[DB_API.WalletEnt.wallet_id.ToString()];
                break;
            }
            rdr = DB_API.SelectWalletByName(account_id, to_wallet_name);
            while (rdr.Read())
            {
                to_wallet_id = (int)rdr[DB_API.WalletEnt.wallet_id.ToString()];
                break;
            }

            // before inserting change amount sign if it is an expense
            // insert new transaction
            int cat_id = subcategory_id != -1 ? subcategory_id : category_id;

            DB_API.InsertTransaction(account_id, cat_id, from_wallet_id, to_wallet_id, transaction_type_id,
                                     amount, date, location, notes);

            // update transactions listBox
            PopulateTransactionsListView();
        }
        // -------------------------------------------------------------------
        // TEXT BOXES --------------------------------------------------------
        // -------------------------------------------------------------------

        private void Populate_comboBox()
        {
            var rdr = DB_API.SelectAllRecurrences();
            var res = new List <String>();

            while (rdr.Read())
            {
                res.Add((string)rdr[DB_API.RecurrenceEnt.designation.ToString()]);
            }
            Periodicity_comboBox.DataSource = res;
        }
示例#19
0
        private void Populate_associatedUsers_listBox(int account_id)
        {
            var rdr = DB_API.SelectMoneyAccountUsers(account_id);
            var res = new List <String>();

            while (rdr.Read())
            {
                res.Add(rdr[DB_API.MoneyAccountEnt.user_email.ToString()].ToString());
            }
            associatedusers_listbox.DataSource = res;
        }
        // -------------------------------------------------------------------
        // LIST AND COMBO BOXES ----------------------------------------------
        // -------------------------------------------------------------------

        private void UpdateCategories()
        {
            this.categories = new Dictionary <string, int>();
            var rdr = DB_API.SelectAccountCategories(account_id);

            while (rdr.Read())
            {
                string cat_name = rdr[DB_API.CategoryEnt.name.ToString()].ToString();
                int    cat_id   = (int)rdr[DB_API.CategoryEnt.category_id.ToString()];
                this.categories[cat_name] = cat_id;
            }
        }
        private void Users_listView_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get selected item value
            User user = Users_listView.SelectedItems.Count > 0 ? (User)Users_listView.SelectedItems[0].Tag : null;

            if (user == null)
            {
                return;
            }                             // to handle listView idiot 2 step item selection process
            string email = user.Email;

            // search DB for user
            var rdr = DB_API.SelectUserByEmail(email);
            var res = new List <Object>();

            while (rdr.Read())
            {
                Console.WriteLine("---> email: " + rdr[DB_API.UserEnt.email.ToString()].ToString());
                email_textbox.Text           = rdr[DB_API.UserEnt.email.ToString()].ToString();
                email_textbox.ForeColor      = email_textbox.Text.Equals("") ? Color.Gray : Color.Black;
                email_textbox.Text           = email_textbox.Text.Equals("") ? "email" : email_textbox.Text;
                username_textbox.Text        = rdr[DB_API.UserEnt.user_name.ToString()].ToString();
                username_textbox.ForeColor   = username_textbox.Text.Equals("") ? Color.Gray : Color.Black;
                username_textbox.Text        = username_textbox.Text.Equals("") ? "username" : username_textbox.Text;
                firstname_textbox.Text       = rdr[DB_API.UserEnt.fname.ToString()].ToString();
                firstname_textbox.ForeColor  = firstname_textbox.Text.Equals("") ? Color.Gray : Color.Black;
                firstname_textbox.Text       = firstname_textbox.Text.Equals("") ? "first name" : firstname_textbox.Text;
                middlename_textbox.Text      = rdr[DB_API.UserEnt.mname.ToString()].ToString();
                middlename_textbox.ForeColor = middlename_textbox.Text.Equals("") ? Color.Gray : Color.Black;
                middlename_textbox.Text      = middlename_textbox.Text.Equals("") ? "middle name" : middlename_textbox.Text;
                lastname_textbox.Text        = rdr[DB_API.UserEnt.lname.ToString()].ToString();
                lastname_textbox.ForeColor   = lastname_textbox.Text.Equals("") ? Color.Gray : Color.Black;
                lastname_textbox.Text        = lastname_textbox.Text.Equals("") ? "last name" : lastname_textbox.Text;
                cardnumber_textbox.Text      = rdr[DB_API.UserEnt.card_number.ToString()].ToString();
                cardnumber_textbox.ForeColor = cardnumber_textbox.Text.Equals("") ? Color.Gray : Color.Black;
                cardnumber_textbox.Text      = cardnumber_textbox.Text.Equals("") ? "card number" : cardnumber_textbox.Text;
                bool activeSubscription = (bool)rdr[DB_API.UserEnt.active_subscription.ToString()];
                Console.WriteLine("---> active subscription: " + activeSubscription);
                if (!activeSubscription)
                {
                    Periodicity_comboBox.Text = DB_API.SelectRecurrenceById(1);
                    term_dateTimePicker.Value = DateTime.Today;
                    active_checkBox.Checked   = false;
                }
                else
                {
                    Console.WriteLine("---> " + rdr[DB_API.UserEnt.periodicity.ToString()].ToString());
                    Periodicity_comboBox.Text = DB_API.SelectRecurrenceById((int)rdr[DB_API.UserEnt.periodicity.ToString()]);
                    term_dateTimePicker.Value = (DateTime)rdr[DB_API.UserEnt.term.ToString()];
                    active_checkBox.Checked   = true;
                }
            }
        }
示例#22
0
        private void Save_btn_Click(object sender, EventArgs e)
        {   //apaga este comentario
            string   loan_name      = Name_textBox.ForeColor == Color.Black ? Name_textBox.Text : "";
            string   initial_amount = InitialAmount_textBox.ForeColor == Color.Black ? InitialAmount_textBox.Text : "";
            string   current_debt   = CurrentDebt_textBox.ForeColor == Color.Black ? CurrentDebt_textBox.Text : "";
            string   interest_str   = Interest_textBox.ForeColor == Color.Black ? Interest_textBox.Text : "";
            DateTime term           = DateTime.Parse(Enddate_dateTimePicker.Value.ToString());

            // verify if mandatory fields are filled
            if (loan_name.Equals("") || initial_amount.Equals("") || current_debt.Equals(""))
            {
                ErrorMessenger.EmptyField("Name, Initial Amount and Current Debt");
                return;
            }

            // process inserted values
            double init_amt = DB_API.UnMoneyfy(initial_amount);
            double cur_debt = DB_API.UnMoneyfy(current_debt);
            double interest = 0.0;

            try
            {
                if (interest_str.Equals(""))
                {
                    interest = 0.0;
                }
                else
                {
                    interest = Double.Parse(interest_str);
                }
            }
            catch
            {
                ErrorMessenger.WrongFormat("A numeric textBox");
                return;
            }

            // add loan
            try
            {
                DB_API.InsertLoan(account_id, loan_name, init_amt, cur_debt, term, interest);
            }
            catch (SqlException ex)
            {
                ErrorMessenger.Exception(ex);
                return;
            }

            // upadte listBox with new user
            PopulateLoansListView();
        }
        private void PopulateComboBoxes()
        {
            StartMonth_comboBox.DataSource = months;
            EndMonth_comboBox.DataSource   = new List <string>(months);

            var rdr = DB_API.SelectAllCategoryTypes();
            var res = new List <string>();

            while (rdr.Read())
            {
                res.Add(rdr[DB_API.CategoryTypeEnt.designation.ToString()].ToString());
            }
            Type_comboBox.DataSource = res;
        }
        // -------------------------------------------------------------------
        // BUTTONS -----------------------------------------------------------
        // -------------------------------------------------------------------

        private void Buy_btn_Click(object sender, EventArgs e)
        {
            // ge selected item values
            Stock stock    = (Stock)StockMarket_listView.SelectedItems[0].Tag;
            int   quantity = (int)quantity_numericupdown.Value;

            // make the buy (insert new purchased stock)
            for (int i = 0; i < quantity; i++)
            {
                DB_API.InsertPurchasedStock(this.account_id, stock.Company, (double)stock.AskPrice);
            }

            // update MyStocks listView
            PopulateMyStocksListView();
        }
示例#25
0
        // -------------------------------------------------------------------
        // LIST BOXES --------------------------------------------------------
        // -------------------------------------------------------------------

        private void Populate_moneyAccounts_listBox(string email)
        {
            // get money accounts from DB
            var rdr = DB_API.SelectUserMoneyAccounts(email);

            // extract money acounts names for listBox
            var res = new List <String>();

            while (rdr.Read())
            {
                string account_name = rdr[DB_API.MoneyAccountEnt.account_name.ToString()].ToString();
                res.Add(account_name);
                CURRENT_USER_ACCOUNTS[account_name] = (int)rdr[DB_API.MoneyAccountEnt.account_id.ToString()];
            }
            accounts_listbox.DataSource = res;
        }
        private void PopulateTransactionTypesComboBox()
        {
            var res       = new List <string>();
            var filterRes = new List <string>();

            filterRes.Add(this.none);
            var rdr = DB_API.SelectAllTransactionTypes();

            while (rdr.Read())
            {
                res.Add(rdr[DB_API.TransactionTypeEnt.designation.ToString()].ToString());
                filterRes.Add(rdr[DB_API.TransactionTypeEnt.designation.ToString()].ToString());
            }
            type_comboBox.DataSource       = res;
            filtertype_comboBox.DataSource = filterRes;
        }
        // -------------------------------------------------------------------
        // LIST AND COMBO BOXES --------------------------------------------------------
        // -------------------------------------------------------------------

        private void Categories_listbox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get selected item value
            string selected     = (string)Categories_listbox.SelectedItem;
            string cat_name     = selected;
            string sub_cat_name = "";
            int    cat_id;
            int    sub_cat_id;
            int    cat_type_id = -1;
            string cat_type_name;

            try
            {
                cat_id = this.categories[selected];
                PopulateBudgetsListBox(account_id, cat_id);
            }
            catch
            {
                selected     = selected.Substring(5);
                sub_cat_id   = this.categories[selected];
                sub_cat_name = selected;
                cat_id       = sub_cat_id / 100 * 100;
                foreach (KeyValuePair <string, int> pair in this.categories)
                {
                    if (categories[pair.Key] == cat_id)
                    {
                        cat_name = pair.Key;
                        break;
                    }
                }
                PopulateBudgetsListBox(account_id, sub_cat_id);
            }

            // update TextBoxes
            Category_textBox.Text    = cat_name;
            Subcategory_textBox.Text = sub_cat_name;
            var rdr = DB_API.SelectCategory(cat_id);

            while (rdr.Read())
            {
                cat_type_id = (int)rdr[DB_API.CategoryEnt.category_type_id.ToString()];
                break;
            }
            cat_type_name      = DB_API.SelectCategoryTypeDesignationById(cat_type_id);
            Type_comboBox.Text = cat_type_name;
        }
        private void PopulateGoalsListBox()
        {
            // get categories from DB
            var rdr = DB_API.SelectAccountGoals(account_id);

            // extract goal names for listBox
            this.user_goals = new List <string>();
            var res = new List <string>();

            while (rdr.Read())
            {
                string goal_name = rdr[DB_API.CategoryEnt.name.ToString()].ToString();
                user_goals.Add(goal_name);
                res.Add(goal_name);
            }
            Goals_listBox.DataSource = new List <string>(res);
        }
        private void Update_btn_Click(object sender, EventArgs e)
        {
            // get values from text boxes if they attrValue inserted by user
            string   username    = username_textbox.ForeColor == Color.Black ? username_textbox.Text : "";
            string   email       = email_textbox.ForeColor == Color.Black ? email_textbox.Text : "";
            string   fname       = firstname_textbox.ForeColor == Color.Black ? firstname_textbox.Text : "";
            string   mname       = middlename_textbox.ForeColor == Color.Black ? middlename_textbox.Text : "";
            string   lname       = lastname_textbox.ForeColor == Color.Black ? lastname_textbox.Text : "";
            string   cardNo      = cardnumber_textbox.ForeColor == Color.Black ? cardnumber_textbox.Text : "";
            int      periodicity = DB_API.SelectRecurenceIdbyDesignation((string)Periodicity_comboBox.SelectedItem);
            DateTime term        = DateTime.Parse(term_dateTimePicker.Value.ToString());

            // verify if email field is filled
            if (email.Equals(""))
            {
                ErrorMessenger.EmptyField("Email");
                return;
            }

            // verify that all mandatory fields are filled (if subscripition is checked)
            if (active_checkBox.Checked)
            {
                if ("".Equals(fname) || "".Equals(lname) || "".Equals(cardNo) || "".Equals(periodicity))
                {
                    ErrorMessenger.EmptyField("Every field marked (*)");
                    return;
                }
            }

            // verify if user exists, so it can be updated
            var exists = DB_API.ExistsUser(email);

            if (!exists)
            {
                ErrorMessenger.Error("User does not exist. Unable to update!");
                return;
            }

            // update user
            DB_API.UpdateUser(username, email, fname, mname, lname, cardNo, periodicity, term, active_checkBox.Checked);


            // update listBox
            PopulateUsersListView();
        }
        private void Delete_btn_Click(object sender, EventArgs e)
        {
            int transaction_id = 0;

            try
            {
                transaction_id = (int)((Transaction)Transactions_listView.SelectedItems[0].Tag).TransactionID;
            }
            catch
            {
                ErrorMessenger.Warning("A transaction must be selected from the list");
                return;
            }
            DB_API.DeleteTransaction(transaction_id);

            // populate transactions listBox
            PopulateTransactionsListView();
        }