Exemplo n.º 1
0
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox2.TextLength == 0)
                {
                    listView1.Items.Clear();//clear list


                    XmlDocument xdoc2 = new XmlDocument();
                    xdoc2.Load("\\BookStore\\Checkin.xml");
                    foreach (XmlNode xn1 in xdoc2.SelectNodes("Patrons/Person"))
                    {
                        Checkedin c = new Checkedin();
                        c.Name       = xn1.SelectSingleNode("Name").InnerText;
                        c.Book       = xn1.SelectSingleNode("Book").InnerText;
                        c.CheckedOut = xn1.SelectSingleNode("CheckedOut").InnerText;
                        c.CheckedIn  = xn1.SelectSingleNode("CheckedIn").InnerText;
                        c.Overdue    = xn1.SelectSingleNode("Overdue").InnerText;
                        checkin.Add(c);
                        ListViewItem list1 = new ListViewItem(c.Name);
                        list1.SubItems.Add(c.Book);
                        list1.SubItems.Add(c.CheckedIn);
                        list1.SubItems.Add(c.CheckedOut);
                        list1.SubItems.Add(c.Overdue);
                        listView1.Items.Add(list1);
                    }
                }
                else
                {
                    int       selection = comboBox1.SelectedIndex;                              //comboBox1 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(textBox2.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 { }
        }
Exemplo n.º 2
0
        private void CheckInHistory_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\\Checkin.xml");
            foreach (XmlNode xn1 in xdoc2.SelectNodes("Patrons/Person"))
            {
                try
                {
                    Checkedin c = new Checkedin();
                    c.Name       = xn1.SelectSingleNode("Name").InnerText;
                    c.Book       = xn1.SelectSingleNode("Book").InnerText;
                    c.CheckedOut = xn1.SelectSingleNode("CheckedOut").InnerText;
                    c.CheckedIn  = xn1.SelectSingleNode("CheckedIn").InnerText;
                    c.Overdue    = xn1.SelectSingleNode("Overdue").InnerText;

                    checkin.Add(c);
                    ListViewItem list1 = new ListViewItem(c.Name);
                    list1.SubItems.Add(c.Book);
                    list1.SubItems.Add(c.CheckedIn);
                    list1.SubItems.Add(c.CheckedOut);
                    list1.SubItems.Add(c.Overdue);
                    listView1.Items.Add(list1);
                }
                catch { }
            }
        }
Exemplo n.º 3
0
        void checkinbook()
        {
            Checkedin i = new Checkedin();



            if (!Directory.Exists("\\BookStore"))
            {
                Directory.CreateDirectory("\\BookStore");
            }
            if (!File.Exists("\\BookStore\\CheckIn.xml"))
            {
                XmlTextWriter xW = new XmlTextWriter("\\BookStore\\CheckIn.xml", Encoding.UTF8);
                xW.WriteStartElement("Patrons");
                xW.WriteEndElement();
                xW.Close();
            }
            Book     b = new Book();
            CheckOut c = new CheckOut();


            c.Name       = listView2.CheckedItems[0].Text + " " + listView2.CheckedItems[0].SubItems[1].Text;
            c.OwnBooks   = listView1.CheckedItems[0].Text;
            i.Name       = listView2.CheckedItems[0].Text + " " + listView2.CheckedItems[0].SubItems[1].Text;
            i.Book       = listView1.CheckedItems[0].Text;
            i.CheckedOut = dateTimePicker2.Text;
            i.CheckedIn  = dateTimePicker1.Text;
            if (DateTime.Parse(i.CheckedIn) > DateTime.Parse(i.CheckedOut))
            {
                i.Overdue = "Yes";
            }
            else
            {
                i.Overdue = "No";
            }
            checkin.Add(i);

            // this code saves everything after the closing the app. Problem was removing but somehow i add the same code for the remove button. It is working so i am not gonna look at it agian. We can check this later.
            XmlDocument xDoc2 = new XmlDocument();

            xDoc2.Load("\\BookStore\\CheckIn.xml");
            XmlNode xNode1 = xDoc2.SelectSingleNode("Patrons");

            foreach (Checkedin d in checkin)
            {
                XmlNode xTopp       = xDoc2.CreateElement("Person");
                XmlNode xName       = xDoc2.CreateElement("Name");
                XmlNode xBook       = xDoc2.CreateElement("Book");
                XmlNode xCheckedOut = xDoc2.CreateElement("CheckedOut");
                XmlNode xCheckedIn  = xDoc2.CreateElement("CheckedIn");
                XmlNode xOverdue    = xDoc2.CreateElement("Overdue");

                xName.InnerText       = d.Name;
                xBook.InnerText       = d.Book;
                xCheckedOut.InnerText = d.CheckedOut;
                xCheckedIn.InnerText  = d.CheckedIn;
                xOverdue.InnerText    = d.Overdue;

                xTopp.AppendChild(xName);
                xTopp.AppendChild(xBook);
                xTopp.AppendChild(xCheckedOut);
                xTopp.AppendChild(xCheckedIn);
                xTopp.AppendChild(xOverdue);


                xDoc2.DocumentElement.AppendChild(xTopp);
                xDoc2.Save("\\BookStore\\CheckIn.xml");
            }



            XmlDocument xdoc3 = new XmlDocument();

            xdoc3.Load("\\BookStore\\books.xml");
            foreach (XmlNode xn in xdoc3.SelectNodes("Books/Book"))
            {
                if (xn.SelectSingleNode("Title").InnerText == c.OwnBooks)
                {
                    b.Copies = int.Parse(xn.SelectSingleNode("Copies").InnerText);
                    b.Copies = b.Copies + 1;
                    xn.SelectSingleNode("Copies").InnerText = b.Copies.ToString();
                }
            }
            xdoc3.Save("\\BookStore\\books.xml");


            XmlDocument xdoc4 = new XmlDocument();

            xdoc4.Load("\\BookStore\\CheckOut.xml");
            foreach (XmlNode xn in xdoc4.SelectNodes("Patrons/Person"))
            {
                if (xn.SelectSingleNode("Name").InnerText == c.Name)
                {
                    if (xn.SelectSingleNode("OwnBooks").InnerText == c.OwnBooks)
                    {
                        xn.ParentNode.RemoveChild(xn);
                    }
                }
            }
            xdoc4.Save("\\BookStore\\CheckOut.xml");

            listView1.Items.Clear();

            XmlDocument xdoc = new XmlDocument();

            xdoc.Load("\\BookStore\\CheckOut.xml");

            foreach (XmlNode xn in xdoc.SelectNodes("Patrons/Person"))
            {
                if (xn.SelectSingleNode("Name").InnerText == c.Name)
                {
                    c.OwnBooks = xn.SelectSingleNode("OwnBooks").InnerText;



                    checkout.Add(c);
                    ListViewItem list = new ListViewItem(c.OwnBooks);



                    listView1.Items.Add(list);
                }
            }
        }