コード例 #1
0
        private void button_SaveEntry(object sender, EventArgs e)
        {
            // Convert the selected spinner items to string and do necessary conversions
            string taxRate = taxSpinner.SelectedItem.ToString();

            taxRate = taxRate.Substring(0, taxRate.Length - 1); // Gets rid of the percentage sign at the end

            // Retrieve the Ids of the selected spinner items
            int accountId      = GetAccountIdFromString(typeSpinner.SelectedItem.ToString());
            int moneyAccountId = GetAccountIdFromString(accountSpinner.SelectedItem.ToString());
            int taxRateId      = bookKeeperManager.TaxRates.Find(t => t.Tax == Convert.ToDouble(taxRate)).Id;

            string imgPath = "";

            if (imagePathUri != null)
            {
                imgPath = imagePathUri.Path; // Decodes to string
            }

            if ("new".Equals(activityType))
            {
                // Request BookKeeperManger to save the entry
                bookKeeperManager.AddEntry(dateOfEntry.Text,
                                           FindViewById <EditText>(Resource.Id.entry_description_edit).Text,
                                           accountId,
                                           moneyAccountId,
                                           Convert.ToDouble(totalWithTax.Text),
                                           taxRateId,
                                           imgPath);
                Toast.MakeText(this, GetString(Resource.String.entry_created), ToastLength.Short).Show();
                resetEntries();
            }
            else if ("update".Equals(activityType))
            {
                // Request BookKeeperManger to update the entry
                bookKeeperManager.UpdateEntry(entryId,
                                              dateOfEntry.Text,
                                              FindViewById <EditText>(Resource.Id.entry_description_edit).Text,
                                              accountId,
                                              moneyAccountId,
                                              Convert.ToDouble(totalWithTax.Text),
                                              taxRateId,
                                              imgPath);
                Toast.MakeText(this, GetString(Resource.String.entry_updated), ToastLength.Short).Show();
                Finish();
            }
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.NewEntry);

            addEntry       = FindViewById <Button>(Resource.Id.addEntryButton);
            incRB          = FindViewById <RadioButton>(Resource.Id.incRB);
            expRB          = FindViewById <RadioButton>(Resource.Id.expRB);
            date           = FindViewById <DatePicker>(Resource.Id.datePicker);
            description    = FindViewById <EditText>(Resource.Id.descriptionET);
            total          = FindViewById <EditText>(Resource.Id.totalET);
            typeSpinner    = FindViewById <Spinner>(Resource.Id.typeSpinner);
            taxSpinner     = FindViewById <Spinner>(Resource.Id.taxSpinner);
            accountSpinner = FindViewById <Spinner>(Resource.Id.accountSpinner);

            addEntry.Click += delegate
            {
                if (incRB.Checked)
                {
                    e1.type      = "Inkomst";
                    e1.isIncome  = true;
                    e1.isExpense = false;
                }
                else
                {
                    e1.type      = "Utgift";
                    e1.isIncome  = false;
                    e1.isExpense = true;
                }

                e1.date        = date.DateTime.ToString("yyyy-MM-dd");
                e1.description = description.Text;
                e1.total       = Double.Parse(total.Text);
                e1.tax         = ((TaxRate)taxSpinner.SelectedItem).tax;
                e1.account     = ((Account)accountSpinner.SelectedItem).accountNr;
                b1.AddEntry(e1);
            };

            getType();
            getTaxRates();
            getAccounts();
        }