124 lines
3.7 KiB
C#
124 lines
3.7 KiB
C#
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<ISeacherResult> Item);
|
|
private ResultUpdate Update;
|
|
private List<IComp> comps = new List<IComp>();
|
|
private bool enable;
|
|
public void Change(ResultUpdate sender, string seach)
|
|
{
|
|
Update = sender;
|
|
if (seach.Length > 2)
|
|
{
|
|
|
|
Update(ResultSeach(seach));
|
|
}
|
|
else
|
|
{
|
|
List<ISeacherResult> result = new List<ISeacherResult>();
|
|
result.Add(new NoResult("Введите запрос"));
|
|
Update(result);
|
|
}
|
|
|
|
}
|
|
//public List<string> ResultSeach(string seach)
|
|
//{
|
|
// int i = 0;
|
|
// comps.Clear();
|
|
// List<string> result = new List<string>();
|
|
// 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<ISeacherResult> ResultSeach(string seach)
|
|
{
|
|
int i = 0;
|
|
comps.Clear();
|
|
List<ISeacherResult> result = new List<ISeacherResult>();
|
|
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 > 20) 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;
|
|
}
|
|
}
|
|
}
|