Esempio n. 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            CashPredictorInstance = Code.clsCashPredictor.Instance(this);

            mClassName = this.GetType().Name;

            // Get reference to paramaters
            Code.clsParameters parameters = Code.clsParameters.Instance();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            mBankDebitListView = FindViewById <ListView>(Resource.Id.fldBankDebitsListView);

            Code.clsBankDebitsListViewAdapter adapter = new Code.clsBankDebitsListViewAdapter(this, Code.clsBankDebitDB.GetBankDebits());

            mBankDebitListView.Adapter    = adapter;
            mBankDebitListView.ItemClick += BankDebitListView_ItemClick;
            Console.WriteLine("[{0}] Registered the item click event for the bank debit list view..", mClassName);

            mBtnUpdateOutgoings        = FindViewById <Button>(Resource.Id.btnUpdateOutgoings);
            mBtnUpdateOutgoings.Click += (object sender, EventArgs e) =>
            {
                var ListOutgoingsActivity = new Intent(this, typeof(Code.clsListOutgoings_Activity));
                StartActivity(ListOutgoingsActivity);
            };

            EditText mfldCurrentBalance = FindViewById <EditText>(Resource.Id.fldCurrentBalance);

            mfldCurrentBalance.AfterTextChanged += MfldCurrentBalance_AfterTextChanged;

            ProgressBar mProgressBarDaysUntilPayday = FindViewById <ProgressBar>(Resource.Id.progressBar1);
            float       mDaysUntilNextPayDay        = Code.HelperMethods.DaysUntilNextPayDay();
            float       mDaysInThisPayPeriod        = Code.HelperMethods.DaysInThisPayPeriod();

            mProgressBarDaysUntilPayday.Progress = Convert.ToInt32(((mDaysInThisPayPeriod - mDaysUntilNextPayDay) / mDaysInThisPayPeriod) * 100);

            TextView txtDaysUntilNextPayDay = FindViewById <TextView>(Resource.Id.txtDaysTillPayDay);
            // txtDaysUntilNextPayDay.Text = mDaysUntilNextPayDay.ToString() + " days until pay day";

            CheckBox mfldIncudeInCalculation = FindViewById <CheckBox>(Resource.Id.txtIncudeInCalculation);
            // mfldIncudeInCalculation.CheckedChange += mfldIncudeInCalculation_CheckedChange;

            // Set the Payday
            TextView txtPayDate = FindViewById <TextView>(Resource.Id.txtPayDate);
            string   myText     = "";

            myText = "Pay Day is the: " + parameters.PayDay.ToString() + Code.HelperMethods.DaySuffix(parameters.PayDay).ToString();

            // Set the todays day text..
            myText += " - Today is the " + DateTime.Now.Day.ToString() + Code.HelperMethods.DaySuffix(DateTime.Now.Day);

            txtPayDate.Text = myText;

            // Register the update balance method for any changes in the include in clacluation checkbox
            //Code.clsBankDebitsListViewAdapter.
        }
