Ejemplo n.º 1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     using (FinanseEntities db = new FinanseEntities())
     {
         usersList = db.Users.ToList();
     }
 }
Ejemplo n.º 2
0
 ///<summary>
 ///Metoda wyswietlajaca naleznosci i zobowiazania w listview
 /// </summary>
 public void ShowPayablesReceivable()
 {
     using (FinanseEntities db = new FinanseEntities())
     {
         ListViewPR.ItemsSource = db.PayablesReceivables.Where(s => s.UserID == User_ID).ToList();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// metoda sluzaca do zakonczenia naleznosci/zobowiazania
        /// </summary>
        public void RemovePR()
        {
            if (ListViewPR.SelectedIndex >= 0)
            {
                Bt_Remove.IsEnabled = true;
                var pR = (PayablesReceivable)ListViewPR.SelectedItem;



                if (MessageBox.Show("Zakonczyć?", "Potwierdzenie", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    if (user.AvailableFunds < pR.Amount && pR.Type == "zobowiązanie")
                    {
                        MessageBox.Show("Nie można zakończyć, brak wystarczających środków");
                    }
                    else
                    {
                        try
                        {
                            double _avFunds   = user.AvailableFunds;
                            double _amount    = pR.Amount;
                            double _newAFunds = 0;


                            if (payablesReceivable.Type == "zobowiązanie")
                            {
                                _newAFunds = _avFunds - _amount;
                            }
                            else
                            {
                                _newAFunds = _avFunds + _amount;
                            }



                            using (FinanseEntities db = new FinanseEntities())
                            {
                                user = db.Users.Where(i => i.ID_User == User_ID).FirstOrDefault();
                                user.AvailableFunds = _newAFunds;

                                var pRToDelete = (from item in db.PayablesReceivables where item.ID_PA == pR.ID_PA select item).First();
                                if (pRToDelete != null)
                                {
                                    db.PayablesReceivables.Remove(pRToDelete);
                                }
                                db.SaveChanges();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            //throw;
                        }
                    }
                }
                else
                {
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Metoda modyfikujaca dostepne srodki dostepne srodki
        /// </summary>
        public void SetAvailableFunds()
        {
            double _avFunds   = user.AvailableFunds;
            double _amount    = transaction.Amount;
            double _newAFunds = 0;


            if (transaction.Type == "wydatek")
            {
                _newAFunds = _avFunds - _amount;
            }
            else
            {
                _newAFunds = _avFunds + _amount;
            }

            try
            {
                using (FinanseEntities db = new FinanseEntities())
                {
                    user = db.Users.Where(i => i.ID_User == User_ID).FirstOrDefault();
                    user.AvailableFunds = _newAFunds;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //throw;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Funkcja logujaca użytkownika do programu
 /// </summary>
 public void LogIn()
 {
     using (FinanseEntities db = new FinanseEntities())
     {
         user = db.Users.FirstOrDefault(p => p.Login == TxB_Login.Text);
         if (user is null)
         {
             TxBl_Login.Text       = "Błędny login";
             TxBl_Login.Visibility = Visibility.Visible;
         }
         else
         {
             TxBl_Login.Visibility = Visibility.Collapsed;
             if (user.Password == PassB_Passowrd.Password)
             {
                 string UserLogin = user.Login;   //zmienna przekazujaca login użytkownika do okna głównego
                 int    UserID    = user.ID_User; //zmienna przekazujaca id użytkownika do okna głównego
                 TxBl_Password.Visibility = Visibility.Collapsed;
                 MessageBox.Show("Witaj " + user.FirstName);
                 MainWindow mainWindow = new MainWindow(UserLogin, UserID);
                 mainWindow.Show();
                 Close();
             }
             else
             {
                 TxBl_Password.Text       = "Błędne hasło";
                 TxBl_Password.Visibility = Visibility.Visible;
             }
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Metoda wyświetlająca transakcje zalogowanego użytkownika w listview w transakcjach
 /// </summary>
 public void ShowAllTransListView()
 {
     using (FinanseEntities db = new FinanseEntities())
     {
         ListViewTransaction.ItemsSource = db.Transactions.Where(s => s.UserID == User_ID).ToList();
         transactionsList = db.Transactions.Where(s => s.UserID == User_ID).ToList();
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// metoda wyswietlajaca transakcjie z wybranego miesiaca
        /// </summary>
        /// <param name="m"></param> paramtrem jest numer wbranego miesiaca
        public void TransSelMonth(int m)
        {
            var firstDay = new DateTime(DateTime.Today.Year, m, 1);
            var tmp      = firstDay.AddMonths(+1);
            var lastDay  = tmp.AddDays(-1);

            using (FinanseEntities db = new FinanseEntities())
            {
                ListViewTransaction.ItemsSource = db.Transactions.Where(s => s.UserID == User_ID).Where(d => d.Date >= firstDay && d.Date <= lastDay).ToList();
                transactionsSelMonthList        = db.Transactions.Where(s => s.UserID == User_ID).Where(d => d.Date >= firstDay && d.Date <= lastDay).ToList();
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Metoda wyswietlajaca dostepne srodki
 /// </summary>
 public void GetAvailableFunds()
 {
     try
     {
         using (FinanseEntities db = new FinanseEntities())
         {
             user = db.Users.Where(i => i.ID_User == User_ID).FirstOrDefault();
             //double tmpAvFunds = Math.Round(user.AvailableFunds, 2);
             Lb_AvFunds.Content = Math.Round(user.AvailableFunds, 2) + " zł"; //tmpAvFunds; //user.AvailableFunds.ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         //throw;
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Funkcja tworząca nowego użytkownika
        /// </summary>
        public void CreateUser()
        {
            user.FirstName = TxB_FirstName.Text.Trim();
            user.LastName  = TxB_LastName.Text.Trim();

            bool LoginCheck   = false;
            bool PassCheck    = false;
            bool AvFundsCheck = false;

            if (String.IsNullOrWhiteSpace(TxB_AvailableFunds.Text))
            {
                TxBl_AvFunds.Text       = "Wprowadź dostępne środki";
                TxBl_AvFunds.Visibility = Visibility.Visible;
                AvFundsCheck            = false;
            }
            else
            {
                TxBl_AvFunds.Visibility = Visibility.Collapsed;
                try
                {
                    user.AvailableFunds = double.Parse(TxB_AvailableFunds.Text.Trim());
                    AvFundsCheck        = true;
                }
                catch (Exception ex)
                {
                    TxBl_AvFunds.Text       = ex.Message;
                    TxBl_AvFunds.Visibility = Visibility.Visible;
                    //throw ex;
                }
            }

            if (String.IsNullOrWhiteSpace(TxB_Login.Text))
            {
                TxBl_Login.Text       = "Podaj login";
                TxBl_Login.Visibility = Visibility.Visible;
                LoginCheck            = false;
            }
            else
            {   /////////////
                foreach (var item in usersList)
                {
                    if (item.Login == TxB_Login.Text)
                    {
                        TxBl_Login.Text       = "Podany login jest zajęty";
                        TxBl_Login.Visibility = Visibility.Visible;
                        LoginCheck            = false;
                        break;
                    }
                    else
                    {
                        TxBl_Login.Visibility = Visibility.Collapsed;
                        user.Login            = TxB_Login.Text.Trim();
                        LoginCheck            = true;
                    }
                }
            }

            if (String.IsNullOrWhiteSpace(PassB_Password.Password))
            {
                TxBl_Password.Text       = "Podaj hasło";
                TxBl_Password.Visibility = Visibility.Visible;
                PassCheck = false;
            }
            else
            {
                TxBl_Password.Visibility = Visibility.Collapsed;
                user.Password            = PassB_Password.Password.Trim();
                PassCheck = true;
            }

            if (LoginCheck && PassCheck && AvFundsCheck == true)
            {
                using (FinanseEntities db = new FinanseEntities())
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                }
                MessageBox.Show("Utworzono użytkownika");
                Clear();
            }
        }
Ejemplo n.º 10
0
        ///<summary>
        ///Metoda dodająca należności i zobowiązania
        /// </summary>
        public void AddPR()
        {
            bool NameCheck   = false;
            bool AmountCheck = false;
            bool TypeCheck   = false;

            if (String.IsNullOrWhiteSpace(TxB_PR_Name.Text))
            {
                Lb_PRNameError.Content    = "Podaj nazwe transakcji";
                Lb_PRNameError.Visibility = Visibility.Visible;
                NameCheck = false;
            }
            else
            {
                Lb_PRNameError.Visibility = Visibility.Collapsed;
                payablesReceivable.Name   = TxB_PR_Name.Text.Trim();
                NameCheck = true;
            }


            if (String.IsNullOrWhiteSpace(TxB_PR_Amount.Text))
            {
                Lb_PRAmountError.Content    = "Podaj kwotę transakcji";
                Lb_PRAmountError.Visibility = Visibility.Visible;
                AmountCheck = false;
            }
            else
            {
                Lb_PRAmountError.Visibility = Visibility.Collapsed;
                try
                {
                    payablesReceivable.Amount = double.Parse(TxB_PR_Amount.Text);
                    AmountCheck = true;
                }
                catch (Exception ex)
                {
                    Lb_PRAmountError.Content    = ex.Message;
                    Lb_PRAmountError.Visibility = Visibility.Visible;
                    AmountCheck = false;
                    //throw;
                }
            }


            if (RadioB_PR_Receivable.IsChecked == true)
            {
                Lb_PRTypeError.Visibility = Visibility.Collapsed;
                payablesReceivable.Type   = "należność";
                TypeCheck = true;
            }
            else if (RadioB_PR_Payables.IsChecked == true)
            {
                Lb_PRTypeError.Visibility = Visibility.Collapsed;
                payablesReceivable.Type   = "zobowiązanie";
                TypeCheck = true;
            }
            else
            {
                Lb_PRTypeError.Content    = "Dokonaj wyboru";
                Lb_PRTypeError.Visibility = Visibility.Visible;
                TypeCheck = false;
            }


            payablesReceivable.Description = TxB_PR_Desc.Text;
            payablesReceivable.UserID      = User_ID;
            payablesReceivable.Date        = DateTime.Now;


            if (NameCheck && AmountCheck && TypeCheck == true)
            {
                if (user.AvailableFunds < double.Parse(TxB_PR_Amount.Text) && RadioB_PR_Receivable.IsChecked == true)
                {
                    MessageBox.Show("Nie można dodać, brak wystarczających środków");
                }
                else
                {
                    try
                    {
                        using (FinanseEntities db = new FinanseEntities())
                        {
                            db.PayablesReceivables.Add(payablesReceivable);
                            db.SaveChanges();
                        }
                        MessageBox.Show("Dodano poprawnie");
                        ClearPR();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        //throw;
                    }

                    ///////////////////////////////////////

                    double _avFunds   = user.AvailableFunds;
                    double _amount    = payablesReceivable.Amount;
                    double _newAFunds = 0;


                    if (payablesReceivable.Type == "zobowiązanie")
                    {
                        _newAFunds = _avFunds + _amount;
                    }
                    else
                    {
                        _newAFunds = _avFunds - _amount;
                    }

                    try
                    {
                        using (FinanseEntities db = new FinanseEntities())
                        {
                            user = db.Users.Where(i => i.ID_User == User_ID).FirstOrDefault();
                            user.AvailableFunds = _newAFunds;
                            db.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        //throw;
                    }
                    ///////////////////////////////////////
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Metoda dodajaca transakcje
        /// </summary>
        public void AddTransaction()
        {
            bool NameCheck   = false;
            bool AmountCheck = false;
            bool TypeCheck   = false;



            if (String.IsNullOrWhiteSpace(TxB_Name.Text))
            {
                Lb_NameError.Content    = "Podaj nazwe transakcji";
                Lb_NameError.Visibility = Visibility.Visible;
                NameCheck = false;
            }
            else
            {
                Lb_NameError.Visibility = Visibility.Collapsed;
                transaction.Name        = TxB_Name.Text.Trim();
                NameCheck = true;
            }


            if (String.IsNullOrWhiteSpace(TxB_Amount.Text))
            {
                Lb_AmountError.Content    = "Podaj kwotę transakcji";
                Lb_AmountError.Visibility = Visibility.Visible;
                AmountCheck = false;
            }
            else
            {
                Lb_AmountError.Visibility = Visibility.Collapsed;
                try
                {
                    transaction.Amount = Math.Round(double.Parse(TxB_Amount.Text), 2);
                    AmountCheck        = true;
                }
                catch (Exception ex)
                {
                    Lb_AmountError.Content    = ex.Message;
                    Lb_AmountError.Visibility = Visibility.Visible;
                    AmountCheck = false;
                    //throw;
                }
            }


            if (RadioB_Expense.IsChecked == true)
            {
                Lb_TypeError.Visibility = Visibility.Collapsed;
                transaction.Type        = "wydatek";
                TypeCheck = true;
            }
            else if (RadioB_Income.IsChecked == true)
            {
                Lb_TypeError.Visibility = Visibility.Collapsed;
                transaction.Type        = "przychod";
                TypeCheck = true;
            }
            else
            {
                Lb_TypeError.Content    = "Dokonaj wyboru";
                Lb_TypeError.Visibility = Visibility.Visible;
                TypeCheck = false;
            }


            transaction.Description = TxB_Desc.Text;
            transaction.UserID      = User_ID;
            transaction.Date        = DateTime.Now;


            if (NameCheck && AmountCheck && TypeCheck == true)
            {
                if (user.AvailableFunds < double.Parse(TxB_Amount.Text) && RadioB_Expense.IsChecked == true)
                {
                    MessageBox.Show("Nie można dodać transakcji, brak wystarczających środków");
                }
                else
                {
                    try
                    {
                        using (FinanseEntities db = new FinanseEntities())
                        {
                            db.Transactions.Add(transaction);
                            db.SaveChanges();
                        }
                        MessageBox.Show("Transakcja dodana");
                        SetAvailableFunds();
                        ClearTrans();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        //throw;
                    }
                }
            }
        }