158 lines
5.2 KiB
C#
158 lines
5.2 KiB
C#
using Remontor.History;
|
|
using Remontor.Seacher;
|
|
using System;
|
|
using System.Collections;
|
|
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());
|
|
// int razdelitel = item.NameNode().IndexOf('(');
|
|
// if (razdelitel != -1)
|
|
// {
|
|
// int beginString = item.NameNode().ToUpper().IndexOf(seach.ToUpper());
|
|
// if (razdelitel<beginString)
|
|
// {
|
|
// ResultStr.Add(item.NameNode().Substring(razdelitel + 1, item.NameNode().Length - razdelitel - 2));
|
|
// }
|
|
// else
|
|
// {
|
|
// ResultStr.Add(item.NameNode().Substring(0, razdelitel));
|
|
// }
|
|
// }
|
|
// else
|
|
//{
|
|
// ResultStr.Add(item.NameNode());
|
|
//}
|
|
//++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)
|
|
{
|
|
string bufferQuest;
|
|
int razdelitel = item.NameNode().IndexOf('(');
|
|
if (razdelitel != -1)
|
|
{
|
|
int beginString = item.NameNode().ToUpper().IndexOf(seach.ToUpper());
|
|
if (razdelitel < beginString)
|
|
{
|
|
bufferQuest = item.NameNode().Substring(razdelitel + 1, item.NameNode().Length - razdelitel - 2);
|
|
}
|
|
else
|
|
{
|
|
bufferQuest = item.NameNode().Substring(0, razdelitel);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bufferQuest = item.NameNode();
|
|
}
|
|
HistoryResult itemResult = new HistoryResult(item.GetComp(), item.GetStart().ToString(), bufferQuest);
|
|
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;
|
|
//}
|
|
}
|
|
}
|