| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252 |
- 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; ////连接是否成功
- #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 = "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;
- /// <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;
- 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());
- var password = EncryptHelper.SHA256(TradeAccount.Trim() + TradePassword.Trim()).ToLower();
- _loginService.TradeAccountLogin((LoginType)CurrentLoginType.Value, Convert.ToUInt64(TradeAccount.Trim()),
- TradeAccount.Trim(), password, LoginCallBack, LoginErrorFunc);
- //LoginCallBack(new TradeAccount() { LoginID = 310020000 });
- }
- 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(1000);
- //创建行情链路, 链路成功后订阅商品
- 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
- }
- }
|