Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
        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();
        }
        // ----------------------------------------------------------------------------------------------
        // SQL SERVER AND DATABASE CONNECTION -----------------------------------------------------------
        // ----------------------------------------------------------------------------------------------

        private static SqlConnection DBconnect()
        {
            SqlConnection cnx = new SqlConnection("Data Source = " + dbServer + " ;" + "Initial Catalog = " + dbName +
                                                  "; uid = " + dbUserName + ";" + "password = "******"Could not connect to database!");
            }

            return(cnx);
        }
Esempio n. 7
0
        private void Deleteuser_btn_Click(object sender, EventArgs e)
        {
            // get textbox value
            string 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("Account 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 (user.Equals(""))
            {
                ErrorMessenger.Error("User must be selected to attribute account to!");
                return;
            }

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

            // delete user access to account
            DB_API.MoneyAccountRemoveUser(account_id, user);

            // repopulate accounts_listbox
            Populate_moneyAccounts_listBox(CURRENT_USER);
        }
Esempio n. 8
0
        private void Login_btn_Click(object sender, EventArgs e)
        {
            string user = CURRENT_USER.Equals("") ? userfindme_textbox.Text : CURRENT_USER;

            if (user.Equals(""))
            {
                ErrorMessenger.EmptyField("Email");
                return;
            }

            string account_name = account_textbox.ForeColor == Color.Black ? account_textbox.Text : "";

            if (account_name.Equals(""))
            {
                ErrorMessenger.Error("Account must be selected!");
                return;
            }

            int account_id = CURRENT_USER_ACCOUNTS[account_name];
            var exists     = DB_API.ExistsMoneyAccount(account_id);

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

            var frm = new UserMenuForm(user, account_id)
            {
                Location      = this.Location,
                StartPosition = FormStartPosition.Manual
            };

            frm.FormClosing += delegate { this.Show(); };
            frm.Show();
            this.Hide();
        }
        private void Save_btn_Click(object sender, EventArgs e)
        {
            // get values from textboxes
            string cat_name = Category_textBox.Text;
            int    cat_id;
            string sub_cat_name = Subcategory_textBox.Text;
            string type_name    = Type_comboBox.SelectedItem.ToString();
            int    type_id      = DB_API.SelectCategoryTypeIdByDesignation(type_name);

            // save new category
            if (!Category_textBox.ReadOnly)
            {
                // verify if field is filled
                if (cat_name.Equals(""))
                {
                    ErrorMessenger.EmptyField("Category");
                    return;
                }

                // verify if new name already exists
                var rdr = DB_API.SelectAccountCategories(account_id);
                while (rdr.Read())
                {
                    if (cat_name.Equals(rdr[DB_API.CategoryEnt.name.ToString()].ToString()))
                    {
                        ErrorMessenger.Error("Category name already exists");
                        return;
                    }
                }

                // add new category
                DB_API.AddCategoryToAccount(account_id, cat_name, type_id);
            }

            // save new sub category
            if (!Subcategory_textBox.ReadOnly)
            {
                cat_id = this.categories[cat_name];

                // verify if field is filled
                if (sub_cat_name.Equals(""))
                {
                    ErrorMessenger.EmptyField("Sub-category");
                    return;
                }

                // verify if new name already exists
                var rdr = DB_API.SelectAccountCategories(account_id);
                while (rdr.Read())
                {
                    if (sub_cat_name.Equals(rdr[DB_API.CategoryEnt.name.ToString()].ToString()))
                    {
                        ErrorMessenger.Error("Category name already exists");
                        return;
                    }
                }

                // add new category
                DB_API.AddSubCategoryToAccount(cat_id, account_id, sub_cat_name, type_id);
            }

            // save new budget
            if (Category_textBox.ReadOnly && Subcategory_textBox.ReadOnly)
            {
                if (Budget_textBox.Text.Equals(""))
                {
                    ErrorMessenger.EmptyField("Monthly Budget");
                    return;
                }

                if (StartMonth_comboBox.SelectedIndex == 0 || EndMonth_comboBox.SelectedIndex == 0)
                {
                    ErrorMessenger.EmptyField("Start month and end month");
                    return;
                }

                cat_id = this.categories[cat_name];
                if (!sub_cat_name.Equals(""))
                {
                    cat_id = this.categories[sub_cat_name];
                }

                double   amount     = DB_API.UnMoneyfy(Budget_textBox.Text);
                int      startMonth = StartMonth_comboBox.SelectedIndex;
                int      startYear  = (int)StartYear_numericBox.Value;
                int      endMonth   = EndMonth_comboBox.SelectedIndex;
                int      endYear    = (int)EndYear_numericBox.Value;
                DateTime startDate  = DateTime.Parse(startYear + "/" + startMonth + "/01");
                DateTime endDate;

                if (endMonth == 2)
                {
                    endDate = DateTime.Parse(endYear + "/" + endMonth + "/28");
                }
                else
                {
                    endDate = DateTime.Parse(endYear + "/" + endMonth + "/30");
                }

                // verify that endaDate is bigger than startDate
                if (startDate.CompareTo(endDate) > 0)
                {
                    ErrorMessenger.InvalidData("End date");
                    return;
                }

                // insert new budget
                DB_API.InsertBudget(account_id, cat_id, amount, startDate, endDate);
            }

            PopulateCategoriesListBox();
        }
        private void Filter_btn_Click(object sender, EventArgs e)
        {
            // get info from textBoxes
            // category and sub_category
            int category_id = filtercategory_comboBox.SelectedItem.ToString().Equals(this.none) ?
                              -1 : categoriesStrInt[filtercategory_comboBox.SelectedItem.ToString()];
            int subcategory_id = filtersubcategory_comboBox.SelectedItem.ToString().Equals(this.none) ?
                                 -1 : categoriesStrInt[filtersubcategory_comboBox.SelectedItem.ToString()];
            int?cat_id = subcategory_id == -1 ? category_id : subcategory_id;

            cat_id = cat_id == -1 ? null : cat_id;

            // start and end dates
            DateTime start_date = filterstartdate_timePicker.Value;

            start_date = new DateTime(start_date.Year, start_date.Month, start_date.Day, 0, 0, 0);
            DateTime end_date = filterenddate_timePicker.Value;

            end_date = new DateTime(end_date.Year, end_date.Month, end_date.Day, 0, 0, 0);
            if (start_date.CompareTo(end_date) == 0)
            {
                end_date = new DateTime(end_date.Year, end_date.Month, end_date.Day + 1, 23, 59, 59, 999);
            }
            if (start_date.CompareTo(end_date) > 0)
            {
                ErrorMessenger.Error("End Date must be equal or greater than Start Date");
                return;
            }

            // type and wallet
            int?transaction_type_id = null;

            if (!filtertype_comboBox.SelectedItem.ToString().Equals(this.none))
            {
                transaction_type_id = DB_API.SelectTransactionTypeIdByName(filtertype_comboBox.SelectedItem.ToString());
            }
            int?wallet_id = null;

            if (!wallet_comboBox.SelectedItem.ToString().Equals(this.none))
            {
                var rdr = DB_API.SelectWalletByName(account_id, filterwallet_comboBox.SelectedItem.ToString());
                while (rdr.Read())
                {
                    wallet_id = (int)rdr[DB_API.WalletEnt.wallet_id.ToString()];
                    break;
                }
            }

            // min and max amount
            string minamt    = filterminamount_textBox.ForeColor == Color.Black ? filterminamount_textBox.Text : "";
            string maxamt    = filtermaxamount_textBox.ForeColor == Color.Black ? filtermaxamount_textBox.Text : "";
            double?minamount = null;
            double?maxamount = null;

            if (!minamt.Equals(""))
            {
                minamount = DB_API.UnMoneyfy(minamt);
            }
            if (!maxamt.Equals(""))
            {
                maxamount = DB_API.UnMoneyfy(maxamt);
            }

            if (minamount != null && maxamount != null && minamount > maxamount)
            {
                ErrorMessenger.Error("Min amount must be less or equal than Max amount");
                return;
            }

            // apply filter
            PopulateTransactionsListView(account_id, cat_id, wallet_id, transaction_type_id, minamount, maxamount,
                                         start_date, end_date);
        }