|
@@ -9,16 +9,6 @@ namespace RaspisKusach
|
|
|
{
|
|
|
public class Functions
|
|
|
{
|
|
|
- // Валидация номера телефона
|
|
|
- public static bool IsValidPhoneNumber(string phoneNumber)
|
|
|
- {
|
|
|
- foreach (char c in phoneNumber)
|
|
|
- if (!char.IsDigit(c))
|
|
|
- return false;
|
|
|
- if (phoneNumber.Length != 11)
|
|
|
- return false;
|
|
|
- return true;
|
|
|
- }
|
|
|
// Получение направления по маршруту или поездке
|
|
|
public static string GetRouteDirection(Routes route)
|
|
|
{
|
|
@@ -61,83 +51,66 @@ namespace RaspisKusach
|
|
|
}
|
|
|
return date;
|
|
|
}
|
|
|
- // Валидация электронной почты
|
|
|
- public static bool IsValidEmail(string email)
|
|
|
+ // Валидация номера телефона
|
|
|
+ public static bool IsPhoneNumberCorrect(string phoneNumber)
|
|
|
{
|
|
|
- if (Regex.IsMatch(email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
|
|
|
- return true;
|
|
|
- else
|
|
|
+ foreach (char c in phoneNumber)
|
|
|
+ if (!char.IsDigit(c))
|
|
|
+ return false;
|
|
|
+ if (phoneNumber.Length != 11)
|
|
|
return false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Валидация электронной почты
|
|
|
+ public static bool IsEmailCorrect(string email)
|
|
|
+ {
|
|
|
+ return Regex.IsMatch(email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
|
|
|
}
|
|
|
// Валидация дня рождения
|
|
|
- public static bool IsValidDateOfBirthday(DateTime Date)
|
|
|
+ public static bool IsDateOfBirthdayCorrect(DateTime Date)
|
|
|
{
|
|
|
- if (Date > DateTime.Now)
|
|
|
- return false;
|
|
|
- else
|
|
|
- return true;
|
|
|
+ return Date <= DateTime.Now;
|
|
|
}
|
|
|
// Валидация логина и пароля при входе
|
|
|
- public static bool IsValidLogAndPass(string login, string password)
|
|
|
+ public static bool IsLogAndPassCorrect(string login, string password)
|
|
|
{
|
|
|
- if (login == "" || password == "")
|
|
|
- return false;
|
|
|
- else
|
|
|
- return true;
|
|
|
+ return login != "" && password != "";
|
|
|
}
|
|
|
// Валидация логина и пароля
|
|
|
public static bool IsLogEqualPass(string login, string password)
|
|
|
{
|
|
|
- if (login == password)
|
|
|
- return false;
|
|
|
- else
|
|
|
- return true;
|
|
|
+ return login == password; // RE
|
|
|
}
|
|
|
// Валидация логина и пароля
|
|
|
- public static bool IsValidLength(string str)
|
|
|
+ public static bool IsLengthCorrect(string str)
|
|
|
{
|
|
|
- if (str.Length < 5)
|
|
|
- return false;
|
|
|
- else
|
|
|
- return true;
|
|
|
+ return str.Length >= 5;
|
|
|
}
|
|
|
// Проверка на правильность введеных данных при входе
|
|
|
public static bool LoginCheck(string login, string password)
|
|
|
{
|
|
|
- if (cnt.db.Users.Select(item => item.Login + item.Password).Contains(login + Encrypt.GetHash(password)))
|
|
|
- return true;
|
|
|
- else
|
|
|
- return false;
|
|
|
+ return cnt.db.Users.Select(item => item.Login + item.Password).Contains(login + Encrypt.GetHash(password));
|
|
|
+ }
|
|
|
+ // Проверка на уникальность логина
|
|
|
+ public static bool IsLoginAlreadyTaken(string login)
|
|
|
+ {
|
|
|
+ return cnt.db.Users.Select(item => item.Login).Contains(login);
|
|
|
}
|
|
|
- //// Проверка на уникальность логина
|
|
|
- //public static bool IsLoginAlreadyTaken(string login)
|
|
|
- //{
|
|
|
- // return cnt.db.User.Select(item => item.NickName).Contains(login);
|
|
|
- //}
|
|
|
- //// Проверка на наличие чата
|
|
|
- //public static bool IsChatAlreadyCreated(string chatName)
|
|
|
- //{
|
|
|
- // return cnt.db.Chat.Select(item => item.Name).Contains(chatName);
|
|
|
- //}
|
|
|
- //// Получение id чата по его названию
|
|
|
- //public static int GetIdChat(string chatName)
|
|
|
- //{
|
|
|
- // return cnt.db.Chat.Where(item => item.Name == chatName).Select(item => item.IdChat).FirstOrDefault();
|
|
|
- //}
|
|
|
//// Проверка на уникальность электронной почты
|
|
|
//public static bool IsEmailAlreadyTaken(string Email)
|
|
|
//{
|
|
|
- // return cnt.db.User.Select(item => item.Email).Contains(Email);
|
|
|
+ // return cnt.db.Users.Select(item => item.).Contains(Email);
|
|
|
//}
|
|
|
//// Проверка на уникальность электронной почты
|
|
|
//public static bool IsPhoneNumberAlreadyTaken(string Phone)
|
|
|
//{
|
|
|
- // return cnt.db.User.Select(item => item.PhoneNumber).Contains(Phone);
|
|
|
+ // return cnt.db.Users.Select(item => item.).Contains(Phone);
|
|
|
//}
|
|
|
|
|
|
+ //Кодирование картинки
|
|
|
public static byte[] BitmapSourceToByteArray(BitmapSource image)
|
|
|
{
|
|
|
- #region Кодирование картинки
|
|
|
using (var stream = new MemoryStream())
|
|
|
{
|
|
|
var encoder = new PngBitmapEncoder();
|
|
@@ -145,9 +118,8 @@ namespace RaspisKusach
|
|
|
encoder.Save(stream);
|
|
|
return stream.ToArray();
|
|
|
}
|
|
|
- #endregion
|
|
|
}
|
|
|
-
|
|
|
+ // Выбор картинки
|
|
|
public static BitmapImage SelectImage()
|
|
|
{
|
|
|
#region Выбор картинки
|
|
@@ -158,13 +130,10 @@ namespace RaspisKusach
|
|
|
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
|
|
|
"Portable Network Graphic (*.png)|*.png"
|
|
|
};
|
|
|
- if (op.ShowDialog() == true)
|
|
|
- return new BitmapImage(new Uri(op.FileName));
|
|
|
- else
|
|
|
- return null;
|
|
|
+ return op.ShowDialog() == true ? new BitmapImage(new Uri(op.FileName)) : null;
|
|
|
#endregion
|
|
|
}
|
|
|
-
|
|
|
+ ////Декодирование картинки
|
|
|
//public static BitmapImage NewImage(Users user)
|
|
|
//{
|
|
|
// MemoryStream ms = new MemoryStream(user.Image);
|