private void change_button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            using (var db = new ArLibCon())
            {
                var adm = db.Administration.First();

                if (name_box.Text != "" && surname_box.Text != "" && login_box.Text != "" && password_box.Password != "")
                {
                    if (password_box.Password == adm.hasło)
                    {
                        adm.imię     = name_box.Text;
                        adm.nazwisko = surname_box.Text;
                        adm.login    = login_box.Text;

                        label.Content = "Dane zmieniono poprawnie.";

                        db.SaveChanges();
                    }
                }
                else
                {
                    label.Content = "Uzupełnij wszystkie dane poprawnie!";
                }
            }
        }
        private void restore_button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            using (var db = new ArLibCon())
            {
                var adm = db.Administration.First();

                if (name_box.Text != "" && surname_box.Text != "" && login_box.Text != "")
                {
                    if (name_box.Text == adm.imię && surname_box.Text == adm.nazwisko && login_box.Text == adm.login)
                    {
                        Random random = new Random();
                        string chars  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                        string hasło  = new string(Enumerable.Repeat(chars, 8).Select(s => s[random.Next(s.Length)]).ToArray());
                        adm.hasło = hasło;
                        db.SaveChanges();

                        label.Content = "Nowe hasło użytkownika to: " + hasło;
                    }
                    else
                    {
                        label.Content = "Podano nieprawidłowe dane!";
                    }
                }
            }
        }
        private void transaction_button_Click(object sender, RoutedEventArgs e)
        {
            StaticTemp.selectedReader = (Reader)results_readers.SelectedItem;
            Transaction tmp = new Transaction(StaticTemp.selectedBook, StaticTemp.selectedReader);

            using (var db = new ArLibCon())
            {
                var result  = db.Books.SingleOrDefault(b => b.ID == StaticTemp.selectedBook.ID);
                var result2 = db.Readers.SingleOrDefault(b => b.ID == StaticTemp.selectedReader.ID);

                if (result != null && result2 != null && StaticTemp.selectedReader.limitWypożyczeń > 0 && StaticTemp.selectedBook.czyWypożyczona == false)
                {
                    result.czyWypożyczona    = true;
                    result2.limitWypożyczeń -= 1;
                    db.Transactions.Add(tmp);

                    db.SaveChanges();
                    MessageBox.Show("Pomyślnie wypożyczono!");
                    NavigationService.Navigate(new Uri("/Pages/MainView.xaml", UriKind.RelativeOrAbsolute));
                }
                else if (StaticTemp.selectedReader.limitWypożyczeń <= 0)
                {
                    tmp_label.Content = "Użytkownik nie może wypożyczyć \nwięcej książek!";
                }
                else if (StaticTemp.selectedBook.czyWypożyczona == true)
                {
                    tmp_label.Content = "Książka już została wypożyczona!";
                }
                else
                {
                    tmp_label.Content = "Nastąpił problem przy wypożyczeniu. \nWciśnij powrót i spróbuj ponownie.";
                }
            }
        }
Beispiel #4
0
        private void returnBook_Click(object sender, RoutedEventArgs e)
        {
            if (results_transactions.SelectedItem != null)
            {
                using (var db = new ArLibCon())
                {
                    Transaction selected     = (Transaction)results_transactions.SelectedItem;
                    var         selectedBook = db.Books.SingleOrDefault(b => b.ID == selected.idKsiążki);
                    if (selectedBook.czyWypożyczona == true)
                    {
                        var transaction = db.Transactions.SingleOrDefault(b => (b.idKsiążki == selectedBook.ID && b.czyZwrócona == false));
                        var reader      = db.Readers.SingleOrDefault(b => b.ID == transaction.idCzytelnika);
                        var book        = db.Books.SingleOrDefault(b => b.ID == selectedBook.ID);

                        transaction.dataZwrotu  = DateTime.Now;
                        transaction.czyZwrócona = true;
                        reader.limitWypożyczeń += 1;
                        book.czyWypożyczona     = false;
                        book.czyZagubiona       = false;

                        db.SaveChanges();

                        if (transaction.dataZwrotu > transaction.terminOddania)
                        {
                            if (transaction.dataZwrotu.HasValue)
                            {
                                double wartośćKary = (transaction.dataZwrotu - transaction.terminOddania).Value.TotalDays * 20;
                                Bill   bill        = new Bill(reader.ID, DateTime.Today, wartośćKary);
                                db.Bills.Add(bill);
                                db.SaveChanges();
                                MessageBox.Show("Naliczono karę o wartości: " + wartośćKary);
                            }
                        }
                        MessageBox.Show("Pomyślnie zwrócono książkę!");
                        NavigationService.Refresh();
                    }
                }
            }
        }
Beispiel #5
0
        private void payBill_button_Click(object sender, RoutedEventArgs e)
        {
            if (results_bills.SelectedItem != null)
            {
                using (var db = new ArLibCon())
                {
                    Bill tmp    = (Bill)results_bills.SelectedItem;
                    var  chosen = db.Bills.SingleOrDefault(bill => bill.idKary == tmp.idKary);

                    chosen.czyOpłacona = true;
                    db.SaveChanges();
                    NavigationService.Refresh();
                }
            }
        }
