using System.Security.AccessControl;
using System.Text;
using System.Threading;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
using Muchinfo.MTPClient.Account.Views;
using Muchinfo.MTPClient.CustomException;
using Muchinfo.MTPClient.Data;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Data.Helper;
using Muchinfo.MTPClient.Data.Model;
using Muchinfo.MTPClient.Data.Model.Account;
using Muchinfo.MTPClient.Data.Model.GoodRules;
using Muchinfo.MTPClient.Infrastructure.Cache;
using Muchinfo.MTPClient.Infrastructure.Helpers;
using Muchinfo.MTPClient.Infrastructure.LinkProxy;
using Muchinfo.MTPClient.Infrastructure.MessageBox;
using Muchinfo.MTPClient.Infrastructure.Users;
using Muchinfo.MTPClient.Infrastructure.Utilities;
using Muchinfo.MTPClient.IService;
using Muchinfo.MTPClient.Resources;
using Muchinfo.MTPClient.Service.Utilities;
using Muchinfo.MTPClient.UI.Utilities;
using Muchinfo.MTPClient.UI.Views;
using Muchinfo.PC.Common.Extensions;
using Muchinfo.PC.Common.Helpers;
using Muchinfo.WPF.Controls.Keyboard;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Collections;
namespace Muchinfo.MTPClient.UI.ViewModels
{
public class LoginWindowBase : Window
{
public LoginWindowBase() { }
}
///
/// 用户登录
///
public class LoginViewModel : ViewModelBase
{
#region Fields
private const int c_MaxLoginError = 6;
private const int c_QueryCount = 2; //登录总共需查询数量
private int _loginCount = 0;
//最近一次登录会员
private LastLoginUser lastLoginUser;
private ISystemService _iSystemService;
private IDBTableMsgService _IDBTableMsgService;
private int _queryComplete ; ///查询完成数量
public static object _lockObject = new object();
private static AutoResetEvent _mutex = new AutoResetEvent(false);
public ILoginService _loginService { get; set; }
private LoginWindowBase _view;
private ValidCode vc;//实例4位字符加数字的验证码
private string _systemName;
private string _progressText;
private bool _connectResult; ////连接是否成功
// 风管云平台
private IErmcpService _ermcpService;
#endregion
#region 绑定属性
///
/// 客户端版本
///
public string Version
{
get
{
return "v"+ ApplicationParameter.Version;
}
}
#region 隐藏控件当指定条件
private Visibility _isVisibilityControlHidden = Visibility.Visible;
///
/// 隐藏控件当指定条件
///
public Visibility IsVisibilityControlHidden
{
get
{
return _isVisibilityControlHidden;
}
set
{
Set(() => IsVisibilityControlHidden, ref _isVisibilityControlHidden, value);
}
}
#endregion
#region 变更集合列数
private decimal _columnSpan3 = 1;
///
/// 变更集合列数
///
public decimal ColumnSpan3
{
get
{
return _columnSpan3;
}
set
{
Set(() => ColumnSpan3, ref _columnSpan3, value);
}
}
#endregion
#region 验证码容器偏移量
private string _marginValue = "35,0,0,0";
///
/// 验证码容器偏移量
///
public string MarginValue
{
get
{
return _marginValue;
}
set
{
Set(() => MarginValue, ref _marginValue, value);
}
}
#endregion
#region 是否显示验证码
private Visibility _isVisibilityIdentifyingCode = Visibility.Collapsed;
///
/// 是否显示验证码
///
public Visibility IsVisibilityIdentifyingCode
{
get
{
return _isVisibilityIdentifyingCode;
}
set
{
Set(() => IsVisibilityIdentifyingCode, ref _isVisibilityIdentifyingCode, value);
}
}
#endregion
///
/// 登录方式集合
///
private List _loginTypeList;
public List LoginTypeList
{
get { return _loginTypeList; }
set
{
Set(() => LoginTypeList, ref _loginTypeList, value);
}
}
///
/// 登录方式
///
private DropDataTemplate _currentLoginType;
public DropDataTemplate CurrentLoginType
{
get { return _currentLoginType; }
set
{
Set(() => CurrentLoginType, ref _currentLoginType, value);
if (CurrentLoginType.Value == 0)
{
TradeLoginVisibility = Visibility.Visible;
PhoneLoginVisibility = Visibility.Collapsed;
}
else if (CurrentLoginType.Value == 1)
{
TradeLoginVisibility = Visibility.Collapsed;
PhoneLoginVisibility = Visibility.Visible;
}
}
}
///
/// 交易登录是否显示,隐藏
///
private Visibility _tradeLoginVisibility;
public Visibility TradeLoginVisibility
{
get
{
return _tradeLoginVisibility;
}
set
{
Set(() => TradeLoginVisibility, ref _tradeLoginVisibility, value);
}
}
///
/// 手机登录是否显示,隐藏
///
private Visibility _phoneLoginVisibility;
public Visibility PhoneLoginVisibility
{
get
{
return _phoneLoginVisibility;
}
set
{
Set(() => PhoneLoginVisibility, ref _phoneLoginVisibility, value);
}
}
private List _loginAccountList = new List();
///
/// 记住账号列表
///
public List LoginAccountList
{
get { return _loginAccountList; }
set
{
Set(() => LoginAccountList, ref _loginAccountList, value);
}
}
private string _tradeAccount = string.Empty;
///
/// 交易账号
///
public string TradeAccount
{
get
{
return _tradeAccount;
}
set
{
if (_tradeAccount == value) return;
_tradeAccount = value;
RaisePropertyChanged(() => TradeAccount);
TradePassword = string.Empty;
#if DEBUG
TradePassword = "123456";
#endif
if (LoginAccountList == null) return;
var frirstUser = LoginAccountList.FirstOrDefault(user => _tradeAccount.Equals(user.UserName));
if (frirstUser != null)
{
IsSaveAccount = frirstUser.RememberAccount;
}
else
{
IsSaveAccount = true;
}
}
}
private string _tradePassword = string.Empty;
///
/// 交易密码
///
public string TradePassword
{
get
{
return _tradePassword;
}
set
{
Set(() => TradePassword, ref _tradePassword, value);
}
}
private bool _isSaveAccount = true;
///
/// 是否保存账号
///
public bool IsSaveAccount
{
get { return _isSaveAccount; }
set
{
Set(() => IsSaveAccount, ref _isSaveAccount, value);
}
}
private double _processRate = 1;
///
/// 处理进度
///
public double ProcessRate
{
set
{
Set(() => ProcessRate, ref _processRate, value);
}
get
{
return _processRate;
}
}
private bool _isEnabled = true;
///
/// 用于控制登录按钮是否可用
///
public bool IsEnabled
{
get { return _isEnabled; }
set
{
Set(() => IsEnabled, ref _isEnabled, value);
}
}
private bool _isMainEnabled = false;
///
/// 是否完成加载数据
///
public bool IsMainEnabled
{
get { return _isMainEnabled; }
set { Set(() => IsMainEnabled, ref _isMainEnabled, value); }
}
private bool _isReadOnly = false;
///
/// 用于控制文本框只读
///
public bool IsReadOnly
{
get { return _isReadOnly; }
set
{
Set(() => IsReadOnly, ref _isReadOnly, value);
}
}
private bool _isOKCommand = true;
///
/// 是否可登录操作
///
public bool IsOKCommand
{
get { return _isOKCommand; }
set { _isOKCommand = value; }
}
public string _imagePath;
public string ImagePath
{
get
{
return _imagePath;
}
set
{
_imagePath = value;
RaisePropertyChanged(() => ImageSource);
}
}
public BitmapImage ImageSource
{
get
{
if (File.Exists(ImagePath))
{
return new BitmapImage(new Uri(ImagePath));
}
else
{
return null;
}
}
}
private ImageSource _identifyingCodeImg;
public ImageSource IdentifyingCodeImg
{
get
{
return _identifyingCodeImg;
}
set
{
Set(() => IdentifyingCodeImg, ref _identifyingCodeImg, value);
}
}
private string _identifyingCode = string.Empty;
public string IdentifyingCode
{
get
{
if (_identifyingCode.Length == 4 && string.Compare(_identifyingCode, vc.CheckCode, true) == 0)
{
IdentifyingCodeRightOrErrorImg = new BitmapImage(new Uri("../../Images/RightIcon.png", UriKind.Relative));
}
else
{
IdentifyingCodeRightOrErrorImg = new BitmapImage(new Uri("../../Images/ErrorIcon.png", UriKind.Relative));
}
return _identifyingCode;
}
set
{
Set(() => IdentifyingCode, ref _identifyingCode, value);
}
}
#region 验证码实时验证对错图标
//private BitmapImage RightIcon = new BitmapImage(new Uri("../../Images/RightIcon.png", UriKind.Relative));
//private BitmapImage ErrorIcon = new BitmapImage(new Uri("../../Images/ErrorIcon.png", UriKind.Relative));
private ImageSource _identifyingCodeRightOrErrorImg = new BitmapImage(new Uri("../../Images/ErrorIcon.png", UriKind.Relative));
public ImageSource IdentifyingCodeRightOrErrorImg
{
get
{
return _identifyingCodeRightOrErrorImg;
}
set
{
Set(() => IdentifyingCodeRightOrErrorImg, ref _identifyingCodeRightOrErrorImg, value);
}
}
#endregion
///
/// 交易系统名称
///
/// The name of the system.
public string SystemName
{
get
{
return _systemName;
}
set
{
Set(() => SystemName, ref _systemName, value);
}
}
///
/// 进度条的名称
///
public string ProgressText
{
get
{
return _progressText;
}
set
{
Set(() => ProgressText, ref _progressText, value);
}
}
public Brush _progressTextForeground;
///
/// 进度条错误提示
///
public Brush ProgressTextForeground
{
get
{
return _progressTextForeground;
}
set
{
Set(() => ProgressTextForeground, ref _progressTextForeground, value);
}
}
#endregion
private int QueryComplete
{
get { return _queryComplete; }
set
{
lock (_lockObject)
{
_queryComplete = value;
}
}
}
#region 构造函数
///
/// Initializes a new instance of the class.
///
public LoginViewModel()
{
_loginService = SimpleIoc.Default.GetInstance();
_IDBTableMsgService = SimpleIoc.Default.GetInstance();
_iSystemService = SimpleIoc.Default.GetInstance();
LoginTypeList = EnumHelper.EnumToDictionary(typeof (LoginType));
CurrentLoginType = LoginTypeList.FirstOrDefault(k => k.Value == 0);
SystemName = ApplicationParameter.TradeSystemName;
_ermcpService = SimpleIoc.Default.GetInstance();
MessengerHelper.DefaultRegister(this, MessengerTokens.TradeCreateConnect, ((result) =>
{
_connectResult = result;
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
_mutex.Set();// IsEnabled = true;
}));
}));
////实例4位字符加数字的验证码
vc = new ValidCode(4, ValidCode.CodeType.Words);
Task.Factory.TryStartNew(() => InitDataAccount(), () => IsMainEnabled = true);
IdentifyingCodeImg = BitmapFrame.Create(vc.CreateCheckCodeImage());
HiddenCotrl();
if (ApplicationParameter.IsShowIdentifyingCode == ((int)eShowIdentifyingCode.Show).ToString())
{
IsVisibilityIdentifyingCode = Visibility.Visible;
}
}
#endregion
#region 绑定命令
///
/// 更新验证码IsSaveAccount
///
public RelayCommand IdentifyingCodeCommand
{
get
{
return new RelayCommand(() =>
{
IdentifyingCodeImg = BitmapFrame.Create(vc.CreateCheckCodeImage());
RaisePropertyChanged(() => IdentifyingCode);
});
}
}
///
/// 打开键盘命令
///
public RelayCommand OpenKeyboardCommand
{
get
{
return new RelayCommand((control) =>
{
PassWordKeyBoard.SetTouchScreenKeyboard(control, true);
control.Focus();
});
}
}
public RelayCommand LoginNewCommand
{
get
{
return new RelayCommand(
(v) =>
{
//验证用户输入基本信息
if (!ValidData()) return;
ProcessRate = 1;
QueryComplete = c_QueryCount; //需查询数量
try
{
//============================
if (IsEnabled == false) return;
IsEnabled = false;
IsReadOnly = true;
ProgressTextForeground = Application.Current.FindResource("MuchinfoBrush124") as Brush;
ProgressText = Client_Resource.Login_Progress_Logining;
_view = v;
//播放加载动画
//BeginStoryboard("ShowProgress");
ProgressText = Client_Resource.Login_Progress_Title;
//创建交易链路
LinkManager.Instance.CreateTradeLink();
Task.Factory.TryStartNew(() =>
{
_mutex.WaitOne();
if (_connectResult)
{
LogInfoHelper.WriteInfo("登陆开始...账号:" + TradeAccount.Trim());
// 风管云平台增加登录代码和手机号码登录
_ermcpService.GetLoginId(TradeAccount.Trim(), new Action((loginId) =>
{
// CTP获取系统信息
var systemInfo = _ermcpService.GetSystemInfo();
var password = EncryptHelper.SHA256(loginId + TradePassword.Trim()).ToLower();
_loginService.TradeAccountLogin((LoginType)CurrentLoginType.Value, Convert.ToUInt64(loginId),
loginId, password, systemInfo, LoginCallBack, LoginErrorFunc);
//LoginCallBack(new TradeAccount() { LoginID = 310020000 });
}), null);
//var password = EncryptHelper.SHA256(TradeAccount.Trim() + TradePassword.Trim()).ToLower();
//_loginService.TradeAccountLogin((LoginType)CurrentLoginType.Value, Convert.ToUInt64(TradeAccount.Trim()),
// TradeAccount.Trim(), password, LoginCallBack, LoginErrorFunc);
}
else
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
ErrorManager.ShowReturnError(ExceptionManager.ConnectTradeServerTimeOut,
Client_Resource.UI2014_LoginTips);
RestStoryboard();
}));
}
});
}
catch (Exception ex)
{
RestStoryboard();
_loginCount++;
if (_loginCount >= c_MaxLoginError) //登录出错超出限制次数
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
ErrorManager.ShowReturnError(ExceptionManager.LoginTimesError,
Client_Resource.UI2014_LoginTips);
WindowHelper.RerunApplication(false);
}));
return;
}
IsEnabled = true;
IsReadOnly = false;
LogHelper.WriteError(typeof(LoginViewModel), ex.ToString());
Application.Current.Dispatcher.BeginInvoke(
new Action(() => MessageBoxHelper.ShowInfo(ex.Message, Client_Resource.UI2014_LoginTips, true)));
}
}, (view) => IsOKCommand);
}
}
///
///
///
public RelayCommand GuestCommand
{
get
{
return new RelayCommand((view) =>
{
IsEnabled = false;
_view = view;
MessengerHelper.DefaultUnregister(this,MessengerTokens.QuoteCheckTokenSuccess);
MessengerHelper.DefaultRegister(this, MessengerTokens.QuoteCheckTokenSuccess, (e) =>
{
IsEnabled = true;
if (e)
{
var dataQuote = SimpleIoc.Default.GetInstance();
dataQuote.QueryQuoteGoodsInfo(QueryGoodsSuccess, QueryGoodsError);
}
else
{
LinkManager.Instance.Dispose();
LinkManager.Instance.GuestQuoteTcpLinkProxy = null; ///清除链路
Application.Current.Dispatcher.BeginInvoke(
new Action(() => MessageBoxHelper.ShowInfo(Client_Resource.GuestQuoteConnectError, Client_Resource.UI2014_LoginTips, true)));
}
});
////ShowMainWindow();
LinkManager.Instance.CreateGuestQuoteTcpLink();
});
}
}
///
/// 打开注册地址
///
public RelayCommand RegAccountCommand
{
get
{
return new RelayCommand(() =>
{
try
{
if (!string.IsNullOrWhiteSpace(ApplicationParameter.RegAccountAddress))
{
IPHelper.OpenWebAddress(ApplicationParameter.RegAccountAddress);
}
}
catch (Exception ex)
{
MessageBoxHelper.ShowInfo(Client_Resource.IsNotSupportOpenBrowner,
Client_Resource.UI2014_Tips, true);
new MsgAlter(ApplicationParameter.RegAccountAddress).ShowDialog();
LogHelper.WriteError(typeof (LoginViewModel), ex.ToString());
}
});
}
}
///
/// 是否可游客登录
///
public bool IsGuestLogin
{
get
{
////未配置游客登录行情地址
if (string.IsNullOrWhiteSpace(ApplicationParameter.GuestQuoteAddress))
{
return false;
}
string[] addArrs = ApplicationParameter.GuestQuoteAddress.Split(':');
if (addArrs.Length != 2)
{
return false;
}
//todo:校验IP,端口
return true;
}
}
///
/// 是否显示注册连接
///
public bool IsRegAccount
{
get
{
return !string.IsNullOrWhiteSpace(ApplicationParameter.RegAccountAddress);
}
}
///
/// 登录回调
///
///
private void LoginCallBack(TradeAccount loginEntity)
{
LogInfoHelper.WriteInfo("登陆成功,AccountId: " + loginEntity.AccountId);
LinkManager.Instance.TradeTcpLinkProxy.StartSendBeat();
// 等待1s,以免行情接入TOKEN检验失败
Thread.Sleep(2000);
//创建行情链路, 链路成功后订阅商品
LinkManager.Instance.CreateQuoteTcpLink();
ApplicationParameter.SetSystemTime(loginEntity.SystemTime);
SetQueryTips(3);
//仅获取更新时间戳
//_loginService.LoginQuerySearch(UserManager.CurrentTradeAccount.LoginID, LoginQueryType.ParamValues, QueryLastUpdateTimeSuccess, QueryError);
//查询所有数据
_loginService.LoginQuerySearch(UserManager.CurrentTradeAccount.LoginID, LoginQueryType.All, QueryLastUpdateTimeSuccess, QueryError);
//todo: 开发期间注释升级
//todo:是否有会员资源升级
var lastLoginUser = UserManager.GetLastLoginUser();
if ((!string.IsNullOrWhiteSpace(ApplicationParameter.UpdateAddress)) && (lastLoginUser == null || string.IsNullOrEmpty(lastLoginUser.MemberId) ||
!lastLoginUser.MemberId.Equals(loginEntity.MemberAreaId + string.Empty))) ////升级会员个性资源
{
KillUpate(); ////
string fileName = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory,
"Client.Update.exe");
var arguments = string.Format("{0},{1}", ApplicationParameter.UpdateAddress,
lastLoginUser == null ? string.Empty : lastLoginUser.MemberId);
Process.Start(fileName, arguments);
}
}
///
/// 查询更新时间列表
///
/// 更新时间列表
private void QueryLastUpdateTimeSuccess(AccountBaseInfoModel itemInfo)
{
SetQueryTips(2);
//查询系统基本参数,登录成功第一时间需要获取系统必要的参数来构建UI界面
//如果系统基本参数有更新,就重新调用接口去更新系统参数,否则直接使用本地文件的系统参数
ulong timeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.ConfigUTime);// 1498122159671;
if (ConfigParamResxManager.ConfigParamResx.ResourceHashtable == null || ConfigParamResxManager.ConfigParamResx.Version != timeUTC)
{
_loginService.ConfigQuerySearch(timeUTC, QueryConfigInfoSuccess, QueryError);
}
else
{
ConfigInfoModel[] configArr = Newtonsoft.Json.JsonConvert.DeserializeObject(Newtonsoft.Json.JsonConvert.SerializeObject(ConfigParamResxManager.ConfigParamResx.ResourceHashtable.Values));
//foreach(DictionaryEntry de in ConfigParamResxManager.ConfigParamResx.ResourceHashtable)
//{
// configLst.Add(Newtonsoft.Json.JsonConvert.DeserializeObject(de.Value.ToString()));
//}
List configLst = configArr.ToList();
QueryConfigInfoSuccess(configLst, 0, false);
SetApplicationParameters(configLst);
}
}
///
/// 设置程序参数
///
/// 查询的参数
private void SetApplicationParameters(List parameterConfigs)
{
try
{
if (parameterConfigs != null && parameterConfigs.Count > 0)
{
Type t = typeof(ApplicationParameter);
var properties = t.GetProperties().Where((item) => item.CanWrite);
foreach (var propertyInfo in properties)
{
var parameter =
parameterConfigs.Where(u => !string.IsNullOrEmpty(u.ParamName) && u.ParamName.Trim().ToLower().Equals(propertyInfo.Name.Trim().ToLower())).ToList();
if (parameter != null && parameter.Count > 0)
{
var finacingModel = parameter[0];
if (propertyInfo.PropertyType == typeof(String))
{
propertyInfo.SetValue(t, finacingModel.ParamValue, null);
}
else if (propertyInfo.PropertyType == typeof(Int32))
{
propertyInfo.SetValue(t, Convert.ToInt32(finacingModel.ParamValue), null);
}
else if (propertyInfo.PropertyType == typeof(DateTime))
{
propertyInfo.SetValue(t, Convert.ToDateTime(finacingModel.ParamValue), null);
}
else if (propertyInfo.PropertyType == typeof(Decimal))
{
propertyInfo.SetValue(t, Convert.ToDecimal(finacingModel.ParamValue), null);
}
else if (propertyInfo.PropertyType == typeof(Boolean))
{
propertyInfo.SetValue(t, Convert.ToBoolean(finacingModel.ParamValue), null);
}
}
}
}
}
catch (Exception ex)
{
////写错误日志
LogHelper.WriteError(typeof(Exception), ex.ToString());
}
}
///
/// 查询系统参
///
/// 更新时间列表
private void QueryConfigInfoSuccess(List itemInfo,ulong configstamp=0,bool bupdate=true)
{
if (bupdate)
{
//如果是调用接口更新的系统参数,需要更新对应的本地文件
Task.Factory.TryStartNew(() =>
{
var hashtable = new Hashtable();
foreach (var config in itemInfo)
{
hashtable.Add(config.ParamCode, config);
}
ConfigParamResxManager.SaveConfigParamResx(hashtable, configstamp, UserManager.UserDataFolder);
});
}
//获取系统参数成功后进入主界面
UserManager.IsAccountLogin = true;
ShowMainWindow();
}
private void QueryError(ErrorEntity error)
{
LogInfoHelper.WriteInfo("登陆成功,系统参数查询失败...");
RestStoryboard();
////清除链路
LinkManager.Instance.Dispose();
}
//private void SystemClientParamterConfigError(ErrorEntity error)
//{
// LogInfoHelper.WriteInfo("登陆成功,系统参数查询失败...");
// RestStoryboard();
// ////清除链路
// LinkManager.Instance.Dispose();
// var format = "交易端系统参数查询:" + string.Format(ErrorManager.FormatErrorMsg(error));
// LogInfoHelper.WriteInfo(format);
//}
private void RestStoryboard()
{
ProgressText = string.Empty;
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
IsEnabled = true;
IsReadOnly = false;
//出错播放回复动画
//BeginStoryboard("ShowLoginButton");
}));
}
public void FeeRuleCallBack(Dictionary GoodsFeeRules)
{
///todo:保存在缓存中
//CacheManager.TradeGoodsFeeRules = GoodsFeeRules.ToDictionary((item) => item.GoodsID);
}
///
/// 更新程序是否正在运行
///
///
private void KillUpate()
{
try
{
var processes = Process.GetProcessesByName("Client.Update.exe");
foreach (var process in processes)
{
process.Kill();
}
}
catch (Exception)
{
}
}
///
/// 错误处理
///
/// 错误内容
private void LoginErrorFunc(ErrorEntity error)
{
ProgressText = string.Empty;
IsEnabled = true;
IsReadOnly = false;
////清除链路
LinkManager.Instance.Dispose();
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
ErrorManager.ShowReturnError(error, Client_Resource.UI2014_Tips, true);
IsEnabled = true;
IsReadOnly = false;
//出错播放回复动画
//BeginStoryboard("ShowLoginButton");
}));
IdentifyingCodeImg = BitmapFrame.Create(vc.CreateCheckCodeImage());
RaisePropertyChanged(() => IdentifyingCode);
if (ApplicationParameter.IsShowIdentifyingCode == ((int)eShowIdentifyingCode.ErrorShow).ToString())
{
IsVisibilityIdentifyingCode = Visibility.Visible;
}
}
#endregion
#region 私有方法
private void HiddenCotrl()
{
if (string.IsNullOrWhiteSpace(ApplicationParameter.GuestQuoteAddress) && string.IsNullOrWhiteSpace(ApplicationParameter.RegAccountAddress))
{
MarginValue = "85,0,0,0";
IsVisibilityControlHidden = Visibility.Collapsed;
ColumnSpan3 = 3;
}
}
///
/// 播放LoginNewView里Storyboard
///
/// Name of the storyboard.
private void BeginStoryboard(string storyboardName)
{
if (_view == null) return;
var storyboard = (Storyboard)_view.FindResource(storyboardName);
if (storyboard != null) storyboard.Begin(_view);
}
///
/// 初始化列表
///
private void InitDataAccount()
{
//获取记住账号内容
try
{
lastLoginUser = UserManager.GetLastLoginUser();
List loginUserInfo = UserManager.GetTradeAccounts();
if (loginUserInfo != null && loginUserInfo.Count > 0)
{
var list = loginUserInfo.FindAll(k => k.UserName != "" && k.RememberAccount);
if (list != null)
{
LoginAccountList = list; //.Where(z => z.RememberAccount).ToList();
}
if (LoginAccountList != null && LoginAccountList.Count > 0)
{
TradeAccount = LoginAccountList[0].UserName;
IsSaveAccount = LoginAccountList[0].RememberAccount;
CurrentLoginType =
LoginTypeList.FirstOrDefault(k => k.Value == (int)LoginAccountList[0].LoginType);
return;
}
}
CurrentLoginType = LoginTypeList.FirstOrDefault(k => k.Value == 0);
}
catch (Exception exception)
{
LogHelper.WriteError(typeof(LoginViewModel), exception.ToString());
}
}
///
/// 登录信息验证
///
/// true if XXXX, false otherwise
private bool ValidData()
{
if (string.IsNullOrWhiteSpace(TradeAccount.Trim()) || TradeAccount.Length < 3)
{
MessageBoxHelper.ShowInfo(Client_Resource.UI2014_AccountNotLessThan3Characters, Client_Resource.UI2014_Tips, true);
//IsVisibilityIdentifyingCode = Visibility.Visible;
return false;
}
if (string.IsNullOrWhiteSpace(TradePassword) || TradePassword.Length < 6)
{
MessageBoxHelper.ShowInfo(Client_Resource.UI2014_AccountNotLessThan6Characters, Client_Resource.UI2014_Tips, true);
//IsVisibilityIdentifyingCode = Visibility.Visible;
return false;
}
if ((ApplicationParameter.IsShowIdentifyingCode == ((int)eShowIdentifyingCode.Show).ToString() || ApplicationParameter.IsShowIdentifyingCode == ((int)eShowIdentifyingCode.ErrorShow).ToString()) && IsVisibilityIdentifyingCode == Visibility.Visible && string.IsNullOrWhiteSpace(IdentifyingCode))
{
//请输入验证码
MessageBoxHelper.ShowInfo(Client_Resource.LoginViewModel_Cs_EnterVerificationCode, Client_Resource.UI2014_Tips, true);
RaisePropertyChanged(() => IdentifyingCode);
return false;
}
if ((ApplicationParameter.IsShowIdentifyingCode == ((int)eShowIdentifyingCode.Show).ToString() || ApplicationParameter.IsShowIdentifyingCode == ((int)eShowIdentifyingCode.ErrorShow).ToString()) && IsVisibilityIdentifyingCode == Visibility.Visible && string.Compare(IdentifyingCode, vc.CheckCode, true) != 0)
{
//验证码错误
MessageBoxHelper.ShowInfo(Client_Resource.LoginViewModel_Cs_VerificationCodeError, Client_Resource.UI2014_Tips, true);
IdentifyingCodeImg = BitmapFrame.Create(vc.CreateCheckCodeImage());
RaisePropertyChanged(() => IdentifyingCode);
return false;
}
return true;
}
private void ShowWarningTips()
{
bool isShowWarnTips = false;
//0 —不显示(即登录后不需要阅读风险告知书)1 —每次显示(每次登录后都弹出)2 —每天显示(每天登录多次仅第一次显示)3 —显示一次(登录后弹出一次,用户阅读后便不再显示)
var tipsType = (RateTipsType) ApplicationParameter.IsShowRateTips;
var info = UserManager.GetTradeAccount(TradeAccount.Trim());
if (info == null)
{
info = new UserInfo() { UserName = TradeAccount.Trim() };
}
switch (tipsType)
{
case RateTipsType.NotRate:
isShowWarnTips = false;
break;
case RateTipsType.EveryTimes:
info.IsShowWarnTips = true;
isShowWarnTips = true;
break;
case RateTipsType.ShowEveryDay:
isShowWarnTips = info.LoginTime.Date.CompareTo(DateTime.Now.Date) < 0 ||
(info.LoginTime.Date.CompareTo(DateTime.Now.Date) == 0 && !info.IsShowWarnTips);
break;
case RateTipsType.ShowOneTimes:
isShowWarnTips = !info.IsShowWarnTips;
break;
}
////是否显示风险提示信息
if ( isShowWarnTips)
{
var rateNotices = new RateNotices();
var dialogResult = rateNotices.ShowDialog();
if (dialogResult == false)
{
WindowHelper.RerunApplication(false);
}
else
{
var noticesViewModel = rateNotices.DataContext as RateNoticeViewModel;
if (noticesViewModel != null)
{
info.IsShowWarnTips = noticesViewModel.IsNotice;
}
}
}
UserManager.LoginedSave(info, IsSaveAccount);
}
///
/// 查询参数配置
///
/// 参数列表
//private void QueryConfigSuccess(List configs)
//{
// //todo:查询系统参数成功
// UserManager.IsAccountLogin = true;
// ShowMainWindow();
//}
///
/// 显示主窗口
///
private void ShowMainWindow()
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var loginView = _view;
loginView.Hide();
ShowWarningTips();
var homePage = ViewModelLocator.MainPage;
Application.Current.MainWindow = homePage;
homePage.Show();
loginView.Close();
}));
}
private void SetQueryTips(int type)
{
var sBuilder = new StringBuilder();
sBuilder.Append(Client_Resource.Query_Title_String);
switch (type)
{
case 0:
sBuilder.Append(Client_Resource.Query_Base_info);
sBuilder.Append("、");
sBuilder.Append(Client_Resource.Query_system_info);
break;
case 1: //提示基本查询未完成
sBuilder.Append(Client_Resource.Query_Base_info);
break;;
case 2: //提示参数查询未完成
break;
case 3: //提示参数查询未完成
// sBuilder.Append("查询时间戳");
// sBuilder.Append("交易规则和费用");
sBuilder.Append(Client_Resource.Resources_Service_QueryAccountGoodsParams);
break;
default:
break;
}
ProgressText = sBuilder.ToString();
}
#region 行情连接
///
/// 查询行情商品成功回应
///
///
private void QueryGoodsSuccess(List quoteGoodses )
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var loginView = _view;
loginView.Hide();
// ShowWarmingTips();
var homePage = ViewModelLocator.MainPage;
Application.Current.MainWindow = homePage;
ViewModelLocator.Home.InitializeThemes();
homePage.Show();
loginView.Close();
}));
////查询商品成功订阅行情
QuoteProxyHelper.QuoteSubscribe(GoodsFromScr.Brown);
}
private void QueryGoodsError(ErrorEntity errorEntity)
{
LinkManager.Instance.GuestQuoteTcpLinkProxy.Dispose();
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
IsEnabled = true;
IsReadOnly = false;
}));
}
#endregion
#endregion
}
}