Example #1
0
        private void btnDeleteBudget_Click(object sender, EventArgs e)
        {
            string name = Prompts.ShowDeleteDialog();

            Database.DeleteBudget(name);
            RefreshLoadBudgetList();

            if (Budget.name == name)
            {
                lvwBudget.Items.Clear();
            }
            else
            {
                RefreshBudgetListView();
            }
        }
Example #2
0
        private void btnSaveBudget_Click(object sender, EventArgs e)
        {
            bool   budgetExists = false, overWriteBudget = false;
            string items = "", amounts = "";
            string budgetName = Prompts.ShowSaveDialog();

            foreach (string budget in Database.RetrieveBudgets())
            {
                if (budget == budgetName)
                {
                    budgetExists    = true;
                    overWriteBudget = Prompts.ShowOverwriteDialog();
                }
            }

            if (overWriteBudget == true)
            {
                Database.DeleteBudget(budgetName);
            }

            if (budgetExists == false || overWriteBudget == true)
            {
                foreach (BudgetItem item in Budget.BudgetItemsList)
                {
                    if (items == "")
                    {
                        items += item.Name;
                    }
                    else
                    {
                        items += "," + item.Name;
                    }

                    if (item.Percent == -1)
                    {
                        if (amounts == "")
                        {
                            amounts += item.Price;
                        }
                        else
                        {
                            amounts += "," + item.Price;
                        }
                    }
                    else
                    {
                        if (amounts == "")
                        {
                            amounts += "p" + item.Percent;
                        }
                        else
                        {
                            amounts += ",p" + item.Percent;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("A budget already exists with that name");
            }
            Database.SaveBudget(budgetName, Budget.total, items, amounts);
            Budget.name = budgetName;
            RefreshLoadBudgetList();
        }