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.";
                }
            }
        }
        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!";
                    }
                }
            }
        }
Exemple #4
0
 public SearchReaderPage()
 {
     InitializeComponent();
     using (var db = new ArLibCon())
     {
         results_readers.ItemsSource = db.Readers.ToList();
     }
 }
Exemple #5
0
 public SearchTransactionPage()
 {
     InitializeComponent();
     using (var db = new ArLibCon())
     {
         results_transactions.ItemsSource = db.Transactions.ToList();
     }
 }
Exemple #6
0
 public SearchBillPage()
 {
     InitializeComponent();
     using (var db = new ArLibCon())
     {
         results_bills.ItemsSource = db.Bills.ToList();
     }
 }
 public MainView()
 {
     InitializeComponent();
     using (var db = new ArLibCon())
     {
         dataGrid.ItemsSource = db.Books.ToList();
     }
 }
Exemple #8
0
 private void QuickSearch_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new ArLibCon())
     {
         string tmp   = quicksearch_tb.Text;
         var    query = db.Readers.Where(reader => (reader.ID.ToString().Contains(tmp) || reader.imię.Contains(tmp) || reader.nazwisko.Contains(tmp) || reader.adres.Contains(tmp) || reader.nrTelefonu.Contains(tmp)));
         results_readers.ItemsSource = query.ToList();
     }
 }
Exemple #9
0
 private void QuickSearch_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new ArLibCon())
     {
         string tmp   = quicksearch_tb.Text;
         var    query = db.Transactions.Where(transaction => (transaction.idWypożyczenia.ToString().Contains(tmp) || transaction.idKsiążki.ToString().Contains(tmp) || transaction.idCzytelnika.ToString().Contains(tmp)));
         results_transactions.ItemsSource = query.ToList();
     }
 }
Exemple #10
0
        private void QuickSearch_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new ArLibCon())
            {
                string tmp = quicksearch_tb.Text;

                var query = db.Bills.Where(Bill => (Bill.idKary.ToString().Contains(tmp) || Bill.wartość.ToString().Contains(tmp) || Bill.idCzytelnika.ToString().Contains(tmp)));
                results_bills.ItemsSource = query.ToList();
            }
        }
        private void QuickSearch_Click(object sender, RoutedEventArgs e)
        {
            string tmp = quicksearch_tb.Text;

            using (var db = new ArLibCon())
            {
                var query = db.Books.Where(book => (book.ID.ToString().Contains(tmp) || book.tytuł.Contains(tmp) || book.autor.Contains(tmp) || book.ISBN.Contains(tmp) || book.wydawnictwo.Contains(tmp) || book.seria.Contains(tmp)));
                dataGrid.ItemsSource = query.ToList();
            }
        }
 public ChangeAdminInfoPage()
 {
     InitializeComponent();
     using (var db = new ArLibCon())
     {
         var adm = db.Administration.First();
         name_box.Text    = adm.imię;
         surname_box.Text = adm.nazwisko;
         login_box.Text   = adm.login;
     }
 }
Exemple #13
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();
                }
            }
        }
 private void button_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new ArLibCon())
     {
         var adm = db.Administration.First();
         if (login_tb.Text == adm.login && password_tb.Password == adm.hasło)
         {
             NavigationService.Navigate(new Uri("/Pages/MainView.xaml", UriKind.RelativeOrAbsolute));
         }
         else
         {
             tmp_label.Content = "Podano błędny login i/lub hasło!";
         }
     }
 }
Exemple #15
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!";
     }
 }
Exemple #16
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!";
     }
 }
Exemple #17
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();
                    }
                }
            }
        }
Exemple #18
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!";
                }
            }
        }
Exemple #21
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();
                    }
                }
            }
        }
Exemple #22
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!";
     }
 }