Exemplo n.º 1
0
        //read XML file for patent info
        public static SortedList<int, Patent> GetPatents()
        {
            XmlDocument doc = new XmlDocument();

            //if file doesn't exist, create it
            if (!File.Exists("Patents.xml"))
                doc.Save("Patents.xml");

            SortedList<int, Patent> patents = new SortedList<int, Patent>();

            XmlReaderSettings readerSettings = new XmlReaderSettings();
            readerSettings.IgnoreWhitespace = true;
            readerSettings.IgnoreComments = true;

            XmlReader readXml = null;

            try
            {
                readXml = XmlReader.Create(path, readerSettings);

                if (readXml.ReadToDescendant("Patent")) //read to first Patent node
                {
                    do
                    {
                        Patent patent = new Patent();
                        patent.Number = Convert.ToInt32(readXml["Number"]);
                        readXml.ReadStartElement("Patent");
                        patent.AppNumber = readXml.ReadElementContentAsString();
                        patent.Description = readXml.ReadElementContentAsString();
                        patent.FilingDate = DateTime.Parse(readXml.ReadElementContentAsString());
                        patent.Inventor = readXml.ReadElementContentAsString();
                        patent.Inventor2 = readXml.ReadElementContentAsString();

                        int key = patent.Number; //assign key to value

                        patents.Add(key, patent); //add key-value pair to list
                    }
                    while (readXml.ReadToNextSibling("Patent"));
                }
            }
            catch (XmlException ex)
            {
                MessageBox.Show(ex.Message, "Xml Error");
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "IO Exception");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception Occurred");
            }
            finally
            {
                if (readXml != null)
                    readXml.Close();
            }

            return patents;
        }
Exemplo n.º 2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (IsValidData())
     {
         updatePatent = new Patent(
             Convert.ToInt32(txtNumber.Text),
             txtAppNumber.Text,
             txtDescription.Text,
             DateTime.Parse(txtFilingDate.Text),
             txtInventor.Text,
             txtInventor2.Text);
         this.Close();
     }
 }
Exemplo n.º 3
0
 //Displays search result in listview
 private void AddSearchPatentToListView(Patent p)
 {
     ListViewItem item = new ListViewItem();
     item.Text = p.Number.ToString();
     item.SubItems.Add(p.AppNumber);
     item.SubItems.Add(p.Description);
     item.SubItems.Add(p.FilingDate.ToString("yyyy-MM-dd"));
     item.SubItems.Add(p.Inventor);
     if (p.Inventor2 != "")
         item.SubItems.Add(p.Inventor2);
     else
         item.SubItems.Add("N/A");
     lvPatents.Items.Add(item);
 }