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.CertManage
{
    public partial class CertLoss : Form
    {
        public CertLoss()
        {
            InitializeComponent();
        }
        LibraryEntities1 dbContext = new LibraryEntities1();
        private void button1_Click(object sender, EventArgs e)
        {
            var Cert_Id = textBoxCertId.Text;
            if(Cert_Id != "")
            {
                CertificateInfo cert = new CertificateInfo();
                try
                {
                    cert = dbContext.CertificateInfo.Single(C => C.Cert_id == Cert_Id);
                }
                catch (System.InvalidOperationException)
                {
                    MessageBox.Show("该借书证不存在！");
                    return;
                };
                cert.flag = 2;
                int res = dbContext.SaveChanges();
                String str = res == 1 ? "挂失成功！" : "挂失失败!";
                MessageBox.Show(str);
            }
            else
            {
                MessageBox.Show("请输入借书证号！");
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            var Cert_Id = textBoxCertId.Text;
            if (Cert_Id != "")
            {
                CertificateInfo cert = new CertificateInfo();
                try
                {
                    cert = dbContext.CertificateInfo.Single(C => C.Cert_id == Cert_Id);
                }
                catch (System.InvalidOperationException)
                {
                    MessageBox.Show("该借书证不存在！");
                    return;
                };
                cert.flag = 1;
                int res = dbContext.SaveChanges();
                String str = res == 1 ? "补办成功！" : "补办失败!";
                MessageBox.Show(str);
            }
            else
            {
                MessageBox.Show("请输入借书证号！");
            }
        }
    }
}
