Exemple #1
0
        private void btnEdit_Click(object sender, System.EventArgs e)
        {
            if (lstBooks.SelectedItem == null)
            {
                MessageBox.Show("Select a book to edit");
                return;
            }

            var selectedIndex = lstBooks.SelectedIndex;
            var selectedBook  = lstBooks.SelectedItem as Book;
            var upsertBook    = new UpsertBook(selectedBook);

            upsertBook.ShowDialog();

            if (upsertBook.IsCanceled)
            {
                return;
            }

            var book = upsertBook.NewOrUpdatedBook;

            book.CWID = cwid;
            var mode = upsertBook.Mode;

            BookFile.SaveBook(book, cwid, mode);

            lstBooks.Items.RemoveAt(selectedIndex);
            lstBooks.Items.Insert(selectedIndex, book);
            SelectItemInListBox(selectedIndex);
        }
Exemple #2
0
        private void BtnRent_Click(object sender, EventArgs e)
        {
            BookClass myBook = (BookClass)lstBooks.SelectedItem;

            myBook.copies--;
            BookFile.SaveBook(myBook, cwid, "edit");
            LoadList();
        }
Exemple #3
0
        private void btnReturn_Click(object sender, EventArgs e)
        {
            Book myBook = (Book)lstBooks.SelectedItem;

            myBook.copies++;
            BookFile.SaveBook(myBook, cwid, "edit");
            LoadList();
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Book myBook = (Book)lstBooks.SelectedItem;

            myBook.copies--;
            BookFile.SaveBook(myBook, cwid, "edit");
            loadList();
        }
Exemple #5
0
        private void btnRent_Click(object sender, EventArgs e)
        {
            Book myBook = (Book)lstBooks.SelectedItem;
            int  temp   = lstBooks.SelectedIndex;

            myBook.copies--;
            BookFile.SaveBook(myBook, cwid, "edit");
            LoadList();
            lstBooks.SelectedIndex = temp;
        }
Exemple #6
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            Book         myBook       = (Book)listBooks.SelectedItem;
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this", "Delete", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                BookFile.DeleteBook(myBook, cwid);
                LoadList();
            }
        }
Exemple #7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                var book = (Book)lbBooks.SelectedItem;

                BookFile.DeleteBook(book, cwid);

                LoadBooks();
            }
            catch (Exception exc)
            {
            }
        }
Exemple #8
0
        private void LoadBooks()
        {
            var books = BookFile.GetAllBooks(cwid);

            foreach (var book in books)
            {
                lstBooks.Items.Add(book);
            }

            if (books.Count > 0)
            {
                lstBooks.SelectedIndex = 0;
            }
        }
