using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.ComponentModel; using System.Net; using FLY.Thick.Base.Common; using FLY.Thick.Base.Client; using FLY.Thick.Base.IService; using FObjBase; using GalaSoft.MvvmLight.Command; namespace FLY.Thick.Base.UI { /// /// WdFlyADAccess.xaml 的交互逻辑 /// public partial class WdFlyADAccess : FLY.ControlLibrary.WindowBigClose { WdFlyADAccessVm viewModel; /// /// /// public WdFlyADAccess() { InitializeComponent(); viewModel = new WdFlyADAccessVm(); this.DataContext = viewModel; } /// /// /// /// public void Init(IFlyADService flyADService) { viewModel.Init(flyADService); } } /// /// WdFlyADAccess 的 ViewModel /// public class WdFlyADAccessVm : INotifyPropertyChanged { IFlyADService mFlyADService = null; public event PropertyChangedEventHandler PropertyChanged; /// /// 使用码 /// [PropertyChanged.DoNotCheckEquality] public byte[] Access { get; set; } = new byte[8]; /// /// 序列码 /// [PropertyChanged.DoNotCheckEquality] public byte[] Code { get; set; } = new byte[7]; public RelayCommand ApplyCmd { get; private set; } public WdFlyADAccessVm() { ApplyCmd = new RelayCommand(Apply); } /// /// /// /// public void Init(IFlyADService flyADService) { mFlyADService = flyADService; mFlyADService.GetAccessInfo( new AsyncCBHandler( delegate (object AsyncState, object retData) { AccessInfo a = (AccessInfo)retData; Access = a.access; Code = a.code; }), null); } void Apply() { if ((Access == null) || (Access.Length != 8)) { FLY.ControlLibrary.Window_Tip.Show("错误", "长度不对,需要 8位 byte!!", TimeSpan.FromSeconds(2)); return; } if (mFlyADService == null) return; mFlyADService.SetAccess( Access, new AsyncCBHandler( delegate (object AsyncState, object retData) { AccessInfo a = (AccessInfo)retData; Access = a.access; Code = a.code; switch (a.ret) { case AREA_ERR.NO_ERR: { FLY.ControlLibrary.Window_Tip.Show("成功", "设置成功!!", TimeSpan.FromSeconds(2)); } break; case AREA_ERR.DUP_ACCESS: { FLY.ControlLibrary.Window_Tip.Show("错误", "授权码重复!!", TimeSpan.FromSeconds(2)); } break; case AREA_ERR.ERR_ACCESS: { FLY.ControlLibrary.Window_Tip.Show("错误", "授权码不正确!!", TimeSpan.FromSeconds(2)); } break; } }), null); FLY.ControlLibrary.Window_Tip.Show("通知", "请等待。。。。。。", TimeSpan.FromSeconds(2)); } } /// /// /// public class BytesConverter : IValueConverter { #region IValueConverter 成员 /// /// /// /// /// /// /// /// public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) return ""; byte[] bs = (byte[])value; string str = ""; for (int i = 0; i < bs.Length; i++) str += bs[i].ToString("X2"); return str; } /// /// /// /// /// /// /// /// public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string str = (string)value; string h = ""; List bs = new List(); for (int i = 0; i < str.Length; i++) { if (str[i] != ' ') h += str[i]; if (((str[i] == ' ') && (h.Length != 0)) || (h.Length >= 2)) { byte b = 0; if (byte.TryParse(h, System.Globalization.NumberStyles.AllowHexSpecifier, null, out b)) { bs.Add(b); } else { break; } h = ""; } } return bs.ToArray(); } #endregion } }