Example #1
0
        private void button_Click(object sender, RoutedEventArgs e)//cancel button
        {
            //return user to admin homepage
            AdminHome ah = new AdminHome();

            ah.Show();
            this.Close();
        }
Example #2
0
//        private void button_Click_1(object sender, RoutedEventArgs e) //placeholder?
//        {
//           /* Microsoft.Win32.OpenFileDialog dlg =
//new Microsoft.Win32.OpenFileDialog();
//            dlg.ShowDialog();

//            FileStream fs = new FileStream(dlg.FileName, FileMode.Open,
//FileAccess.Read);

//            byte[] data = new byte[fs.Length];
//            fs.Read(data, 0, System.Convert.ToInt32(fs.Length));

//            fs.Close();
//            ImageSourceConverter imgs = new ImageSourceConverter();
//            imagebox.SetValue(Image.SourceProperty, imgs.
//            ConvertFromString(dlg.FileName.ToString()));*/
//        }
        private void button_Click(object sender, RoutedEventArgs e)//register button
        {
            Book    book = new Book();
            int     stock;
            Double  price;
            Boolean okay      = book.ISBN_Cheker(txtIsbn.Text);            //check isbn is valid
            Boolean testPrice = Double.TryParse(txtPrice.Text, out price); //check price is valid
            Boolean testStock = Int32.TryParse(txtStock.Text, out stock);  //check stock is a valid number

            if (okay == false)
            {
                MessageBox.Show("Invalid ISBN. Please enter a valid 10 digit ISBN-10 number.");
            }
            if (txtTitle.Text != "" && txtAuthor.Text != "" && txtPrice.Text != "" && txtStock.Text != "" && txtIsbn.Text != "")//make sure no fields are empty
            {
                string title, author;
                title  = Regex.Replace(txtTitle.Text, @"[^\w\d\s]+", ""); //remove any special characters
                author = Regex.Replace(txtAuthor.Text, @"[^\w\d\s]+", "");
                if (okay && testPrice && testStock)                       //if everything is valid
                {
                    book.Title  = title;
                    book.Author = author;
                    if (txtEdition.Text == "")    //if no edition is entered it will be considered 1st edition
                    {
                        book.Edition = "1st";
                    }
                    else
                    {
                        book.Edition = txtEdition.Text.Replace("edition", "").Replace("Edition", "").Replace("ed.", "");    //removes edition
                    }
                    book.Price = Convert.ToDouble(txtPrice.Text);
                    book.ISBN  = txtIsbn.Text;
                    Boolean added = book.ADD_Book(book.Title, book.Author, book.Edition, book.Price, book.ISBN, 0, stock); //adds book to database
                    if (added)                                                                                             //if add is successfull
                    {
                        AdminHome ah = new AdminHome();
                        ah.Show();
                        this.Close();
                    }
                }
                else if (!testPrice)    //if price is invalid
                {
                    MessageBox.Show("Invalid Price. Do not include \"$\".");
                }
                else if (!testStock)    //if stock entry is invalid
                {
                    MessageBox.Show("Invalid stock. Whole Numbers only!");
                }
            }
            else     //if fields are empty
            {
                MessageBox.Show("Make sure all fields are filled.");
            }
        }
        private void updatebook(object sender, RoutedEventArgs e)//updates the book with the entered data
        {
            Book    se = new Book();
            int     stock;
            Double  price;
            Boolean okay      = se.ISBN_Cheker(txtIsbn.Text);                           //check for valid isbn
            Boolean testPrice = Double.TryParse(txtPrice.Text, out price);              //check for valid price
            Boolean testStock = Int32.TryParse(txtStock.Text, out stock);               //check for valid stock

            if (!label_isbnholder.Content.Equals("") && okay && testPrice && testStock) //makes sure data is valid and book has been searched
            {
                if (txtTitle.Text != "" && txtAuthor.Text != "" && txtEdition.Text != "" && txtPrice.Text != "" && txtStock.Text != "")
                {
                    bool result = se.Update_Book(txtTitle.Text, txtAuthor.Text, txtEdition.Text, Convert.ToDouble(txtPrice.Text), label_isbnholder.Content.ToString(), Convert.ToInt32(txtStock.Text), txtIsbn.Text);
                    if (result == true)
                    {
                        AdminHome ah = new AdminHome();
                        ah.Show();
                        this.Close();
                    }
                }
                else //if fields are empty
                {
                    MessageBox.Show("Make sure all data inputs are filled in!");
                }
            }
            else if (!testPrice || !testStock)
            {
                if (!testPrice)//error in price entry
                {
                    MessageBox.Show("Invalid price entered. Do not include \"$\".");
                }
                else//error in stock entry
                {
                    MessageBox.Show("Invalid stock. Whole numbers only.");
                }
            }
            else
            {
                if (label_isbnholder.Content.Equals("") && txtAuthor.Text != "" && txtTitle.Text != "" && txtEdition.Text != "" && txtStock.Text != "")
                {
                    MessageBox.Show("Please enter a valid ISBN-10.");
                }
                else if (label_isbnholder.Content.Equals(""))//user hasnt searched for a book
                {
                    MessageBox.Show("You must have a book to update! Search for a book.");
                }
                else if (!okay)//isbn is invalid
                {
                    MessageBox.Show("Invalid ISBN-10");
                }
            }
        }
        private void create_Click(object sender, RoutedEventArgs e)//create new admin
        {
            Admins  addadmin = new Admins();
            Boolean okay     = true;
            Boolean checkUserNameExistsnce = addadmin.get_Admin_by_username(adminuname.Text);//checks if entered username is already in use
            long    num = 0;

            if (checkUserNameExistsnce == true)
            {
                adminleble.Content = "User name already in use.";
            }
            else
            {
                if (adminphone.Text == "")//make sure phone number was given
                {
                    okay = false;
                    MessageBox.Show("Phone number field required!");
                }
                else if (adminfname.Text == "" || adminemail.Text == "" || adminlname.Text == "" || adminuname.Text == "" || AdminPassword.Password == "")
                {
                    MessageBox.Show("Make sure all data fields are filled in!");
                }
                else if (AdminPassword.Password.Length < 6)
                {
                    MessageBox.Show("Password not long enough! Needs to be at least 6 characters.");
                }
                else//if entries are valid
                {
                    string temp = adminphone.Text.Replace("-", "").Replace("(", "").Replace(")", "");//remove special characters from phone number
                    okay = long.TryParse(temp, out num);//test if phone number is valid
                    if (okay)
                    {
                        okay = addadmin.Add_Admin(adminfname.Text, adminlname.Text, adminuname.Text, AdminPassword.Password, adminemail.Text, num); //registers the new admin account
                        if (okay)                                                                                                                   //if admin successfully added
                        {
                            AdminHome ah = new AdminHome();                                                                                         //return to admin homepage
                            ah.Show();
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid phone number");
                    }
                }
            }
        }
        private void deletebook(object sender, RoutedEventArgs e)//deletes the book
        {
            Book se = new Book();

            if (txtTitle.Text != "" && txtAuthor.Text != "" && !label_isbnholder.Content.Equals(""))//makes sure a book has been searched
            {
            }
            else
            {
                MessageBox.Show("Make sure this is the right book before deleting!\nDon't remove book information before deleting.");
            }
            bool result = se.Delete_Book(searchtxt.Text);

            if (result == true)
            {
                AdminHome ah = new AdminHome();
                ah.Show();
                this.Close();
            }
        }
Example #6
0
        private void button1_Click(object sender, RoutedEventArgs e)//create button
        {
            Boolean okay = true;
            long    num  = 0;
            string  temp = "";
            User    us   = new User();

            //fills user class with data
            us.Firstname = textBox_fname.Text;
            us.Lastname  = textBox_lname.Text;
            us.Username  = textBox_user.Text;
            us.Password  = passwordBox.Password;
            us.Email     = textBox_email.Text;
            if (textBox_phone.Text == "")//makes sure a phone number has been entered
            {
                okay = false;
                MessageBox.Show("Phone number field required!");
            }
            else
            {
                temp = textBox_phone.Text.Replace("-", "").Replace("(", "").Replace(")", ""); //removes special characters from phone number
                okay = long.TryParse(temp, out num);                                          //checks phone number is valid
                if (okay)
                {
                    us.PhoneNumber = num;
                    User user = new User();
                    okay = user.Add_User(us.Username, us.Password, us.Firstname, us.Lastname, us.Email, us.PhoneNumber);
                    if (okay)
                    {
                        AdminHome ah = new AdminHome();
                        ah.Show();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Invalid phone number!");
                }
            }
        }
Example #7
0
        private void button_Click(object sender, RoutedEventArgs e)//login button
        {
            LoginPclass log = new LoginPclass();

            log.UserName = txtuname.Text;
            log.Password = passwordBox.Password;
            bool auth = log.AdminLogin(log.UserName, log.Password);

            if (txtuname.Text == "" || passwordBox.Password == "")//display errors
            {
                if (txtuname.Text == "")
                {
                    nameandpassword.Content = "";
                    username.Content        = "Username required";
                }
                else
                {
                    username.Content = "";
                }
                if (passwordBox.Password == "")
                {
                    nameandpassword.Content = "";
                    password.Content        = "Password required";
                }
                else
                {
                    password.Content = "";
                }
            }
            else
            {
                username.Content = "";
                password.Content = "";
                if (radAdmin.IsChecked == true)//admin login
                {
                    if (auth == true)
                    {
                        //send user to admin homepage
                        AdminHome adh = new AdminHome();
                        adh.Show();
                        this.Close();
                        //MessageBox.Show("user name and password correct");
                    }
                    else//invalid admin login credentials
                    {
                        username.Content        = "";
                        password.Content        = "";
                        nameandpassword.Content = ("Username or Password incorrect.");
                    }
                }
                else if (radUser.IsChecked == true)//user/clerk login
                {
                    log.UserName = txtuname.Text;
                    log.Password = passwordBox.Password;
                    Boolean authorized = log.UserLogin(log.UserName, log.Password);
                    if (authorized)
                    {
                        ClerkHome ch = new ClerkHome();
                        ch.Show();
                        this.Close();
                    }
                    else//invalid clerk login credentials
                    {
                        nameandpassword.Content = ("Username or Password incorrect.");
                    }
                }
            }
        }