-
Notifications
You must be signed in to change notification settings - Fork 2
/
frm13MemberSearch.cs
109 lines (101 loc) · 3.51 KB
/
frm13MemberSearch.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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 frm13MemberSearch : frmTemplateSearch
{
public frm13MemberSearch()
{
InitializeComponent();
// Set search filters
cbxSearchBy.DataSource = new List<string> { "Member ID", "Name", "Phone Number", "Email Address" };
// Display all books
gvSearchResult.DataSource = context.Members.Select(x => new
{
x.MemberID,
x.Name,
x.MemberCategory,
x.DateOfBirth,
x.Address,
x.PhoneNumber,
x.EmailAddress,
x.CurrentBorrowing,
x.FineAmount,
x.Status
}).ToList();
}
public override void btnSearch_Click(object sender, EventArgs e)
{
// Perform SQL query with condition indicated by user has input search text
if (txSearchDetail.Text != "")
{
switch (cbxSearchBy.SelectedItem.ToString())
{
case "Member ID":
gvSearchResult.DataSource = context.Members.Where(x => x.MemberID.Contains(txSearchDetail.Text)).
OrderBy(y => y.MemberID).Select(x => new {
x.MemberID,
x.Name,
x.MemberCategory,
x.DateOfBirth,
x.Address,
x.PhoneNumber,
x.EmailAddress,
x.CurrentBorrowing,
x.FineAmount,
x.Status
}).ToList(); break;
case "Name":
gvSearchResult.DataSource = context.Members.Where(x => x.Name.Contains(txSearchDetail.Text)).
OrderBy(y => y.Name).Select(x => new {
x.MemberID,
x.Name,
x.MemberCategory,
x.DateOfBirth,
x.Address,
x.PhoneNumber,
x.EmailAddress,
x.CurrentBorrowing,
x.FineAmount,
x.Status
}).ToList(); break;
case "Phone Number":
gvSearchResult.DataSource = context.Members.Where(x => x.PhoneNumber.Contains(txSearchDetail.Text)).
OrderBy(y => y.PhoneNumber).Select(x => new {
x.MemberID,
x.Name,
x.MemberCategory,
x.DateOfBirth,
x.Address,
x.PhoneNumber,
x.EmailAddress,
x.CurrentBorrowing,
x.FineAmount,
x.Status
}).ToList(); break;
case "Email Address":
gvSearchResult.DataSource = context.Members.Where(x => x.EmailAddress.Contains(txSearchDetail.Text)).
OrderBy(y => y.EmailAddress).Select(x => new {
x.MemberID,
x.Name,
x.MemberCategory,
x.DateOfBirth,
x.Address,
x.PhoneNumber,
x.EmailAddress,
x.CurrentBorrowing,
x.FineAmount,
x.Status
}).ToList(); break;
}
}
}
}
}