Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private void BtnRent_Click(object sender, EventArgs e)
        {
            BookClass myBook = (BookClass)lstBooks.SelectedItem;

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

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

            myBook.copies--;
            BookFile.SaveBook(myBook, cwid, "edit");
            loadList();
        }
Exemplo n.º 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;
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                var book = (Book)lbBooks.SelectedItem;

                BookFile.DeleteBook(book, cwid);

                LoadBooks();
            }
            catch (Exception exc)
            {
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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)
            {
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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) { }
        }
Exemplo n.º 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) { }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 19
0
 private void LoadList()  //method to keep the list up to date
 {
     myBooks             = BookFile.GetAllBooks(cwid);
     lstBooks.DataSource = myBooks;
 }
Exemplo n.º 20
0
 public void LoadList()
 {
     myBooks = BookFile.GetAllBooks(cwid);
     listBooks.DataSource = myBooks;
 }
Exemplo n.º 21
0
 private void LoadList()
 {
     myBooks             = BookFile.GetAllBooks(cwid);
     lstBooks.DataSource = myBooks;
 }
Exemplo n.º 22
0
 private void LoadBooks()
 {
     // Load books from API
     myBooks            = BookFile.GetAllBooks(cwid);
     lbBooks.DataSource = myBooks;
 }