Learning/Mysql-example/Util/Utility.cs
2023-05-05 20:58:11 +02:00

43 lines
1.5 KiB
C#

using Mysql_example.Database.Schema;
using System.Text.RegularExpressions;
namespace Mysql_example.Util
{
public static class Utility
{
private static Regex emailValidationRegex = new Regex(@"^([\w\.\-\+]+)@([\w\-]+)((\.(\w){2,3})+)$");
public static SortableBindingList<Address> addressesToBindingList(Dictionary<ulong, Address> adresses)
{
SortableBindingList<Address> bindingList = new SortableBindingList<Address>();
foreach (Address address in adresses.Values)
{
bindingList.Add(address);
}
return bindingList;
}
public static SortableBindingList<User> usersToBindingList(Dictionary<ulong, User> users)
{
SortableBindingList<User> bindingList = new SortableBindingList<User>();
foreach (User user in users.Values)
{
bindingList.Add(new User(user));
}
return bindingList;
}
public static string dateTimeToDatabaseTimestamp(DateTime dateTime)
{
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
public static string dateTimeToDatabaseBirthday(DateTime dateTime)
{
return dateTime.ToString("yyyy-MM-dd");
}
public static bool IsValidEmail(string email)
{
return emailValidationRegex.Match(email).Success;
}
}
}