using Remontor.History; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Remontor.Seacher { internal class SeahcLocal : ISeaherMetod { internal delegate void ResultUpdate(List Item); private ResultUpdate Update; private List comps = new List(); private bool enable; public void Change(ResultUpdate sender, string seach) { Update = sender; if (seach.Length > 2) { Update(ResultSeach(seach)); } else { List result = new List(); result.Add(new NoResult("Введите запрос")); Update(result); } } //public List ResultSeach(string seach) //{ // int i = 0; // comps.Clear(); // List result = new List(); // foreach(HistoryItem item in HistoryList.Hitem) // { // if (item.NameNode().ToUpper().Contains(seach.ToUpper())) // { // int y = 0; // foreach(string itemOk in result) // { // if (itemOk.ToUpper() == item.NameNode().ToUpper()) ++y; // } // if(y == 0) // { // result.Add(item.NameNode()); // comps.Add(item.GetComp()); // ++i; // enable = true; // if (i>6) return result; // } // } // } // if (i == 0) // { // enable = false; // result.Add("Ничего не найдено"); // } // return result; //} public List ResultSeach(string seach) { int i = 0; comps.Clear(); List result = new List(); foreach (HistoryItem item in HistoryList.Hitem) { if (item.NameNode().ToUpper().Contains(seach.ToUpper())) { int y = 0; foreach (ISeacherResult itemOk in result) { if (itemOk.toString().ToUpper() == item.NameNode().ToUpper()) ++y; } if (y == 0) { HistoryResult itemResult = new HistoryResult(item.GetComp(), item.GetStart()); result.Add(itemResult); ++i; enable = true; if (i > 6) return result; } } } if (i == 0) { enable = false; result.Add(new NoResult("Ничего не найдено")); } return result; } public IComp Result(int index) { return comps[index]; } public string ResultString(int index) { string buf; if (comps[index].GetName() == null) { buf = comps[index].GetNetNameStr(); } else { buf = comps[index].GetName(); if (comps[index].GetNetNameStr() != null) buf += "(" + comps[index].GetNetNameStr() + ")"; } return buf; } } }