Exemplo n.º 1
0
        //btns

        private void BtnReturnMedia_Click(object sender, EventArgs e)
        {
            if (activeBookingsViewRow == null)
            {
                MessageBox.Show("please select row correctly using selector column on the left.");
            }
            else
            {
                //BID == 0
                string myStrBorrowId = activeBookingsViewRow.Cells[0].Value.ToString(); //initialy it is saved as an object
                bool   parseResult   = int.TryParse(myStrBorrowId, out int borrowId);

                // set late fee
                // currently hardcoded $10
                int lateFee = 10;

                if (parseResult)
                {
                    //if (borrowLogic.updateMediaForReturn(borrowId, lateFee))

                    bool result = dtFunc.getBool(ws.updateMediaForReturn(borrowId, lateFee));
                    if (result)
                    {
                        MessageBox.Show("successfull media returned.");

                        //resfresh DGV
                        setDataForDataGridViews();
                        activeBookingsViewRow = null;  //reset active row value
                    }
                    else
                    {
                        MessageBox.Show("error media not returned on update.");
                    }
                }
                else
                {
                    MessageBox.Show("could not convert str of borrowId to int for media Return.");
                    return;
                }
            }
        }
Exemplo n.º 2
0
        private void BtnAdminResetPassword_Click(object sender, EventArgs e)
        {
            string newPass = TextBoxAdminPasswordReset.Text;

            //check if empty
            if (newPass.Length <= 0)
            {
                MessageBox.Show("please fill in the admin new password textbox ");
                return;
            }


            //bool result = userLogic.updateUserPassword(user.Id, newPass);
            bool result = dtFunc.getBool(ws.updateUserPassword(user.Id, newPass));

            if (result)
            {
                MessageBox.Show("Password updated to: " + newPass);
            }
            else
            {
                MessageBox.Show("db returned false their was an error.");
            }
        }
        private void checkOutMediaToUser(int userId)
        {
            if (activeMediaViewRow == null) // if no active row selected return
            {
                MessageBox.Show("please reselect active row");
                return;
            }

            //check if user exists


            System.Data.DataTable dt = ws.getUserById(userId);
            User curUser             = dtFunc.getOneUserFromDt(dt);

            //User curUser = userLogic.getUserById(userId); //sets user id to -1 if error
            if (curUser.Id == -1)
            {
                //ERROR couldent get user by their id
                MessageBox.Show("unable to find current user in list");
                return;
            }


            //get selected media data
            string mIdAsStr = activeMediaViewRow.Cells[0].Value.ToString();

            //checker bool
            bool result = false;

            //if mediaId parse worked correctly
            result = int.TryParse(mIdAsStr, out int mediaId);  //try parse idAsStr to int id
            if (result)
            {
                result = dtFunc.getBool(ws.getIsMediaAvailable(mediaId));
                //result = borrowLogic.getIsMediaAvailable(mediaId);

                //if media is already checked out
                if (result)
                {
                    //result = borrowLogic.insertForCheckOutMedia(userId, mediaId);
                    result = dtFunc.getBool(ws.insertForCheckOutMedia(userId, mediaId));

                    //if checkOut went smoothly
                    if (result)
                    {
                        MessageBox.Show("successfully checked out media.");
                    }
                    else
                    {
                        MessageBox.Show("error checking out media.");
                    }
                }
                else
                {
                    MessageBox.Show("Media Item is not currently available");
                }
            }
            else
            {
                MessageBox.Show("checkOut Error: could not parse mediaIdStr to mediaIdInt ");
            }
        }
        private void BtnRegister_Click(object sender, EventArgs e)
        {
            // get data
            string username  = TextBoxUsername.Text;
            string email     = TextBoxEmail.Text;
            string password  = TextBoxPassword.Text;
            int    userLevel = 1;

            if (isAdmin)
            {
                userLevel = getAdminUserLevelRadioBtnValue();
                if (userLevel == -1)
                {
                    //if for some reason no radio btn set (should default to student)
                    MessageBox.Show("Please select a userlevel for this new student");
                    return;
                }
            }


            //check fields valid
            if (username.Length == 0 || email.Length == 0 || password.Length == 0)
            {
                MessageBox.Show("Please Fill in all text boxes.");
                return;
            }


            if (userLevel == 1 || userLevel == 2)  // has to be student or admin user
            {
                //run update method
                //bool result = userLogic.insertNewUser(username, email, password, userLevel);
                bool result = dtFunc.getBool(ws.insertNewUser(username, email, password, userLevel));

                if (result)
                {
                    //reset signUp pg class vars
                    resetSignUpPgAdminStatus();

                    if (isAdmin)
                    {
                        //for more details go to STUDENT SETTINGS return btn method
                        Form mainform = Application.OpenForms["MainMenu"];
                        mainform.Show();
                        this.Close();
                    }
                    //for more details go to STUDENT SETTINGS return btn method
                    Form login = Application.OpenForms["Login"];
                    login.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("DB returned false");
                }
            }
            else
            {
                MessageBox.Show("UserLevel out of range");
                return;
            }
        }