private void CountBalance() { double bills; double expenses; float balance; DateTime today = DateTime.Today; DateTime startDate = new DateTime(today.Year, today.Month, 1); DateTime endDate = startDate.AddMonths(1).AddDays(-1); int daysOfMonth = endDate.Day; int dayOfMonth = today.Day; using (var db = new ExpenseManager()) { bills = db.GetSomeItems(startDate, endDate, "Rachunki").Sum(a => a.Amount); expenses = db.GetItemsByDates(startDate, endDate) .Where(a => a.CategoryId != 1) .Sum(a => a.Amount); } balance = (((monthLimit - (float)bills - estBills) / daysOfMonth) * dayOfMonth) - (float)expenses; if (balance > 0) { textBalance.Text = balance.ToString(); textPlusMinus.Text = " zł do przodu."; } else if (balance == 0) { textBalance.Text = ""; textPlusMinus.Text = "na zero"; } else { balance = Math.Abs(balance); textBalance.Text = balance.ToString(); textPlusMinus.Text = " zł do tyłu."; } }
public override Dialog OnCreateDialog(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var builder = new AlertDialog.Builder(Activity); var inflater = Activity.LayoutInflater; var dialogView = inflater.Inflate(Resource.Layout.ReportDialogView, null); if (dialogView != null) { monthTV = dialogView.FindViewById <TextView>(Resource.Id.textMonth); yearTV = dialogView.FindViewById <TextView>(Resource.Id.textYear); catTV = dialogView.FindViewById <TextView>(Resource.Id.textRepCategory); expensesTV = dialogView.FindViewById <TextView>(Resource.Id.textRepExpenses); realExpensesTV = dialogView.FindViewById <TextView>(Resource.Id.textRealExpenses); spinner = dialogView.FindViewById <Spinner>(Resource.Id.spinnerRep); GetTVText(); startDate = new DateTime(selectedYear, selectedMonth, 1); endDate = startDate.AddMonths(1).AddDays(-1); LoadSpinnerData(); spinner.ItemSelected += Spinner_ItemSelected; spinner.SetSelection(1); using (var db = new ExpenseManager()) { expensesSum = db.GetItemsByDates(startDate, endDate).Sum(a => a.Amount); } expensesTV.Text = expensesSum.ToString(); SetAmounts(); if (startAmount == -1 || endAmount == -1) { realExpensesTV.Text = "Brak wystarczających danych"; } else { using (var db = new IncomeManager()) { incomesSum = db.GetItemsByDates(startDate, endDate).Sum(a => a.Amount); } realSum = startAmount + (float)incomesSum - endAmount; realExpensesTV.Text = realSum.ToString(); } builder.SetView(dialogView); builder.SetNeutralButton("Wróć", HandleNeutralButtonClick); } var dialog = builder.Create(); return(dialog); }