Browse Source

ceshi

master
pry 2 years ago
parent
commit
c5439e219c
12 changed files with 183 additions and 57 deletions
  1. +14
    -7
      HBLConsole.MainConsole/Main.cs
  2. +4
    -4
      HBLConsole.Model/ViewModel/SimOrderVisibleData.cs
  3. +5
    -2
      HBLConsole.Service/Json.cs
  4. +24
    -0
      HBLConsole.Service/TextHelper.cs
  5. +2
    -1
      HBLConsole/App.xaml.cs
  6. +4
    -1
      HBLConsole/DialogWindow/View/SimOrderConfitView.xaml
  7. +17
    -3
      HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs
  8. +46
    -11
      HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs
  9. +29
    -16
      HBLConsole/View/DebugView.xaml
  10. +1
    -1
      HBLConsole/View/MainView.xaml
  11. +36
    -10
      HBLConsole/ViewModel/DebugViewModel.cs
  12. +1
    -1
      HBLConsole/ViewModel/ViewModelBase.cs

+ 14
- 7
HBLConsole.MainConsole/Main.cs View File

@@ -19,19 +19,25 @@ namespace HBLConsole.MainConsole


private volatile static Main _Instance; private volatile static Main _Instance;
public static Main GetInstance => _Instance ?? (_Instance = new Main()); 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>(); List<string> Topics = new List<string>();


public void DataInit() 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"); 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<MorkOrderPushPar>.Read();
Json<BatchingInfoPar>.Read(); Json<BatchingInfoPar>.Read();
Json<SimOrderConfig>.Read(); Json<SimOrderConfig>.Read();
@@ -49,6 +55,7 @@ namespace HBLConsole.MainConsole
Json<KeepDataBase>.Save(); Json<KeepDataBase>.Save();
Sqlite<Alarm>.GetInstance.Save(); Sqlite<Alarm>.GetInstance.Save();
TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo"); TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo");
TextHelper.GetInstance.WriteTextInfo(GVL.GeneralConfig.DeviceType.ToString());
} }


public void BusinessInit() public void BusinessInit()


+ 4
- 4
HBLConsole.Model/ViewModel/SimOrderVisibleData.cs View File

@@ -25,11 +25,11 @@ namespace HBLConsole.Model
public string Text { get { return _mText; } set { _mText = value; OnPropertyChanged(); } } public string Text { get { return _mText; } set { _mText = value; OnPropertyChanged(); } }
private string _mText; 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;








+ 5
- 2
HBLConsole.Service/Json.cs View File

@@ -11,12 +11,15 @@ namespace HBLConsole.Service
/// </summary> /// </summary>
public class Json<T> where T : class, new() public class Json<T> where T : class, new()
{ {

private static string DeviceType = ActionOperate.GetInstance.SendResult("GetDeviceType").ToString();

static string path static string path
{ {
get 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";
} }
} }




+ 24
- 0
HBLConsole.Service/TextHelper.cs View File

@@ -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();
}

} }
} }

+ 2
- 1
HBLConsole/App.xaml.cs View File

@@ -22,7 +22,7 @@ namespace HBLConsole
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
MainView mainView = new MainView();
MainView mainView;
ListDialogView listDialogView; ListDialogView listDialogView;
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
@@ -32,6 +32,7 @@ namespace HBLConsole
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
MainConsole.Main.GetInstance.DataInit(); MainConsole.Main.GetInstance.DataInit();
ThreadOperate.GetInstance.Start(new Action(() => { SqlHelper.GetInstance.GetData(); }), "GetSqliteData"); ThreadOperate.GetInstance.Start(new Action(() => { SqlHelper.GetInstance.GetData(); }), "GetSqliteData");
mainView = new MainView();
mainView.Show(); mainView.Show();
NoCompleteOrderInit(); NoCompleteOrderInit();
MainConsole.Main.GetInstance.BusinessInit(); MainConsole.Main.GetInstance.BusinessInit();


+ 4
- 1
HBLConsole/DialogWindow/View/SimOrderConfitView.xaml View File

