예제 #1
0
        /// <summary>
        /// Logic for button (save new dream in database and on dream page)
        /// </summary>
        private void add_Click(object sender, RoutedEventArgs e)
        {
            if (dbContext.Set <Dream>().Where(d => d.UserId == controller.user.Id).ToList().Count != 0)
            {
                dbContext.Set <Dream>().RemoveRange(dbContext.Set <Dream>().Where(d => d.UserId == controller.user.Id));
            }
            dreamPage.dreamName              = DreamName.Text;
            dreamPage.dreamPrice             = Double.Parse(DreamPrice.Text);
            dreamPage.dreamNameLabel.Content = dreamPage.dreamName + " " + dreamPage.dreamPrice;

            if (Double.TryParse(DreamPrice.Text, out double amount))
            {
                Dream dream = new Dream();
                dream.UserId = controller.user.Id;
                dream.Name   = DreamName.Text;
                dream.Price  = amount;

                dbContext.Set <Dream>().Add(dream);
                dbContext.SaveChanges();

                dreamPage.UpdateProgressBar();
                this.Close();
            }
            else
            {
                MessageBox.Show("Wrong price entered");
            }
        }
예제 #2
0
 /// <summary>
 /// Function, which  chooses tmo-month's expenses and incomes, calls the function for drawing grafics
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void but_Click(object sender, RoutedEventArgs e)
 {
     expenses  = dbContext.Set <Expense>().ToList().FindAll(u => (u.Date.Month == mounth[0]));
     expenses2 = dbContext.Set <Expense>().ToList().FindAll(u => (u.Date.Month == mounth[1]));
     incomes1  = dbContext.Set <Income>().ToList().FindAll(u => (u.Date.Month == mounth[0]));
     incomes2  = dbContext.Set <Income>().ToList().FindAll(u => (u.Date.Month == mounth[1]));
     CreatePoints();
     col1.Visibility = Visibility.Visible;
     graf_1.Content  = monthes[mounth[0]];
     col2.Visibility = Visibility.Visible;
     graf_2.Content  = monthes[mounth[1]];
 }
예제 #3
0
        /// <summary>
        /// logic for progress bar (function for change progress bar when change amount of money in user)
        /// </summary>
        public void UpdateProgressBar()
        {
            double totalExpance = dbContext.Set <Expense>().ToList().Where(e => (e.UserId == controller.user.Id)).Sum(e => e.AmountOfMoney);
            double totalIncome  = dbContext.Set <Income>().ToList().Where(e => (e.UserId == controller.user.Id)).Sum(e => e.MoneyCount);
            double difference   = (totalIncome - totalExpance);

            if (difference >= 0)
            {
                ProgressBar.Value = (difference * 100) / dbContext.Set <Dream>().ToList().Find(p => p.UserId == controller.user.Id).Price;
                money.Text        = "(" + difference + " UAH)";
            }
            else
            {
                ProgressBar.Value = 0;
            }
        }
예제 #4
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            // Validation of field price
            if (Double.TryParse(price.Text, out double amount))
            {
                CategoryRepository categories = new CategoryRepository();
                Category           cat        = categories.GetItems().Find(c => c.Name == category);

                // Adding new expense to database
                Expense expense = new Expense();
                expense.CategoryId    = cat.Id;
                expense.AmountOfMoney = amount;
                expense.Date          = date;
                expense.UserId        = controller.user.Id;

                dbContext.Set <Expense>().Add(expense);
                dbContext.SaveChanges();

                // Updating progress bar
                expensePage.SetProgressBar(date);
                this.Close();
            }
            else
            {
                MessageBox.Show("Wrong price entered");
            }
        }
예제 #5
0
        private void SignInButton_Click(object sender, RoutedEventArgs e)
        {
            bool checkPassed = true;

            checkPassed &= mail.Text.Length != 0 && App.ContainAtSign(mail.Text);
            checkPassed &= password.Text.Length != 0;
            if (checkPassed)
            {
                User user = dbContext.Set <User>().ToList().Find(u => (u.Email == mail.Text && u.Password == savedPassword));

                if (user == null)
                {
                    MessageBox.Show("Incorrect data");
                }
                else
                {
                    controller.user = user;
                    controller.OpenPage(MainWindow.pages.home);
                }
            }
            else
            {
                MessageBox.Show("Incorrect data");
            }
        }
예제 #6
0
        public void ShowResult(double money, int?catcheck)
        {
            double user_income_written = database_variable.Set <Income>().ToList().Where(e => (e.UserId == controller.user.Id && e.Date.Month == month_id)).Sum(e => e.MoneyCount);

            if (catcheck == 1)
            {
                active_sum        = asum + money;
                progressBar.Value = asum + money;
            }
            if (catcheck == 2)
            {
                passive_sum        = psum + money;
                progressBar2.Value = psum + money;
            }

            total_sum       = active_sum + passive_sum;
            active.Content  = active_sum.ToString();
            passive.Content = passive_sum.ToString();
            total.Content   = total_sum.ToString();
        }
