@@ -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<object>(() => { return GeneralConfig.DeviceType.ToString(); }), "GetDeviceType"); | |||
} | |||
List<string> Topics = new List<string>(); | |||
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<Alarm>.GetInstance.GetData(); }), "GetAlarm"); | |||
Json<SetPar>.Read(); | |||
if (Enum.TryParse(Json<SetPar>.Data.ClientDeviceType, out DeviceClientType dct)) | |||
{ | |||
GeneralConfig.DeviceType = dct; | |||
} | |||
else { GeneralConfig.DeviceType = DeviceClientType.MORKS; } | |||
//Json<SetPar>.Read(); | |||
//if (Enum.TryParse(Json<SetPar>.Data.ClientDeviceType, out DeviceClientType dct)) | |||
//{ | |||
// GeneralConfig.DeviceType = dct; | |||
//} | |||
//else { GeneralConfig.DeviceType = DeviceClientType.MORKS; } | |||
Json<MorkOrderPushPar>.Read(); | |||
Json<BatchingInfoPar>.Read(); | |||
Json<SimOrderConfig>.Read(); | |||
@@ -49,6 +55,7 @@ namespace HBLConsole.MainConsole | |||
Json<KeepDataBase>.Save(); | |||
Sqlite<Alarm>.GetInstance.Save(); | |||
TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo"); | |||
TextHelper.GetInstance.WriteTextInfo(GVL.GeneralConfig.DeviceType.ToString()); | |||
} | |||
public void BusinessInit() | |||
@@ -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; | |||
@@ -11,12 +11,15 @@ namespace HBLConsole.Service | |||
/// </summary> | |||
public class Json<T> 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"; | |||
} | |||
} | |||
@@ -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(); | |||
} | |||
} | |||
} |
@@ -22,7 +22,7 @@ namespace HBLConsole | |||
/// </summary> | |||
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(); | |||
@@ -110,7 +110,7 @@ | |||
<!--#endregion--> | |||
<!--#region 内容显示区--> | |||
<Grid Grid.Row="1" Margin="10"> | |||
<Grid KeyDown="Grid_KeyDown" Grid.Row="1" Margin="10"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition /> | |||
<RowDefinition /> | |||
@@ -139,6 +139,7 @@ | |||
FontFamily="楷体" | |||
FontSize="21" | |||
Foreground="#ff34f7f7" | |||
TabIndex="0" | |||
Text="{Binding Name}" /> | |||
<TextBlock | |||
@@ -160,6 +161,7 @@ | |||
FontFamily="楷体" | |||
FontSize="21" | |||
Foreground="#ff34f7f7" | |||
TabIndex="1" | |||
Text="{Binding Min}" /> | |||
<TextBlock | |||
@@ -181,6 +183,7 @@ | |||
FontFamily="楷体" | |||
FontSize="21" | |||
Foreground="#ff34f7f7" | |||
TabIndex="2" | |||
Text="{Binding Max}" /> | |||
@@ -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; | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -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<object>((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<KeepDataBase>.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) | |||
if (!Json<KeepDataBase>.Data.simOrderConfig.ContainsKey(DeviceType)) | |||
{ | |||
Json<KeepDataBase>.Data.simOrderConfig.TryAdd(GVL.GeneralConfig.DeviceType.ToString(), new ObservableCollection<SimOrderVisibleData>()); | |||
Json<KeepDataBase>.Data.simOrderConfig.TryAdd(DeviceType, new ObservableCollection<SimOrderVisibleData>()); | |||
} | |||
Json<KeepDataBase>.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].Add(new SimOrderVisibleData() | |||
if (!IsEdit) | |||
{ | |||
Json<KeepDataBase>.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<KeepDataBase>.Data.simOrderConfig[DeviceType].ToArray(), p => p.Text == simOrderVisibleData.Text); | |||
if (index >= 0 && index < Json<KeepDataBase>.Data.simOrderConfig[DeviceType].Count()) | |||
{ | |||
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).Text = Name; | |||
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).MinValue = Min; | |||
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).MaxValue = Max; | |||
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).IsEnable = simOrderVisibleData.IsEnable; | |||
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).IsSelected = simOrderVisibleData.IsSelected; | |||
} | |||
} | |||
ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); | |||
}); | |||
CancelCommand = new RelayCommand(() => { ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); }); | |||
@@ -11,19 +11,14 @@ | |||
d:DesignWidth="1000" | |||
mc:Ignorable="d"> | |||
<UserControl.DataContext> | |||
<vm:DebugViewModel /> | |||
</UserControl.DataContext> | |||
<UserControl.Resources> | |||
<ResourceDictionary> | |||
<ResourceDictionary.MergedDictionaries> | |||
<ResourceDictionary Source="../Resources/ResourceDictionarys/BasicStyle.xaml"> | |||
<Style x:Key="TextBoxStyle" TargetType="TextBox"> | |||
<Setter Property="FontFamily" Value="楷体" /> | |||
<Setter Property="FontSize" Value="22" /> | |||
<Setter Property="FontSize" Value="18" /> | |||
<Setter Property="Background" Value="Transparent" /> | |||
<Setter Property="Foreground" Value="#9934F7F7" /> | |||
<Setter Property="BorderBrush" Value="#00c2f4" /> | |||
@@ -151,6 +146,10 @@ | |||
</ResourceDictionary> | |||
</UserControl.Resources> | |||
<UserControl.DataContext> | |||
<vm:DebugViewModel /> | |||
</UserControl.DataContext> | |||
<Grid> | |||
<Grid.ColumnDefinitions> | |||
@@ -173,12 +172,14 @@ | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition Width="150" /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
</Grid.ColumnDefinitions> | |||
<TextBlock | |||
HorizontalAlignment="Right" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
FontSize="14" | |||
Foreground="#00c2f4" | |||
Text="{Binding Text}" /> | |||
@@ -195,10 +196,28 @@ | |||
VerticalAlignment="Center" | |||
Background="#FF2AB2E7" | |||
Content="启用随机数" | |||
FontSize="16" | |||
FontSize="14" | |||
Foreground="#00c2f4" | |||
IsChecked="{Binding IsSelected}" | |||
Template="{StaticResource CbTemplate}" /> | |||
<Button | |||
Style="{StaticResource ButtonStyle}" | |||
Grid.Column="3" | |||
FontSize="14" | |||
Margin="10 0 0 0" | |||
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}" | |||
CommandParameter="{Binding Text}" | |||
Content="编辑" /> | |||
<Button | |||
Grid.Column="4" | |||
Margin="5 0 0 0" | |||
FontSize="14" | |||
Style="{StaticResource ButtonStyle}" | |||
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}" | |||
CommandParameter="{Binding Text}" | |||
Content="删除" /> | |||
</Grid> | |||
</DataTemplate> | |||
</ItemsControl.ItemTemplate> | |||
@@ -217,15 +236,9 @@ | |||
Style="{StaticResource ButtonStyle}" /> | |||
</UniformGrid> | |||
</StackPanel> | |||
</Grid> | |||
<Grid Grid.Column="1"> | |||
<Grid Margin="20 0 0 0" Grid.Column="1"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="40" /> | |||
<RowDefinition Height="10" /> | |||
@@ -235,7 +235,7 @@ | |||
Grid.RowSpan="2" | |||
Margin="10"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="50" /> | |||
<RowDefinition Height="{Binding ContentHeight}" /> | |||
<RowDefinition /> | |||
</Grid.RowDefinitions> | |||
@@ -28,7 +28,7 @@ namespace HBLConsole.ViewModel | |||
AddSimDataCommand = new RelayCommand(() => | |||
{ | |||
SimOrderConfitView simOrderConfitView = new SimOrderConfitView(); | |||
simOrderConfitView.ShowDialog(); | |||
simOrderConfitView.Show(); | |||
}); | |||
SimOrderCommand = new RelayCommand(() => | |||
@@ -43,7 +43,7 @@ namespace HBLConsole.ViewModel | |||
} | |||
if (locs.Count == 0) | |||
{ | |||
locs.Add((ushort)(new Random().Next(1,5))); | |||
locs.Add((ushort)(new Random().Next(1, 5))); | |||
locs.Add(10); | |||
} | |||
@@ -91,6 +91,36 @@ namespace HBLConsole.ViewModel | |||
// //} | |||
// Thread.Sleep(1000); | |||
//}), "循环订单"); | |||
EditCommand = new RelayCommand<object>((o) => | |||
{ | |||
if (o != null) | |||
{ | |||
if (Json<KeepDataBase>.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) | |||
{ | |||
var res = Json<KeepDataBase>.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].FirstOrDefault(p => p.Text == o.ToString()); | |||
if (res != null) | |||
{ | |||
SimOrderConfitView simOrderConfitView = new SimOrderConfitView(); | |||
simOrderConfitView.Show(); | |||
ActionOperate.GetInstance.Send("SendSimData", res); | |||
} | |||
} | |||
} | |||
}); | |||
RemoveCommand = new RelayCommand<object>((o) => | |||
{ | |||
if (o != null) | |||
{ | |||
if (Json<KeepDataBase>.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString())) | |||
{ | |||
var res = Json<KeepDataBase>.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].FirstOrDefault(p => p.Text == o.ToString()); | |||
if (res != null) Json<KeepDataBase>.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].Remove(res); | |||
} | |||
} | |||
}); | |||
} | |||
public ObservableCollection<SimOrderVisibleData> simOrderConfig | |||
@@ -113,14 +143,6 @@ namespace HBLConsole.ViewModel | |||
} | |||
} | |||
public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged; | |||
private static void OnStaticPropertyChanged([CallerMemberName] string PropName = "") | |||
{ | |||
StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName)); | |||
} | |||
public RelayCommand AddSimDataCommand { get; set; } | |||
public RelayCommand SimOrderCommand { get; set; } | |||
@@ -129,6 +151,10 @@ namespace HBLConsole.ViewModel | |||
public RelayCommand LoopSimOrderCommand { get; set; } | |||
public RelayCommand<object> EditCommand { get; set; } | |||
public RelayCommand<object> RemoveCommand { get; set; } | |||
public static bool IsLoop = false; | |||
public static bool IsLoopzc = false; | |||
@@ -59,7 +59,7 @@ namespace HBLConsole.ViewModel | |||
/// 内容高度显示 | |||
/// </summary> | |||
public static int ContentHeight { get { return _mContentHeight; } set { _mContentHeight = value; OnStaticPropertyChanged(); } } | |||
private static int _mContentHeight = 0; | |||
private static int _mContentHeight = 50; | |||
/// <summary> | |||