using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LibraryMangementSystem.BookManage
{
    public partial class BookDel : Form
    {
        public BookDel()
        {
            InitializeComponent();
        }
        LibraryEntities1 dbContext = new LibraryEntities1();
        private void button1_Click(object sender, EventArgs e)
        {   
            var BookId = textBoxDelBookId.Text;
            if(BookId != "")
            {
                try
                {
                    //从实体序列返回指定BookId的实体
                    BookInfo bookInfo = dbContext.BookInfo.Single(B => B.BookID == BookId);
                    //从实体序列当中删除
                    dbContext.BookInfo.Remove(bookInfo);
                    int result = dbContext.SaveChanges();
                    String str = result == 1 ? "删除成功！" : "删除失败！";
                    MessageBox.Show(str);
                }catch(System.InvalidOperationException E) {
                    MessageBox.Show("图书不存在！"+E.Message);
                }
               
            }
            else
            {
                MessageBox.Show("请输入图书编号以删除！");
            }
           
        }
    }
}
