using LibraryMangementSystem.Util;
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.SystemSet
{
    public partial class UI_UpdateDays : Form
    {
        public UI_UpdateDays()
        {
            InitializeComponent();
        }
        public UI_UpdateDays(object sender, EventArgs e)
        {
            InitializeComponent();
            load_data(sender, e);
        }


        LibraryEntities1 dbContext = new LibraryEntities1();

        private void button_loan_Click(object sender, EventArgs e)
        {
            BaseSet baseSet = dbContext.BaseSet.Find("1");
            var Borrow_temp = textBox1.Text;
            int Borrow_nums;
            if (Borrow_temp == "")
            {
                Util_UI_Alert alert1 = new Util_UI_Alert("天数不得为空！");
                alert1.ShowDialog();
                return;
            }
            Borrow_nums = int.Parse(Borrow_temp);
            if (radioButton1.Checked)
            {
                baseSet.Borrow_days = Borrow_nums;
            }
            else
            {
                baseSet.Tch_BorrowDays = Borrow_nums;
            }
            int i = dbContext.SaveChanges();
            String str = i == 1 ? "修改成功" : "修改失败";
            Util_UI_Alert alert = new Util_UI_Alert(str);
            alert.ShowDialog();
            load_data(sender, e);
        }
        private void load_data(object sender, EventArgs e)
        {
            BaseSet baseSet = dbContext.BaseSet.Find("1");
            label1.Text = "现学生可借天数为" + baseSet.Borrow_days + "天,老师可借天数为" + baseSet.Tch_BorrowDays + "天";
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            BookUtil.textBox1_KeyPress(sender, e);
        }
    }
}
