static public string[] NameAndCasNmber(string compoundName) { string[] retVal = new string[2]; gov.nih.nlm.chemspell.SpellAidService service = new gov.nih.nlm.chemspell.SpellAidService(); string response = service.getSugList(compoundName, "All databases"); var XMLReader = new System.Xml.XmlTextReader(new System.IO.StringReader(response)); System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Synonym)); if (serializer.CanDeserialize(XMLReader)) { Synonym synonym = (Synonym)serializer.Deserialize(XMLReader); foreach (SynonymChemical chemical in synonym.Chemical) { int result = String.Compare(compoundName, chemical.Name, true); if (result == 0) { retVal[0] = chemical.CAS; retVal[1] = chemical.Name; return retVal; } } } serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpellAid)); if (serializer.CanDeserialize(XMLReader)) { SpellAid aid = (SpellAid)serializer.Deserialize(XMLReader); bool different = true; retVal[0] = aid.Chemical[0].CAS; retVal[1] = aid.Chemical[0].Name; for (int i = 0; i < aid.Chemical.Length - 1; i++) { if (retVal[0] != aid.Chemical[i + 1].CAS) { different = false; retVal[0] = aid.Chemical[i].CAS; retVal[1] = aid.Chemical[i].Name; } } if (!different) { foreach (SpellAidChemical chemical in aid.Chemical) { int result = String.Compare(compoundName, 0, chemical.Name, 0, compoundName.Length, true); if (result == 0 && compoundName.Length >= chemical.Name.Length) { retVal[0] = chemical.CAS; retVal[1] = chemical.Name; return retVal; } } SelectChemicalForm form = new SelectChemicalForm(aid, compoundName); form.ShowDialog(); retVal[0] = form.SelectedChemical.CAS; retVal[1] = form.SelectedChemical.Name; return retVal; } } return retVal; }
private void button2_Click(object sender, EventArgs e) { this.dataGridView1.Visible = false; compoundName = this.textBox1.Text; casNo = NISTChemicalList.casNumber(compoundName); if (string.IsNullOrEmpty(casNo)) { gov.nih.nlm.chemspell.SpellAidService service = new gov.nih.nlm.chemspell.SpellAidService(); string response = service.getSugList(compoundName, "All databases"); var XMLReader = new System.Xml.XmlTextReader(new System.IO.StringReader(response)); System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Synonym)); if (serializer.CanDeserialize(XMLReader)) { // Synonyms means more than one name for the same chemical/CAS Number. Synonym synonym = (Synonym)serializer.Deserialize(XMLReader); casNo = synonym.Chemical[0].CAS; foreach (SynonymChemical chemical in synonym.Chemical) { if (casNo != chemical.CAS) { System.Windows.Forms.MessageBox.Show(compoundName + "has a synonym with a different CAS Number."); return; } } label2.Text = "The CAS Number of the chemical is: " + casNo + ". Now select the finished button to exit."; return; } serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpellAid)); if (serializer.CanDeserialize(XMLReader)) { SpellAid aid = (SpellAid)serializer.Deserialize(XMLReader); //bool different = true; chemicalList = new List<SpellAidChemical>(); foreach (SpellAidChemical chemical in aid.Chemical) { chemicalList.Add(chemical); } this.dataGridView1.DataSource = chemicalList; this.dataGridView1.Visible = true; this.label2.Text = "Select the desired chemical from the list below and click the 'Finished' button to exit."; return; // retVal[0] = aid.Chemical[0].CAS; // retVal[1] = aid.Chemical[0].Name; // for (int i = 0; i < aid.Chemical.Length - 1; i++) // { // if (retVal[0] != aid.Chemical[i + 1].CAS) // { // different = false; // retVal[0] = aid.Chemical[i].CAS; // retVal[1] = aid.Chemical[i].Name; // } // } // if (!different) // { // foreach (SpellAidChemical chemical in aid.Chemical) // { // int result = String.Compare(compoundName, 0, chemical.Name, 0, compoundName.Length, true); // if (result == 0 && compoundName.Length >= chemical.Name.Length) // { // retVal[0] = chemical.CAS; // retVal[1] = chemical.Name; // return retVal; // } // } // SelectChemicalForm form = new SelectChemicalForm(aid, compoundName); // form.ShowDialog(); // retVal[0] = form.SelectedChemical.CAS; // retVal[1] = form.SelectedChemical.Name; // return retVal; // } } } label2.Text = "The CAS Number of the chemical is: " + casNo + ". Now select the 'Finished' button to exit."; return; }
private void findCompound(ref string compoundName, ref string CasNo) { gov.nih.nlm.chemspell.SpellAidService service = new gov.nih.nlm.chemspell.SpellAidService(); string response = service.getSugList(compoundName, "All databases"); response = response.Replace("&", "&"); var XMLReader = new System.Xml.XmlTextReader(new System.IO.StringReader(response)); System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Synonym)); if (serializer.CanDeserialize(XMLReader)) { // Synonyms means more than one name for the same chemical/CAS Number. Synonym synonym = (Synonym)serializer.Deserialize(XMLReader); CasNo = synonym.Chemical[0].CAS; this.listBox1.BeginUpdate(); foreach (SynonymChemical chemical in synonym.Chemical) { this.listBox1.Items.Add(chemical.Name); if (CasNo != chemical.CAS) { System.Windows.Forms.MessageBox.Show(compoundName + " has a synonym with a different CAS Number."); return; } } this.listBox1.EndUpdate(); return; } serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpellAid)); if (serializer.CanDeserialize(XMLReader)) { SpellAid aid = (SpellAid)serializer.Deserialize(XMLReader); Form3 selector = new Form3(); selector.chemicals = aid; selector.ShowDialog(); compoundName = selector.SelectedChemical; this.findCompound(ref compoundName, ref CasNo); return; } CasNo = string.Empty; }