Exemple #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            myBook.title  = txtTitleData.Text;
            myBook.author = txtAuthorData.Text;
            myBook.genre  = txtGenreData.Text;
            myBook.copies = int.Parse(txtCopiesData.Text);
            myBook.isbn   = txtIbsnData.Text;
            myBook.cover  = txtCoverData.Text;
            myBook.length = int.Parse(txtCopiesData.Text);
            myBook.cwid   = cwid;

            BookFile.SaveBook(myBook, cwid, mode);
            MessageBox.Show("Content was saved", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
Exemple #10
0
        private void btnReturn_Click(object sender, EventArgs e)
        {
            try
            {
                var book = (Book)lbBooks.SelectedItem;

                book.copies++;

                BookFile.SaveBook(book, cwid, "edit");

                LoadBooks();
            }
            catch (Exception exc)
            {
            }
        }
Exemple #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            myBook.title  = txtTitleData.Text;
            myBook.author = txtAuthorData.Text;
            myBook.genre  = txtGeneData.Text;
            myBook.copies = int.Parse(txtCopiesData.Text); //number of copies is and int so you have to use a ToString
            myBook.isbn   = txtISBNData.Text;
            myBook.cover  = txtCoverData.Text;
            myBook.length = int.Parse(txtLengthData.Text); //number of copies is and int so you have to use a ToString

            myBook.cwid = cwid;

            BookFile.SaveBook(myBook, cwid, mode);

            MessageBox.Show("Content was saved", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
Exemple #12
0
        //saves the edit
        private void btnSave_Click(object sender, EventArgs e)
        {
            myBook.title  = txtTitleData.Text;
            myBook.author = txtAuthorData.Text;
            myBook.genre  = txtGenreData.Text;
            myBook.copies = int.Parse(txtCopiesData.Text);
            myBook.isbn   = txtIsbnData.Text;
            myBook.cover  = txtCoverData.Text;
            myBook.length = int.Parse(txtLengthData.Text);
            myBook.cwid   = cwid;

            BookFile.SaveBook(myBook, cwid, mode);

            //displays a message box showing the user that their book was saved
            MessageBox.Show("The Book Was Saved!", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
Exemple #13
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                var book = (Book)lbBooks.SelectedItem;

                frmEdit editForm = new frmEdit(book, cwid);
                if (editForm.ShowDialog() == DialogResult.OK)
                {
                    var editedBook = (Book)editForm.Tag;

                    BookFile.SaveBook(editedBook, cwid, "edit");

                    LoadBooks();
                }
            }
            catch (Exception exc) { }
        }
Exemple #14
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            try
            {
                var book = new Book();

                frmEdit newForm = new frmEdit(book, cwid);
                if (newForm.ShowDialog() == DialogResult.OK)
                {
                    var editedBook = (Book)newForm.Tag;

                    BookFile.SaveBook(editedBook, cwid, "");

                    LoadBooks();
                }
            }
            catch (Exception exc) { }
        }
Exemple #15
0
        //rents a book
        private void btnRent_Click(object sender, EventArgs e)
        {
            Book myBook = (Book)lstBooks.SelectedItem;

            //the user cannot rent books if their are 0 copies
            if (myBook.copies <= 0)
            {
                MessageBox.Show("Sorry, this book is currently unavailable.", "Unavailable", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                myBook.copies--;
                BookFile.SaveBook(myBook, cwid, "edit");
            }

            LoadList();
        }
Exemple #16
0
        private void BtnSave_Click(object sender, EventArgs e) //closes the form, saving all data that was changed
        {
            myBook.title  = txtTitleData.Text;
            myBook.author = txtAuthorData.Text;
            myBook.genre  = txtGenreData.Text;
            myBook.copies = int.Parse(txtCopiesData.Text);
            myBook.isbn   = txtIsbnData.Text;
            myBook.length = int.Parse(txtLengthData.Text);
            myBook.cover  = txtCoverData.Text;
            //Console.WriteLine(cwid);
            //Console.ReadKey();
            myBook.cwid = cwid;

            BookFile.SaveBook(myBook, cwid, mode);

            MessageBox.Show("Content was saved", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); //saved message
            this.Close();
        }
Exemple #17
0
        private void btnNew_Click(object sender, System.EventArgs e)
        {
            var upsertBook = new UpsertBook();

            upsertBook.ShowDialog();

            if (upsertBook.IsCanceled)
            {
                return;
            }

            var book = upsertBook.NewOrUpdatedBook;

            book.CWID = cwid;
            var mode = upsertBook.Mode;

            BookFile.SaveBook(book, cwid, mode);

            this.lstBooks.Items.Add(book);
        }
Exemple #18
0
        private void btnDelete_Click(object sender, System.EventArgs e)
        {
            if (lstBooks.SelectedItem == null)
            {
                MessageBox.Show("Select a book to edit");
                return;
            }

            var selectedBook = lstBooks.SelectedItem as Book;

            var message = MessageBox.Show($"Are you sure you want to delete\n'{selectedBook.Title}'", "Delete Movie", MessageBoxButtons.YesNo);

            if (message == DialogResult.No)
            {
                return;
            }

            BookFile.DeleteBook(selectedBook, cwid);

            lstBooks.Items.Remove(selectedBook);
        }
Exemple #19
0
 private void LoadList()  //method to keep the list up to date
 {
     myBooks             = BookFile.GetAllBooks(cwid);
     lstBooks.DataSource = myBooks;
 }
Exemple #20
0
 public void LoadList()
 {
     myBooks = BookFile.GetAllBooks(cwid);
     listBooks.DataSource = myBooks;
 }
Exemple #21
0
 private void LoadList()
 {
     myBooks             = BookFile.GetAllBooks(cwid);
     lstBooks.DataSource = myBooks;
 }
Exemple #22
0
 private void LoadBooks()
 {
     // Load books from API
     myBooks            = BookFile.GetAllBooks(cwid);
     lbBooks.DataSource = myBooks;
 }