@@ -110,7 +110,7 @@
<!--#endregion--> <!--#endregion-->


<!--#region 内容显示区--> <!--#region 内容显示区-->
<Grid Grid.Row="1" Margin="10">
<Grid KeyDown="Grid_KeyDown" Grid.Row="1" Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
@@ -139,6 +139,7 @@
FontFamily="楷体" FontFamily="楷体"
FontSize="21" FontSize="21"
Foreground="#ff34f7f7" Foreground="#ff34f7f7"
TabIndex="0"
Text="{Binding Name}" /> Text="{Binding Name}" />


<TextBlock <TextBlock
@@ -160,6 +161,7 @@
FontFamily="楷体" FontFamily="楷体"
FontSize="21" FontSize="21"
Foreground="#ff34f7f7" Foreground="#ff34f7f7"
TabIndex="1"
Text="{Binding Min}" /> Text="{Binding Min}" />


<TextBlock <TextBlock
@@ -181,6 +183,7 @@
FontFamily="楷体" FontFamily="楷体"
FontSize="21" FontSize="21"
Foreground="#ff34f7f7" Foreground="#ff34f7f7"
TabIndex="2"
Text="{Binding Max}" /> Text="{Binding Max}" />






+ 17
- 3
HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs View File

@@ -1,4 +1,5 @@
using HBLConsole.Service;
using HBLConsole.Model;
using HBLConsole.Service;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -12,6 +13,7 @@ using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using HBLConsole.DialogWindow.ViewModel;


namespace HBLConsole.DialogWindow.View namespace HBLConsole.DialogWindow.View
{ {
@@ -26,17 +28,29 @@ namespace HBLConsole.DialogWindow.View
this.MoveBorder.MouseLeftButtonDown += (o, e) => { this.DragMove(); }; this.MoveBorder.MouseLeftButtonDown += (o, e) => { this.DragMove(); };
this.ButMin.Click += (o, e) => { this.WindowState = WindowState.Minimized; }; 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.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.MaxWidth = SystemParameters.WorkArea.Width;
this.MaxHeight = SystemParameters.WorkArea.Height; this.MaxHeight = SystemParameters.WorkArea.Height;


ActionOperate.GetInstance.Register(new Action(() => ActionOperate.GetInstance.Register(new Action(() =>
{ {
this.DialogResult = true;
this.Close(); this.Close();
ActionOperate.GetInstance.CancelRegister("SimOrderConfitViewModelExit"); ActionOperate.GetInstance.CancelRegister("SimOrderConfitViewModelExit");
ActionOperate.GetInstance.CancelRegister("SendSimData");
}), "SimOrderConfitViewModelExit"); }), "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;
}
}
} }
} }
} }

+ 46
- 11
HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs View File

@@ -13,24 +13,59 @@ namespace HBLConsole.DialogWindow.ViewModel
{ {
public class SimOrderConfitViewModel : ViewModelBase public class SimOrderConfitViewModel : ViewModelBase
{ {
bool IsEdit = false;
SimOrderVisibleData simOrderVisibleData;
string DeviceType = string.Empty;
public SimOrderConfitViewModel() 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(() => 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"); ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit");
}); });
CancelCommand = new RelayCommand(() => { ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); }); CancelCommand = new RelayCommand(() => { ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); });


+ 29
- 16
HBLConsole/View/DebugView.xaml View File

@@ -11,19 +11,14 @@
d:DesignWidth="1000" d:DesignWidth="1000"
mc:Ignorable="d"> mc:Ignorable="d">


<UserControl.DataContext>
<vm:DebugViewModel />
</UserControl.DataContext>

<UserControl.Resources> <UserControl.Resources>


<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Resources/ResourceDictionarys/BasicStyle.xaml"> <ResourceDictionary Source="../Resources/ResourceDictionarys/BasicStyle.xaml">

