166 lines
5.5 KiB
C#
166 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.RegularExpressions;
|
|
using Kreta.BusinessLogic.Classes;
|
|
using Kreta.BusinessLogic.Utils;
|
|
using Kreta.Core;
|
|
|
|
namespace Kreta.BusinessLogic.HelperClasses.ImportCo
|
|
{
|
|
public class BaseImportItemCo
|
|
{
|
|
public int? Id;
|
|
|
|
public int LineNumber { get; set; }
|
|
|
|
public int Operation { get; set; }
|
|
|
|
public string CompareHash { get; set; }
|
|
|
|
public List<string> ErrorList { get; set; } = new List<string>();
|
|
|
|
public DateTime Now => DateTime.Now;
|
|
|
|
#region Methods
|
|
|
|
public static bool? GetBooleanValue(string data, bool? defaultValue = null)
|
|
{
|
|
bool? result = !string.IsNullOrWhiteSpace(data) ? data.GetBooleanValueFromString() : defaultValue;
|
|
return result;
|
|
}
|
|
|
|
protected string GetStringValue(string data, string defaultValue = null)
|
|
{
|
|
string result = !string.IsNullOrWhiteSpace(data) ? data : defaultValue;
|
|
return result;
|
|
}
|
|
|
|
protected int? GetIntValue(string data, int? defaultValue = null)
|
|
{
|
|
int? result = !string.IsNullOrWhiteSpace(data) ? data.ToNullableInt() : defaultValue;
|
|
return result;
|
|
}
|
|
|
|
protected double? GetDoubleValue(string data, double? defaultValue = null)
|
|
{
|
|
double? result = !string.IsNullOrWhiteSpace(data) ? data.GetDoubleFromString() : defaultValue;
|
|
return result;
|
|
}
|
|
|
|
protected DateTime? GetDateTimeValue(string data, DateTime? defaultValue = null)
|
|
{
|
|
DateTime? result = !string.IsNullOrWhiteSpace(data) ? data.GetDateTimeFromString() : defaultValue;
|
|
return result;
|
|
}
|
|
|
|
public static DateTime? GetDateTimeValueFromTimeString(string data, DateTime? defaultValue = null)
|
|
{
|
|
var trimmed = data.ReplaceMultipleSpacesAndTrim();
|
|
|
|
if (string.IsNullOrWhiteSpace(trimmed))
|
|
{
|
|
return defaultValue;
|
|
}
|
|
|
|
var timeRegex = new Regex(@"([01]?[0-9]|2[0-3]):([0-5][0-9])");
|
|
|
|
var matches = timeRegex.Match(trimmed);
|
|
|
|
if (matches.Groups.Count < 3)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (!int.TryParse(matches.Groups[1].Value.ReplaceMultipleSpacesAndTrim(), out var hours) ||
|
|
!int.TryParse(matches.Groups[2].Value.ReplaceMultipleSpacesAndTrim(), out var minutes))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (hours < 0 || hours >= 24)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (minutes < 0 || minutes >= 60)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new DateTime(1900, 1, 1).AddHours(hours).AddMinutes(minutes);
|
|
}
|
|
|
|
protected string GetDateTimeString(DateTime? data)
|
|
{
|
|
//NOTE: Azért a SortableDateTimePattern-t használjuk, mert az sql ezt a formátumot hibátlanul kezeli!
|
|
string result = data?.ToString(Constants.ToStringPattern.SortableDateTimePattern);
|
|
return result;
|
|
}
|
|
|
|
//NOTE: Erre akkor van szükség, ha névegyezőség van, de külön személyről van szó. Akkor a születési dátummal tudjuk megkülönböztetni.
|
|
// Az alábbi formátumot kell alkalmaznia a felhasználónak: Tanár Neve (1985.01.01.)
|
|
protected DateTime? GetSzuletesIdoFromNev(string nevImportData)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(nevImportData))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
Regex regex = new Regex(@"\((.+?)\)");
|
|
MatchCollection matchCollection = regex.Matches(nevImportData);
|
|
DateTime? result = null;
|
|
if (matchCollection.Count > 0)
|
|
{
|
|
result = matchCollection[0].Groups[1].Value.Replace(" ", string.Empty).GetDateTimeFromString();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
protected string GetElotagFromTeljesNev(string nevImportData)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(nevImportData))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var elotag = NevUtils.GetNevCo(nevImportData).Elotag;
|
|
string result = string.IsNullOrWhiteSpace(elotag) ? null : elotag;
|
|
return result;
|
|
}
|
|
|
|
protected string GetVezeteknevFromTeljesNev(string nevImportData)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(nevImportData))
|
|
{
|
|
return null;
|
|
}
|
|
string result = NevUtils.GetNevCo(nevImportData).Vezeteknev;
|
|
return result;
|
|
}
|
|
|
|
protected string GetKeresztnevekFromTeljesNev(string nevImportData)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(nevImportData))
|
|
{
|
|
return null;
|
|
}
|
|
string result = NevUtils.GetNevCo(nevImportData).Keresztnev;
|
|
return result;
|
|
}
|
|
|
|
//NOTE: Ha a névben szerepelt születési dátum(a névegyezőségnél azzal különböztetjük meg), akkor azt levágva adjuk vissza a nevet.
|
|
protected string GetNev(string nevImportData, DateTime? szuletesiIdo)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(nevImportData))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var result = szuletesiIdo != null ? nevImportData.Substring(0, nevImportData.IndexOf("(", StringComparison.Ordinal)).ReplaceMultipleSpacesAndTrim() : nevImportData;
|
|
return result;
|
|
}
|
|
|
|
#endregion Methods
|
|
}
|
|
}
|