pry преди 2 години
родител
ревизия
6288520f58
променени са 33 файла, в които са добавени 954 реда и са изтрити 123 реда
  1. +5
    -1
      BPASmartClient.Business/Plugin/MQTTMgr.cs
  2. +3
    -7
      BPASmartClient.CustomResource/Pages/Model/NfcServer.cs
  3. +1
    -1
      BPASmartClient.CustomResource/Pages/Model/UserInfo.cs
  4. +2
    -1
      BPASmartClient.CustomResource/Pages/View/LoginView.xaml.cs
  5. +130
    -25
      BPASmartClient.CustomResource/Pages/View/NfcSetView.xaml
  6. +2
    -0
      BPASmartClient.CustomResource/Pages/View/NfcSetView.xaml.cs
  7. +12
    -0
      BPASmartClient.CustomResource/Pages/View/RecipeQueueView.xaml
  8. +28
    -0
      BPASmartClient.CustomResource/Pages/View/RecipeQueueView.xaml.cs
  9. +4
    -1
      BPASmartClient.CustomResource/Pages/View/SubPagLoginView.xaml.cs
  10. +47
    -20
      BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs
  11. +4
    -4
      BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs
  12. +81
    -51
      BPASmartClient.CustomResource/Pages/ViewModel/NfcSetViewModel.cs
  13. +1
    -1
      BPASmartClient.CustomResource/RecDictionarys/DatePickeerDictionary.xaml
  14. +9
    -0
      BPASmartClient.Model/柔性味魔方/RawMaterialModel.cs
  15. +29
    -0
      BPASmartClient.Model/柔性味魔方/RecipeQueueModel.cs
  16. +1
    -1
      BPASmartClient.MorkS/Control_Morks.cs
  17. +1
    -0
      BPASmartClient/App.config
  18. +1
    -1
      DosingSystem/App.xaml.cs
  19. +2
    -2
      DosingSystem/Model/DeviceInquire.cs
  20. +1
    -7
      DosingSystem/ViewModel/NewMaterialViewModel.cs
  21. +23
    -0
      SmartClient.sln
  22. +9
    -0
      WPFDemo/App.xaml
  23. +17
    -0
      WPFDemo/App.xaml.cs
  24. +10
    -0
      WPFDemo/AssemblyInfo.cs
  25. +23
    -0
      WPFDemo/MainWindow.xaml
  26. +53
    -0
      WPFDemo/MainWindow.xaml.cs
  27. +31
    -0
      WPFDemo/Segment.cs
  28. +36
    -0
      WPFDemo/Silo.xaml
  29. +60
    -0
      WPFDemo/Silo.xaml.cs
  30. +16
    -0
      WPFDemo/SiloPanel.xaml
  31. +288
    -0
      WPFDemo/SiloPanel.xaml.cs
  32. +24
    -0
      WPFDemo/WPFDemo.csproj
  33. Двоични данни
     

+ 5
- 1
BPASmartClient.Business/Plugin/MQTTMgr.cs Целия файл

@@ -32,6 +32,7 @@ namespace BPASmartClient.Business
private MQTTProxy mqttProxy = new MQTTProxy();
//消息处理者
private List<RecivedHandle> messageRecives = new List<RecivedHandle>();

public void Initialize()
{

@@ -59,8 +60,11 @@ namespace BPASmartClient.Business
});
var MqttServerConfig = Plugin.GetInstance().GetPlugin<ConfigMgr>().MQTT_Config;
var MqttServerAccount = Plugin.GetInstance().GetPlugin<ConfigMgr>().Mqtt_Account;
var deviceConfig = Plugin.GetInstance().GetPlugin<ConfigMgr>().deviceConfigModelJsons;
string deviceId = deviceConfig[0].deviceModels[0].DeviceId;
clientId = Plugin.GetInstance().GetPlugin<ConfigMgr>().ClientId;
//MQTT 初始化
mqttProxy.Connect(MqttServerAccount.UserName, MqttServerAccount.Password, MqttServerConfig.Host, MqttServerConfig.Port, "qsqd--morks--"+ Guid.NewGuid().ToString());
mqttProxy.Connect(MqttServerAccount.UserName, MqttServerAccount.Password, MqttServerConfig.Host, MqttServerConfig.Port, "ClientId:" + clientId + "DeviceId:" + deviceId + Guid.NewGuid().ToString());

ThreadManage.GetInstance().Start(() =>
{


+ 3
- 7
BPASmartClient.CustomResource/Pages/Model/NfcServer.cs Целия файл

@@ -28,16 +28,12 @@ namespace BPASmartClient.CustomResource.Pages.Model
if (NFCHelper.GetInstance.GetReadResult?.CardNum.Length > 0)
{
string id = NFCHelper.GetInstance.GetReadResult?.CardNum;
var res = Global.userManager.userInfos.FirstOrDefault(p => p.CardId?.FirstOrDefault(s => s == id) != null);
var res = Global.userManager.userInfos.FirstOrDefault(p => p.CardId == id) ;
if (res != null)
{
if (Global.userInfo.permission != res.permission)
{
BPASmartClient.Message.MessageLog.GetInstance.ShowDebugLog("NFC卡登录");
LoginViewModel.NfcLogin(id);
}
BPASmartClient.Message.MessageLog.GetInstance.ShowDebugLog("NFC卡登录");
LoginViewModel.NfcLogin(id);
}

}
}
});


