private void textBoxX2_TextChanged(object sender, EventArgs e) { RefreshScreen(); if (f == 1) { try { int id = Convert.ToInt32(textBoxX2.Text); BorrowInfor bi = new BorrowInfor(id); dataGridView1.DataSource = bi.ListBook; labelX22.Text = "" + bi.Reader.ID; labelX7.Text = bi.Reader.FullName; labelX8.Text = bi.Reader.Class; labelX3.Text = bi.Reader.Birthday.Day + "/" + bi.Reader.Birthday.Month + "/" + bi.Reader.Birthday.Year; MemoryStream ms = new MemoryStream(bi.Reader.Images); reflectionImage1.Image = Image.FromStream(ms); labelX4.Text = bi.Reader.Gender == 1 ? "Nam" : "Nữ"; richTextBox1.Text = bi.Reader.Note; labelX10.Text = bi.Reader.InitDate.Day + "/" + bi.Reader.InitDate.Month + "/" + bi.Reader.InitDate.Year; labelX12.Text = bi.Reader.ExpDate.Day + "/" + bi.Reader.ExpDate.Month + "/" + bi.Reader.ExpDate.Year; textBoxX4.Enabled = true; // MessageBox.Show("Đã mượn cuốn sách có id=" + id + "của người có ID=" + bi.Reader.ID); } catch (Exception ee) { textBoxX4.Enabled = false; } } else { try { int id = Convert.ToInt32(textBoxX2.Text); PayInfor pi = (new BookModel()).PayBook(id); dataGridView1.DataSource = pi.LisBook; labelX22.Text = "" + pi.Reader.ID; labelX7.Text = pi.Reader.FullName; labelX8.Text = pi.Reader.Class; labelX3.Text = pi.Reader.Birthday.Day + "/" + pi.Reader.Birthday.Month + "/" + pi.Reader.Birthday.Year; labelX4.Text = pi.Reader.Gender == 1 ? "Nam" : "Nữ"; richTextBox1.Text = pi.Reader.Note; labelX10.Text = pi.Reader.InitDate.Day + "/" + pi.Reader.InitDate.Month + "/" + pi.Reader.InitDate.Year; labelX12.Text = pi.Reader.ExpDate.Day + "/" + pi.Reader.ExpDate.Month + "/" + pi.Reader.ExpDate.Year; textBoxX4.Enabled = true; MessageBox.Show("Đã trả cuốn sách có id=" + id + "của người có ID=" + pi.Reader.ID); } catch (Exception ee) { // MessageBox.Show(ee.Message); } } }
public PayInfor PayBook(int idBook) { PayInfor pi = new PayInfor(); if (!checkBook(idBook)) { Object[] param = { idBook }; pi.Reader = data.Borrows.Find(param).Reader; data.Borrows.Remove(data.Borrows.Find(idBook)); data.SaveChanges(); pi.LisBook = GetBookByReader(pi.Reader.ID); return(pi); } return(null); }