<Style x:Key="TextBoxStyle" TargetType="TextBox"> <Style x:Key="TextBoxStyle" TargetType="TextBox">
<Setter Property="FontFamily" Value="楷体" /> <Setter Property="FontFamily" Value="楷体" />
<Setter Property="FontSize" Value="22" />
<Setter Property="FontSize" Value="18" />
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="#9934F7F7" /> <Setter Property="Foreground" Value="#9934F7F7" />
<Setter Property="BorderBrush" Value="#00c2f4" /> <Setter Property="BorderBrush" Value="#00c2f4" />
@@ -151,6 +146,10 @@
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>


<UserControl.DataContext>
<vm:DebugViewModel />
</UserControl.DataContext>

<Grid> <Grid>


<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@@ -173,12 +172,14 @@
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition Width="150" />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock <TextBlock
HorizontalAlignment="Right" HorizontalAlignment="Right"
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="16"
FontSize="14"
Foreground="#00c2f4" Foreground="#00c2f4"
Text="{Binding Text}" /> Text="{Binding Text}" />


@@ -195,10 +196,28 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Background="#FF2AB2E7" Background="#FF2AB2E7"
Content="启用随机数" Content="启用随机数"
FontSize="16"
FontSize="14"
Foreground="#00c2f4" Foreground="#00c2f4"
IsChecked="{Binding IsSelected}" IsChecked="{Binding IsSelected}"
Template="{StaticResource CbTemplate}" /> 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> </Grid>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
@@ -217,15 +236,9 @@
Style="{StaticResource ButtonStyle}" /> Style="{StaticResource ButtonStyle}" />
</UniformGrid> </UniformGrid>
</StackPanel> </StackPanel>



</Grid> </Grid>





<Grid Grid.Column="1">
<Grid Margin="20 0 0 0" Grid.Column="1">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="40" /> <RowDefinition Height="40" />
<RowDefinition Height="10" /> <RowDefinition Height="10" />


+ 1
- 1
HBLConsole/View/MainView.xaml View File

@@ -235,7 +235,7 @@
Grid.RowSpan="2" Grid.RowSpan="2"
Margin="10"> Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="{Binding ContentHeight}" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>




+ 36
- 10
HBLConsole/ViewModel/DebugViewModel.cs View File

@@ -28,7 +28,7 @@ namespace HBLConsole.ViewModel
AddSimDataCommand = new RelayCommand(() => AddSimDataCommand = new RelayCommand(() =>
{ {
SimOrderConfitView simOrderConfitView = new SimOrderConfitView(); SimOrderConfitView simOrderConfitView = new SimOrderConfitView();
simOrderConfitView.ShowDialog();
simOrderConfitView.Show();
}); });


SimOrderCommand = new RelayCommand(() => SimOrderCommand = new RelayCommand(() =>
@@ -43,7 +43,7 @@ namespace HBLConsole.ViewModel
} }
if (locs.Count == 0) if (locs.Count == 0)
{ {
locs.Add((ushort)(new Random().Next(1,5)));
locs.Add((ushort)(new Random().Next(1, 5)));
locs.Add(10); locs.Add(10);


} }
@@ -91,6 +91,36 @@ namespace HBLConsole.ViewModel
// //} // //}
// Thread.Sleep(1000); // 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 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 AddSimDataCommand { get; set; }


public RelayCommand SimOrderCommand { get; set; } public RelayCommand SimOrderCommand { get; set; }
@@ -129,6 +151,10 @@ namespace HBLConsole.ViewModel


public RelayCommand LoopSimOrderCommand { get; set; } 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 IsLoop = false;
public static bool IsLoopzc = false; public static bool IsLoopzc = false;




+ 1
- 1
HBLConsole/ViewModel/ViewModelBase.cs View File

@@ -59,7 +59,7 @@ namespace HBLConsole.ViewModel
/// 内容高度显示 /// 内容高度显示
/// </summary> /// </summary>
public static int ContentHeight { get { return _mContentHeight; } set { _mContentHeight = value; OnStaticPropertyChanged(); } } public static int ContentHeight { get { return _mContentHeight; } set { _mContentHeight = value; OnStaticPropertyChanged(); } }
private static int _mContentHeight = 0;
private static int _mContentHeight = 50;




/// <summary> /// <summary>


Loading…
Cancel
Save