+ 1
- 1
BPASmartClient.CustomResource/Pages/Model/UserInfo.cs Целия файл

@@ -27,7 +27,7 @@ namespace BPASmartClient.CustomResource.Pages.Model
public string Password { get { return _password; } set { _password = value; OnPropertyChanged(); } }
private string _password = "admin";

public List<string> CardId { get; set; } = new List<string>();
public string CardId { get; set; } = String.Empty;

public List<RawMaterialModel> locaRawMaterials { get; set; } = new List<RawMaterialModel>();



+ 2
- 1
BPASmartClient.CustomResource/Pages/View/LoginView.xaml.cs Целия файл

@@ -1,4 +1,5 @@
using BPASmartClient.Helper;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.Helper;
using System;
using System.Collections.Generic;
using System.Diagnostics;


+ 130
- 25
BPASmartClient.CustomResource/Pages/View/NfcSetView.xaml Целия файл

@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:BPASmartClient.CustomResource.Pages.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:BPASmartClient.CustomResource.Pages.ViewModel"
xmlns:common="clr-namespace:BPASmartClient.CustomResource.Pages.Model"
Title="NfcSetView"
Width="500"
Height="250"
@@ -121,6 +122,39 @@
</Setter>
</Style>

<!--#region 密码输入框样式-->
<Style x:Key="PasswordBoxStyle" TargetType="{x:Type PasswordBox}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="FontFamily" Value="Times New Roman" />
<Setter Property="PasswordChar" Value="●" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Padding" Value="1" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="AllowDrop" Value="true" />
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="CaretBrush" Value="#009DFF" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="#009DFF" />
<Setter Property="BorderThickness" Value="0,0,0,1" />
</Style>
<!--#endregion-->

<!--#region 用户输入框样式-->
<Style x:Key="UserTextBoxStyle" TargetType="TextBox">
<Setter Property="Background" Value="Transparent" />
<Setter Property="CaretBrush" Value="#009DFF" />
<Setter Property="BorderBrush" Value="#009DFF"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="14" />
</Style>
<!--#endregion-->

</Window.Resources>

<Grid>
@@ -138,6 +172,7 @@
<TextBlock
FontSize="16"
Foreground="#32B8FF"
Margin="0,0,0,10"
Text="用户权限列表:" />

<ItemsControl ItemsSource="{Binding permissions}">
@@ -176,33 +211,96 @@

<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="0.5*" />
<RowDefinition Height="0.25*" />
</Grid.RowDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="92*"/>
<ColumnDefinition Width="135*"/>
<ColumnDefinition Width="67*"/>
</Grid.ColumnDefinitions>
<TextBlock
HorizontalAlignment="Center"
FontSize="16"
VerticalAlignment="Center"
Foreground="#FF32B8FF"
Text="当前卡号:" Height="21" Width="80" />

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">

<StackPanel Margin="0,5,0,5" Orientation="Horizontal">
<TextBlock
<TextBlock Grid.Row="1"
HorizontalAlignment="Center"
FontSize="16"
VerticalAlignment="Center"
Foreground="#FF32B8FF"
Text="用户名:" Height="20" Width="64" />
<TextBlock Grid.Row="2"
HorizontalAlignment="Center"
FontSize="16"
VerticalAlignment="Center"
Foreground="#FF32B8FF"
Text="当前密码:" Height="20" Width="80" />
<TextBlock Grid.Row="3"
HorizontalAlignment="Center"
FontSize="16"
VerticalAlignment="Center"
Foreground="#FF32B8FF"
Text="当前卡号:" />
Text="确认密码:" Height="20" Width="80" />

<TextBlock
<TextBlock Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="16"
Foreground="#FF32B8FF"
Text="{Binding CardNum}" />
</StackPanel>
Text="{Binding CardNum}" />

<TextBlock
Margin="0,5,0,5"
<TextBox Grid.Row="1" Grid.Column="1"
Margin="11,4,10,4"
Text="{Binding UserName}"
Style="{DynamicResource UserTextBoxStyle}"/>

<PasswordBox Grid.Column="1" Grid.Row="2"
Name="newpb1"
Margin="11,4,10,4"
common:PasswordHelper.Attach="True"
common:PasswordHelper.Password="{Binding CurrentPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
BorderBrush="#009DFF"
FontSize="16"
Foreground="#aadddddd"
Style="{DynamicResource PasswordBoxStyle}"
TabIndex="2" />
<PasswordBox Grid.Column="1" Grid.Row="3"
Name="newpb2"
Margin="11,4,10,4"
common:PasswordHelper.Attach="True"
common:PasswordHelper.Password="{Binding CheckPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
BorderBrush="#009DFF"
FontSize="16"
Foreground="#aadddddd"
Style="{DynamicResource PasswordBoxStyle}"
TabIndex="2" />
<TextBlock Grid.Row="2" Grid.Column="2"
HorizontalAlignment="Center"
FontSize="10"
VerticalAlignment="Center"
Foreground="#FF32B8FF"
Text="(默认888888)" Height="12" Width="62" />

<TextBlock Grid.Row="4" Grid.ColumnSpan="3" Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="16"
Foreground="#FFF53F62"
Text="{Binding Info}" />
</Grid>

</StackPanel>

<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
@@ -210,20 +308,27 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>

<RadioButton
VerticalAlignment="Center"
Content="用户添加"
GroupName="add"
IsChecked="{Binding UserAdd}"
Style="{StaticResource rbStyle}" />
<Button VerticalAlignment="Center"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Content="用户添加"
FontSize="16"
Style="{DynamicResource ButtonStyle}"
Command="{Binding UserAddCommand}"/>
<Button Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Content="用户注销"
FontSize="16"
Style="{DynamicResource ButtonStyle}"
Command="{Binding UserCancelCommand}"/>



<RadioButton
Grid.Column="1"
VerticalAlignment="Center"
Content="用户注销"
GroupName="add"
IsChecked="{Binding UserCnange}"
Style="{StaticResource rbStyle}" />
</Grid>
</Grid>



+ 2
- 0
BPASmartClient.CustomResource/Pages/View/NfcSetView.xaml.cs Целия файл

@@ -29,6 +29,7 @@ namespace BPASmartClient.CustomResource.Pages.View
{
Application.Current.Dispatcher.Invoke(new Action(() => { this.Close(); }));
NfcServer.GetInstance.EnableLogin = false;

}), "Exit", true);
}

@@ -41,5 +42,6 @@ namespace BPASmartClient.CustomResource.Pages.View
{
this.Close();
}

}
}

+ 12
- 0
BPASmartClient.CustomResource/Pages/View/RecipeQueueView.xaml Целия файл

@@ -0,0 +1,12 @@
<UserControl x:Class="BPASmartClient.CustomResource.Pages.View.RecipeQueueView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.CustomResource.Pages.View"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

+ 28
- 0
BPASmartClient.CustomResource/Pages/View/RecipeQueueView.xaml.cs Целия файл

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;

namespace BPASmartClient.CustomResource.Pages.View
{
/// <summary>
/// RecipeQueueView.xaml 的交互逻辑
/// </summary>
public partial class RecipeQueueView : UserControl
{
public RecipeQueueView()
{
InitializeComponent();
}
}
}

+ 4
- 1
BPASmartClient.CustomResource/Pages/View/SubPagLoginView.xaml.cs Целия файл

@@ -1,4 +1,5 @@
using BPASmartClient.Helper;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -42,6 +43,8 @@ namespace BPASmartClient.CustomResource.Pages.View
this.Close();
}
}), "ExitAction", true);

NfcServer.GetInstance.EnableLogin = false;
}

private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)


+ 47
- 20
BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs Целия файл

@@ -22,14 +22,17 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
{
ActionManage.GetInstance.Send("ExitAction");
});
}

public static void NfcLogin(string cardId)
{
var res = Global.userManager.userInfos.FirstOrDefault(p => p.CardId?.FirstOrDefault(s => s == cardId && s.Length > 0) != null);
var res = Global.userManager.userInfos.FirstOrDefault(p => p.CardId == cardId);
if (res != null)
{
Global.userInfo = res;
//permission权限
for (int i = 0; i < MenuManage.GetInstance.menuModels.Count; i++)
{
if (MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuPermission.Contains(res.permission))
@@ -48,6 +51,24 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Collapsed;
}
}
//分配后的权限
if (res.userTreeViewModels != null)
{
if (res.userTreeViewModels.Count > 0)
{
foreach (var items in MenuManage.GetInstance.menuModels)
{
foreach (var item in items.subMenumodels)
{
items.MainMenuVisibility = Visibility.Visible;
if (res.userTreeViewModels.FirstOrDefault(p => p.Name == item.SubMenuName) != null)
{
item.SubMenuVisibility = Visibility.Visible;
}
}
}
}
}
Application.Current.Dispatcher.Invoke(new Action(() => { ActionManage.GetInstance.Send("LoginOk"); }));

}
@@ -63,10 +84,32 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
Global.userInfo.LastLogInTime = DateTime.Now.ToString();
res.LastLogInTime = DateTime.Now.ToString();
Config.GetInstance.SaveUser();
if(res.permission == Enums.Permission.管理员)
//permission权限
for (int i = 0; i < MenuManage.GetInstance.menuModels.Count; i++)
{
if (MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuPermission.Contains(res.permission))
MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Visible;
else
MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed;

if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.SubMenuPermission.Contains(res.permission)) == null)
MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed;

for (int m = 0; m < MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.Count; m++)
{
if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuPermission.Contains(res.permission))
MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Visible;
else
MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Collapsed;
}
}

//分配后的权限
if (res.permission == Enums.Permission.管理员)
{
foreach( var items in MenuManage.GetInstance.menuModels)
{
items.MainMenuVisibility = Visibility.Visible;
foreach(var item in items.subMenumodels)
{
item.SubMenuVisibility = Visibility.Visible;
@@ -83,6 +126,7 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
{
foreach (var item in items.subMenumodels)
{
items.MainMenuVisibility = Visibility.Visible;
if (res.userTreeViewModels.FirstOrDefault(p => p.Name == item.SubMenuName) != null)
{
item.SubMenuVisibility = Visibility.Visible;
@@ -93,24 +137,7 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
}
}

//for (int i = 0; i < MenuManage.GetInstance.menuModels.Count; i++)
//{
// if (MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuPermission.Contains(res.permission))
// MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Visible;
// else
// MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed;

// if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.SubMenuPermission.Contains(res.permission)) == null)
// MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed;

// for (int m = 0; m < MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.Count; m++)
// {
// if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuPermission.Contains(res.permission))
// MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Visible;
// else
// MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Collapsed;
// }
//}
ActionManage.GetInstance.Send("PermissionChange");
ActionManage.GetInstance.Send("LoginOk");


+ 4
- 4
BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs Целия файл

@@ -27,10 +27,10 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
}), "PermissionChange");

//测试用
//Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "营养强化剂", DeviceIp = "192.168.1.111" });
//Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "甜味剂", DeviceIp = "192.168.1.112" });
//Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "抗氧化剂", DeviceIp = "192.168.1.113" });
//Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "食用香料", DeviceIp = "192.168.1.114" });
Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "营养强化剂", DeviceIp = "192.168.1.111", RawMaterialSource = 1 });
Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "甜味剂", DeviceIp = "192.168.1.112", RawMaterialSource = 1 });
Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "抗氧化剂", DeviceIp = "192.168.1.113", RawMaterialSource = 1 });
Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "食用香料", DeviceIp = "192.168.1.114", RawMaterialSource = 1 });

}



+ 81
- 51
BPASmartClient.CustomResource/Pages/ViewModel/NfcSetViewModel.cs Целия файл

@@ -20,71 +20,94 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
{
NfcServer.GetInstance.EnableLogin = true;
permissions.Clear();
Enum.GetNames(typeof(Permission)).ToList()?.ForEach(item => { permissions.Add(new PermissionSelect() { PermissionName = item }); });
Enum.GetNames(typeof(Permission)).ToList()?.ForEach(item => {
if(item !="管理员") permissions.Add(new PermissionSelect() { PermissionName = item });
});

NfcServer.GetInstance.Update = new Action(() =>
UserAddCommand = new RelayCommand(() =>
{
CardNum = NFCHelper.GetInstance.GetReadResult.CardNum;
if (CardNum.Length <= 0) return;

if (!UserAdd && !UserCnange)
if (permissions?.FirstOrDefault(p => p.PermissionSelected == true) == null)
{
Info = "Error:请选择一个权限;";
return ;
}
if (CardNum == null || CardNum?.Length <= 0)
{
Info = "Error:请将卡放到刷卡区;";
return ;
}
var per = Global.userManager.userInfos.FirstOrDefault(p => p.CardId == CardNum);
if (per != null)
{
Info = "Error:用户已存在!;";
return;
}
if (permissions?.FirstOrDefault(p => p.PermissionSelected == true) == null)
{
Info = "Error:请选择操作模式;";
Info = "Error:请选择一个权限;";
return;
}

if (UserAdd)
if (UserName == string.Empty)
{
var per = Global.userManager.userInfos.FirstOrDefault(p => p.CardId.Contains(CardNum));
if (per != null)
{
Info = "Error:用户已存在!;";
return;
}
if (permissions?.FirstOrDefault(p => p.PermissionSelected == true) == null)
{
Info = "Error:请选择一个权限;";
return;
}
var res = permissions.FirstOrDefault(p => p.PermissionSelected == true);
if (res != null)
{
int index = Array.FindIndex(Global.userManager.userInfos.ToArray(), p => p.permission.ToString() == res.PermissionName);
if (index >= 0 && index < Global.userManager.userInfos.Count)
{
if (!Global.userManager.userInfos.ElementAt(index).CardId.Contains(NFCHelper.GetInstance.GetReadResult.CardNum))
{
Global.userManager.userInfos.ElementAt(index).CardId.Add(NFCHelper.GetInstance.GetReadResult.CardNum);
Config.GetInstance.SaveUser();
Info = $"Info:ID {NFCHelper.GetInstance.GetReadResult.CardNum} 添加成功;";
Thread.Sleep(1000);
ActionManage.GetInstance.Send("Exit");
}
}
else
Info = $"Info:ID {NFCHelper.GetInstance.GetReadResult.CardNum} 已存在;";
}
Info = "Error:请添加用户名;";
return;
}

if (UserCnange)
var name = Global.userManager.userInfos.FirstOrDefault(p =>p.UserName == UserName);
if (name != null)
{
Info = "Error:用户名已存在!;";
}
var res = permissions.FirstOrDefault(p => p.PermissionSelected == true);
if (res != null)
{
int index = Array.FindIndex(Global.userManager.userInfos.ToArray(), p => p.CardId.FirstOrDefault(s => s == CardNum) != null);
if (index >= 0 && index < Global.userManager.userInfos.Count)
int index = Array.FindIndex(Global.userManager.userInfos.ToArray(), p => p.CardId.ToString() == CardNum);
if (index == -1)
{
if (Global.userManager.userInfos.ElementAt(index).CardId.Contains(CardNum))
Global.userManager.userInfos.ElementAt(index).CardId.Remove(CardNum);
Global.userManager.userInfos.Add(new UserInfo
{
CardId = CardNum,
UserName = UserName,
Password = CurrentPassword,
permission = (Permission)Enum.Parse(typeof(Permission), res.PermissionName)
});
Config.GetInstance.SaveUser();
Info = $"Info:ID {CardNum} 注销成功;";
Info = $"Info:ID {CardNum} 添加成功;";
MessageLog.GetInstance.ShowRunLog($" ID {CardNum} 用户添加成功");
Thread.Sleep(1000);
ActionManage.GetInstance.Send("Exit");
}
else
{
Info = "Info:当前卡在系统中不存在;";
return;
}
Info = $"Info:ID {NFCHelper.GetInstance.GetReadResult.CardNum} 已存在;";
}
});

UserCancelCommand = new RelayCommand(() =>
{
var res = Global.userManager.userInfos.FirstOrDefault(p=>p.CardId == CardNum);
if(res != null)
{
Global.userManager.userInfos.Remove(res);
Config.GetInstance.SaveUser();
Info = $"Info:ID {CardNum} 注销成功;";
MessageLog.GetInstance.ShowRunLog($"ID {CardNum} 用户注销成功");
Thread.Sleep(1000);
ActionManage.GetInstance.Send("Exit");
}
else
{
Info = "Info:当前卡在系统中不存在;";
return;
}
});

NfcServer.GetInstance.Update = new Action(() =>
{
CardNum = NFCHelper.GetInstance.GetReadResult.CardNum;
});
}

private bool Verify()
@@ -110,16 +133,23 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
public string Info { get { return _mInfo; } set { _mInfo = value; OnPropertyChanged(); } }
private string _mInfo;

public bool UserAdd { get { return _mUserAdd; } set { _mUserAdd = value; OnPropertyChanged(); } }
private bool _mUserAdd;
public string UserName { get { return _userName; } set { _userName = value; OnPropertyChanged(); } }
private string _userName = string.Empty;

public string CurrentPassword { get { return _currentPassword; } set { _currentPassword = value; OnPropertyChanged(); } }
private string _currentPassword = "888888";

public bool UserCnange { get { return _mUserCnange; } set { _mUserCnange = value; OnPropertyChanged(); } }
private bool _mUserCnange;
public string CheckPassword { get { return _checkPassword; } set { _checkPassword = value; OnPropertyChanged(); } }
private string _checkPassword = "888888";

public RelayCommand SavePermission { get; set; }

public RelayCommand DeletePermission { get; set; }

public RelayCommand UserAddCommand { get; set; }

public RelayCommand UserCancelCommand { get; set; }

}

public class PermissionSelect : ObservableObject


+ 1
- 1
BPASmartClient.CustomResource/RecDictionarys/DatePickeerDictionary.xaml Целия файл

@@ -354,7 +354,7 @@
<Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
<Setter TargetName="PART_YearView" Property="Visibility" Value="Visible" />
</DataTrigger>
<!-- Decade 美 ['dɛked] n. 十年,十年期;十 -->
<DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Decade">
<Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
<Setter TargetName="PART_YearView" Property="Visibility" Value="Visible" />


+ 9
- 0
BPASmartClient.Model/柔性味魔方/RawMaterialModel.cs Целия файл

@@ -30,6 +30,15 @@ namespace BPASmartClient.Model
private float _mRawMaterialWeight;


/// <summary>
/// 原料来源
/// 0:本地
/// 1:设备
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public ushort RawMaterialSource { get { return _mRawMaterialSource; } set { _mRawMaterialSource = value; OnPropertyChanged(); } }
private ushort _mRawMaterialSource;

/// <summary>
/// 原料类型 MW18
/// 1:液体


+ 29
- 0
BPASmartClient.Model/柔性味魔方/RecipeQueueModel.cs Целия файл

@@ -0,0 +1,29 @@
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Model.柔性味魔方
{
public class RecipeQueueModel :ObservableObject
{
public string RecipeName { get{ return _recipeName; }set { _recipeName = value; OnPropertyChanged(); } }
private string _recipeName;

public ObservableCollection<MaterailStates> rawMaterialModels { get; set; } = new ObservableCollection<MaterailStates>();

}

public class MaterailStates: ObservableObject
{
public RawMaterialModel RawMaterial { get; set; } = new RawMaterialModel();

public bool IsCompeleted { get { return _isCompeleted; } set { _isCompeleted = value; OnPropertyChanged(); } }
private bool _isCompeleted;

}
}

+ 1
- 1
BPASmartClient.MorkS/Control_Morks.cs Целия файл

@@ -636,7 +636,7 @@ namespace BPASmartClient.MorkS
{
VoiceAPI.m_SystemPlayWav(@"Vioce\电子提示音.wav");
Thread.Sleep(1000);
mORKS.speech.Speak(meal);
if(meal!= null) mORKS.speech.Speak(meal);
VoiceAPI.m_SystemPlayWav(@"Vioce\取餐通知.wav");
}



+ 1
- 0
BPASmartClient/App.config Целия файл

@@ -40,5 +40,6 @@
<add key="COM_ICChip" value="COM6"/>
<add key="BAUD_IChip" value="9600"/>


</appSettings>
</configuration>

+ 1
- 1
DosingSystem/App.xaml.cs Целия файл

@@ -182,7 +182,7 @@ namespace BPASmartClient.DosingSystem

UserManager.Add(new SubMenumodel()
{
SubMenuName = "NFC登录设置",
SubMenuName = "NFC登录管理",
SubMenuPermission = new Permission[] { Permission.管理员 },
AssemblyName = "BPASmartClient.CustomResource",
ToggleWindowPath = "Pages.View.NfcSetView"


+ 2
- 2
DosingSystem/Model/DeviceInquire.cs Целия файл

@@ -115,12 +115,12 @@ namespace BPASmartClient.DosingSystem.Model
{
if (Global.DeviceRawMaterials.FirstOrDefault(p => p.RawMaterialName == DeviceName) == null)
{
Global.DeviceRawMaterials.Add(new RawMaterialModel() { RawMaterialName = DeviceName, DeviceIp = ip });
Global.DeviceRawMaterials.Add(new RawMaterialModel() { RawMaterialName = DeviceName, DeviceIp = ip ,RawMaterialSource = 1});
}
}
else
{
Global.DeviceRawMaterials.Add(new RawMaterialModel() { RawMaterialName = DeviceName, DeviceIp = ip });
Global.DeviceRawMaterials.Add(new RawMaterialModel() { RawMaterialName = DeviceName, DeviceIp = ip , RawMaterialSource = 1 });
}

}));