예제 #7
0
        private void SignUpButton_Click(object sender, RoutedEventArgs e)
        {
            bool checkPassed = true;

            // Check data and write to db:
            checkPassed &= name.Text.Length != 0 && !App.ContainNumbers(name.Text);
            checkPassed &= surname.Text.Length != 0 && !App.ContainNumbers(surname.Text);
            checkPassed &= mail.Text.Length != 0 && App.ContainAtSign(mail.Text);
            checkPassed &= (String.Equals(savedPassword, savedConfirmPassword) && savedPassword.Length != 0 && savedConfirmPassword.Length != 0);

            if (checkPassed)
            {
                User u = dbContext.Set <User>().ToList().Find(u => (u.Email == mail.Text));
                if (u == null)
                {
                    User user = new User
                    {
                        Name     = name.Text,
                        Surname  = surname.Text,
                        Email    = mail.Text,
                        Password = savedPassword
                    };

                    dbContext.Set <User>().Add(user);
                    dbContext.SaveChanges();

                    controller.user = user;

                    controller.OpenPage(MainWindow.pages.home);
                }
                else
                {
                    MessageBox.Show("User with entered email is already exist");
                }
            }
            else
            {
                MessageBox.Show("Check data failed");
            }
        }
예제 #8
0
        private void Add_Income_Click(object sender, RoutedEventArgs e)
        {
            if (Double.TryParse(price.Text, out double amount))
            {
                Category categ      = database_variable.Set <Category>().ToList().Find(a => a.Name == category);
                Income   new_income = new Income();

                new_income.CategoryId    = categ.Id;
                new_income.MoneyCount    = Double.Parse(price.Text);
                new_income.Date          = date;
                new_income.UserId        = controller.user.Id;
                new_income.CategoryCheck = categ.CategoryType;


                database_variable.Set <Income>().Add(new_income);
                database_variable.SaveChanges();
                incomePage.ShowResult(new_income.MoneyCount, new_income.CategoryCheck);
                this.Close();
            }
            else
            {
                MessageBox.Show("Wrong price entered!");
            }
        }
예제 #9
0
        public DreamPage(MainWindow _mainWindow)
        {
            InitializeComponent();
            controller = _mainWindow;
            dbContext  = new MonnyDbContext();

            /// <summary>
            /// Array phrases
            /// </summary>
            phrases     = new string[13];
            phrases[0]  = "The best things in life are free.";
            phrases[1]  = "There are things more important than money, \n but you don't buy them without money.";
            phrases[2]  = "Money is a holiday that is always with you.";
            phrases[3]  = "Money doesn't grow on trees.";
            phrases[4]  = "The happiness is in the purchases rather than \n the actual money.";
            phrases[5]  = "Wealth is the ability to spend less than you earn.";
            phrases[6]  = "Wealth is the ability to invest.";
            phrases[7]  = "A rich one is not the one who earns a lot, \n rather the one who spends a little.";
            phrases[8]  = "The poor is not the one who has no money \n but the one who has no dream.";
            phrases[9]  = " The ability to properly manage money \n is one of  the main qualities of rich people.";
            phrases[10] = " Wealth does not come from desires. \n It comes from a thoughtful plan of action \n and from hard work.";
            phrases[11] = "You shouldnt bring the topic of money, \n with people who earn either much more \n or much less.";
            phrases[12] = "It's not about the money, but rather \n the amount.";
            generatePhrase();


            /// <summary>
            /// show page
            /// </summary>
            Dream dreamCheck = dbContext.Set <Dream>().ToList().Find(d => d.UserId == controller.user.Id);

            if (dreamCheck != null)
            {
                dreamNameLabel.Content = dreamCheck.Name;
                dreamNameLabel.Content = dreamNameLabel.Content + " " + dreamCheck.Price.ToString();
                UpdateProgressBar();
            }
        }
예제 #10
0
 public List <Expense> GetExpensesForThismonth(int userId)
 {
     return(dbContext.Set <Expense>().Where(
                expense => expense.Date.Month == DateTime.Now.Month &&
                expense.UserId == userId).ToList());
 }
예제 #11
0
 public Limitation GetItemByUserId(int id)
 {
     return(dbContext.Set <Limitation>().FirstOrDefault(l => l.UserId == id));
 }
예제 #12
0
 public List <Expense> GetItems()
 {
     return(dbContext.Set <Expense>().ToList());
 }
예제 #13
0
 public List <Income> GetItems()
 {
     return(dbContext.Set <Income>().ToList());
 }
예제 #14
0
 public List <User> GetItems()
 {
     return(dbContext.Set <User>().ToList());
 }
예제 #15
0
 public User GetItem(int id)
 {
     return(dbContext.Set <User>().Find(id));
 }
예제 #16
0
 public List <Category> GetItems()
 {
     return(dbContext.Set <Category>().ToList());
 }
예제 #17
0
 public List <CustomCategory> GetItems(int userId)
 {
     return(dbContext.Set <CustomCategory>().Where(customCategory =>
                                                   customCategory.UserId == userId).ToList());
 }