Esempio n. 1
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            //delete from app xaml
            App.categories = null;
            App.data = null;
            App.selectedCurrency = null;

            //delete budget
            IsolatedStorageSettings budget = IsolatedStorageSettings.ApplicationSettings;
            int budzet;
            if (budget.TryGetValue<int>("budget", out budzet))
            {
                budget["budget"] = 0;
                budget.Save();
            }

            //set default currency
            string currency;
            if (budget.TryGetValue<string>("currency", out currency))
            {
                budget["currency"] = "EUR";
                budget.Save();
            }
            else
            {
                //postavuvame default currency ako veke ne postoi

                budget["currency"] = "EUR";
                budget.Save();
            }

            //add default categories

            IsolatedStorageSettings categories = IsolatedStorageSettings.ApplicationSettings;
            List<string> tmpCategories = new List<string>();

            //ako veke sme gi dodale nema potreba pak
            if (categories.TryGetValue<List<string>>("categories", out tmpCategories))
            {
                List<string> tmpCategories2 = new List<string>();
                tmpCategories2.Add("Food");
                tmpCategories2.Add("Clothing");
                tmpCategories2.Add("Bills");
                tmpCategories2.Add("Personal Care");
                tmpCategories2.Add("Gifts");
                categories["categories"] = tmpCategories2;
                categories.Save();
                App.categories = tmpCategories2;

            }
            //ako prv pat ja vklucuva aplikacijata treba da dodademe kategorii
            else
            {
                List<string> tmpCategories2 = new List<string>();
                tmpCategories2.Add("Food");
                tmpCategories2.Add("Clothing");
                tmpCategories2.Add("Bills");
                tmpCategories2.Add("Personal Care");
                tmpCategories2.Add("Gifts");
                categories["categories"] = tmpCategories2;
                categories.Save();
                App.categories = tmpCategories2;
            }

            //delete expenses in memory

            IsolatedStorageSettings expenses = IsolatedStorageSettings.ApplicationSettings;
            expensesData data = new expensesData();

            if (expenses.TryGetValue<expensesData>("data", out data))
            {
                expenses.Remove("data");
            }

            MessageBox.Show("Data deleted successfully!");
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //proveruvame dali se prazni polinjata
            if (addDesc.Text == "" || addPrice.Text == "")
            {
                message.Text = "Text fields can not be empty!";
            }
            else
            { //proveruvame dali e validna cenata
                    int p;
                    bool isNumeric = Int32.TryParse(addPrice.Text, out p);
                    if (!isNumeric) { message.Text = "The price is not valid!"; }
                    else
                    {//proveruvame dali ima dovolno budzet
                         IsolatedStorageSettings budget = IsolatedStorageSettings.ApplicationSettings;
                         int budzet;
                         if (budget.TryGetValue<int>("budget", out budzet))
                         {
                             if (budzet < Convert.ToInt32(addPrice.Text))
                             { message.Text = "Not enough money in your budget!"; }
                             else {
                             //update storage
                             IsolatedStorageSettings expenses = IsolatedStorageSettings.ApplicationSettings;
                             expensesData data = new expensesData();

                             //ako vekje postoela barem 1 expense memorirano
                             if (expenses.TryGetValue<expensesData>("data", out data))
                             {
                                 string category = txtCategory.Text.ToString();
                                 DateTime newDate = new DateTime();
                                 DateTime.TryParse(date.Value.ToString(), out newDate);

                                 data.addNewExpense(new Expenses(category, newDate.Date, addDesc.Text.ToString(), Convert.ToInt32(addPrice.Text.ToString())));
                                 expenses["data"] = data;
                                 expenses.Save();

                                 //update vo App.data
                                 App.data = data;

                                 //update budget

                                 //tuka ako vekje postoi nekoja vrednost na budzetot vo memorija

                                 //za currency ke imame nekoja default valuta primer evro za da ne proveruvame celo vreme i dane ni pagja

                                 if (budget.TryGetValue<int>("budget", out budzet))
                                 {

                                     //odzemi od budzet i zacuvaj vo memorija
                                     budzet -= Convert.ToInt32(addPrice.Text.ToString());

                                     budget["budget"] = budzet;
                                     budget.Save();

                                     //show message
                                     message.Text = "Successfully added new expense";
                                     addDesc.Text = "";
                                     addPrice.Text = "";

                                 }
                                 else
                                     message.Text = "There was an error while adding the expense.";

                             }
                             //ako ne postoi ni 1 expense vo memorija
                             else
                             {
                                 expensesData data2 = new expensesData();
                                 string category = txtCategory.Text.ToString();
                                 DateTime newDate = new DateTime();
                                 DateTime.TryParse(date.Value.ToString(), out newDate);

                                 int price = Convert.ToInt32(addPrice.Text.ToString());

                                 data2.addNewExpense(new Expenses(category, newDate.Date, addDesc.Text.ToString(), price));
                                 expenses["data"] = data2;
                                 expenses.Save();

                                 //update vo App.data
                                 App.data = data2;

                                 //update budget

                                 //tuka ako vekje postoi nekoja vrednost na budzetot vo memorija

                                 //za currency ke imame nekoja default valuta primer evro za da ne proveruvame celo vreme i dane ni pagja

                                 if (budget.TryGetValue<int>("budget", out budzet))
                                 {
                                     //odzemi od budzet i zacuvaj vo memorija
                                     budzet -= Convert.ToInt32(addPrice.Text.ToString());
                                     budget["budget"] = budzet;
                                     budget.Save();

                                     //show message
                                     message.Text = "Successfully added new expense";
                                     addDesc.Text = "";
                                     addPrice.Text = "";

                                 }
                                 else
                                     message.Text = "There was an error while adding the expense.";

                                 //shot message
                                 message.Text = "Successfully added new expense";
                                 addDesc.Text = "";
                                 addPrice.Text = "";
                             }

                         }
            }

                         else
                         {
                             message.Text = "There was an error while adding the expense.";

                         }
                    }
            }
        }
