Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        //Get user by username
        public objUser Get_User(string t_username)
        {
            try
            {
                DataContext          dbConnection = Create_DBConnection();
                Table <User.db_User> userTable    = dbConnection.GetTable <User.db_User>();


                var returnList = new List <objUser>();

                //select
                var returnValue =
                    from i_u in userTable
                    where i_u.Username == t_username
                    select i_u;
                //Convert DB search to objects
                foreach (var i in returnValue)
                {
                    var customer = new objUser(i.Username, i.Password, i.Surname, i.Last_name, i.Adress, i.ZIP, i.City, i.Pkey_1, i.Write, i.Write_rent);
                    returnList.Add(customer);
                }

                //Close DB connection
                dbConnection.Dispose();

                objUser userReturn = returnList.First();

                return(userReturn);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #4
0
        private void BntLogin_Click(object sender, RoutedEventArgs e)
        {
            //Create view object
            Controller con= new Controller();

            //Call login function
            bool loginCorrect = con.Login(txtUsername.Text, txtPassword.Password);
            
            //Create user interface
            if (loginCorrect)
            {
                objUser currentUser = con.Get_User(txtUsername.Text);
                if (currentUser.Write == true || currentUser.Write_rent == true) {
                    AdminInterface guiAdmin = new AdminInterface(txtUsername.Text);
                    guiAdmin.Show();
                }
                else
                {
                    UserInterface guiUser = new UserInterface(txtUsername.Text);
                    guiUser.Show();
                }
            } else
            {

                MessageBox.Show("Username or password is not correct", "Invalide credntials", MessageBoxButton.OK,MessageBoxImage.Exclamation);
            }
        }
Beispiel #5
0
        // Simplifyes the code in the view
        public bool Login(string t_username, string t_password)
        {
            //Check if username and pass which where provides are correct
            bool returnValue = false;

            objUser objUser = Get_User(t_username);

            if (objUser.Password == t_password)
            {
                returnValue = true;
            }

            return(returnValue);
        }
Beispiel #6
0
        public void Set_AdminPermission(objUser t_User, GUI.AdminInterface t_IntAdmin)
        {
            if (t_User.Write == true)
            {
                t_IntAdmin.tbAddBook.IsEnabled    = true;
                t_IntAdmin.tbRemoveBook.IsEnabled = true;
            }

            if (t_User.Write_rent == true)
            {
                t_IntAdmin.tbApprovel.IsEnabled      = true;
                t_IntAdmin.tbCurrentRent.IsEnabled   = true;
                t_IntAdmin.tbTriggerRental.IsEnabled = true;
            }

            if (t_User.Write == false && t_User.Write_rent == false)
            {
                t_IntAdmin.tbReport.Focus();
            }
        }
Beispiel #7
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);
        }