Пример #1
0
        public static int BorrowExtendsCount(BorrowedBook borrowedBook)
        {
            string command = "SELECT ilosc_przedluzen FROM zamowienia WHERE id_zamowienia = " + borrowedBook.Id;
            int    count   = Convert.ToInt32(DoScalar(command));

            return(count);
        }
Пример #2
0
        private void BtnExtendEvent(object sender, RoutedEventArgs e)
        {
            MainWindow mainWindow = Window.GetWindow(this) as MainWindow;

            if (DatabaseManager.user == null)
            {
                mainWindow.ShowLoginPage();
                return;
            }

            BorrowedBook borrowedBook = ((FrameworkElement)sender).DataContext as BorrowedBook;

            if (!DatabaseManager.IsBorrowAccepted(borrowedBook))
            {
                return;
            }
            if (DatabaseManager.IsBorrowReturned(borrowedBook))
            {
                return;
            }
            if (DatabaseManager.BorrowExtendsCount(borrowedBook) >= 2)
            {
                return;
            }
            DatabaseManager.ExtendBorrow(borrowedBook);
            UpdateBorrows();
        }
Пример #3
0
        public static bool IsBorrowReturned(BorrowedBook borrowedBook)
        {
            string command = "SELECT termin_oddania FROM zamowienia WHERE id_zamowienia = " + borrowedBook.Id;

            Nullable <DateTime> dataOddania = DoScalar(command) as Nullable <DateTime>;

            return(dataOddania != null);
        }
Пример #4
0
        public static void ExtendBorrow(BorrowedBook borrowedBook)
        {
            List <string> commands = new List <string>();

            String date = DateTime.Now.ToString("yy-MM-dd");

            commands.Add(
                "UPDATE zamowienia SET ilosc_przedluzen = ilosc_przedluzen + 1 WHERE id_zamowienia = " + borrowedBook.Id
                );

            commands.Add(
                "INSERT INTO logi (id_uzytkownik, operacja, data_wykonania)" +
                " VALUES (" + borrowedBook.IdUser + ", 'przedluzenie id_zamowienia = " + borrowedBook.Id + "', '" + date + "')"
                );

            DoTransaction(commands);
        }
Пример #5
0
        public static void AcceptBorrow(BorrowedBook borrowedBook)
        {
            List <string> commands = new List <string>();

            String date = DateTime.Now.ToString("yy-MM-dd");

            commands.Add(
                "UPDATE zamowienia SET termin_odbioru = '" + date + "' WHERE id_zamowienia = " + borrowedBook.Id
                );

            commands.Add(
                "INSERT INTO logi (id_uzytkownik, operacja, data_wykonania)" +
                " VALUES (" + borrowedBook.IdUser + ", 'odebranie id_zamowienia = " + borrowedBook.Id + "', '" + date + "')"
                );

            DoTransaction(commands);
        }
Пример #6
0
        public static void ReturnBorrow(BorrowedBook borrowedBook)
        {
            List <string> commands = new List <string>();

            String date = DateTime.Now.ToString("yy-MM-dd");

            commands.Add(
                "UPDATE zamowienia SET termin_oddania = '" + date + "' WHERE id_zamowienia = " + borrowedBook.Id
                );

            commands.Add(
                "UPDATE stan_ksiazek SET ilosc_dostepna = ilosc_dostepna + 1 WHERE id_ksiazka = " + borrowedBook.IdBook
                );

            commands.Add(
                "INSERT INTO logi (id_uzytkownik, operacja, data_wykonania)" +
                " VALUES (" + borrowedBook.IdUser + ", 'oddanie id_zamowienia = " + borrowedBook.Id + "', '" + date + "')"
                );

            DoTransaction(commands);
        }
Пример #7
0
        public static List <BorrowedBook> GetBorrowedBooks(User user1, int page, int count)
        {
            string command = "SELECT z.id_zamowienia, z. id_uzytkownik, z.id_ksiazka, k.autor, k.tytul, z.termin_wypozyczenia, z.termin_odbioru, z.termin_oddania, z.ilosc_przedluzen " +
                             "FROM zamowienia z, ksiazki k WHERE z.id_uzytkownik = " + user1.Id +
                             " AND z.id_ksiazka = k.id_ksiazka ORDER BY termin_wypozyczenia" +
                             " OFFSET " + (page * count) + " ROW FETCH NEXT " + count + " ROWS ONLY";

            DataTable dt = GetDataTable(command);

            List <BorrowedBook> borrowedBooks = new List <BorrowedBook>();

            foreach (DataRow row in dt.Rows)
            {
                BorrowedBook borrowedBook = new BorrowedBook();
                borrowedBook.Id     = row["id_zamowienia"] as Nullable <decimal>;
                borrowedBook.IdUser = row["id_uzytkownik"] as Nullable <decimal>;
                borrowedBook.IdBook = row["id_ksiazka"] as Nullable <decimal>;
                borrowedBook.Autor  = row["autor"] as string;
                borrowedBook.Tytul  = row["tytul"] as string;

                Nullable <DateTime> dataWypozyczenia = row["termin_wypozyczenia"] as Nullable <DateTime>;
                borrowedBook.DataWypozyczenia = dataWypozyczenia == null ? null : dataWypozyczenia.Value.ToString("dd-MM-yyyy");

                Nullable <DateTime> dataOdbioru = row["termin_odbioru"] as Nullable <DateTime>;
                borrowedBook.DataOdbioru = dataOdbioru == null ? null : dataOdbioru.Value.ToString("dd-MM-yyyy");

                Nullable <DateTime> dataOddania = row["termin_oddania"] as Nullable <DateTime>;
                borrowedBook.DataOddania = dataOddania == null ? null : dataOddania.Value.ToString("dd-MM-yyyy");

                borrowedBook.IloscPrzedluzen = row["ilosc_przedluzen"] as Nullable <decimal>;

                borrowedBooks.Add(borrowedBook);
            }

            return(borrowedBooks);
        }