Esempio n. 2
0
        public static clsParameters Instance()
        {
            if (mInstance == null)
            {
                mInstance = new clsParameters();
            }

            return(mInstance);
        }
        public void CalculateListOfBankDebits()
        {
            //TODO: Ensure this takes into consideration that user may of set an include-in-calculation manually

            // Generate the list
            List <clsBankDebit> ListOfAllBankDebits = new List <clsBankDebit>();

            // Get reference to paramaters
            clsParameters parameters = clsParameters.Instance();

            DateTime Today = DateTime.Now;

            // Today = new DateTime(2017, 10, 27);

            int  PayDay            = parameters.PayDay;
            bool PayDayIsNextMonth = Today.Day > PayDay;

            // Cycle through the outgoings
            foreach (clsOutgoing Outgoing in clsOutgoingDB.GetOutgoings())
            {
                if (Outgoing.Reoccuring == true)
                {
                    DateTime TodayDateToUse = Today;

                    // Calculate number remaining before pay day
                    List <clsBankDebit> bankDebits = new List <clsBankDebit>();
                    bool HaveMovedToNextMonth      = false;
                    int  DaysSinceLastBankDebit    = Outgoing.Frequency;

                    // Generate a list of the debits from one payday to the next

                    int LastDayToCheck = PayDay; // Set last day to check as payday intially

                    // If payday is next month then set lastdaytocheck to lastday of the month
                    if (PayDayIsNextMonth)
                    {
                        LastDayToCheck = Code.HelperMethods.LastDayInMonth(TodayDateToUse);
                    }

                    // Loop from today to lastdaytocheck
                    for (int d = TodayDateToUse.Day; d <= LastDayToCheck; d++)
                    {
                        DaysSinceLastBankDebit++;

                        // check if this day is the same day of week as the outgoing
                        DateTime CheckDate = new DateTime(TodayDateToUse.Year, TodayDateToUse.Month, d);
                        if (((int)CheckDate.DayOfWeek == Outgoing.DayOfWeekLeavesAccount) && (DaysSinceLastBankDebit >= Outgoing.Frequency))
                        {
                            DateTime DateLeavesAccount = new DateTime(TodayDateToUse.Year, TodayDateToUse.Month, d);
                            bankDebits.Add(new clsBankDebit(-1, Outgoing.Description, Outgoing.Amount, d, DateLeavesAccount));
                            DaysSinceLastBankDebit = 0;
                        }

                        if (d == LastDayToCheck)
                        {
                            if (PayDayIsNextMonth && !HaveMovedToNextMonth)
                            {
                                LastDayToCheck = PayDay;
                                d = 0;
                                HaveMovedToNextMonth = true;
                                TodayDateToUse       = TodayDateToUse.AddMonths(1);
                                TodayDateToUse       = new DateTime(TodayDateToUse.Year, TodayDateToUse.Month, 1);
                            }
                        }
                    }

                    // Loop from today to Payday

                    // Cycle throught the debits and remove those that are not valid i.e. before todays date but after pay day

                    // Add the bankdebits to the list of bank debits
                    foreach (clsBankDebit theBankDebit in bankDebits)
                    {
                        ListOfAllBankDebits.Add(theBankDebit);
                    }
                }
                else
                {
                    // If not re-occuring, add to the list if before next payday
                    DateTime DateLeavesAccount = new DateTime(Today.Year, Today.Month, Outgoing.DayleavesAccount);

                    // check if date in outgoing is next month, if so need to ass one to the month
                    if (Outgoing.DayleavesAccount < Today.Day)
                    {
                        DateLeavesAccount = DateLeavesAccount.AddMonths(1);
                    }

                    bool saveBankDebit = true;

                    if (PayDayIsNextMonth && (DateLeavesAccount.Day > PayDay))
                    {
                        saveBankDebit = false;
                    }
                    if (!PayDayIsNextMonth && (DateLeavesAccount.Day < Today.Day))
                    {
                        saveBankDebit = false;
                    }

                    if (saveBankDebit)
                    {
                        ListOfAllBankDebits.Add(new clsBankDebit(-1, Outgoing.Description, Outgoing.Amount, Outgoing.DayleavesAccount, DateLeavesAccount));
                    }
                }
            }

            // Sort the list by date order, using a bubble sort routine
            Code.clsBankDebit tempBankDebit;
            bool ListIsInOrder = false;

            do
            {
                ListIsInOrder = true;
                for (int i = 0; i < ListOfAllBankDebits.Count - 1; i++)
                {
                    if (ListOfAllBankDebits[i + 1].DateLeaveAccount < ListOfAllBankDebits[i].DateLeaveAccount)
                    {
                        // Swap the entries over
                        tempBankDebit              = ListOfAllBankDebits[i];
                        ListOfAllBankDebits[i]     = ListOfAllBankDebits[i + 1];
                        ListOfAllBankDebits[i + 1] = tempBankDebit;
                        ListIsInOrder              = false;
                    }
                }
            } while (!ListIsInOrder);

            // Loop through all the bank debits and set include in calculation to false if today is the day it is due to come out of account and it is set do do so in the parameters
            if (parameters.SetReoccuringToFalseIfSameDayAsCurrentDay)
            {
                foreach (clsBankDebit i in ListOfAllBankDebits)
                {
                    if (i.DateLeaveAccount.Day == Today.Day)
                    {
                        i.IncludeInCalculation = false;
                    }
                }
            }

            //Save the list to the database class so can be used by other scripts
            clsDatabase DatabaseInstance = clsDatabase.Instance();

            DatabaseInstance.BankDebits = ListOfAllBankDebits;
        }