Beispiel #1
0
        private async void saCreate_btn_Click(object sender, RoutedEventArgs e)
        {
            String name   = saName_box.Text;
            double amount = 0.0;

            if (!(saAmount_box.Text.Equals("")))
            {
                amount = Convert.ToDouble(saAmount_box.Text);
            }

            double initial = 0.0;

            if (!(saStarting_box.Text.Equals("")))
            {
                initial = Convert.ToDouble(saStarting_box.Text);
            }

            if (name.Equals("") || name == null)
            {
                MessageDialog msg = new MessageDialog("Savings name cannot be empty!");
                await msg.ShowAsync();
            }
            else if (amount == 0.0)
            {
                MessageDialog msg = new MessageDialog("Goal amount cannot be 0!");
                await msg.ShowAsync();
            }
            else if (amount < 0)
            {
                MessageDialog msg = new MessageDialog("Goal amount cannot be less than 0!");
                await msg.ShowAsync();
            }
            else if (initial < 0)
            {
                MessageDialog msg = new MessageDialog("Initial amount cannot be less than 0!");
                await msg.ShowAsync();
            }
            else
            {
                CommonController contCom = new CommonController();
                String           sID     = contCom.idGenerator("sa");
                String           ieID    = contCom.idGenerator("ie");

                IncExp incexp = new IncExp(name + "[Savings]", initial, "default_null", "default_null", "Savings plan", ieID, "default_null", false, "AC_ID123");
                IncomeExpenseController ieCont = new IncomeExpenseController();

                Savings           savings    = new Savings(name, amount, initial, sID, "AC_ID123");
                SavingsController controller = new SavingsController();

                if (update)
                {
                    savings.Id = updateID;
                    String ieIDUpdate = contCom.idOtherCheck(updateID, "SAID");
                    incexp.Id = ieIDUpdate;
                    int status  = controller.updateSaving(savings);
                    int status2 = ieCont.updateTransaction(incexp);

                    if (status == 1 && status2 == 1)
                    {
                        MessageDialog msg = new MessageDialog("Updated Successfully!");
                        await msg.ShowAsync();

                        Frame.Navigate(typeof(SavingsDetails), savings);
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog("Failed to update!");
                        await msg.ShowAsync();
                    }
                }
                else
                {
                    int status  = ieCont.addTransaction(incexp);
                    int status1 = controller.addSavings(savings);
                    int status2 = contCom.insertIDs(incexp.Id, savings.Id);

                    if (status == 1 && status1 == 1 && status2 == 1)
                    {
                        MessageDialog msg = new MessageDialog("Added Successfully!");
                        await msg.ShowAsync();

                        Frame.Navigate(typeof(SavingsMainView));
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog("Failed to add!");
                        await msg.ShowAsync();
                    }
                }
            }
        }
Beispiel #2
0
        private async void tAdd_btn_Click(object sender, RoutedEventArgs e)
        {
            String name   = tName_box.Text;
            double amount = 0.0;

            if (!(tAmount_box.Text.Equals("")))
            {
                amount = Convert.ToDouble(tAmount_box.Text);
            }
            String payer = "default_null";

            if (!(tPerson_box.Text.Equals("")))
            {
                payer = tPerson_box.Text;
            }

            bool income_radio  = (bool)tIncome_radio.IsChecked;
            bool expense_radio = (bool)tExpense_radio.IsChecked;

            String category = "default_null";
            //String category = testing_box.Text;
            String desc = "default_null";

            if (!(tDesc_box.Text.Equals("")))
            {
                desc = tDesc_box.Text;
            }
            String date = tDate_box.Date.ToString();

            if (name.Equals("") || name == null)
            {
                MessageDialog msg = new MessageDialog("Transaction name cannot be empty!");
                await msg.ShowAsync();
            }
            else if (amount == 0.0)
            {
                MessageDialog msg = new MessageDialog("Amount cannot be 0!");
                await msg.ShowAsync();
            }
            else if (amount < 0)
            {
                MessageDialog msg = new MessageDialog("Amount cannot be less than 0!");
                await msg.ShowAsync();
            }
            else if (!(income_radio || expense_radio))
            {
                MessageDialog msg = new MessageDialog("Please select the type!");
                await msg.ShowAsync();
            }
            else
            {
                bool incExpCond = false;
                if (income_radio)
                {
                    incExpCond = true;
                }

                CommonController        comCont    = new CommonController();
                String                  id         = comCont.idGenerator("ie");
                IncExp                  incExp     = new IncExp(name, amount, payer, category, desc, id, date, incExpCond, "AC_ID123");
                IncomeExpenseController controller = new IncomeExpenseController();

                if (cond)
                {
                    incExp.Id = updateID;

                    int status = controller.updateTransaction(incExp);

                    if (status == 1)
                    {
                        MessageDialog msg = new MessageDialog("Updated successfully!");
                        await msg.ShowAsync();

                        Frame.Navigate(typeof(IndiviualIncExp), incExp);
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog("Failed to update!");
                        await msg.ShowAsync();

                        Frame.Navigate(typeof(IncExpTransactions));
                    }
                }
                else
                {
                    int status = controller.addTransaction(incExp);

                    if (status == 1)
                    {
                        MessageDialog msg = new MessageDialog("Added successfully!");
                        await msg.ShowAsync();

                        Frame.Navigate(typeof(MainView));
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog("Failed to add!");
                        await msg.ShowAsync();

                        Frame.Navigate(typeof(MainView));
                    }
                }
            }
        }