Пример #1
0
        internal static List <TransactionImportExport> GetTransactionForExport(Account account, string type, DateTime from, DateTime to)
        {
            var transactionsExport = new List <TransactionImportExport>();
            var transactions       = SilverCoinsManager.GetTransactions().Where(x => x.CreatedDate >= from && x.CreatedDate <= to).ToList();

            if (account.Id != 0)
            {
                transactions.Where(x => x.Account == account.Id).ToList();
            }

            if (type != "Both")
            {
                transactions.Where(x => x.Type == type).ToList();
            }

            foreach (var transaction in transactions)
            {
                var category  = SilverCoinsManager.GetCategory(transaction.Category);
                var accountAc = SilverCoinsManager.GetAccount(transaction.Account);
                transactionsExport.Add(new TransactionImportExport
                {
                    Account     = accountAc.Name,
                    Category    = category.Name,
                    Type        = transaction.Type,
                    Amount      = transaction.Amount.ToString("N2"),
                    Currency    = accountAc.Currency,
                    Date        = transaction.CreatedDate.ToString("dd/MM/yyyy"),
                    PaymentType = transaction.PaymentType,
                    Name        = transaction.Name,
                    Balance     = accountAc.Balance.ToString("N2")
                });
            }

            return(transactionsExport);
        }
Пример #2
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View itemView = convertView;

            if (itemView == null)
            {
                itemView = context.LayoutInflater.Inflate(Resource.Layout.list_view_item_transaction, parent, false);
            }

            Transaction transaction = this[position];
            var         category    = SilverCoinsManager.GetCategory(transaction.Category);
            var         account     = SilverCoinsManager.GetAccount(transaction.Account);

            itemView.FindViewById <ImageView>(Resource.Id.tran_category_icon).SetImageResource(category.Icon != 0 ? category.Icon : Resource.Drawable.ic_launcher);
            itemView.FindViewById <TextView>(Resource.Id.tran_category_name).Text      = category.Name;
            itemView.FindViewById <TextView>(Resource.Id.transaction_name).Text        = transaction.Name;
            itemView.FindViewById <TextView>(Resource.Id.tran_payment_type).Text       = transaction.PaymentType;
            itemView.FindViewById <TextView>(Resource.Id.tran_account).Text            = account.Name;
            itemView.FindViewById <TextView>(Resource.Id.transaction_amount).Text      = transaction.Amount.ToString("N2");
            itemView.FindViewById <TextView>(Resource.Id.transaction_crated_date).Text = transaction.CreatedDate.ToString("dd/MM/yyyy");
            itemView.FindViewById <TextView>(Resource.Id.transaction_currency).Text    = " " + account.Currency;

            if (transaction.Type == "Transfer" && transaction.AccountTransfer == this.account.Id)
            {
                transaction.Type = "Income";
            }

            switch (transaction.Type)
            {
            case "Income":
                itemView.FindViewById <TextView>(Resource.Id.transaction_amount).SetTextColor(Android.Graphics.Color.ForestGreen);
                break;

            case "Expense":
                itemView.FindViewById <TextView>(Resource.Id.transaction_amount).SetTextColor(Android.Graphics.Color.OrangeRed);
                itemView.FindViewById <TextView>(Resource.Id.transaction_amount).Text = "-" + transaction.Amount.ToString("N2");
                break;

            case "Transfer":
                itemView.FindViewById <TextView>(Resource.Id.transaction_amount).SetTextColor(Android.Graphics.Color.OrangeRed);
                itemView.FindViewById <TextView>(Resource.Id.transaction_amount).Text = "-" + transaction.Amount.ToString("N2");
                break;

            default:
                break;
            }

            return(itemView);
        }
 private void DeleteTransaction()
 {
     new AlertDialog.Builder(this)
     .SetCancelable(true)
     .SetMessage("Delete this item?")
     .SetPositiveButton("Yes", (sender, args) =>
     {
         AccountCalculations.AccountCalculations.
         UpdateBalanceAfterTransactionDelete(SilverCoinsManager.GetAccount(transaction.Account),
                                             SilverCoinsManager.GetAccount(transaction.AccountTransfer),
                                             transaction);
         SilverCoinsManager.DeleteTransaction(transaction.Id);
         OnBackPressed();
         Finish();
     })
     .SetNegativeButton("No", (sender, args) => { })
     .Show();
 }
        private void InitalizeSpinners()
        {
            adapterAccount         = new ArrayAdapter <Account>(this, Resource.Layout.spinner_item, listOfAccounts);
            adapterAccountTransfer = new ArrayAdapter <Account>(this, Resource.Layout.spinner_item, listOfAccounts);
            adapterCategory        = new ArrayAdapter <Category>(this, Resource.Layout.spinner_item, EditMode ? (transaction.Type == "Income" ? listOfIncomeCategories : listOfExpenseCategories) : listOfIncomeCategories);
            adapterPaymentType     = new ArrayAdapter <string>(this, Resource.Layout.spinner_item, paymentTypes);

            adapterAccount.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            adapterCategory.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            adapterPaymentType.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            adapterAccountTransfer.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);

            spinnerTransactionAccount         = FindViewById <Spinner>(Resource.Id.spinner_transaction_account);
            spinnerTransactionCategory        = FindViewById <Spinner>(Resource.Id.spinner_transaction_category);
            spinnerTransactionPaymentType     = FindViewById <Spinner>(Resource.Id.spinner_transaction_payment_type);
            spinnerTransactionAccountTransfer = FindViewById <Spinner>(Resource.Id.spinner_transaction_account_transfer);

            spinnerTransactionAccount.Adapter         = adapterAccount;
            spinnerTransactionCategory.Adapter        = adapterCategory;
            spinnerTransactionPaymentType.Adapter     = adapterPaymentType;
            spinnerTransactionAccountTransfer.Adapter = adapterAccountTransfer;

            spinnerTransactionAccount.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(SpinnerTransactionAccount_ItemClick);

            if (EditMode)
            {
                spinnerTransactionAccount.SetSelection(GetIndex(spinnerTransactionAccount, SilverCoinsManager.GetAccount(transaction.Account).Name));
                spinnerTransactionCategory.SetSelection(GetIndex(spinnerTransactionCategory, SilverCoinsManager.GetCategory(transaction.Category).Name));
                spinnerTransactionPaymentType.SetSelection(adapterPaymentType.GetPosition(transaction.PaymentType));
                if (transaction.AccountTransfer != 0)
                {
                    spinnerTransactionAccountTransfer.SetSelection(GetIndex(spinnerTransactionAccountTransfer, SilverCoinsManager.GetAccount(transaction.AccountTransfer).Name));
                }

                switch (transaction.Type)
                {
                case "Income":
                    spinnerTransactionAccountTransfer.Visibility = ViewStates.Gone;
                    break;

                case "Expense":
                    spinnerTransactionAccountTransfer.Visibility = ViewStates.Gone;
                    break;

                case "Transfer":
                    spinnerTransactionCategory.Visibility = ViewStates.Gone;
                    break;

                default:
                    break;
                }
            }
            else
            {
                spinnerTransactionAccountTransfer.Visibility = ViewStates.Gone;
            }
        }