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
addressesToBindingList(Dictionary adresses)
{
SortableBindingList bindingList = new SortableBindingList();
foreach (Address address in adresses.Values)
{
bindingList.Add(address);
}
return bindingList;
}
public static SortableBindingList usersToBindingList(Dictionary users)
{
SortableBindingList bindingList = new SortableBindingList();
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;
}
}
}