예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.KostenView);

            string      userId = Intent.GetStringExtra("userId");
            KostenModel model  = new KostenModel();

            Button   addKosten    = FindViewById <Button>(Resource.Id.addKostenpostbtn);
            EditText nummer       = FindViewById <EditText>(Resource.Id.kostenEditText);
            EditText kommaGetal   = FindViewById <EditText>(Resource.Id.kostenEditText2);
            EditText beschrijving = FindViewById <EditText>(Resource.Id.beschrijvingkostenEditText);

            addKosten.Click += delegate
            {
                if (string.IsNullOrEmpty(nummer.Text) || string.IsNullOrEmpty(kommaGetal.Text))
                {
                    messageHandler(2);
                }
                else if (string.IsNullOrEmpty(beschrijving.Text))
                {
                    messageHandler(1);
                }
                else
                {
                    string kostenTotaal = nummer.Text + "." + kommaGetal.Text;
                    model.createKosten(kostenTotaal, beschrijving.Text, userId);
                    List <Kosten> kosten = model.GetAllKosten(userId);
                    foreach (Kosten item in kosten)
                    {
                        Console.WriteLine(item.kosten + "\t" + item.beschrijving);
                    }
                    messageHandler(3);
                }
            };

            void messageHandler(int switchId)
            {
                switch (switchId)
                {
                case 1:
                    Android.App.AlertDialog.Builder popupMessage1 = new AlertDialog.Builder(this);
                    AlertDialog alert1 = popupMessage1.Create();
                    alert1.SetTitle("Kostenpost invoeren mislukt!");
                    alert1.SetMessage("Er moet een beschrijving ingevoerd worden!");
                    alert1.SetButton("OK", (c, ev) =>
                    {
                        nummer.Text       = "";
                        beschrijving.Text = "";
                        kommaGetal.Text   = "";
                    });
                    alert1.Show();
                    break;

                case 2:
                    Android.App.AlertDialog.Builder popupMessage2 = new AlertDialog.Builder(this);
                    AlertDialog alert2 = popupMessage2.Create();
                    alert2.SetTitle("Kostenpost invoeren mislukt!");
                    alert2.SetMessage("De ingevoerde waarde moet een waarde hoger zijn dan nul!");
                    alert2.SetButton("OK", (c, ev) =>
                    {
                        nummer.Text       = "";
                        beschrijving.Text = "";
                        kommaGetal.Text   = "";
                    });
                    alert2.Show();
                    break;

                case 3:
                    Android.App.AlertDialog.Builder popupMessage3 = new AlertDialog.Builder(this);
                    AlertDialog alert3 = popupMessage3.Create();
                    alert3.SetTitle("Kostenpost succesvol toegevoegd!");
                    alert3.SetMessage("Klik op refresh in het budget menu om de toegevoegde waarde te zien.");
                    alert3.SetButton("OK", (c, ev) =>
                    {
                        Finish();
                    });
                    alert3.Show();
                    break;
                }
            }
        }
예제 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            string userId = Intent.GetStringExtra("userId");

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.BudgetMeterView);
            ListView      kostenMenu   = FindViewById <ListView>(Resource.Id.listView1);
            LinearLayout  linearLayout = FindViewById <LinearLayout>(Resource.Id.linearLayout2);
            KostenAdapter adapter;
            List <Kosten> kosten;
            Button        limiet     = FindViewById <Button>(Resource.Id.kostenpostbtn);
            ImageButton   addKosten  = FindViewById <ImageButton>(Resource.Id.plusbudgetbtn);
            Button        refresh    = FindViewById <Button>(Resource.Id.refreshBtn);
            TextView      budgetOver = FindViewById <TextView>(Resource.Id.BudgetOvertxt);


            if (!model.checkUser(userId))
            {
                kosten             = model.GetAllKosten(userId);
                adapter            = new KostenAdapter(this, kosten, Resource.Layout.KostenpostenListview);
                kostenMenu.Adapter = adapter;
            }
            else
            {
                kosten             = model.GetAllKosten(userId);
                adapter            = new KostenAdapter(this, kosten, Resource.Layout.KostenpostenListview);
                kostenMenu.Adapter = adapter;
                double kostenDbl = 0;

                foreach (Kosten item in kosten)
                {
                    kostenDbl += Convert.ToDouble(item.kosten);
                }

                double budgetOverDbl = Math.Round(Convert.ToDouble(model.GetLimiet(userId).kosten) - kostenDbl, 2);

                if (budgetOverDbl >= 0)
                {
                    budgetOver.SetBackgroundColor(Android.Graphics.Color.Rgb(112, 255, 104));
                }
                else
                {
                    budgetOver.SetBackgroundColor(Android.Graphics.Color.Rgb(255, 104, 104));
                }

                budgetOver.Text = budgetOverDbl.ToString();
            }

            limiet.Click += delegate
            {
                Intent newMaandActivity = new Intent(this, typeof(NewMaandActivity));
                newMaandActivity.PutExtra("userId", userId);
                this.StartActivity(newMaandActivity);
            };

            addKosten.Click += delegate
            {
                if (model.checkUser(userId))
                {
                    Intent budgetToInputActivity = new Intent(this, typeof(BudgettoinputActivity));
                    budgetToInputActivity.PutExtra("userId", userId);
                    this.StartActivity(budgetToInputActivity);
                }
                else
                {
                    messageHandler(1);
                }
            };

            refresh.Click += delegate
            {
                if (model.checkUser(userId))
                {
                    budgetOver.Text    = model.GetLimiet(userId).kosten;
                    kosten             = model.GetAllKosten(userId);
                    adapter            = new KostenAdapter(this, kosten, Resource.Layout.KostenpostenListview);
                    kostenMenu.Adapter = adapter;

                    double kostenDbl = 0;

                    foreach (Kosten item in kosten)
                    {
                        kostenDbl += Convert.ToDouble(item.kosten);
                    }
                    double budgetOverDbl = Math.Round(Convert.ToDouble(model.GetLimiet(userId).kosten) - kostenDbl, 2);
                    if (budgetOverDbl >= 0)
                    {
                        budgetOver.SetBackgroundColor(Android.Graphics.Color.Rgb(112, 255, 104));
                    }
                    else
                    {
                        budgetOver.SetBackgroundColor(Android.Graphics.Color.Rgb(255, 104, 104));
                    }
                    budgetOver.Text = budgetOverDbl.ToString();
                }
                else
                {
                    messageHandler(2);
                }
            };

            void messageHandler(int switchId)
            {
                switch (switchId)
                {
                case 1:
                    Android.App.AlertDialog.Builder popupMessage1 = new AlertDialog.Builder(this);
                    AlertDialog alert1 = popupMessage1.Create();
                    alert1.SetTitle("Kostenpost toevoegen uitgeschakeld!");
                    alert1.SetMessage("Dit is de eerste keer dat u deze functie gebruikt. Maak eerst een nieuwe maand aan.");
                    alert1.SetButton("OK", (c, ev) =>
                    {
                    });
                    alert1.Show();
                    break;

                case 2:
                    Android.App.AlertDialog.Builder popupMessage2 = new AlertDialog.Builder(this);
                    AlertDialog alert2 = popupMessage2.Create();
                    alert2.SetTitle("Refresh uitgeschakeld!");
                    alert2.SetMessage("Dit is de eerste keer dat u deze functie gebruikt. Maak eerst een nieuwe maand aan.");
                    alert2.SetButton("OK", (c, ev) =>
                    {
                    });
                    alert2.Show();
                    break;
                }
            }
        }