public BalancePage(Wallet w, DatabaseOps d)
        {
            this.Title = "Balance";

            wallet = w;
            db     = d;

            screenWidth  = DeviceInfo.Hardware.ScreenWidth;
            screenHeight = ConvertPixelsToDp(DeviceInfo.Hardware.ScreenHeight);

            Debug.WriteLine("Height: " + screenHeight + " # Width: " + screenWidth);
            graphMaxHeight = screenHeight * 0.6;

            selectedCurrency = db.GetCurrency(db.GetGlobal("favouriteCurrency"));

            InitializeMainGrid();
            InitializeGraph();
            InitializeTotals();

            var scrollview = new ScrollView
            {
                Content = new StackLayout
                {
                    Children = { mainGrid }
                }
            };

            Content = new StackLayout
            {
                Children = { scrollview }
            };
        }
예제 #2
0
        private static void CallWebAsync(string uri, DatabaseOps db, AsyncCallback cb, InputValuePage page)
        {
            var request = HttpWebRequest.Create(uri);

            request.Method = "GET";
            var state = new Tuple <DatabaseOps, WebRequest, InputValuePage>(db, request, page);

            request.BeginGetResponse(cb, state);
        }
예제 #3
0
 public static void RefreshRates(DatabaseOps db, InputValuePage page)
 {
     foreach (string code in Utils.currencyCodes)
     {
         var uri = string.Format("http://download.finance.yahoo.com/d/quotes?f=sl1d1t1&s={0}{1}=X", "EUR", code);
         var cb  = new AsyncCallback(CallHandler);
         CallWebAsync(uri, db, cb, page);
     }
 }
예제 #4
0
        public double GetTotal(string code, DatabaseOps db)
        {
            double total = 0.0;

            foreach (KeyValuePair <string, double> entry in balances)
            {
                // do something with entry.Value or entry.Key
                if (entry.Key != code)
                {
                    total += Currency.ConvertAmount(db, entry.Value, entry.Key, code);
                }
                else
                {
                    total += entry.Value;
                }
            }
            return(total);
        }
예제 #5
0
        public static double ConvertAmount(DatabaseOps db, double amount, string codeFrom, string codeTo)
        {
            double rate = db.GetCurrency(codeTo).rate / db.GetCurrency(codeFrom).rate;

            return(amount * rate);
        }
예제 #6
0
 public static Currency getFavouriteCurrency(DatabaseOps db)
 {
     return(db.GetCurrency(db.GetGlobal("favouriteCurrency")));
 }
        public InputValuePage(DatabaseOps db, Wallet w)
        {
            Title = "Add/Remove Money";

            this.db = db;
            wallet  = w;

            favouriteCurrency = Utils.getFavouriteCurrency(db);

            //////////////////// TOOLBAR /////////////////////
            var balancePageButton = new ToolbarItem
            {
                Text    = "Balance",
                Command = new Command(this.ShowBalancePage)
            };

            if (Device.OS == TargetPlatform.Windows)
            {
                balancePageButton.Order = ToolbarItemOrder.Secondary;
            }

            ToolbarItems.Add(balancePageButton);

            var setFavouriteCurrencyButton = new ToolbarItem
            {
                Text    = "Favourite Currency",
                Command = new Command(this.ShowSetFavouriteCurrencyPage)
            };

            setFavouriteCurrencyButton.Order = ToolbarItemOrder.Secondary;
            ToolbarItems.Add(setFavouriteCurrencyButton);

            var showRatesPageButton = new ToolbarItem
            {
                Text    = "Rates",
                Command = new Command(this.ShowRatesPage)
            };

            showRatesPageButton.Order = ToolbarItemOrder.Secondary;
            ToolbarItems.Add(showRatesPageButton);


            var updateCurrenciesButton = new ToolbarItem
            {
                Text    = "Update Currencies",
                Command = new Command(this.UpdateCurrencies)
            };

            updateCurrenciesButton.Order = ToolbarItemOrder.Secondary;
            ToolbarItems.Add(updateCurrenciesButton);

            /////////////////// PROGRESS BAR //////////////////

            progressBar = new ProgressBar
            {
                Progress = 0,
            };


            ////////////////// ACTION PICKER //////////////////
            actionPicker = new Picker
            {
                Title             = "Action",
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
            actionPicker.Items.Add("Add");
            actionPicker.Items.Add("Remove");
            actionPicker.SelectedIndex         = 0;
            actionPicker.SelectedIndexChanged += actionChanged;

            ////////////////// VALUE INPUT //////////////////
            entryLabel = new Label()
            {
                Text = "Amount:"
            };
            valueEntry = new Entry()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Placeholder       = "Amount",
                Keyboard          = Keyboard.Numeric
            };

            ////////////////// CURRENCY PICKER //////////////////
            currencyPicker = new Picker
            {
                Title             = "Currency",
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            int favouriteIndex = 0;

            numberOfCurrencies = 0;
            foreach (Currency c in db.GetCurrencies())
            {
                currencyPicker.Items.Add(c.code);
                if (c.code == favouriteCurrency.code)
                {
                    favouriteIndex = numberOfCurrencies;
                }
                numberOfCurrencies++;
            }
            currencyPicker.SelectedIndex         = favouriteIndex;
            selectedCurrency                     = db.GetCurrencies().ElementAt(favouriteIndex);
            currencyPicker.SelectedIndexChanged += currencyChanged;

            ////////////////// CURRENT CURRENCY RATE //////////////////

            currencyRateLabel = new Label();
            updateCurrencyRateLabelText();

            ////////////////// BUTTON //////////////////
            button = new Button()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Add",
                BackgroundColor = Utils.addColor
            };
            button.Clicked += OnButtonClicked;

            ////////////////// ERROR LABEL //////////////////
            errorLabel = new Label()
            {
                Text      = "",
                TextColor = Color.Red,
                HorizontalTextAlignment = TextAlignment.Center
            };

            ////////////////// GRID //////////////////
            var grid = new Grid()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };

            grid.ColumnDefinitions = new ColumnDefinitionCollection
            {
                new ColumnDefinition {
                    Width = new GridLength(2, GridUnitType.Star)
                },
                new ColumnDefinition {
                    Width = new GridLength(3, GridUnitType.Star)
                },
                new ColumnDefinition {
                    Width = new GridLength(2, GridUnitType.Star)
                }
            };

            for (int i = 0; i < 7; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
            }

            grid.Children.Add(errorLabel, 1, 0);
            grid.Children.Add(actionPicker, 1, 1);
            grid.Children.Add(entryLabel, 1, 2);
            grid.Children.Add(valueEntry, 1, 3);
            grid.Children.Add(currencyPicker, 1, 4);
            grid.Children.Add(currencyRateLabel, 1, 5);
            grid.Children.Add(button, 1, 6);

            Content = new StackLayout
            {
                Children = { progressBar, grid }
            };
        }