Exemplo n.º 1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // save current date passed at navigation
            m_CurrentDate = (DateTime)e.Parameter;

            ExpensesStorage dbcontacts = new ExpensesStorage();

            DB_ContactList = dbcontacts.GetExpensesByDate(m_CurrentDate);//Get all DB contacts
            //if (DB_ContactList.Count > 0)
            //{
            //    btnDelete.IsEnabled = true;
            //}

            // set list data - recent dates first
            var dailySet = DB_ContactList.OrderByDescending(i => i.Date).ToList();

            listBoxobj.ItemsSource = dailySet;

//            CultureInfo myCI = CultureInfo.CurrentCulture;
//            w_DailyCurrentDate.Text = myCI.NumberFormat.CurrencyDecimalSeparator + myCI.NumberFormat.NumberDecimalSeparator + myCI.NumberFormat.CurrencySymbol;

            // THIS IS PROPER CODE!!!
            // TODO: use VM, not direct setter
            w_DailyCurrentDate.Text = string.Format("{0:D}", m_CurrentDate);

            float dailySum = 0;

            foreach (var r in dailySet)
            {
                dailySum += r.Amount;
            }
            w_DailySumAmount.Text = string.Format("{0:C}", dailySum);
        }
Exemplo n.º 2
0
        private void ReadContactList_Loaded(object sender, RoutedEventArgs e)
        {
            ExpensesStorage dbcontacts  = new ExpensesStorage();
            AllExpensesVM   allExpenses = new AllExpensesVM();

            // everyday expenses
            ExpensesVM expenses = dbcontacts.GetAllExpenses();//Get all DB expenses

            allExpenses.Expenses = expenses;

            // unique expenses
            UniqueExpensesStorage db             = App.GlobalPersistanceService.GetUniqueExpensesStorage();
            UniqueExpensesVM      uniqueExpenses = db.GetAllUniqueExpenses();

            allExpenses.UniqueExpenses = uniqueExpenses;

            // overall
            // TODO: use DB
            //UniqueExpensesStorage db = new UniqueExpensesStorage();
            //OverallVM overall = db.GetAllUniqueExpenses();

            OverallVM overall = new OverallVM(new DateTime(2018, 03, 25), DateTime.Now, new DateTime(2018, 06, 22), App.GlobalPersistanceService.GetAverageSavingsPerDay(),
                                              new DateTime(2018, 03, 29), 7855);

            allExpenses.Overall = overall;


            this.DataContext = allExpenses;


            // use Binding, not setters!!

            //            TotalStatistics stats = new DatabaseHelperClass().GetTotalStatistics();

            //            w_TotalExpenses.Text = string.Format("{0:C}", DataConversion.ConvertCentsToCurrency(stats.m_TotalExpenses));

            // set list data - recent dates first
            //            listBoxobj.ItemsSource = DB_ContactList.OrderByDescending(i => i.Date).ToList();


            Random rand = new Random();
            List <FinancialStuff> financialStuffList = new List <FinancialStuff>();

            int   idx = 0;;
            float sum = 78.55f;

            // sum up unique expenses before first regular date
            if (allExpenses.Expenses.ExpensesList.Count > 0)
            {
                DateTime dateOnlyFrom = allExpenses.Expenses.ExpensesList[allExpenses.Expenses.ExpensesList.Count - 1].GetDateOnly().Date;
                var      uniqueExpensesBeforeTheDate = allExpenses.UniqueExpenses.ExpensesList.Where((v) => ((v.Date < dateOnlyFrom))).Sum((v) => v.SignedAmount);
                sum += uniqueExpensesBeforeTheDate;
            }

            DateTime now = DateTime.Now;

            for (int i = allExpenses.Expenses.ExpensesList.Count - 1, ei = 0; i >= ei; --i)
            {
                var r = allExpenses.Expenses.ExpensesList[i];
                sum += r.Amount;

                // get unique expenses for the date
                DateTime dateOnlyFrom             = r.GetDateOnly().Date;
                DateTime dateOnlyTo               = dateOnlyFrom.AddDays(1).Date;
                var      uniqueExpensesForTheDate = allExpenses.UniqueExpenses.ExpensesList.Where((v) => ((v.Date >= dateOnlyFrom) && (v.Date < dateOnlyTo))).Sum((v) => v.SignedAmount);

                sum += uniqueExpensesForTheDate;

                // display 30 last days (to limit amount of chart data)
                if ((DateTime.Now - r.GetDateOnly()).Days < 30)
                {
                    // add point to the chart
                    financialStuffList.Add(new FinancialStuff()
                    {
                        IdX = idx, Amount = sum
                    });
                    idx += 1;
                }
            }

            (LineChart.Series[0] as LineSeries).ItemsSource = financialStuffList;
        }