예제 #1
0
 partial void DeleteBOOK(BOOK instance);
예제 #2
0
 partial void InsertBOOK(BOOK instance);
예제 #3
0
 partial void UpdateBOOK(BOOK instance);
예제 #4
0
 private void detach_BOOKs(BOOK entity)
 {
     this.SendPropertyChanging();
     entity.PUBLISHER = null;
 }
예제 #5
0
 private void attach_BOOKs(BOOK entity)
 {
     this.SendPropertyChanging();
     entity.PUBLISHER = this;
 }
예제 #6
0
 private void detach_BOOKs(BOOK entity)
 {
     this.SendPropertyChanging();
     entity.GENRE = null;
 }
예제 #7
0
 private void attach_BOOKs(BOOK entity)
 {
     this.SendPropertyChanging();
     entity.GENRE = this;
 }
        public void insertbook()
        {
            try
            {
                BOOK b = new BOOK();
                b.Book_ID        = Convert.ToInt32(bookidbox.Text);
                b.Book_Name      = booknamebox.Text;
                b.Book_Price     = Convert.ToInt32(bookpricebox.Text);
                b.Availability   = availabilitycombobox.Text;
                b.Language       = languagebox.Text;
                b.Publish_Year   = Convert.ToInt32(yearbox.Text);
                b.Publisher_Name = pubnamebox.Text;
                // b.Publisher_ID = Convert.ToInt32(pub_idbox.Text);
                b.Genre_Name = Genrecombobox.Text;
                if (b.Publish_Year <= DateTime.Today.Year)
                {
                    using (DataClasses1DataContext context = new DataClasses1DataContext())
                    {
                        foreach (BOOK b1 in context.BOOKs)
                        {
                            if (b1.Book_ID == b.Book_ID)
                            {
                                id_flag = true;
                            }
                        }
                        if (id_flag == true)
                        {
                            MessageBox.Show("Duplicate id detected");
                        }
                        else
                        {
                            BOOK_AUTHOR ba = new BOOK_AUTHOR();

                            foreach (AUTHOR a in context.AUTHORs)
                            {
                                if (a.Author_Name.ToLower() == authornamebox.Text.ToLower())
                                {
                                    ba.Book_ID    = b.Book_ID;
                                    ba.Author_ID  = a.Author_ID;
                                    b.Author_Name = authornamebox.Text;
                                    author_flag   = true;
                                }
                            }

                            if (author_flag == false)
                            {
                                MessageBox.Show("Author not found.Click 'Add Author' to add Publisher.");
                            }
                            else
                            {
                                foreach (PUBLISHER p in context.PUBLISHERs)
                                {
                                    if (b.Publisher_Name.ToLower() == p.Publisher_Name.ToLower())
                                    {
                                        b.Publisher_ID      = p.Publisher_ID;
                                        b.Publisher_Address = p.Publisher_Address;
                                        publisher_flag      = true;
                                    }
                                }

                                if (publisher_flag == false)
                                {
                                    MessageBox.Show("Publisher not found.Click 'Add Publisher' to add Publisher.");
                                }

                                else
                                {
                                    foreach (GENRE g in context.GENREs)
                                    {
                                        if (b.Genre_Name == g.Genre_Name)
                                        {
                                            b.Genre_ID = g.Genre_ID;
                                        }
                                    }

                                    context.BOOKs.InsertOnSubmit(b);
                                    context.BOOK_AUTHORs.InsertOnSubmit(ba);
                                    context.SubmitChanges();
                                    MessageBox.Show("Book Added Succssessfully.");
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Invalid year");
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Input Error.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }