public bool Eq(Emploee e) { if(e.Department == Department&& e.Degree==Degree&& e.audience==audience && e.GetPhone()==GetPhone()&& e.Interests==Interests&& e.Name==Name&& e.Position==Position ) { return true; } return false; }
private Emploee ReadParameters() { Emploee empl = new Emploee(); if (departmentCheckBox.Checked) { if (comboBox1.SelectedItem != null) { empl.Department = comboBox1.SelectedItem.ToString(); } } if (nameCheckBox.Checked) { empl.Name = nameTextBox1.Text; } if (degreeCheckBox1.Checked) { empl.Degree = degreeTextBox1.Text; } if (positionCheckBox.Checked) { empl.Position = positionTextBox2.Text; } if (rankCheckBox1.Checked) { string[]ranks = rankTextBox1.Text.Split(new Char[]{',','.',';'}); if(ranks!=null) { foreach(string s in ranks) { empl.rank.Add(s); } } else { empl.rank.Add(String.Empty); } } if (audienceCheckBox1.Checked) { empl.SetAudience(audienceNumericUpDown1.Value.ToString(), null); if (letterCheckBox1.Checked) { empl.SetAudience(audienceNumericUpDown1.Value.ToString(), letterTextBox2.Text); } } if (phoneCheckBox1.Checked) { empl.SetPhone(phoneTextBox2.Text); } if (interestsCheckBox1.Checked) { empl.Interests = interestsTextBox1.Text; } return empl; }
private void ShowEmploee(Emploee empl) { List<string> data = new List<string>(); string s = String.Empty; string t = String.Empty; //department s = "Department: "; t = empl.Department; if (t == String.Empty) { t = "-"; } s = s + t; data.Add(s); //name s = "Name: "; t = empl.Name; if (t == String.Empty) { t = "-"; } s = s + t; data.Add(s); //position t = empl.Position; s = "Position: "; if (t == String.Empty) { t = "-"; } s = s + t; data.Add(s); //degree s = "Degree: "; t = empl.Degree; if (t == String.Empty) { t = "-"; } s = s + t; data.Add(s); //rank s = "Rank(s): "; t = String.Empty; string[] ar = empl.rank.ToArray(); if(ar!=null) { foreach(string st in ar) { if (t != String.Empty) { t = t + ", "; } t = t + st; } } if (t == String.Empty) { t = "-"; } s = s + t; data.Add(s); //audience s = "Audience: "; t = empl.GetNumberOfAudience(); if (empl.GetLetterOfAudience() != String.Empty) { t = t + " (" + empl.GetLetterOfAudience() + ")"; } if (t == String.Empty) { t = "-"; } s = s + t; data.Add(s); //phone s = "Phone: "; t = empl.GetPhone(); if (t == String.Empty) { t = "-"; } s = s + t; data.Add(s); //interests s = "Interests: "; t = empl.Interests; if (t == String.Empty) { t = "-"; } s = s + t; data.Add(s); // data is seted string[] str = data.ToArray(); foreach(string h in str) { resultRichTextBox1.AppendText(h+'\n'); } resultRichTextBox1.AppendText("---------------------------------------------------------------------------\n"); }
//DOM public static List<Emploee> SearchByDOM(Emploee empl) { List<List<Emploee>> allResults = new List<List<Emploee>>(); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"C:\Users\nazar\Documents\Visual Studio 2013\Projects\Laba3\Base.xml"); allResults.Add(SearchByDomDepartment(empl.Department, xmlDoc)); allResults.Add(SearchByDomName(empl.Name, xmlDoc)); allResults.Add(SearchByDomPosition(empl.Position, xmlDoc)); allResults.Add(SearchByDomDegree(empl.Degree, xmlDoc)); allResults.Add(SearchByDomAudience(empl.GetNumberOfAudience(), empl.GetLetterOfAudience(), xmlDoc)); allResults.Add(SearchByDomPhone(empl.GetPhone(), xmlDoc)); allResults.Add(SearchByDomInterests(empl.Interests, xmlDoc)); if (empl.rank.Count > 0) { allResults.Add(SearchByDomRank((empl.rank.ToArray())[0], xmlDoc)); } else { allResults.Add(SearchByDomRank(String.Empty, xmlDoc)); } } catch { } return CrossingOfResults(allResults); }
private static Emploee GetDataAboutEmploee(XmlNode em) { Emploee e = new Emploee(); XmlAttributeCollection at = em.Attributes; e.Department = em.ParentNode.Attributes[1].Value; e.Name = at[1].Value; e.Position = at[2].Value; e.Degree = at[3].Value; e.SetAudience(Emploee.GetOnlyNumbersFromPhone(at[4].Value), CutNumbers(at[4].Value)); e.SetPhone(at[5].Value); e.Interests = at[6].Value; XmlNodeList r = em.ChildNodes; foreach (XmlNode v in r) { e.rank.Add(v.Attributes[0].Value); } return e; }
static List<Emploee> FiltrByEmployee(List<Emploee> allEmpl, Emploee param) { List<Emploee> result = new List<Emploee>(); if(allEmpl!=null) { foreach(Emploee e in allEmpl) { try { if ((e.Name == param.Name || param.Name == String.Empty) && (e.Interests == param.Interests || param.Interests == String.Empty) && (e.Position == param.Position || param.Position == String.Empty) && (e.Department == param.Department || param.Department == String.Empty) && (e.Degree == param.Degree || param.Degree == String.Empty) && (e.GetPhone() == param.GetPhone() || param.GetPhone() == String.Empty) && ((e.GetLetterOfAudience() == param.GetLetterOfAudience() && e.GetNumberOfAudience() == param.GetNumberOfAudience()) || (param.GetNumberOfAudience() == String.Empty)) ) { if (e.rank.Count <= 0 || param.rank.Count <=0) { result.Add(e); } else { if(e.rank.Contains(param.rank[0])) result.Add(e); } } } catch { } } } return result; }
public static List<Emploee> SearchBySAX(Emploee empl) { List<Emploee> results = new List<Emploee>(); string dep = String.Empty; var xmlReader = new XmlTextReader(@"C:\Users\nazar\Documents\Visual Studio 2013\Projects\Laba3\Base.xml"); Emploee betw = null; while(xmlReader.Read()) { if (xmlReader.Name == "department") { while (xmlReader.MoveToNextAttribute()) { if (xmlReader.Name == "NANE") { dep = xmlReader.Value; } } } if(xmlReader.Name == "employee") { if(betw == null) { betw = new Emploee(); betw.Department = dep; } else { if(betw.Name!=String.Empty) results.Add(betw); betw = new Emploee(); betw.Department = dep; } if(xmlReader.HasAttributes) while(xmlReader.MoveToNextAttribute()) { if (xmlReader.Name == "NAME") {if(xmlReader.HasValue) betw.Name = xmlReader.Value; } if (xmlReader.Name == "DEGREE") { if (xmlReader.HasValue) betw.Degree = xmlReader.Value; } if (xmlReader.Name == "POSITION") { if (xmlReader.HasValue) betw.Position = xmlReader.Value; } if (xmlReader.Name == "INTERESTS") { if (xmlReader.HasValue) betw.Interests = xmlReader.Value; } if (xmlReader.Name == "PHONE") { if (xmlReader.HasValue)betw.SetPhone(xmlReader.Value); } if (xmlReader.Name == "AUDIENCE") { if (xmlReader.HasValue) betw.SetAudience(Emploee.GetOnlyNumbersFromPhone(xmlReader.Value), CutNumbers(xmlReader.Value)); } } } if (xmlReader.Name == "rank") { while (xmlReader.MoveToNextAttribute()) { if (xmlReader.HasValue) betw.rank.Add(xmlReader.Value); } } } // now we have all employees return FiltrByEmployee(results,empl); }
public static List<Emploee> SearchByLINQ(Emploee empl) { List<Emploee> results = new List<Emploee>(); XDocument docXML = XDocument.Load(@"C:\Users\nazar\Documents\Visual Studio 2013\Projects\Laba3\Base.xml"); var result = (from obj in docXML.Descendants("employee") where ( (empl.Name == String.Empty || empl.Name == obj.Attribute("NAME").Value) && (empl.Position == String.Empty || empl.Position == obj.Attribute("POSITION").Value) && (empl.Degree == String.Empty || empl.Degree == obj.Attribute("DEGREE").Value) && ((empl.GetLetterOfAudience() == CutNumbers(obj.Attribute("AUDIENCE").Value) && empl.GetNumberOfAudience() == Emploee.GetOnlyNumbersFromPhone(obj.Attribute("AUDIENCE").Value)) || empl.GetNumberOfAudience() == String.Empty) && (empl.GetPhone() == String.Empty || empl.GetPhone() == Emploee.GetOnlyNumbersFromPhone( obj.Attribute("PHONE").Value)) && (empl.Interests == String.Empty || empl.Interests == obj.Attribute("INTERESTS").Value) && (empl.Department == String.Empty || empl.Department == obj.Parent.Attribute("NANE").Value) && (empl.rank.Count <= 0 || obj.Descendants().Any(elem => (elem.Attribute("RANK").Value == empl.rank[0]))) ) select obj ).ToList(); foreach(var r in result) { Emploee e = new Emploee(); e.Name = r.Attribute("NAME").Value; e.Position = r.Attribute("POSITION").Value; e.Degree = r.Attribute("DEGREE").Value; e.Department = r.Parent.Attribute("NANE").Value; e.SetAudience(Emploee.GetOnlyNumbersFromPhone(r.Attribute("AUDIENCE").Value), CutNumbers(r.Attribute("AUDIENCE").Value)); e.SetPhone(r.Attribute("PHONE").Value); e.Interests = r.Attribute("INTERESTS").Value; var ranks = r.Descendants(); foreach(var rank in ranks) { e.rank.Add(rank.Attribute("RANK").Value); } results.Add(e); } return results; }