+ 1
- 7
DosingSystem/ViewModel/NewMaterialViewModel.cs Целия файл

@@ -50,15 +50,9 @@ public class NewMaterialViewModel:ObservableObject
if(MaterialName == String.Empty) { ErrorInfo = "原料名称不能为空";return; }
if(Global.DeviceRawMaterials.FirstOrDefault(p=>p.RawMaterialName == MaterialName) != null) { ErrorInfo = "设备中已存在该原料名称";return;}
if(Json<LocaMaterial>.Data.LocalMaterails.FirstOrDefault(p=>p.RawMaterialName == MaterialName) != null) { ErrorInfo = "本地原料名称重复";return ;}
Json<LocaMaterial>.Data.LocalMaterails.Add(new RawMaterialModel { RawMaterialName = MaterialName, RawMaterialId = Guid.NewGuid().ToString() });
Json<LocaMaterial>.Data.LocalMaterails.Add(new RawMaterialModel { RawMaterialName = MaterialName, RawMaterialId = Guid.NewGuid().ToString() , RawMaterialSource = 0 });
Json<LocaMaterial>.Save();
MessageLog.GetInstance.ShowUserLog($"添加原料--{MaterialName}");
});




}
}

+ 23
- 0
SmartClient.sln Целия файл

@@ -132,6 +132,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.JXJFoodBigSt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.JXJFoodSmallStation", "BPASmartClient.JXJFoodSmallStation\BPASmartClient.JXJFoodSmallStation.csproj", "{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFDemo", "WPFDemo\WPFDemo.csproj", "{A456D582-D910-4CA2-8620-6D8F63344B47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -1266,6 +1268,26 @@ Global
{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40}.Release|x64.Build.0 = Release|Any CPU
{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40}.Release|x86.ActiveCfg = Release|Any CPU
{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40}.Release|x86.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|ARM.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|ARM.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|ARM64.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|x64.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|x64.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|x86.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|x86.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|Any CPU.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|ARM.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|ARM.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|ARM64.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|ARM64.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|x64.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|x64.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|x86.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1327,6 +1349,7 @@ Global
{D1F2379E-1755-4B50-9D67-15C960C33FFA} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
{FA695D7E-6F12-4483-A16D-8494609FAE68} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
{A456D582-D910-4CA2-8620-6D8F63344B47} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC}


+ 9
- 0
WPFDemo/App.xaml Целия файл

@@ -0,0 +1,9 @@
<Application x:Class="WPFDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFDemo"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

+ 17
- 0
WPFDemo/App.xaml.cs Целия файл

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace WPFDemo
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

+ 10
- 0
WPFDemo/AssemblyInfo.cs Целия файл

@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

+ 23
- 0
WPFDemo/MainWindow.xaml Целия файл

@@ -0,0 +1,23 @@
<Window x:Class="WPFDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFDemo"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Width="120" Height="30" Content="ADD" Click="Button_Click" />
<Button Width="120" Height="30" Content="DRAW LINE" Click="Button_Click_1" />
<Button Width="120" Height="30" Content="LOAD" Click="Button_Click_2" />
<Button Width="120" Height="30" Content="SAVE" Click="Button_Click_3" />
<Button Width="120" Height="30" Content="CLR" Click="Button_Click_4" />
</StackPanel>
<local:SiloPanel x:Name="sp" Grid.Row="1" PanelHeight="1030" PanelWidth="2000"/>
</Grid>
</Window>

+ 53
- 0
WPFDemo/MainWindow.xaml.cs Целия файл

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;

namespace WPFDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
sp.AddSilo();
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
sp.AddLine();
}

