2024-01-30 00:48:46 +00:00
|
|
|
|
|
|
|
|
|
|
using GalaSoft.MvvmLight;
|
2024-01-31 06:26:57 +00:00
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
|
|
using StandardDesign.IDataAccess;
|
|
|
|
|
|
using StandardDesign.Models;
|
|
|
|
|
|
using System.CodeDom;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using System.Windows;
|
2024-01-30 00:48:46 +00:00
|
|
|
|
|
|
|
|
|
|
namespace StandardDesign.ViewModels
|
|
|
|
|
|
{
|
|
|
|
|
|
public class LoginViewModel : ViewModelBase
|
|
|
|
|
|
{
|
2024-01-31 06:26:57 +00:00
|
|
|
|
ILoacalDataAccess _localDataAccess;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//ip
|
|
|
|
|
|
public string ip;
|
|
|
|
|
|
public string IP
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ip; }
|
|
|
|
|
|
set { Set(ref ip, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
//Port
|
|
|
|
|
|
public string port;
|
|
|
|
|
|
public string Port
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return port; }
|
|
|
|
|
|
set { Set(ref port, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><>Ȩ<EFBFBD><C8A8>
|
|
|
|
|
|
public string _authorizeCode;
|
|
|
|
|
|
public string AuthorizeCode
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _authorizeCode; }
|
|
|
|
|
|
set { Set(ref _authorizeCode, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>쳣<EFBFBD><ECB3A3>Ϣ
|
|
|
|
|
|
public string _failedMsg;
|
|
|
|
|
|
public string FailedMsg
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _failedMsg; }
|
|
|
|
|
|
set { Set(ref _failedMsg, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>Ƿ<C7B7><F1B1A3B4><EFBFBD>¼
|
|
|
|
|
|
private bool _isRecord;
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsRecord
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _isRecord; }
|
|
|
|
|
|
set { Set<bool>(ref _isRecord, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><>¼<EFBFBD><C2BC>ť
|
|
|
|
|
|
public RelayCommand<object> LoginCommand { get; set; }
|
|
|
|
|
|
public RelayCommand<object> SkipCommand { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LoginViewModel(ILoacalDataAccess localDataAccess)
|
|
|
|
|
|
{
|
|
|
|
|
|
_localDataAccess = localDataAccess;
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists("temp.txt"))
|
|
|
|
|
|
{
|
|
|
|
|
|
string info = File.ReadAllText("temp.txt");
|
|
|
|
|
|
this.IP = info.Split("|")[0];
|
|
|
|
|
|
this.Port = info.Split("|")[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!IsInDesignMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoginCommand = new RelayCommand<object>(DoLogin);
|
|
|
|
|
|
SkipCommand = new RelayCommand<object>(SkipLogin);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void DoLogin(object obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>¼
|
|
|
|
|
|
if (IsRecord)
|
|
|
|
|
|
{
|
|
|
|
|
|
string info = $"{this.IP}|{this.Port}";
|
|
|
|
|
|
File.WriteAllText("temp.txt", info);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists("temp.txt"))
|
|
|
|
|
|
File.Delete("temp.text");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(IP))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("IP<49><50>ַΪ<D6B7><CEAA>!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!ValidateIPAddress(IP))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("IP<49><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (string.IsNullOrEmpty(Port))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("<22>˿ں<CBBF>Ϊ<EFBFBD><CEAA>!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!ValidatePortAddress(Port))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("<22>˿ں<CBBF><DABA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
(obj as Window).DialogResult = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
FailedMsg = ex.Message;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
|
|
|
|
|
|
|
private void SkipLogin(object obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
(obj as Window).DialogResult = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// У<><D0A3>Ip
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ipAddress"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static bool ValidateIPAddress(string ipAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
Regex validipregex = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
|
|
|
|
|
|
return (ipAddress != "" && validipregex.IsMatch(ipAddress.Trim())) ? true : false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// У<><D0A3><EFBFBD>˿ں<CBBF>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="prtAddress"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static bool ValidatePortAddress(string prtAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
Regex validipregex = new Regex(@"^(\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$");
|
|
|
|
|
|
return (prtAddress != "" && validipregex.IsMatch(prtAddress.Trim())) ? true : false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-30 00:48:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|