public List <Scientists> Search(Scientists scientists) { List <Scientists> allResult = new List <Scientists>(); var doc = XDocument.Load(@"C:\Users\Denis\source\repos\lab_3\lab_3\XMLFile1.xml"); var result = from obj in doc.Descendants("Scientist") where ((obj.Parent.Attribute("FACULTY").Value.Equals(scientists.Faculty) || scientists.Faculty == null) && (obj.Attribute("FullName").Value.Equals(scientists.FullName) || scientists.FullName == null) && (obj.Attribute("Department").Value.Equals(scientists.Department) || scientists.Department == null) && (obj.Attribute("Field").Value.Equals(scientists.Field) || scientists.Field == null) && (obj.Attribute("Chair").Value.Equals(scientists.Chair) || scientists.Chair == null) && (obj.Attribute("Laboratory").Value.Equals(scientists.Laboratory) || scientists.Laboratory == null) && (obj.Attribute("Position").Value.Equals(scientists.Position) || scientists.Position == null) && (obj.Attribute("OnPositionFrom").Value.Equals(scientists.OnPositionFrom) || scientists.OnPositionFrom == null) && (obj.Attribute("OnPositionTo").Value.Equals(scientists.OnPositionTo) || scientists.OnPositionTo == null) ) select new { faculty = (string)obj.Parent.Attribute("FACULTY"), fullname = (string)obj.Attribute("FullName"), department = (string)obj.Attribute("Department"), field = (string)obj.Attribute("Field"), chair = (string)obj.Attribute("Chair"), laboratory = (string)obj.Attribute("Laboratory"), position = (string)obj.Attribute("Position"), onpositionfrom = (string)obj.Attribute("OnPositionFrom"), onpositionto = (string)obj.Attribute("OnPositionTo") }; foreach (var n in result) { Scientists myScientist = new Scientists(); myScientist.Faculty = n.faculty; myScientist.FullName = n.fullname; myScientist.Department = n.department; myScientist.Field = n.field; myScientist.Chair = n.chair; myScientist.Laboratory = n.laboratory; myScientist.Position = n.position; myScientist.OnPositionFrom = n.onpositionfrom; myScientist.OnPositionTo = n.onpositionto; allResult.Add(myScientist); } return(allResult); }
private void search() { Results.Text = ""; Scientists scientists = new Scientists(); if (FullName_CheckBox.Checked) { scientists.FullName = comboBox1.SelectedItem.ToString(); } if (Department_CheckBox.Checked) { scientists.Department = comboBox2.SelectedItem.ToString(); } if (Field_CheckBox.Checked) { scientists.Field = comboBox3.SelectedItem.ToString(); } if (Chair_CheckBox.Checked) { scientists.Chair = comboBox4.SelectedItem.ToString(); } if (Laboratory_CheckBox.Checked) { scientists.Laboratory = comboBox5.SelectedItem.ToString(); } if (Position_CheckBox.Checked) { scientists.Position = comboBox6.SelectedItem.ToString(); } if (OnPositionFrom_CheckBox.Checked) { scientists.OnPositionFrom = comboBox7.SelectedItem.ToString(); } if (OnPositionTo_checkBox.Checked) { scientists.OnPositionTo = comboBox8.SelectedItem.ToString(); } if (Faculty_checkBox.Checked) { scientists.Faculty = comboBox9.SelectedItem.ToString(); } IAnalystXMLStrategy analyst = new AnalystXMLDOMStrategy(); if (DOM_radioButton.Checked) { analyst = new AnalystXMLDOMStrategy(); } if (SAX_radioButton.Checked) { analyst = new AnalystXMLSAXStrategy(); } if (LINQ_TO_XML_radioButton.Checked) { analyst = new AnalystXMLLINQStrategy(); } Search search = new Search(analyst, scientists); List <Scientists> result = search.SearchAlgoritm(); foreach (Scientists sc in result) { Results.Text += "Факультет: " + sc.Faculty + "\n"; Results.Text += "П.І.П.: " + sc.FullName + "\n"; Results.Text += "Департамент: " + sc.Department + "\n"; Results.Text += "Відділення: " + sc.Field + "\n"; Results.Text += "Кафедра: " + sc.Chair + "\n"; Results.Text += "Лабораторія: " + sc.Laboratory + "\n"; Results.Text += "Посада: " + sc.Position + "\n"; Results.Text += "На посаді з: " + sc.OnPositionFrom + "\n"; Results.Text += "На посаді до: " + sc.OnPositionTo + "\n"; Results.Text += "\n\n\n"; } }
public List <Scientists> Search(Scientists scientists) { List <Scientists> result = new List <Scientists>(); XmlDocument doc = new XmlDocument(); int l = 5; int k = 0; doc.Load(@"C:\Users\Denis\source\repos\lab_3\lab_3\XMLFile1.xml"); XmlNode node = doc.DocumentElement; foreach (XmlNode nod in node.ChildNodes) { string FullName = ""; string Department = ""; string Field = ""; string Chair = ""; string Laboratory = ""; string Position = ""; string OnPositionFrom = ""; string OnPositionTo = ""; string Faculty = ""; foreach (XmlAttribute nod2 in nod.Attributes) { if (nod2.Name.Equals("FACULTY") && (nod2.Value.Equals(scientists.Faculty) || scientists.Faculty == null)) { Faculty = nod2.Value; } } foreach (XmlNode nod1 in nod.ChildNodes) { foreach (XmlAttribute attribute in nod1.Attributes) { if (attribute.Name.Equals("FullName") && (attribute.Value.Equals(scientists.FullName) || scientists.FullName == null)) { FullName = attribute.Value; k++; } if (attribute.Name.Equals("Department") && (attribute.Value.Equals(scientists.Department) || scientists.Department == null)) { Department = attribute.Value; k++; } if (attribute.Name.Equals("Field") && (attribute.Value.Equals(scientists.Field) || scientists.Field == null)) { Field = attribute.Value; k++; } if (attribute.Name.Equals("Chair") && (attribute.Value.Equals(scientists.Chair) || scientists.Chair == null)) { Chair = attribute.Value; k++; } if (attribute.Name.Equals("Laboratory") && (attribute.Value.Equals(scientists.Laboratory) || scientists.Laboratory == null)) { Laboratory = attribute.Value; k++; } if (attribute.Name.Equals("Position") && (attribute.Value.Equals(scientists.Position) || scientists.Position == null)) { Position = attribute.Value; k++; } if (attribute.Name.Equals("OnPositionFrom") && (attribute.Value.Equals(scientists.OnPositionFrom) || scientists.OnPositionFrom == null)) { OnPositionFrom = attribute.Value; k++; } if (attribute.Name.Equals("OnPositionTo") && (attribute.Value.Equals(scientists.OnPositionTo) || scientists.OnPositionTo == null)) { OnPositionTo = attribute.Value; k++; } if (k == 0) { l = k; } k = 0; } if (FullName != "" && Department != "" && Field != "" && Chair != "" && Laboratory != "" && Position != "" && OnPositionFrom != "" && OnPositionTo != "" && Faculty != "" && l != 0) { Scientists myScientist = new Scientists(); myScientist.FullName = FullName; myScientist.Department = Department; myScientist.Field = Field; myScientist.Chair = Chair; myScientist.Laboratory = Laboratory; myScientist.Position = Position; myScientist.OnPositionFrom = OnPositionFrom; myScientist.OnPositionTo = OnPositionTo; myScientist.Faculty = Faculty; result.Add(myScientist); } l = 5; } } return(result); }
public List <Scientists> Search(Scientists scientists) { List <Scientists> allresult = new List <Scientists>(); XmlReader xmlreader = XmlReader.Create(@"C:\Users\Denis\source\repos\lab_3\lab_3\XMLFile1.xml"); string Faculty = ""; while (xmlreader.Read()) { if (xmlreader.HasAttributes) { if (xmlreader.AttributeCount == 1) { xmlreader.MoveToNextAttribute(); } if ((xmlreader.Name.Equals("FACULTY") && xmlreader.Value.Equals(scientists.Faculty)) || (scientists.Faculty == null && xmlreader.Name.Equals("FACULTY"))) { Faculty = ""; Faculty = xmlreader.Value; xmlreader.Read(); } else if ((xmlreader.Value != scientists.Faculty) && xmlreader.Name.Equals("FACULTY") && allresult.Count > 0) { return(allresult); } while (xmlreader.MoveToNextAttribute()) { string FullName = ""; string Department = ""; string Field = ""; string Chair = ""; string Laboratory = ""; string Position = ""; string OnPositionFrom = ""; string OnPositionTo = ""; if (xmlreader.Name.Equals("FullName") && xmlreader.Value.Equals(scientists.FullName) || scientists.FullName == null) { FullName = xmlreader.Value; xmlreader.MoveToNextAttribute(); if (xmlreader.Name.Equals("Department") && xmlreader.Value.Equals(scientists.Department) || scientists.Department == null) { Department = xmlreader.Value; xmlreader.MoveToNextAttribute(); if (xmlreader.Name.Equals("Field") && xmlreader.Value.Equals(scientists.Field) || scientists.Field == null) { Field = xmlreader.Value; xmlreader.MoveToNextAttribute(); if (xmlreader.Name.Equals("Chair") && xmlreader.Value.Equals(scientists.Chair) || scientists.Chair == null) { Chair = xmlreader.Value; xmlreader.MoveToNextAttribute(); if (xmlreader.Name.Equals("Laboratory") && xmlreader.Value.Equals(scientists.Laboratory) || scientists.Laboratory == null) { Laboratory = xmlreader.Value; xmlreader.MoveToNextAttribute(); if (xmlreader.Name.Equals("Position") && xmlreader.Value.Equals(scientists.Position) || scientists.Position == null) { Position = xmlreader.Value; xmlreader.MoveToNextAttribute(); if (xmlreader.Name.Equals("OnPositionFrom") && xmlreader.Value.Equals(scientists.OnPositionFrom) || scientists.OnPositionFrom == null) { OnPositionFrom = xmlreader.Value; xmlreader.MoveToNextAttribute(); if (xmlreader.Name.Equals("OnPositionTo") && xmlreader.Value.Equals(scientists.OnPositionTo) || scientists.OnPositionTo == null) { OnPositionTo = xmlreader.Value; } } } } } } } } if (FullName != "" && Department != "" && Field != "" && Chair != "" && Laboratory != "" && Position != "" && OnPositionFrom != "" && OnPositionTo != "" && Faculty != "") { Scientists myScientist = new Scientists(); myScientist.Faculty = Faculty; myScientist.FullName = FullName; myScientist.Department = Department; myScientist.Field = Field; myScientist.Chair = Chair; myScientist.Laboratory = Laboratory; myScientist.Position = Position; myScientist.OnPositionFrom = OnPositionFrom; myScientist.OnPositionTo = OnPositionTo; allresult.Add(myScientist); } } } } xmlreader.Close(); return(allresult); }
internal Search(IAnalystXMLStrategy analyst, Scientists scientists) { _analyst = analyst; _scientists = scientists; }