Example #1
0
        public int deleteIncome(IncExp incExp)
        {
            int status = DatabaseHandler.deleteIncExp(incExp.Id);

            if (status == 1)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Example #2
0
        public int updateTransaction(IncExp incexp)
        {
            int status = DatabaseHandler.updateIncome(incexp);

            if (status == 1)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Example #3
0
        public int addTransaction(IncExp incExp)
        {
            int status = DatabaseHandler.insertIncome(incExp);

            if (status == 1)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
        private async void dDeposit_btn_Click(object sender, RoutedEventArgs e)
        {
            double amount = Convert.ToDouble(dAmount_box.Text);
            String date   = dDate_box.Date.ToString();


            if (amount == 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
            {
                CommonController        comCont = new CommonController();
                IncomeExpenseController ieCont  = new IncomeExpenseController();

                String ieID = comCont.idGenerator("ie");
                String stID = comCont.idGenerator("st");

                IncExp            incexp     = new IncExp(savings.Name + "[Transaction]", amount, "default_null", "default_null", "Saving transaction - depost", ieID, "default_null", false, "AC_ID123");
                SmallTransactions sTrans     = new SmallTransactions(amount, "", 'd', savings.Id, stID, date, "AC_ID123");
                SavingsController controller = new SavingsController();
                int status  = controller.addDepositWithdraw(sTrans);
                int status2 = ieCont.addTransaction(incexp);
                int status3 = comCont.insertMoreIDs(ieID, savings.Id, stID);

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

                    Frame.Navigate(typeof(SavingsDetails), savings);
                }
                else
                {
                    MessageDialog msg = new MessageDialog("Failed to deposit!");
                    await msg.ShowAsync();
                }
            }
        }
        private async void wWithdraw_btn_Click(object sender, RoutedEventArgs e)
        {
            SavingsController cont          = new SavingsController();
            double            currentAmount = cont.savingsCurrentAmount(savings);

            if (Convert.ToDouble(wAmount_box.Text) > currentAmount)
            {
                MessageDialog msg = new MessageDialog("You don't have that much in your savings");
                await msg.ShowAsync();
            }
            else
            {
                double amount = Convert.ToDouble(wAmount_box.Text);
                String date   = wDate_box.Date.ToString();

                IncomeExpenseController ieCont  = new IncomeExpenseController();
                CommonController        comCont = new CommonController();

                String wID  = comCont.idGenerator("st");
                String ieID = comCont.idGenerator("ie");

                IncExp            incexp     = new IncExp(savings.Name + "[Transaction]", amount, "default_null", "default_null", "Saving transaction - withdraw", ieID, "default_null", true, "AC_ID123");
                SmallTransactions sTrans     = new SmallTransactions(amount, "", 'w', savings.Id, wID, date, "AC_ID123");
                SavingsController controller = new SavingsController();

                int status  = controller.addDepositWithdraw(sTrans);
                int status2 = ieCont.addTransaction(incexp);
                int status3 = comCont.insertMoreIDs(ieID, savings.Id, wID);

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

                    Frame.Navigate(typeof(SavingsDetails), savings);
                }
                else
                {
                    MessageDialog msg = new MessageDialog("Failed to withdraw!");
                    await msg.ShowAsync();
                }
            }
        }
Example #6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                incexp1          = (IncExp)e.Parameter;
                updateID         = incexp1.Id;
                tName_box.Text   = incexp1.Name;
                tAmount_box.Text = incexp1.Amount.ToString();

                if (incexp1.Person.Equals("default_null"))
                {
                    tPerson_box.Text = "";
                }
                else
                {
                    tPerson_box.Text = incexp1.Person;
                }

                if (incexp1.Description.Equals("default_null"))
                {
                    tDesc_box.Text = "";
                }
                else
                {
                    tDesc_box.Text = incexp1.Description;
                }

                //testing_box = incexp1.Category;
                tDate_box.Date = Convert.ToDateTime(incexp1.Date);

                if (incexp1.Income)
                {
                    tIncome_radio.IsChecked = true;
                }
                else
                {
                    tExpense_radio.IsChecked = true;
                }

                cond = true;
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            incexp = (IncExp)e.Parameter;
            detailsIncExp_name.Text = incexp.Name;

            if (incexp.Income)
            {
                detailsIncExp_type.Text = "Income";
            }
            else
            {
                detailsIncExp_type.Text = "Expense";
            }

            detailsAmount.Text = incexp.Amount.ToString();

            if (incexp.Person.Equals("default_null"))
            {
                detailsPerson.Text = "";
            }
            else
            {
                detailsPerson.Text = incexp.Person;
            }

            detailsCategory.Text = incexp.Category;

            detailsDate.Text = incexp.Date;

            if (incexp.Description.Equals("default_null"))
            {
                detailsDesc.Text = "";
            }
            else
            {
                detailsDesc.Text = incexp.Description;
            }
        }
Example #8
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();
                    }
                }
            }
        }
        //Update info

        public static int updateIncome(IncExp incExp)
        {
            int    status      = 0;
            String name        = incExp.Name;
            double amount      = incExp.Amount;
            String payer       = incExp.Person;
            String category    = incExp.Category;
            String description = incExp.Description;
            String id          = incExp.Id;
            String date        = incExp.Date;
            bool   isIncome    = incExp.Income;
            int    cond        = 0;

            if (isIncome)
            {
                cond = 1;
            }
            String accID = incExp.AccID;

            try
            {
                using (var connection = new SQLitePCL.SQLiteConnection("Storage.db"))
                {
                    using (var statement = connection.Prepare(@"UPDATE IncExp SET Name=?, Amount=?, Person=?,
                                                                Category=?, Description=?, ID=?, Date=?, Income=?, Acc_ID=?
                                                                WHERE ID=?;"))
                    {
                        statement.Bind(1, name);
                        statement.Bind(2, amount.ToString());
                        statement.Bind(3, payer);
                        statement.Bind(4, category);
                        statement.Bind(5, description);
                        statement.Bind(6, id);
                        statement.Bind(7, date.ToString());
                        statement.Bind(8, cond);
                        statement.Bind(9, accID);
                        statement.Bind(10, id);


                        SQLiteResult s = statement.Step();
                        statement.Reset();
                        statement.ClearBindings();

                        if ((s.ToString().Equals("DONE")))
                        {
                            Debug.WriteLine("Update done");
                            status = 1;
                        }
                        else
                        {
                            Debug.WriteLine("Update failed");
                            status = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(status);
        }
        //Insert info

        public static int insertIncome(IncExp incExp)
        {
            int    status      = 0;
            String name        = incExp.Name;
            double amount      = incExp.Amount;
            String payer       = incExp.Person;
            String category    = incExp.Category;
            String description = incExp.Description;
            String id          = incExp.Id;

            String[] dateArray = incExp.Date.ToString().Split(' ');
            String   date      = dateArray[0];

            bool isIncome = incExp.Income;
            int  cond     = 0;

            if (isIncome)
            {
                cond = 1;
            }
            String accID = incExp.AccID;

            try
            {
                using (var connection = new SQLitePCL.SQLiteConnection("Storage.db"))
                {
                    using (var statement = connection.Prepare(@"INSERT INTO IncExp (Name, Amount, Person,
                                                                Category, Description, ID, Date, Income, Acc_ID)
                                    VALUES(?,?,?,?,?,?,?,?,?);"))
                    {
                        statement.Bind(1, name);
                        statement.Bind(2, amount.ToString());
                        statement.Bind(3, payer);
                        statement.Bind(4, category);
                        statement.Bind(5, description);
                        statement.Bind(6, id);
                        statement.Bind(7, date.ToString());
                        statement.Bind(8, cond);
                        statement.Bind(9, accID);


                        SQLiteResult s = statement.Step();
                        statement.Reset();
                        statement.ClearBindings();
                        if ((s.ToString().Equals("DONE")))
                        {
                            Debug.WriteLine("Step done");
                            status = 1;
                        }
                        else
                        {
                            Debug.WriteLine("Step failed");
                            status = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(status);
        }
Example #11
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));
                    }
                }
            }
        }