private void Button_Click_2(object sender, RoutedEventArgs e)
{
sp.Load();
}

private void Button_Click_3(object sender, RoutedEventArgs e)
{
sp.Save();
}

private void Button_Click_4(object sender, RoutedEventArgs e)
{
sp.Clear();
}
}
}

+ 31
- 0
WPFDemo/Segment.cs Целия файл

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shapes;

namespace WPFDemo
{
public class Segment
{
public List<SimpleSilo> Silos { get; set; } = new List<SimpleSilo>();

public List<SimpleLine> Lines { get; set; } = new List<SimpleLine>();

public class SimpleSilo
{
public string Caption { get; set; }
public string Index { get; set; }
public double Top { get; set; }
public double Left { get; set; }
}

public class SimpleLine {
public double X1 { get; set; }
public double X2 { get; set; }
public double Y1 { get; set; }
public double Y2 { get; set; }
}
}
}

+ 36
- 0
WPFDemo/Silo.xaml Целия файл

@@ -0,0 +1,36 @@
<UserControl x:Class="WPFDemo.Silo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WPFDemo"
Width="120"
Height="150"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
>
<Border BorderBrush="#FF243654" Background="#FF79E8C7">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="35"></RowDefinition>
</Grid.RowDefinitions>
<Image Width="120" Height="120" Source="device.png"></Image>
<Grid Grid.Row="1" Margin="10,2">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="编号" Grid.Row="0" Grid.Column="0"></TextBlock>
<TextBlock Text="{Binding Index}" Grid.Row="0" Grid.Column="1"></TextBlock>

<TextBlock Text="编号" Grid.Row="1" Grid.Column="0"></TextBlock>
<TextBlock Text="{Binding Caption}" Grid.Row="1" Grid.Column="1"></TextBlock>
</Grid>
</Grid>
</Border>
</UserControl>

+ 60
- 0
WPFDemo/Silo.xaml.cs Целия файл

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;

namespace WPFDemo
{
/// <summary>
/// Silo.xaml 的交互逻辑
/// </summary>
public partial class Silo : UserControl, INotifyPropertyChanged
{


public string Index
{
get { return (string)GetValue(IndexProperty); }
set { SetValue(IndexProperty, value);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Index"));
}
}

// Using a DependencyProperty as the backing store for Index. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IndexProperty =
DependencyProperty.Register("Index", typeof(string), typeof(Silo), new PropertyMetadata("Unkown"));



public string Caption
{
get { return (string)GetValue(CaptionProperty); }
set { SetValue(CaptionProperty, value);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Caption"));
}
}

// Using a DependencyProperty as the backing store for Caption. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CaptionProperty =
DependencyProperty.Register("Caption", typeof(string), typeof(Silo), new PropertyMetadata("Null"));


public Silo()
{
InitializeComponent();
}

public event PropertyChangedEventHandler? PropertyChanged;
}
}

+ 16
- 0
WPFDemo/SiloPanel.xaml Целия файл

@@ -0,0 +1,16 @@
<UserControl x:Name="userControl" x:Class="WPFDemo.SiloPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WPFDemo"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d" >
<Viewbox >
<Canvas Name="cvMain" Width="{Binding PanelWidth}" Height="{Binding PanelHeight}" Background="#B2C0E2E1">
<StackPanel Orientation="Horizontal" Canvas.Top="5" Canvas.Left="5">
<TextBlock FontSize="15" Text="{Binding Tips}"></TextBlock>
</StackPanel>
</Canvas>
</Viewbox>
</UserControl>

+ 288
- 0
WPFDemo/SiloPanel.xaml.cs Целия файл

@@ -0,0 +1,288 @@
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;