Beispiel #6
0
 private void add_button_Click(object sender, RoutedEventArgs e)
 {
     if (title_box.Text != "" && author_box.Text != "" && isbn_box.Text != "" && pages_box.Text != "" && publisher_box.Text != "")
     {
         Book tmp = new Book(title_box.Text, author_box.Text, isbn_box.Text, pages_box.Text, publisher_box.Text, series_box.Text);
         using (var db = new ArLibCon())
         {
             db.Books.Add(tmp);
             db.SaveChanges();
         }
         tmp_label.Content = "Pomyślnie dodano! Wciśnij Powrót.";
     }
     else
     {
         tmp_label.Content = "Uzupełnij wszystkie wymagane pola!";
     }
 }
Beispiel #7
0
 private void add_button_Click(object sender, RoutedEventArgs e)
 {
     if (name_box.Text != "" && surname_box.Text != "" && address_box.Text != "" && number_box.Text != "")
     {
         Reader tmp = new Reader(name_box.Text, surname_box.Text, address_box.Text, number_box.Text);
         using (var db = new ArLibCon())
         {
             db.Readers.Add(tmp);
             db.SaveChanges();
         }
         tmp_label.Content = "Pomyślnie dodano! Wciśnij Powrót.";
     }
     else
     {
         tmp_label.Content = "Uzupełnij wszystkie wymagane pola!";
     }
 }
Beispiel #8
0
        private void deleteReader_button_Click(object sender, RoutedEventArgs e)
        {
            if (results_readers.SelectedItem != null)
            {
                if (MessageBox.Show("Czy na pewno usunąć?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    using (var db = new ArLibCon())
                    {
                        Reader tmp   = (Reader)results_readers.SelectedItem;
                        var    query = db.Readers.Where(reader => reader.ID == tmp.ID);

                        db.Readers.RemoveRange(query);
                        db.SaveChanges();
                        NavigationService.Refresh();
                    }
                }
            }
        }
Beispiel #9
0
        private void deleteTransaction_button_Click(object sender, RoutedEventArgs e)
        {
            if (results_transactions.SelectedItem != null)
            {
                if (MessageBox.Show("Czy na pewno usunąć?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    using (var db = new ArLibCon())
                    {
                        Transaction tmp   = (Transaction)results_transactions.SelectedItem;
                        var         query = db.Transactions.Where(transaction => transaction.idWypożyczenia == tmp.idWypożyczenia);

                        db.Transactions.RemoveRange(query);
                        db.SaveChanges();
                        NavigationService.Refresh();
                    }
                }
            }
        }
 private void edit_button_Click(object sender, RoutedEventArgs e)
 {
     if (name_box.Text != "" && surname_box.Text != "" && address_box.Text != "" && number_box.Text != "")
     {
         using (var db = new ArLibCon())
         {
             var editedReader = db.Readers.SingleOrDefault(b => b.ID == StaticTemp.selectedReader.ID);
             editedReader.imię       = name_box.Text;
             editedReader.nazwisko   = surname_box.Text;
             editedReader.adres      = address_box.Text;
             editedReader.nrTelefonu = number_box.Text;
             db.SaveChanges();
         }
         tmp_label.Content = "Pomyślnie zmieniono! Wciśnij Powrót.";
     }
     else
     {
         tmp_label.Content = "Uzupełnij wszystkie wymagane pola!";
     }
 }
        private void change_button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            using (var db = new ArLibCon())
            {
                var adm = db.Administration.First();

                if (login_box.Text != "" && old_password_box.Password != "" && new_password_box.Password != "")
                {
                    if (login_box.Text == adm.login && old_password_box.Password == adm.hasło)
                    {
                        adm.hasło = new_password_box.Password;
                        db.SaveChanges();
                        label.Content = "Poprawnie zmieniono hasło.";
                    }
                }
                else
                {
                    label.Content = "Uzupełnij wszystkie dane poprawnie!";
                }
            }
        }
Beispiel #12
0
 private void edit_button_Click(object sender, RoutedEventArgs e)
 {
     if (title_box.Text != "" && author_box.Text != "" && isbn_box.Text != "" && pages_box.Text != "" && publisher_box.Text != "")
     {
         using (var db = new ArLibCon())
         {
             var editedBook = db.Books.SingleOrDefault(b => b.ID == StaticTemp.selectedBook.ID);
             editedBook.tytuł       = title_box.Text;
             editedBook.autor       = author_box.Text;
             editedBook.ISBN        = isbn_box.Text;
             editedBook.liczbaStron = pages_box.Text;
             editedBook.wydawnictwo = publisher_box.Text;
             editedBook.seria       = series_box.Text;
             db.SaveChanges();
         }
         tmp_label.Content = "Pomyślnie zmieniono! Wciśnij Powrót.";
     }
     else
     {
         tmp_label.Content = "Uzupełnij wszystkie wymagane pola!";
     }
 }