| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269 |
- 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() { }
- }
- /// <summary>
- /// 用户登录
- /// </summary>
- 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 绑定属性
- /// <summary>
- /// 客户端版本
- /// </summary>
- public string Version
- {
- get
- {
- return "v"+ ApplicationParameter.Version;
- }
- }
- #region 隐藏控件当指定条件
- private Visibility _isVisibilityControlHidden = Visibility.Visible;
- /// <summary>
- /// 隐藏控件当指定条件
- /// </summary>
- public Visibility IsVisibilityControlHidden
- {
- get
- {
- return _isVisibilityControlHidden;
- }
- set
- {
- Set(() => IsVisibilityControlHidden, ref _isVisibilityControlHidden, value);
- }
- }
- #endregion
- #region 变更集合列数
- private decimal _columnSpan3 = 1;
- /// <summary>
- /// 变更集合列数
- /// </summary>
- public decimal ColumnSpan3
- {
- get
- {
- return _columnSpan3;
- }
- set
- {
- Set(() => ColumnSpan3, ref _columnSpan3, value);
- }
- }
- #endregion
- #region 验证码容器偏移量
- private string _marginValue = "35,0,0,0";
- /// <summary>
- /// 验证码容器偏移量
- /// </summary>
- public string MarginValue
- {
- get
- {
- return _marginValue;
- }
- set
- {
- Set(() => MarginValue, ref _marginValue, value);
- }
- }
- #endregion
- #region 是否显示验证码
- private Visibility _isVisibilityIdentifyingCode = Visibility.Collapsed;
- /// <summary>
- /// 是否显示验证码
- /// </summary>
- public Visibility IsVisibilityIdentifyingCode
- {
- get
- {
- return _isVisibilityIdentifyingCode;
- }
- set
- {
- Set(() => IsVisibilityIdentifyingCode, ref _isVisibilityIdentifyingCode, value);
- }
- }
- #endregion
- /// <summary>
- /// 登录方式集合
- /// </summary>
- private List<DropDataTemplate> _loginTypeList;
- public List<DropDataTemplate> LoginTypeList
- {
- get { return _loginTypeList; }
- set
- {
- Set(() => LoginTypeList, ref _loginTypeList, value);
- }
- }
- /// <summary>
- /// 登录方式
- /// </summary>
- 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;
- }
- }
- }
- /// <summary>
- /// 交易登录是否显示,隐藏
- /// </summary>
- private Visibility _tradeLoginVisibility;
- public Visibility TradeLoginVisibility
- {
- get
- {
- return _tradeLoginVisibility;
- }
- set
- {
- Set(() => TradeLoginVisibility, ref _tradeLoginVisibility, value);
- }
- }
- /// <summary>
- /// 手机登录是否显示,隐藏
- /// </summary>
- private Visibility _phoneLoginVisibility;
- public Visibility PhoneLoginVisibility
- {
- get
- {
- return _phoneLoginVisibility;
- }
- set
- {
- Set(() => PhoneLoginVisibility, ref _phoneLoginVisibility, value);
- }
- }
- private List<UserInfo> _loginAccountList = new List<UserInfo>();
- /// <summary>
- /// 记住账号列表
- /// </summary>
- public List<UserInfo> LoginAccountList
- {
- get { return _loginAccountList; }
- set
- {
- Set(() => LoginAccountList, ref _loginAccountList, value);
- }
- }
- private string _tradeAccount = string.Empty;
- /// <summary>
- /// 交易账号
- /// </summary>
- public string TradeAccount
- {
- get
- {
- return _tradeAccount;
- }
- set
- {
- if (_tradeAccount == value) return;
- _tradeAccount = value;
- RaisePropertyChanged(() => TradeAccount);
- TradePassword = string.Empty;
- #if DEBUG
- TradePassword = "123123";
- #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;
- /// <summary>
- /// 交易密码
- /// </summary>
- public string TradePassword
- {
- get
- {
- return _tradePassword;
- }
- set
- {
- Set(() => TradePassword, ref _tradePassword, value);
- }
- }
- private bool _isSaveAccount = true;
- /// <summary>
- /// 是否保存账号
- /// </summary>
- public bool IsSaveAccount
- {
- get { return _isSaveAccount; }
- set
- {
- Set(() => IsSaveAccount, ref _isSaveAccount, value);
- }
- }
- private double _processRate = 1;
- /// <summary>
- /// 处理进度
- /// </summary>
- public double ProcessRate
- {
- set
- {
- Set(() => ProcessRate, ref _processRate, value);
- }
- get
- {
- return _processRate;
- }
- }
- private bool _isEnabled = true;
- /// <summary>
- /// 用于控制登录按钮是否可用
- /// </summary>
- public bool IsEnabled
- {
- get { return _isEnabled; }
- set
- {
- Set(() => IsEnabled, ref _isEnabled, value);
- }
- }
- private bool _isMainEnabled = false;
- /// <summary>
- /// 是否完成加载数据
- /// </summary>
- public bool IsMainEnabled
- {
- get { return _isMainEnabled; }
- set { Set(() => IsMainEnabled, ref _isMainEnabled, value); }
- }
- private bool _isReadOnly = false;
- /// <summary>
- /// 用于控制文本框只读
- /// </summary>
- public bool IsReadOnly
- {
- get { return _isReadOnly; }
- set
- {
- Set(() => IsReadOnly, ref _isReadOnly, value);
- }
- }
- private bool _isOKCommand = true;
- /// <summary>
- /// 是否可登录操作
- /// </summary>
- 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
- /// <summary>
- /// 交易系统名称
- /// </summary>
- /// <value>The name of the system.</value>
- public string SystemName
- {
- get
- {
- return _systemName;
- }
- set
- {
- Set(() => SystemName, ref _systemName, value);
- }
- }
- /// <summary>
- /// 进度条的名称
- /// </summary>
- public string ProgressText
- {
- get
- {
- return _progressText;
- }
- set
- {
- Set(() => ProgressText, ref _progressText, value);
- }
- }
- public Brush _progressTextForeground;
- /// <summary>
- /// 进度条错误提示
- /// </summary>
- 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 构造函数
- /// <summary>
- /// Initializes a new instance of the <see cref="LoginViewModel"/> class.
- /// </summary>
- public LoginViewModel()
- {
- _loginService = SimpleIoc.Default.GetInstance<ILoginService>();
- _IDBTableMsgService = SimpleIoc.Default.GetInstance<IDBTableMsgService>();
- _iSystemService = SimpleIoc.Default.GetInstance<ISystemService>();
- LoginTypeList = EnumHelper.EnumToDictionary(typeof (LoginType));
- CurrentLoginType = LoginTypeList.FirstOrDefault(k => k.Value == 0);
- SystemName = ApplicationParameter.TradeSystemName;
- _ermcpService = SimpleIoc.Default.GetInstance<IErmcpService>();
- MessengerHelper.DefaultRegister<bool>(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 绑定命令
- /// <summary>
- /// 更新验证码IsSaveAccount
- /// </summary>
- public RelayCommand IdentifyingCodeCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- IdentifyingCodeImg = BitmapFrame.Create(vc.CreateCheckCodeImage());
- RaisePropertyChanged(() => IdentifyingCode);
- });
- }
- }
- /// <summary>
- /// 打开键盘命令
- /// </summary>
- public RelayCommand<Control> OpenKeyboardCommand
- {
- get
- {
- return new RelayCommand<Control>((control) =>
- {
- PassWordKeyBoard.SetTouchScreenKeyboard(control, true);
- control.Focus();
- });
- }
- }
- public RelayCommand<LoginWindowBase> LoginNewCommand
- {
- get
- {
- return new RelayCommand<LoginWindowBase>(
- (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<string>((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);
- }
- }
- /// <summary>
- ///
- /// </summary>
- public RelayCommand<LoginWindowBase> GuestCommand
- {
- get
- {
- return new RelayCommand<LoginWindowBase>((view) =>
- {
- IsEnabled = false;
-
- _view = view;
- MessengerHelper.DefaultUnregister<bool>(this,MessengerTokens.QuoteCheckTokenSuccess);
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.QuoteCheckTokenSuccess, (e) =>
- {
- IsEnabled = true;
- if (e)
- {
- var dataQuote = SimpleIoc.Default.GetInstance<IQuoteDataService>();
- 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();
-
- });
- }
- }
- /// <summary>
- /// 打开注册地址
- /// </summary>
- 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());
- }
- });
- }
- }
- /// <summary>
- /// 是否可游客登录
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 是否显示注册连接
- /// </summary>
- public bool IsRegAccount
- {
- get
- {
- return !string.IsNullOrWhiteSpace(ApplicationParameter.RegAccountAddress);
- }
- }
- /// <summary>
- /// 登录回调
- /// </summary>
- /// <param name="loginEntity"></param>
- 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);
- }
- }
- /// <summary>
- /// 查询更新时间列表
- /// </summary>
- /// <param name="LastUpdateTimeModel">更新时间列表</param>
- 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<ConfigInfoModel[]>(Newtonsoft.Json.JsonConvert.SerializeObject(ConfigParamResxManager.ConfigParamResx.ResourceHashtable.Values));
- //foreach(DictionaryEntry de in ConfigParamResxManager.ConfigParamResx.ResourceHashtable)
- //{
- // configLst.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<ConfigInfoModel>(de.Value.ToString()));
- //}
- List<ConfigInfoModel> configLst = configArr.ToList();
- QueryConfigInfoSuccess(configLst, 0, false);
- SetApplicationParameters(configLst);
- }
- }
- /// <summary>
- /// 设置程序参数
- /// </summary>
- /// <param name="parameterConfigs">查询的参数</param>
- private void SetApplicationParameters(List<ConfigInfoModel> 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());
- }
- }
- /// <summary>
- /// 查询系统参
- /// </summary>
- /// <param name="LastUpdateTimeModel">更新时间列表</param>
- private void QueryConfigInfoSuccess(List<ConfigInfoModel> 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<int, TradeGoodsFeeRule> GoodsFeeRules)
- {
- ///todo:保存在缓存中
- //CacheManager.TradeGoodsFeeRules = GoodsFeeRules.ToDictionary((item) => item.GoodsID);
- }
- /// <summary>
- /// 更新程序是否正在运行
- /// </summary>
- /// <returns></returns>
- private void KillUpate()
- {
- try
- {
- var processes = Process.GetProcessesByName("Client.Update.exe");
- foreach (var process in processes)
- {
- process.Kill();
- }
- }
- catch (Exception)
- {
- }
- }
-
- /// <summary>
- /// 错误处理
- /// </summary>
- /// <param name="error">错误内容</param>
- 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;
- }
- }
- /// <summary>
- /// 播放LoginNewView里Storyboard
- /// </summary>
- /// <param name="storyboardName">Name of the storyboard.</param>
- private void BeginStoryboard(string storyboardName)
- {
- if (_view == null) return;
- var storyboard = (Storyboard)_view.FindResource(storyboardName);
- if (storyboard != null) storyboard.Begin(_view);
- }
- /// <summary>
- /// 初始化列表
- /// </summary>
- private void InitDataAccount()
- {
- //获取记住账号内容
- try
- {
- lastLoginUser = UserManager.GetLastLoginUser();
- List<UserInfo> 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());
- }
- }
- /// <summary>
- /// 登录信息验证
- /// </summary>
- /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
- 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);
-
- }
-
- /// <summary>
- /// 查询参数配置
- /// </summary>
- /// <param name="configs">参数列表</param>
- //private void QueryConfigSuccess(List<ParameterConfig> configs)
- //{
-
- // //todo:查询系统参数成功
- // UserManager.IsAccountLogin = true;
- // ShowMainWindow();
- //}
- /// <summary>
- /// 显示主窗口
- /// </summary>
- 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 行情连接
- /// <summary>
- /// 查询行情商品成功回应
- /// </summary>
- /// <param name="quoteGoodses"></param>
- private void QueryGoodsSuccess(List<QuoteGoods> 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
- }
- }
|