namespace WPFDemo
{
/// <summary>
/// SiloPanel.xaml 的交互逻辑
/// </summary>
public partial class SiloPanel : UserControl, INotifyPropertyChanged
{
//料仓模块左键按下标识
bool siloIsMouseDown = false;
//画线标识
bool lineIsDraw = false;
//当前线条
private Line currentLine;
//线条集合
private List<Line> lines = new List<Line>();
//料仓集合
private List<Silo> silos = new List<Silo>();
//用于序列化
private Segment segment = new Segment();

//提示
private string tips = "常规模式";
/// <summary>
/// 提示
/// </summary>
public string Tips
{
get { return tips; }
set
{
tips = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Tips"));
}
}
/// <summary>
/// 当前选中的料仓
/// </summary>
public Silo CurrentSilo { get; private set; }

/// <summary>
/// 画布宽度
/// </summary>
public double PanelWidth
{
get { return (double)GetValue(PanelWidthProperty); }
set { SetValue(PanelWidthProperty, value); }
}

// Using a DependencyProperty as the backing store for PanelWidth. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PanelWidthProperty =
DependencyProperty.Register("PanelWidth", typeof(double), typeof(SiloPanel), new PropertyMetadata(1920d));


/// <summary>
/// 画布高度
/// </summary>
public double PanelHeight
{
get { return (double)GetValue(PanelHeightProperty); }
set { SetValue(PanelHeightProperty, value); }
}

// Using a DependencyProperty as the backing store for PanelHeight. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PanelHeightProperty =
DependencyProperty.Register("PanelHeight", typeof(double), typeof(SiloPanel), new PropertyMetadata(1080d));

public event PropertyChangedEventHandler? PropertyChanged;

public SiloPanel()
{
InitializeComponent();
cvMain.PreviewMouseLeftButtonDown += CvMain_PreviewMouseLeftButtonDown;
cvMain.PreviewMouseMove += CvMain_PreviewMouseMove;
cvMain.PreviewMouseLeftButtonUp += CvMain_PreviewMouseLeftButtonUp;
}

/// <summary>
/// 开始画线
/// </summary>
public void AddLine()
{
lineIsDraw = true;
Tips = "线条绘制";
}

/// <summary>
/// 添加料仓模块
/// </summary>
public void AddSilo()
{
if (lineIsDraw)
lineIsDraw = false;
newSilo(String.Empty, String.Empty);
}

/// <summary>
/// 保存文件
/// </summary>
public void Save()
{
segment.Silos.Clear();
segment.Lines.Clear();
lines.ForEach(line =>
{
segment.Lines.Add(new Segment.SimpleLine() { X1 = line.X1, X2 = line.X2, Y1 = line.Y1, Y2 = line.Y2 });
});
silos.ForEach(silo =>
{
segment.Silos.Add(new Segment.SimpleSilo()
{
Left = (double)silo.GetValue(Canvas.LeftProperty),
Top = (double)silo.GetValue(Canvas.TopProperty),
Caption = silo.Caption,
Index = silo.Index
});
});


string ResultJson = JsonConvert.SerializeObject(segment);
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "配置文件|*.json";
if (dialog.ShowDialog() == true)
{
File.WriteAllText(dialog.FileName, ResultJson);
}
}

/// <summary>
/// 加载文件
/// </summary>
public void Load()
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "配置文件|*.json";
if (dialog.ShowDialog() == true)
{
string content = File.ReadAllText(dialog.FileName);
try
{
segment = JsonConvert.DeserializeObject<Segment>(content);
lines.Clear();
silos.Clear();
cvMain.Children.Clear();
foreach (var line in segment.Lines)
{
newLine(line.X1, line.Y1, line.X2, line.Y2);
}
foreach (var temp in segment.Silos)
{
newSilo(temp.Caption, temp.Index,temp.Left,temp.Top);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}

/// <summary>
/// 清空画布
/// </summary>
public void Clear()
{
lines.Clear();
silos.Clear();
cvMain.Children.Clear();
}

private void newSilo(string caption, string index, double left = -1, double top = -1)
{
Silo silo = new Silo() { Caption = caption, Index = index };
if (left == -1)
silo.SetValue(Canvas.LeftProperty, cvMain.ActualWidth / 2 - silo.Width / 2);
else
silo.SetValue(Canvas.LeftProperty, left);

if (top == -1)
silo.SetValue(Canvas.TopProperty, cvMain.ActualHeight / 2 - silo.Height / 2);
else
silo.SetValue(Canvas.TopProperty, top);

silo.AllowDrop = true;
cvMain.Children.Add(silo);
silos.Add(silo);
silo.PreviewMouseLeftButtonDown += Silo_PreviewMouseLeftButtonDown;
silo.PreviewMouseMove += Silo_PreviewMouseMove;
silo.PreviewMouseLeftButtonUp += Silo_PreviewMouseLeftButtonUp;

CurrentSilo = silo;
}

private void newLine(double x1, double y1, double x2, double y2)
{
var temp = new Line();
temp.Stroke = Brushes.Green;
temp.StrokeThickness = 1;
temp.X1 = x1;
temp.Y1 = y1;
temp.X2 = x2;
temp.Y2 = y2;
cvMain.Children.Add(temp);
lines.Add(temp);

currentLine = temp;
}

private void CvMain_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
lineIsDraw = false;
Tips = "常规模式";
}

private void CvMain_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && lineIsDraw)
{
Point point = e.GetPosition(cvMain);
currentLine.X2 = point.X;
currentLine.Y2 = point.Y;
}
}

private void CvMain_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!lineIsDraw)
return;
var point = e.GetPosition(cvMain);
newLine(point.X, point.Y, point.X, point.Y);

}



private void Silo_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var c = sender as UIElement;
siloIsMouseDown = false;
c.ReleaseMouseCapture();
CurrentSilo = sender as Silo;
}

private void Silo_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (siloIsMouseDown)
{
var c = sender as UIElement;
var pos = e.GetPosition(this);
c.SetValue(Canvas.LeftProperty, pos.X);
c.SetValue(Canvas.TopProperty, pos.Y);
}
}

private void Silo_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var c = sender as UIElement;
siloIsMouseDown = true;
var transform = c.RenderTransform as TranslateTransform;
if (transform == null)
{
transform = new TranslateTransform();
c.RenderTransform = transform;
}
c.CaptureMouse();
}


}
}

+ 24
- 0
WPFDemo/WPFDemo.csproj Целия файл

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<None Remove="device.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
<Resource Include="device.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>

</Project>

Двоични данни
Целия файл


Зареждане…
Отказ
Запис