DeliveryAdminWindow is now able to look at deliveries
This commit is contained in:
@ -15,7 +15,9 @@ using System.Collections;
|
||||
namespace Elwig.Helpers {
|
||||
public static partial class Utils {
|
||||
|
||||
public static int CurrentSeason => DateTime.Now.Year - (DateTime.Now.Month <= 3 ? 1 : 0);
|
||||
public static int CurrentNextSeason => DateTime.Now.Year - (DateTime.Now.Month <= 3 ? 1 : 0);
|
||||
public static int CurrentLastSeason => DateTime.Now.Year - (DateTime.Now.Month <= 7 ? 1 : 0);
|
||||
public static DateTime Today => (DateTime.Now.Hour >= 3) ? DateTime.Today : DateTime.Today.AddDays(-1);
|
||||
|
||||
public static readonly Regex SerialRegex = GeneratedSerialRegex();
|
||||
public static readonly Regex TcpRegex = GeneratedTcpRegex();
|
||||
@ -164,6 +166,13 @@ namespace Elwig.Helpers {
|
||||
dataGrid.CurrentCell = new(dataGrid.SelectedItem, column);
|
||||
}
|
||||
|
||||
public static void RenewItemsSource(ListBox listBox, IEnumerable? source, Func<object?, object?> getId) {
|
||||
var selectedId = getId(listBox.SelectedItem);
|
||||
listBox.ItemsSource = source;
|
||||
if (selectedId != null && source != null)
|
||||
listBox.SelectedItem = source.Cast<object>().FirstOrDefault(i => selectedId.Equals(getId(i)));
|
||||
}
|
||||
|
||||
public static int Modulo(string a, int b) {
|
||||
if (a.Length == 0 || !a.All(char.IsAsciiDigit)) {
|
||||
throw new ArgumentException("First argument has to be a decimal string");
|
||||
@ -214,5 +223,28 @@ namespace Elwig.Helpers {
|
||||
var b = (birthday.Year * 100 + birthday.Month) * 100 + birthday.Day;
|
||||
return (a - b) / 10000;
|
||||
}
|
||||
|
||||
public static int GetSearchScore(IEnumerable<string?> words, IEnumerable<string> searchKeywords) {
|
||||
searchKeywords = searchKeywords.Where(s => s.Length >= 2 || (s.Length > 0 && s.All(c => char.IsAsciiDigit(c))));
|
||||
if (!searchKeywords.Any())
|
||||
return 0;
|
||||
|
||||
words = words.Select(w => w?.ToLower());
|
||||
int i = 0;
|
||||
foreach (string? c in words) {
|
||||
if (c == null) continue;
|
||||
var parts = c.Split(" ");
|
||||
if (searchKeywords.Any(f => c == f)) {
|
||||
i += 100;
|
||||
} else if (searchKeywords.Any(f => parts.Any(a => a == f))) {
|
||||
i += 90;
|
||||
} else if (searchKeywords.Any(f => parts.Any(a => a.StartsWith(f)))) {
|
||||
i += 50;
|
||||
} else if (searchKeywords.Any(f => f != null && c.Contains(f))) {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user