-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckOutHistory.cs
137 lines (111 loc) · 4.81 KB
/
CheckOutHistory.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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;
using System.IO;
using System.Xml;
using System.Collections;
namespace BookStoreProject
{
public partial class CheckOutHistory : Form
{
public CheckOutHistory()
{
InitializeComponent();
}
List<CheckOut> checkout = new List<CheckOut>();
private void CheckOutHistory_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
if (!Directory.Exists("\\BookStore"))
Directory.CreateDirectory("\\BookStore");
if (!File.Exists("\\BookStore\\CheckOutHistory.xml"))
{
XmlTextWriter xW = new XmlTextWriter("\\BookStore\\CheckOutHistory.xml", Encoding.UTF8);
xW.WriteStartElement("Patrons");
xW.WriteEndElement();
xW.Close();
}
XmlDocument xdoc2 = new XmlDocument();
xdoc2.Load("\\BookStore\\CheckOutHistory.xml");
foreach (XmlNode xn1 in xdoc2.SelectNodes("Patrons/Person"))
{
try
{
CheckOut c = new CheckOut();
c.Name = xn1.SelectSingleNode("Name").InnerText;
c.OwnBooks = xn1.SelectSingleNode("OwnBooks").InnerText;
c.AllowedDays = int.Parse(xn1.SelectSingleNode("AllowedDays").InnerText);
c.took = xn1.SelectSingleNode("Took").InnerText;
c.due = xn1.SelectSingleNode("Due").InnerText;
checkout.Add(c);
ListViewItem list1 = new ListViewItem(c.Name);
list1.SubItems.Add(c.OwnBooks);
list1.SubItems.Add(c.AllowedDays.ToString());
list1.SubItems.Add(c.took);
list1.SubItems.Add(c.due);
listView1.Items.Add(list1);
}
catch { }
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
if (textBox1.TextLength == 0)
{
listView1.Items.Clear();//clear list
XmlDocument xdoc2 = new XmlDocument();
xdoc2.Load("\\BookStore\\CheckOutHistory.xml");
foreach (XmlNode xn1 in xdoc2.SelectNodes("Patrons/Person"))
{
CheckOut c = new CheckOut();
c.Name = xn1.SelectSingleNode("Name").InnerText;
c.OwnBooks = xn1.SelectSingleNode("OwnBooks").InnerText;
c.AllowedDays = int.Parse(xn1.SelectSingleNode("AllowedDays").InnerText);
c.took = xn1.SelectSingleNode("Took").InnerText;
c.due = xn1.SelectSingleNode("Due").InnerText;
checkout.Add(c);
ListViewItem list1 = new ListViewItem(c.Name);
list1.SubItems.Add(c.OwnBooks);
list1.SubItems.Add(c.AllowedDays.ToString());
list1.SubItems.Add(c.took);
list1.SubItems.Add(c.due);
listView1.Items.Add(list1);
}
}
else
{
int selection = comboBox1.SelectedIndex;//comboBox2 is drop down with First Name, Last ....etc
ArrayList results = new ArrayList();//initialize arraylist
for (int i = 0; i < listView1.Items.Count; i++)//loops rows of ListView1
{
string a = listView1.Items[i].SubItems[selection].Text;//creates a string based on row i, column 'selection'
if (a.IndexOf(textBox1.Text, StringComparison.OrdinalIgnoreCase) != -1)//compares user types in textBox6 (search) ignores case
{
results.Add(listView1.Items[i]);
}
}
listView1.Items.Clear();
for (int i = 0; i < results.Count; i++)
{
listView1.Items.Add((ListViewItem)results[i]);
}
}
}
catch { }
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}