Ejemplo n.º 1
0
        public void Delete_Book()
        {
            LibraryDBDataContext db = new LibraryDBDataContext();

            tbl_Borrow temp = (from T in db.tbl_Borrows
                               where T.BookID == this.ID
                               select T
                               ).FirstOrDefault();

            if (temp != null)
            {
                MessageBox.Show("Someone has this Book!");
                return;
            }
            else
            {
                tbl_Book B = (from T in db.tbl_Books
                              where T.ID == this.ID
                              select T).FirstOrDefault();
                tbl_Edition e = (from E in db.tbl_Editions
                                 where E.BookID == this.ID
                                 select E).FirstOrDefault();

                if (e != null)
                {
                    db.tbl_Editions.DeleteOnSubmit(e);
                }
                db.tbl_Books.DeleteOnSubmit(B);
                db.SubmitChanges();
            }
        }
Ejemplo n.º 2
0
        public void saveChanges()
        {
            LibraryDBDataContext db = new LibraryDBDataContext();
            var editBook            = (from B in db.tbl_Books
                                       where B.ID == this.ID
                                       select B).FirstOrDefault();
            var oldEdition = (from E in db.tbl_Editions
                              where E.BookID == this.ID
                              select E).FirstOrDefault();
            tbl_Edition newEdition = new tbl_Edition();


            editBook.ISBN        = this.ISBN;
            editBook.Name        = this.Name;
            editBook.PublisherID = this.Publisher.ID;
            editBook.AuthorID    = this.Author.ID; //l stren dol 7atet feehom l touch bta3y
            editBook.Genre       = this.Genre;
            editBook.Copies      = this.Copies;

            if (oldEdition != null && this.Version != null)
            {
                newEdition.BookID  = oldEdition.BookID;
                newEdition.Pages   = this.Pages;
                newEdition.Version = this.Version;
                db.tbl_Editions.DeleteOnSubmit(oldEdition);
                db.tbl_Editions.InsertOnSubmit(newEdition);
            }

            db.SubmitChanges();
        }
Ejemplo n.º 3
0
 public Book(tbl_Book b, tbl_Edition e)
 {
     this.ID        = b.ID;
     this.ISBN      = b.ISBN;
     this.Publisher = Publisher.LoadById(b.PublisherID);
     this.Author    = Author.LoadById(b.AuthorID);
     this.Name      = b.Name;
     this.Genre     = b.Genre;
     this.Copies    = b.Copies;
     if (e != null)
     {
         this.Pages   = e.Pages;
         this.Version = e.Version;
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            if (ISBN_TB.Text == "")
            {
                MessageBox.Show("Please Enter ISBN");
                return;
            }
            Book b      = Book.LoadByISBN(int.Parse(ISBN_TB.Text));
            int  bookID = b.ID;

            if (b == null)
            {
                MessageBox.Show("Book doesn't exist");
            }
            else
            {
                LibraryDBDataContext db = new LibraryDBDataContext();
                tbl_Edition          ed = (
                    from Edition in db.tbl_Editions
                    where (Edition.BookID == bookID) && (Edition.Version == Edition_TB.Text)
                    select Edition
                    ).FirstOrDefault();
                if (ed != null)
                {
                    MessageBox.Show("Edition already exists");
                }
                else
                {
                    tbl_Edition Edition = new tbl_Edition();
                    Edition.BookID  = bookID;
                    Edition.Version = Edition_TB.Text;
                    Edition.Pages   = int.Parse(Pages_TB.Text);
                    db.tbl_Editions.InsertOnSubmit(Edition);
                    db.SubmitChanges();
                    this.Close();
                }
            }
        }