示例#1
0
        public bool Remove_Book(objBook t_book)
        {
            try
            {
                DataContext          dbConnection = Create_DBConnection();
                Table <Book.db_Book> bookTable    = dbConnection.GetTable <Book.db_Book>();

                //Convert DB search to objects
                Book.db_Book removeBook = new Book.db_Book
                {
                    Pkey_1    = t_book.PK,
                    Name      = t_book.Name,
                    ISBN      = t_book.ISBN,
                    Author    = t_book.Author,
                    Publisher = t_book.Publisher
                };
                bookTable.Attach(removeBook);
                bookTable.DeleteOnSubmit(removeBook);
                dbConnection.SubmitChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        public bool End_Rent(string t_ISBN, DateTime t_Reservation_date, string t_username)
        {
            try
            {
                DataContext          dbConnection = Create_DBConnection();
                Table <Rent.db_Rent> rentTable    = dbConnection.GetTable <Rent.db_Rent>();
                objUser user = Get_User(t_username);
                objBook book = Get_Book(t_ISBN).First();

                //select
                var returnValue =
                    from i in rentTable
                    where i.FKey_User == user.PK && i.FKey_Book == book.PK && i.Lend_date == t_Reservation_date
                    select i;
                //Convert DB search to objects
                foreach (var i in returnValue)
                {
                    i.Return_date = DateTime.Now;
                }
                dbConnection.SubmitChanges();
            } catch
            {
                return(false);
            }
            return(true);
        }
示例#3
0
        public bool Add_Book(objBook t_book)
        {
            bool returnValue = true;

            try
            {
                //Get DB connction
                var dbConnection = Create_DBConnection();

                Book.db_Book newBook = new Book.db_Book
                {
                    Name      = t_book.Name,
                    ISBN      = t_book.ISBN,
                    Author    = t_book.Author,
                    Publisher = t_book.Publisher,
                    Amount    = t_book.Amount,
                    Avaiable  = true
                };

                //Sql insert
                Table <Book.db_Book> reservationTable = dbConnection.GetTable <Book.db_Book>();
                reservationTable.InsertOnSubmit(newBook);
                dbConnection.SubmitChanges();
            }
            catch
            {
                returnValue = false;
            }

            return(returnValue);
        }
示例#4
0
        public bool Approve_Reservation(string t_ISBN, string t_Username)
        {
            objBook book = Get_Book(t_ISBN).First();
            objUser user = Get_User(t_Username);

            try {
                var          dbConnection = Create_DBConnection();
                DateTime     today        = DateTime.Now;
                DateTime     returnDate   = today.AddDays(30);
                Rent.db_Rent rent         = new Rent.db_Rent
                {
                    Lend_date    = today,
                    End_rentdate = returnDate,
                    FKey_Book    = book.PK,
                    FKey_User    = user.PK
                };

                // Add the new object to the Orders collection.
                Table <Rent.db_Rent> rentTable = dbConnection.GetTable <Rent.db_Rent>();
                rentTable.InsertOnSubmit(rent);
                dbConnection.SubmitChanges();

                //Set done flag on Reservation
                Set_DoneFlag(t_ISBN, true);
            } catch
            {
                return(false);
            }

            return(true);
        }
示例#5
0
        private void BtnRent_Click(object sender, RoutedEventArgs e)
        {
            if (lvFoundBooks.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a book", "Please enter a search string", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            //Pop Up reservation question
            //first I should check if the book is currently avaiable
            //call function check reservation
            //Create view object
            Controller con        = new Controller();
            objBook    selectBook = (objBook)lvFoundBooks.Items[lvFoundBooks.SelectedIndex];

            if (!con.Get_ReservationState(selectBook.ISBN))
            {
                MessageBox.Show("Book is currently not avaiable", "Sorry", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            //ask for approvle
            var reservationChoice = MessageBox.Show("Do you want to make a reservation for the book " + selectBook.Name + " from " + selectBook.Author, "Are your sure?", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (reservationChoice.ToString() == "No")
            {
                return;
            }

            //Do reservation sql boooooooooooooy
            con.Set_Reseravtion(selectBook.ISBN, User);
        }
示例#6
0
        //Check if a book is currently avaiable or not
        public bool Get_ReservationState(string t_ISBN)
        {
            //Get DB connction
            var     dbConnection = Create_DBConnection();
            objBook book         = Get_Book(t_ISBN).First();

            return(book.Avaiable);
        }
示例#7
0
        //Get books by Name -> Change it later so you can search with whatever you want (more than one constructor or how can I do that?)
        public List <objBook> Get_Book(string t_name)
        {
            DataContext          dbConnection = Create_DBConnection();
            Table <Book.db_Book> bookTable    = dbConnection.GetTable <Book.db_Book>();

            //return value
            var returnList = new List <objBook>();

            //definiere nach was man suchen muss
            var returnedBooks = Enumerable.Empty <Book.db_Book>().AsQueryable();
            //checken ob es eine ISBN Nummer ist
            string pattern = @"[0-9]*[-| ][0-9]*[-| ][0-9]*[-| ][0-9]*[-| ][0-9]*";
            Regex  rg      = new Regex(pattern);

            if (rg.IsMatch(t_name))
            {
                //search for ISBN
                returnedBooks =
                    from i_u in bookTable
                    where i_u.ISBN == t_name
                    select i_u;
            }
            else if (t_name.ToLower() == "all")
            {
                returnedBooks =
                    from i_u in bookTable
                    select i_u;
            }
            else
            {
                //search for author, titel, publisher
                returnedBooks =
                    from i_u in bookTable
                    where i_u.Name == t_name || i_u.Author == t_name || i_u.Publisher == t_name
                    select i_u;
            }

            //Convert DB search to objects
            foreach (var i in returnedBooks)
            {
                var book = new objBook(i.Name, i.ISBN, i.Author, i.Publisher, i.Pkey_1, i.Amount, i.Avaiable);
                returnList.Add(book);
            }

            //Close DB connection
            dbConnection.Dispose();

            return(returnList);
        }
示例#8
0
        public bool Set_DoneFlag(string t_ISBN, bool t_value)
        {
            //Get DB connction
            var dbConnection = Create_DBConnection();
            Table <Reservation.db_Reservation> reservationTable = dbConnection.GetTable <Reservation.db_Reservation>();
            objBook book            = Get_Book(t_ISBN).First();
            var     reservationList = new List <objReservation>();

            //select
            var currentReservations =
                from i_u in reservationTable
                where i_u.FKey_Book == book.PK
                select i_u;

            foreach (var i in currentReservations)
            {
                i.Done = t_value;
            }
            dbConnection.SubmitChanges();
            return(true);
        }
示例#9
0
        //Create a reservation
        public bool Set_Reseravtion(string t_ISBN, string t_CurrentUser)
        {
            bool returnValue = true;

            try
            {
                //Get DB connction
                var dbConnection = Create_DBConnection();

                //Get_CurrentUser
                objUser user = Get_User(t_CurrentUser);

                //Get Book for reservation
                objBook book = Get_Book(t_ISBN).First();



                //Sql insert
                // Create a new Order object.
                Reservation.db_Reservation reservation = new Reservation.db_Reservation
                {
                    Reservation_date = DateTime.Now,
                    Done             = false,
                    FKey_Book        = book.PK,
                    FKey_User        = user.PK
                };

                // Add the new object to the Orders collection.
                Table <Reservation.db_Reservation> reservationTable = dbConnection.GetTable <Reservation.db_Reservation>();
                reservationTable.InsertOnSubmit(reservation);
                dbConnection.SubmitChanges();
            }
            catch
            {
                returnValue = false;
            }

            return(returnValue);
        }