コード例 #1
0
        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 { }
        }
コード例 #2
0
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.TextLength == 0)
                {
                    listView1.Items.Clear();//clear list
                    // when we click manage people in main program, add people loads and start with creating xml file then fill it with information which come from class person and textboxes.
                    //comboBox1.SelectedIndex = 0;
                    CheckOut b = new CheckOut();
                    b.Name = listView2.CheckedItems[0].Text + " " + listView2.CheckedItems[0].SubItems[1].Text;


                    XmlDocument xdoc2 = new XmlDocument();
                    xdoc2.Load("\\BookStore\\CheckOut.xml");
                    foreach (XmlNode xn in xdoc2.SelectNodes("Patrons/Person"))
                    {
                        if (xn.SelectSingleNode("Name").InnerText == b.Name)
                        {
                            b.OwnBooks = xn.SelectSingleNode("OwnBooks").InnerText;

                            listView1.Items.Add(b.OwnBooks);
                        }
                    }
                }
                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 < listView2.Items.Count; i++)                             //loops rows of ListView1
                    {
                        string a = listView2.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(listView2.Items[i]);
                        }
                    }
                    listView2.Items.Clear();
                    for (int i = 0; i < results.Count; i++)
                    {
                        listView2.Items.Add((ListViewItem)results[i]);
                    }
                }
            }
            catch { }
        }
コード例 #3
0
        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 { }
            }
        }
コード例 #4
0
        private void listView2_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            try
            {
                listView1.Items.Clear();
                CheckOut b = new CheckOut();
                b.Name = listView2.CheckedItems[0].Text + " " + listView2.CheckedItems[0].SubItems[1].Text;


                XmlDocument xdoc2 = new XmlDocument();
                xdoc2.Load("\\BookStore\\CheckOut.xml");
                foreach (XmlNode xn in xdoc2.SelectNodes("Patrons/Person"))
                {
                    if (xn.SelectSingleNode("Name").InnerText == b.Name)
                    {
                        b.OwnBooks = xn.SelectSingleNode("OwnBooks").InnerText;

                        listView1.Items.Add(b.OwnBooks);
                    }
                }
            }
            catch { }
        }
コード例 #5
0
        private void Check_Out_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 14;
            comboBox2.SelectedIndex = 0;
            if (!Directory.Exists("\\BookStore"))
            {
                Directory.CreateDirectory("\\BookStore");
            }
            if (!File.Exists("\\BookStore\\CheckOut.xml"))
            {
                XmlTextWriter xW = new XmlTextWriter("\\BookStore\\CheckOut.xml", Encoding.UTF8);
                xW.WriteStartElement("Patrons");
                xW.WriteEndElement();
                xW.Close();
            }

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("\\BookStore\\people.xml");
            foreach (XmlNode xNode in xDoc.SelectNodes("People/Patrons"))
            {
                Patrons p = new Patrons();
                p.FirstName = xNode.SelectSingleNode("FirstName").InnerText;
                p.LastName  = xNode.SelectSingleNode("LastName").InnerText;
                p.Address   = xNode.SelectSingleNode("Address").InnerText;
                p.City      = xNode.SelectSingleNode("City").InnerText;
                p.Zipcode   = xNode.SelectSingleNode("Zipcode").InnerText;
                p.Email     = xNode.SelectSingleNode("Email").InnerText;
                p.PhoneNum  = xNode.SelectSingleNode("PhoneNum").InnerText;
                p.State     = xNode.SelectSingleNode("State").InnerText;
                p.BirthDay  = xNode.SelectSingleNode("Birthday").InnerText;
                people.Add(p);
                ListViewItem list2 = new ListViewItem(p.FirstName);
                list2.SubItems.Add(p.LastName);
                listView2.Items.Add(list2);
            }

            XmlDocument xdoc = new XmlDocument();

            xdoc.Load("\\BookStore\\books.xml");
            foreach (XmlNode xn in xdoc.SelectNodes("Books/Book"))
            {
                Book b = new Book();
                b.Title  = xn.SelectSingleNode("Title").InnerText;
                b.Author = xn.SelectSingleNode("Author").InnerText;
                b.Genre  = xn.SelectSingleNode("Genre").InnerText;
                b.ISBN   = xn.SelectSingleNode("ISBN").InnerText;
                b.Copies = int.Parse(xn.SelectSingleNode("Copies").InnerText);
                books.Add(b);
                ListViewItem list = new ListViewItem(b.Title);
                if (b.Copies > 0)
                {
                    list.SubItems.Add(b.Copies.ToString());
                }
                else
                {
                    return;
                }

                listView1.Items.Add(list);
            }
            XmlDocument xdoc2 = new XmlDocument();

            xdoc2.Load("\\BookStore\\CheckOut.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);
            }
            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();
            }
        }
コード例 #6
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);
                }
            }
        }