Esempio n. 3
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            //CURRENCT AND BUDGET ********************************************

            //tuka ako vekje postoi nekoja vrednost na budzetot vo memorija

            //za currency ke imame nekoja default valuta primer evro za da ne proveruvame celo vreme i dane ni pagja

            //da proverime dali currency si ima postaveno korisnikot ako nema postavuvame default
            IsolatedStorageSettings budget = IsolatedStorageSettings.ApplicationSettings;
            int budzet;
            if (!budget.TryGetValue<int>("budget", out budzet))
            {
                budget["budget"] = 0;
                budget.Save();
            }
            string currency;
            if (budget.TryGetValue<string>("currency", out currency))
            {
                //znaci veke deka postoi i nisto ne pravime
            }
            else {
                //postavuvame default currency ako veke ne postoi

                budget["currency"] = "EUR";
                budget.Save();
            }

            // CATEGORIES   ********************************************
            IsolatedStorageSettings categories = IsolatedStorageSettings.ApplicationSettings;
            List<string> tmpCategories=new List<string>();

            //ako veke sme gi dodale nema potreba pak
            if (categories.TryGetValue<List<string>>("categories", out tmpCategories))
            {
                App.categories = tmpCategories;
            }
            //ako prv pat ja vklucuva aplikacijata treba da dodademe kategorii
            else {
                List<string> tmpCategories2 = new List<string>();
                tmpCategories2.Add("Food");
                tmpCategories2.Add("Clothing");
                tmpCategories2.Add("Bills");
                tmpCategories2.Add("Personal Care");
                tmpCategories2.Add("Gifts");
                categories["categories"] = tmpCategories2;
                categories.Save();
                App.categories = tmpCategories2;
            }

            //EXPENSES DATA ************************************************
            IsolatedStorageSettings expenses = IsolatedStorageSettings.ApplicationSettings;
            expensesData data = new expensesData();

            //ako ima nekakvi expenses na storage vekje
            if (expenses.TryGetValue<expensesData>("data", out data))
            {
                App.data = data;
            }
            else {
                //ako nema togas mu davame prazen objekt
                App.data = data;
            }
        }