-
Notifications
You must be signed in to change notification settings - Fork 2
/
frm4BooksDetailForMember.cs
89 lines (78 loc) · 2.78 KB
/
frm4BooksDetailForMember.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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 SA47Team10a_GalaxyLibrary
{
public partial class frm4BooksDetailForMember : Form
{
GalaxyEntities context;
Form f;
Book b;
public frm4BooksDetailForMember()
{
InitializeComponent();
context = new GalaxyEntities();
}
private void btnSearch_Click(object sender, EventArgs e)
{
frm5BookSearchForMember f = new frm5BookSearchForMember();
DialogResult r = f.ShowDialog(this);
f.Location = this.Location;
if (r == DialogResult.OK)
{
b = context.Books.Where(x => x.BookID == f.SelectedID).First();
PopulateFields(b);
}
}
private void btnRetrieve_Click(object sender, EventArgs e)
{
if (txBookID.Text.Length==5 && txBookID.Text.Substring(0, 1).ToUpper() == "G" && Convert.ToDouble(txBookID.Text.Substring(1, 4)) >= 1 && Convert.ToDouble(txBookID.Text.Substring(1, 4)) <= context.Books.Count())
{
var q = from x in context.Books where x.BookID == txBookID.Text select x;
Book b = q.First();
PopulateFields(b);
}
else
{
MessageBox.Show("This book is not existing! You may input the wrong BookID, please check and input again!");
}
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Hide();
f = new frm1Welcome();
f.Location = this.Location;
f.ShowDialog();
this.Close();
}
private void txBookID_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter) {
btnRetrieve_Click(sender, e);
}
}
private void PopulateFields(Book b)
{
txBookID.Text = "";
txID.Text = b.BookID;
txTitle.Text = b.Title;
txAuthor.Text = b.Author;
txPublisher.Text = b.Publisher;
txCategory.Text = b.BookCategory;
txLocation.Text = b.Location;
txPrice.Text = b.Price.ToString();
txTotalStock.Text = b.TotalStock.ToString();
txNumber.Text = (b.TotalStock - b.NumberBorrowed).ToString();
var q = from x in context.Transactions
where (x.BookID == b.BookID && x.ReturnDate == null)
select new { x.BookID, x.IssueDate, x.DueDate, x.LoanStatus };
gvBorrowedList.DataSource = q.ToList();
}
}
}