diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index 00627c7..25fb10a 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -19,19 +19,25 @@ namespace HBLConsole.MainConsole private volatile static Main _Instance; public static Main GetInstance => _Instance ?? (_Instance = new Main()); - private Main() { } + private Main() + { + ActionOperate.GetInstance.Register(new Func(() => { return GeneralConfig.DeviceType.ToString(); }), "GetDeviceType"); + } List Topics = new List(); public void DataInit() { + string deviceType = TextHelper.GetInstance.ReadTextInfo(); + GeneralConfig.DeviceType = DeviceClientType.MORKS; + if (Enum.TryParse(deviceType, out DeviceClientType dct)) GeneralConfig.DeviceType = dct; ThreadOperate.GetInstance.Start(new Action(() => { Sqlite.GetInstance.GetData(); }), "GetAlarm"); - Json.Read(); - if (Enum.TryParse(Json.Data.ClientDeviceType, out DeviceClientType dct)) - { - GeneralConfig.DeviceType = dct; - } - else { GeneralConfig.DeviceType = DeviceClientType.MORKS; } + //Json.Read(); + //if (Enum.TryParse(Json.Data.ClientDeviceType, out DeviceClientType dct)) + //{ + // GeneralConfig.DeviceType = dct; + //} + //else { GeneralConfig.DeviceType = DeviceClientType.MORKS; } Json.Read(); Json.Read(); Json.Read(); @@ -49,6 +55,7 @@ namespace HBLConsole.MainConsole Json.Save(); Sqlite.GetInstance.Save(); TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo"); + TextHelper.GetInstance.WriteTextInfo(GVL.GeneralConfig.DeviceType.ToString()); } public void BusinessInit() diff --git a/HBLConsole.Model/ViewModel/SimOrderVisibleData.cs b/HBLConsole.Model/ViewModel/SimOrderVisibleData.cs index 3ed9e36..e0dc8bc 100644 --- a/HBLConsole.Model/ViewModel/SimOrderVisibleData.cs +++ b/HBLConsole.Model/ViewModel/SimOrderVisibleData.cs @@ -25,11 +25,11 @@ namespace HBLConsole.Model public string Text { get { return _mText; } set { _mText = value; OnPropertyChanged(); } } private string _mText; - public int MinValue { get { return _mMinValue; } set { _mMinValue = value; OnPropertyChanged(); } } - private int _mMinValue; + public ushort MinValue { get { return _mMinValue; } set { _mMinValue = value; OnPropertyChanged(); } } + private ushort _mMinValue; - public int MaxValue { get { return _mMaxValue; } set { _mMaxValue = value; OnPropertyChanged(); } } - private int _mMaxValue; + public ushort MaxValue { get { return _mMaxValue; } set { _mMaxValue = value; OnPropertyChanged(); } } + private ushort _mMaxValue; diff --git a/HBLConsole.Service/Json.cs b/HBLConsole.Service/Json.cs index 46c6565..9a761e1 100644 --- a/HBLConsole.Service/Json.cs +++ b/HBLConsole.Service/Json.cs @@ -11,12 +11,15 @@ namespace HBLConsole.Service /// public class Json where T : class, new() { + + private static string DeviceType = ActionOperate.GetInstance.SendResult("GetDeviceType").ToString(); + static string path { get { - Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\JSON")); - return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\JSON\\{typeof(T).Name}.json"; + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\{DeviceType}\\JSON")); + return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\{DeviceType}\\JSON\\{typeof(T).Name}.json"; } } diff --git a/HBLConsole.Service/TextHelper.cs b/HBLConsole.Service/TextHelper.cs index 10a60d4..3f59339 100644 --- a/HBLConsole.Service/TextHelper.cs +++ b/HBLConsole.Service/TextHelper.cs @@ -36,5 +36,29 @@ namespace HBLConsole.Service } } + public string ReadTextInfo() + { + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile")); + string path = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DeviceType.txt"; + FileStream fs = new FileStream(path, FileMode.OpenOrCreate); + StreamReader sr = new StreamReader(fs); + string GetStr = sr.ReadLine(); + if (GetStr == null) GetStr = string.Empty; + sr.Close(); + fs.Close(); + return GetStr; + } + + public void WriteTextInfo(string info) + { + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile")); + string path = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DeviceType.txt"; + FileStream fs = new FileStream(path, FileMode.Create); + StreamWriter sw = new StreamWriter(fs); + sw.WriteLine(info); + sw.Close(); + fs.Close(); + } + } } diff --git a/HBLConsole/App.xaml.cs b/HBLConsole/App.xaml.cs index 50a0eb7..8597754 100644 --- a/HBLConsole/App.xaml.cs +++ b/HBLConsole/App.xaml.cs @@ -22,7 +22,7 @@ namespace HBLConsole /// public partial class App : Application { - MainView mainView = new MainView(); + MainView mainView; ListDialogView listDialogView; protected override void OnStartup(StartupEventArgs e) { @@ -32,6 +32,7 @@ namespace HBLConsole AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; MainConsole.Main.GetInstance.DataInit(); ThreadOperate.GetInstance.Start(new Action(() => { SqlHelper.GetInstance.GetData(); }), "GetSqliteData"); + mainView = new MainView(); mainView.Show(); NoCompleteOrderInit(); MainConsole.Main.GetInstance.BusinessInit(); diff --git a/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml b/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml index 0f72956..3590f2c 100644 --- a/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml +++ b/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml @@ -110,7 +110,7 @@ - + @@ -139,6 +139,7 @@ FontFamily="楷体" FontSize="21" Foreground="#ff34f7f7" + TabIndex="0" Text="{Binding Name}" /> diff --git a/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs b/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs index 4ad765e..dc6a7fe 100644 --- a/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs +++ b/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs @@ -1,4 +1,5 @@ -using HBLConsole.Service; +using HBLConsole.Model; +using HBLConsole.Service; using System; using System.Collections.Generic; using System.Linq; @@ -12,6 +13,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using HBLConsole.DialogWindow.ViewModel; namespace HBLConsole.DialogWindow.View { @@ -26,17 +28,29 @@ namespace HBLConsole.DialogWindow.View this.MoveBorder.MouseLeftButtonDown += (o, e) => { this.DragMove(); }; this.ButMin.Click += (o, e) => { this.WindowState = WindowState.Minimized; }; this.ButMax.Click += (o, e) => { this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; }; - this.ButClose.Click += (o, e) => { this.DialogResult = false; }; + this.ButClose.Click += (o, e) => { this.Close(); ActionOperate.GetInstance.CancelRegister("SendSimData"); }; this.MaxWidth = SystemParameters.WorkArea.Width; this.MaxHeight = SystemParameters.WorkArea.Height; ActionOperate.GetInstance.Register(new Action(() => { - this.DialogResult = true; this.Close(); ActionOperate.GetInstance.CancelRegister("SimOrderConfitViewModelExit"); + ActionOperate.GetInstance.CancelRegister("SendSimData"); }), "SimOrderConfitViewModelExit"); + } + private void Grid_KeyDown(object sender, KeyEventArgs e) + { + var uie = e.OriginalSource as TextBox; + if (uie != null) + { + if (e.Key == Key.Enter) + { + uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); + e.Handled = true; + } + } } } } diff --git a/HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs b/HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs index bba77a2..93bcc83 100644 --- a/HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs +++ b/HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs @@ -13,24 +13,59 @@ namespace HBLConsole.DialogWindow.ViewModel { public class SimOrderConfitViewModel : ViewModelBase { + bool IsEdit = false; + SimOrderVisibleData simOrderVisibleData; + string DeviceType = string.Empty; public SimOrderConfitViewModel() { + DeviceType = GVL.GeneralConfig.DeviceType.ToString(); + ActionOperate.GetInstance.Register(new Action((o) => + { + if (o != null) + { + if (o is SimOrderVisibleData sim) + { + Name = sim.Text; + Max = sim.MaxValue; + Min = sim.MinValue; + IsEdit = true; + simOrderVisibleData = sim; + } + } + }), "SendSimData"); + ConfirmCommand = new RelayCommand(() => { - if (!Json.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) + if (!Json.Data.simOrderConfig.ContainsKey(DeviceType)) { - Json.Data.simOrderConfig.TryAdd(GVL.GeneralConfig.DeviceType.ToString(), new ObservableCollection()); + Json.Data.simOrderConfig.TryAdd(DeviceType, new ObservableCollection()); } - Json.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].Add(new SimOrderVisibleData() + + if (!IsEdit) + { + Json.Data.simOrderConfig[DeviceType].Add(new SimOrderVisibleData() + { + ClientDeviceType = GVL.GeneralConfig.DeviceType.ToString(), + IsEnable = true, + IsSelected = true, + Text = Name, + Loc = Min, + MaxValue = Max, + MinValue = Min, + }); + } + else { - ClientDeviceType = GVL.GeneralConfig.DeviceType.ToString(), - IsEnable = true, - IsSelected = true, - Text = Name, - Loc = Min, - MaxValue = Max, - MinValue = Min, - }); + int index = Array.FindIndex(Json.Data.simOrderConfig[DeviceType].ToArray(), p => p.Text == simOrderVisibleData.Text); + if (index >= 0 && index < Json.Data.simOrderConfig[DeviceType].Count()) + { + Json.Data.simOrderConfig[DeviceType].ElementAt(index).Text = Name; + Json.Data.simOrderConfig[DeviceType].ElementAt(index).MinValue = Min; + Json.Data.simOrderConfig[DeviceType].ElementAt(index).MaxValue = Max; + Json.Data.simOrderConfig[DeviceType].ElementAt(index).IsEnable = simOrderVisibleData.IsEnable; + Json.Data.simOrderConfig[DeviceType].ElementAt(index).IsSelected = simOrderVisibleData.IsSelected; + } + } ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); }); CancelCommand = new RelayCommand(() => { ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); }); diff --git a/HBLConsole/View/DebugView.xaml b/HBLConsole/View/DebugView.xaml index be70102..990399f 100644 --- a/HBLConsole/View/DebugView.xaml +++ b/HBLConsole/View/DebugView.xaml @@ -11,19 +11,14 @@ d:DesignWidth="1000" mc:Ignorable="d"> - - - - -