init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
59
Kreta.BusinessLogic/Extensions/DataSetExtensions.cs
Normal file
59
Kreta.BusinessLogic/Extensions/DataSetExtensions.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Kreta.Web.Helpers.Extension
|
||||
{
|
||||
public static class DataSetExtensions
|
||||
{
|
||||
public static List<SelectListItem> CreateMvcGroupedSelectListItem(this DataSet ds, string keyColumn, string valueColumn, string groupNamesColumn, string groupOrderColumn = null)
|
||||
{
|
||||
DataTable dt = ds.Tables.Count > 0 ? ds.Tables[0] : null;
|
||||
if (dt == null)
|
||||
{
|
||||
return new List<SelectListItem>();
|
||||
}
|
||||
EnumerableRowCollection<DataRow> dataRowList = dt.AsEnumerable();
|
||||
if (!string.IsNullOrWhiteSpace(groupOrderColumn))
|
||||
{
|
||||
dataRowList = dataRowList.OrderBy(x => x.Field<int>(groupOrderColumn));
|
||||
}
|
||||
var groups = dataRowList
|
||||
.GroupBy(x => x.Field<string>(groupNamesColumn))
|
||||
.Select(group => new KeyValuePair<string, SelectListGroup>(group.Key, new SelectListGroup { Name = group.Key }))
|
||||
.ToDictionary(item => item.Key, item => item.Value);
|
||||
|
||||
var result = dt.Rows
|
||||
.Cast<DataRow>()
|
||||
.Select(item => new SelectListItem
|
||||
{
|
||||
Group = groups[item.Field<string>(groupNamesColumn)],
|
||||
Text = item.Field<string>(valueColumn),
|
||||
Value = item.Field<int>(keyColumn).ToString()
|
||||
})
|
||||
.ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<SelectListItem> CreateMvcSelectListItem(this DataSet ds, string keyColumn, string valueColumn)
|
||||
{
|
||||
DataTable dt = ds.Tables.Count > 0 ? ds.Tables[0] : null;
|
||||
if (dt == null)
|
||||
{
|
||||
return new List<SelectListItem>();
|
||||
}
|
||||
EnumerableRowCollection<DataRow> dataRowList = dt.AsEnumerable();
|
||||
|
||||
var result = dt.Rows
|
||||
.Cast<DataRow>()
|
||||
.Select(item => new SelectListItem
|
||||
{
|
||||
Text = item.Field<string>(valueColumn),
|
||||
Value = item.Field<int>(keyColumn).ToString()
|
||||
})
|
||||
.ToList();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
31
Kreta.BusinessLogic/Extensions/DataTableExtensions.cs
Normal file
31
Kreta.BusinessLogic/Extensions/DataTableExtensions.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Kreta.Web.Helpers.Extension
|
||||
{
|
||||
public static class DataTableExtensions
|
||||
{
|
||||
public static void RemoveDataRowIfAnyColumnValueMatch(this DataTable dataTable, string columnName, List<int> columnValues)
|
||||
{
|
||||
if (!dataTable.Columns.Contains(columnName) || (dataTable.Columns[columnName].DataType != typeof(int?) && dataTable.Columns[columnName].DataType != typeof(int)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
{
|
||||
foreach (var columnValue in columnValues)
|
||||
{
|
||||
if (row.RowState != DataRowState.Deleted && row.Field<int?>(columnName) == columnValue)
|
||||
{
|
||||
row.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dataTable.AcceptChanges();
|
||||
}
|
||||
}
|
||||
}
|
140
Kreta.BusinessLogic/Extensions/FelhasznaloExtensions.cs
Normal file
140
Kreta.BusinessLogic/Extensions/FelhasznaloExtensions.cs
Normal file
|
@ -0,0 +1,140 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.BusinessLogic.Extensions
|
||||
{
|
||||
public static class FelhasznaloExtensions
|
||||
{
|
||||
public static bool IsValidTajSzam(this string tajSzam, bool isNullValid = false)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(tajSzam))
|
||||
{
|
||||
if (tajSzam.Length != 9)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var tajSzamSzamok = new int[9];
|
||||
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
if (!int.TryParse(tajSzam[i].ToString(), out int tajSzamSzam))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
tajSzamSzamok[i] = tajSzamSzam;
|
||||
}
|
||||
|
||||
if ((((tajSzamSzamok[1] + tajSzamSzamok[3] + tajSzamSzamok[5] + tajSzamSzamok[7]) * 7) + ((tajSzamSzamok[0] + tajSzamSzamok[2] + tajSzamSzamok[4] + tajSzamSzamok[6]) * 3)) % 10 != tajSzamSzamok[8])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return isNullValid;
|
||||
}
|
||||
|
||||
|
||||
public static bool IsValidOktatasiAzonosito(this string oktatasiAzonosito)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(oktatasiAzonosito))
|
||||
{
|
||||
if (oktatasiAzonosito.Length != 11)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var oktatasiAzonositoSzamok = new int[11];
|
||||
|
||||
for (int i = 0; i <= 10; i++)
|
||||
{
|
||||
if (!int.TryParse(oktatasiAzonosito[i].ToString(), out int oktatasiAzonositoSzam))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (i == 0 && oktatasiAzonositoSzam != 7)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
oktatasiAzonositoSzamok[i] = oktatasiAzonositoSzam;
|
||||
}
|
||||
|
||||
int oktatasiAzonositoSzorzat = 0;
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
oktatasiAzonositoSzorzat += oktatasiAzonositoSzamok[i - 1] * i;
|
||||
}
|
||||
|
||||
if (oktatasiAzonositoSzorzat % 11 != oktatasiAzonositoSzamok[10])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsValidAdoazonositoJel(this string adoazonositoJel, DateTime szuletesiDatum, bool isNullValid = false)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(adoazonositoJel))
|
||||
{
|
||||
if (adoazonositoJel.Length != 10)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var adoazonositoJelSzamok = new int[10];
|
||||
|
||||
for (int i = 0; i <= 9; i++)
|
||||
{
|
||||
if (!int.TryParse(adoazonositoJel[i].ToString(), out int adoazonositoJelSzam))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (i == 0 && adoazonositoJelSzam != 8)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
adoazonositoJelSzamok[i] = adoazonositoJelSzam;
|
||||
}
|
||||
|
||||
var szuletesiDatumKontroll = new DateTime(1867, 01, 01);
|
||||
var szuletesiDatumKulonbseg = szuletesiDatum - szuletesiDatumKontroll;
|
||||
var szuletesiDatumAdoazonositoJel = adoazonositoJelSzamok[1].ToString() + adoazonositoJelSzamok[2].ToString() + adoazonositoJelSzamok[3].ToString() + adoazonositoJelSzamok[4].ToString() + adoazonositoJelSzamok[5].ToString();
|
||||
|
||||
if (!int.TryParse(szuletesiDatumAdoazonositoJel, out int szuletesiDatumAdoazonositoJelSzam))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (szuletesiDatumAdoazonositoJelSzam != szuletesiDatumKulonbseg.Days)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int adoazonositoJelSzorzat = 0;
|
||||
for (int i = 1; i <= 9; i++)
|
||||
{
|
||||
adoazonositoJelSzorzat += adoazonositoJelSzamok[i - 1] * i;
|
||||
}
|
||||
|
||||
if (adoazonositoJelSzorzat % 11 != adoazonositoJelSzamok[9])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return isNullValid;
|
||||
}
|
||||
}
|
||||
}
|
30
Kreta.BusinessLogic/Extensions/NameExtensions.cs
Normal file
30
Kreta.BusinessLogic/Extensions/NameExtensions.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using Kreta.Core;
|
||||
|
||||
namespace Kreta.BusinessLogic.Extensions
|
||||
{
|
||||
public static class NameExtensions
|
||||
{
|
||||
public static string CleanElotag(this string elotag)
|
||||
{
|
||||
var trimmed = elotag.ReplaceMultipleSpacesAndTrim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(trimmed))
|
||||
{
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
return GetStringWithoutDuplicatedDots(trimmed);
|
||||
}
|
||||
|
||||
public static string GetNevSorrendben(string nevSorrend, string nevElotag, string vezetekNev, string keresztNev)
|
||||
=> $"{nevElotag} {(string.Equals(nevSorrend, "F", StringComparison.OrdinalIgnoreCase) ? $"{vezetekNev} {keresztNev}" : $"{keresztNev} {vezetekNev}")}".ReplaceMultipleSpacesAndTrim();
|
||||
|
||||
private static string GetStringWithoutDuplicatedDots(string text)
|
||||
=> NullableRegexReplace(text, @"\.+", ".");
|
||||
|
||||
private static string NullableRegexReplace(this string text, string pattern, string replacement)
|
||||
=> string.IsNullOrWhiteSpace(text) ? text : Regex.Replace(text, pattern, replacement);
|
||||
}
|
||||
}
|
16
Kreta.BusinessLogic/Extensions/TimeSpanExtensions.cs
Normal file
16
Kreta.BusinessLogic/Extensions/TimeSpanExtensions.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Kreta.BusinessLogic.Extensions
|
||||
{
|
||||
public static class TimeSpanExtensions
|
||||
{
|
||||
public static TimeSpan RoundDownToNearestTargetMinute(this TimeSpan timeSpan, int targetMinute)
|
||||
{
|
||||
return timeSpan.Subtract(new TimeSpan(0, timeSpan.Minutes % targetMinute, 0));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue