diff --git a/BPASmart.Model/CommDeviceModel/AddressConvert.cs b/BPASmart.Model/CommDeviceModel/AddressConvert.cs index 6341bd09..f410fa7a 100644 --- a/BPASmart.Model/CommDeviceModel/AddressConvert.cs +++ b/BPASmart.Model/CommDeviceModel/AddressConvert.cs @@ -12,19 +12,22 @@ namespace BPASmart.Model public static AddressConvert GetInstance => _Instance ?? (_Instance = new AddressConvert()); private AddressConvert() { } - public string PlcConverter(ICommunicationDevice device, string Address) + public PlcConvertModel PlcConverter(ICommunicationDevice device, string Address) { - string address = string.Empty; - //if (Address != null && int.TryParse(Address, out int result)) return result; + PlcConvertModel plcConvertModel = new PlcConvertModel(); if (device != null && Address != null && Address.Length > 0) { switch (device) { case Invoance _tempInvoance: - if (Address.ToUpper().Contains("LW") && Address.Length >= 3) + if (Address.ToUpper().Contains("D") && Address.Length >= 3) { var res = Address.Substring(2); - if (res != null && int.TryParse(res, out int LwAddress)) return LwAddress.ToString(); + if (res != null && int.TryParse(res, out int LwAddress)) + { + plcConvertModel.Address = LwAddress.ToString(); + plcConvertModel.DataType = EDataType.Word.ToString(); + } } break; case kinco _tempKinco: @@ -37,7 +40,8 @@ namespace BPASmart.Model { if (ExitAddress >= 0 && ExitAddress <= 7) { - return ((firstAddress * 8) + 320 + ExitAddress).ToString(); + plcConvertModel.Address = ((firstAddress * 8) + 320 + ExitAddress).ToString(); + plcConvertModel.DataType = EDataType.Bool.ToString(); } } } @@ -45,21 +49,29 @@ namespace BPASmart.Model else if ((Address.ToUpper().Contains("VW") || Address.ToUpper().Contains("VD")) && Address.Length >= 3) { var res = Address.Substring(2); - if (res != null && int.TryParse(res, out int tempAddress)) return ((tempAddress / 2) + 100).ToString(); + if (res != null && int.TryParse(res, out int tempAddress)) + { + plcConvertModel.Address = ((tempAddress / 2) + 100).ToString(); + plcConvertModel.DataType = Address.ToUpper().Contains("VW") ? EDataType.Word.ToString() : EDataType.Dword.ToString(); + } } break; case KincoOneMachine _tempKincoOneMachine: - if (Address.ToUpper().Contains("D") && Address.Length >= 2) + if (Address.ToUpper().Contains("LW") && Address.Length >= 2) { var res = Address.Substring(1); - if (res != null && int.TryParse(res, out int LwAddress)) return LwAddress.ToString(); + if (res != null && int.TryParse(res, out int LwAddress)) + { + plcConvertModel.Address = LwAddress.ToString(); + plcConvertModel.DataType = EDataType.Word.ToString(); + } } break; default: break; } } - return address; + return plcConvertModel; } } diff --git a/BPASmart.Model/Enums/EDataType.cs b/BPASmart.Model/Enums/EDataType.cs index 463447a4..ff7c2aab 100644 --- a/BPASmart.Model/Enums/EDataType.cs +++ b/BPASmart.Model/Enums/EDataType.cs @@ -17,6 +17,8 @@ namespace BPASmart.Model Word = 4, Dint = 5, Dword = 6, - Float = 7 + Float = 7, + Double = 8, + String = 9, } } diff --git a/BPASmart.Model/ExpandMethod.cs b/BPASmart.Model/ExpandMethod.cs new file mode 100644 index 00000000..fdd08064 --- /dev/null +++ b/BPASmart.Model/ExpandMethod.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model +{ + public static class ExpandMethod + { + /// + /// 获取数据类型的大小 + /// + /// + /// + public static ushort GetEDataSize(this EDataType eDataType) + { + switch (eDataType) + { + case EDataType.Bool: + case EDataType.Byte: + case EDataType.Int: + case EDataType.Word: + return 1; + case EDataType.Dint: + case EDataType.Dword: + case EDataType.Float: + return 2; + case EDataType.Double: + break; + case EDataType.String: + break; + default: + break; + } + return 1; + } + + /// + /// 获取Modbus Tcp 连续变量数据的组对象 + /// + /// + /// + /// + public static List GetDataGroup(this IGrouping variableInfos, int by = 1) + { + List ReturnValue = new List(); + var res = variableInfos?.OrderBy(p => p.RealAddress).ToList(); + List RealAddresss = new List(); + variableInfos.ToList()?.ForEach(item => { if (int.TryParse(item.RealAddress, out int add)) RealAddresss.Add(add); }); + int count = 0; + if (res != null) + { + int address = RealAddresss.Min(); + int startAddress = address; + for (int i = 0; i < res.Count; i++) + { + if (int.TryParse(res.ElementAt(i).RealAddress, out int TempAddress)) + { + if (TempAddress == address) + { + count++; + address += by; + } + else + { + ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count }); + count = 1; + address = TempAddress + by; + startAddress = TempAddress; + } + } + + } + ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count }); + } + return ReturnValue; + } + + public static Dictionary> GetReadDataModels(this ObservableCollection varialeInfos) + { + Dictionary> readDataModels = new Dictionary>(); + varialeInfos.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar => + { + if (tempVar.Key != null && tempVar.Key.Length > 0) + { + EDataType dataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.Key); + switch (dataType) + { + case EDataType.Bool: + case EDataType.Byte: + case EDataType.Int: + case EDataType.Word: + if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, tempVar.GetDataGroup()); + break; + case EDataType.Dint: + case EDataType.Dword: + case EDataType.Float: + if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, tempVar.GetDataGroup(2)); + break; + default: + break; + } + } + }); + return readDataModels; + } + } +} diff --git a/BPASmart.Model/GlobalVar.cs b/BPASmart.Model/GlobalVar.cs new file mode 100644 index 00000000..3b1f1532 --- /dev/null +++ b/BPASmart.Model/GlobalVar.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model +{ + public class GlobalVar + { + public static ICommunicationDevice DeviceType { get; set; } + } +} diff --git a/BPASmart.Model/PlcConvertModel.cs b/BPASmart.Model/PlcConvertModel.cs new file mode 100644 index 00000000..696595e8 --- /dev/null +++ b/BPASmart.Model/PlcConvertModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model +{ + public class PlcConvertModel + { + public string Address { get; set; } = string.Empty; + public string DataType { get; set; } = string.Empty; + } +} diff --git a/BPASmart.Model/PublishModel.cs b/BPASmart.Model/PublishModel.cs index 9e008472..71bc9fe4 100644 --- a/BPASmart.Model/PublishModel.cs +++ b/BPASmart.Model/PublishModel.cs @@ -8,11 +8,35 @@ namespace BPASmart.Model { public class PublishModel { - public string DeviceName { get; set; } - public string RealAddress { get; set; } - public string Value { get; set; } + /// + /// 设备名称 + /// + public string DeviceName { get; set; } = string.Empty; + + /// + /// 变量实际地址 + /// + public string RealAddress { get; set; } = string.Empty; + + /// + /// 变量名称 + /// + public string VarName { get; set; } = string.Empty; + + /// + /// 变量长度 + /// + public int Length { get; set; } = 1; + + /// + /// 变量当前值 + /// + public string Value { get; set; } = string.Empty; + + /// + /// 变量数据类型 + /// public EDataType DataType { get; set; } - public int Sleep { get; set; } } } diff --git a/BPASmart.Model/RedisDataModel.cs b/BPASmart.Model/RedisDataModel.cs index 943d8ff9..07e9cf15 100644 --- a/BPASmart.Model/RedisDataModel.cs +++ b/BPASmart.Model/RedisDataModel.cs @@ -10,5 +10,6 @@ namespace BPASmart.Model { public string VarName { get; set; } public string VarVaule { get; set; } + public EDataType DataType { get; set; } } } diff --git a/BPASmart.Model/VariableInfo.cs b/BPASmart.Model/VariableInfo.cs index ffa7e156..c1f99811 100644 --- a/BPASmart.Model/VariableInfo.cs +++ b/BPASmart.Model/VariableInfo.cs @@ -17,13 +17,8 @@ namespace BPASmart.Model { public class VariableInfo : AlarmSet { - private ICommunicationDevice DeviceType; public VariableInfo(params object[] s) { - if (s != null && s.Length >= 0) - { - DeviceType = s[0] as ICommunicationDevice; - } CancelCommand = new RelayCommand(() => { IsOpen = false; }); ConfirmCommand = new RelayCommand(() => { IsOpen = false; }); } @@ -56,8 +51,9 @@ namespace BPASmart.Model { _mAddress = value; OnPropertyChanged(); - string address = AddressConvert.GetInstance.PlcConverter(DeviceType, value); - if (address.Length > 0) RealAddress = address; + var address = AddressConvert.GetInstance.PlcConverter(GlobalVar.DeviceType, value); + if (address.Address.Length > 0) RealAddress = address.Address; + if (DataType.Length <= 0) DataType = address.DataType; } } private string _mAddress = string.Empty; diff --git a/BPASmart.Model/配方/LocalMaterails.cs b/BPASmart.Model/配方/LocalMaterails.cs new file mode 100644 index 00000000..3ede4927 --- /dev/null +++ b/BPASmart.Model/配方/LocalMaterails.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model.配方 +{ + public class LocalMaterails + { + public ObservableCollection locaMaterails { get; set; } = new ObservableCollection(); + } +} diff --git a/BPASmart.Model/配方/LocalRecipes.cs b/BPASmart.Model/配方/LocalRecipes.cs new file mode 100644 index 00000000..74a4c335 --- /dev/null +++ b/BPASmart.Model/配方/LocalRecipes.cs @@ -0,0 +1,16 @@ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model.配方 +{ + public class LocalRecipes + { + public ObservableCollection locaRecipes { get; set; } = new ObservableCollection(); + } + +} diff --git a/BPASmart.Model/配方/Order.cs b/BPASmart.Model/配方/Order.cs new file mode 100644 index 00000000..bcc4a8aa --- /dev/null +++ b/BPASmart.Model/配方/Order.cs @@ -0,0 +1,36 @@ +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 BPASmart.Model.配方 +{ + public class Order:ObservableObject + { + /// + /// 订单ID + /// + public string OrderId { get { return _orderId; } set { _orderId = value; OnPropertyChanged(); } } + private string _orderId; + + /// + /// 下单时间 + /// + public string OrderdateTime { get { return _orderDateTime; } set { _orderDateTime = value; OnPropertyChanged(); } } + private string _orderDateTime; + + /// + /// 订单完成时间 + /// + public string OrderCompeleteTime { get { return _orderCompeleteTime; } set { _orderCompeleteTime = value; OnPropertyChanged(); } } + private string _orderCompeleteTime; + + /// + /// 配方集合 + /// + public ObservableCollection Recipes { get; set; } = new ObservableCollection(); + } +} diff --git a/BPASmart.Model/配方/RecipeMaterials.cs b/BPASmart.Model/配方/RecipeMaterials.cs new file mode 100644 index 00000000..35cb7dfd --- /dev/null +++ b/BPASmart.Model/配方/RecipeMaterials.cs @@ -0,0 +1,48 @@ +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model.配方 +{ + public class RecipeMaterials:ObservableObject + { + /// + /// 原料ID + /// + public string ID { get { return _id; } set { _id = value; OnPropertyChanged(); } } + private string _id; + /// + /// 物料名称 + /// + public string Name { get { return _name; } set { _name = value;OnPropertyChanged(); } } + private string _name; + /// + /// 物料种类 + /// + public MaterialType MaterialType { get { return _materialType; } set { _materialType = value; OnPropertyChanged(); } } + private MaterialType _materialType; + /// + /// 物料重量 + /// + public int MaterialWeight { get { return _materialWeight; } set { _materialWeight = value; OnPropertyChanged(); } } + private int _materialWeight; + /// + /// 原料位置 + /// + public string MaterialPosion { get { return _materialPosion; } set { _materialPosion = value;OnPropertyChanged(); } } + private string _materialPosion; + } + + public enum MaterialType + { + 无 = 0, + 干料 = 1, + 湿料 = 2, + 粉体 = 3, + 膏体 = 4 + } + +} diff --git a/BPASmart.Model/配方/Recipes.cs b/BPASmart.Model/配方/Recipes.cs new file mode 100644 index 00000000..27f66760 --- /dev/null +++ b/BPASmart.Model/配方/Recipes.cs @@ -0,0 +1,50 @@ +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 BPASmart.Model.配方 +{ + public class Recipes:ObservableObject + { + /// + /// 配方ID + /// + public string ID { get { return _id; } set { _id = value; OnPropertyChanged(); } } + private string _id; + + /// + /// 配方名称 + /// + public string Name { get { return _name; } set { _name = value; OnPropertyChanged(); } } + public string _name; + + /// + /// 配方状态 + /// + public RecipeStates RecipeState { get { return _recipeState; } set { _recipeState = value; OnPropertyChanged(); } } + public RecipeStates _recipeState; + + /// + /// 配方单数 + /// + public int RecipeCount { get { return _recipeCount; } set { _recipeCount = value; OnPropertyChanged(); } } + private int _recipeCount; + /// + /// 配方原料集合 + /// + public ObservableCollection recipeMaterials { get; set; } + + } + + public enum RecipeStates + { + 等待制作 = 0, + 制作中 = 1, + 制作完成 = 2 + } +} + diff --git a/BPASmart.RecipeManagement/App.xaml b/BPASmart.RecipeManagement/App.xaml new file mode 100644 index 00000000..c488f68c --- /dev/null +++ b/BPASmart.RecipeManagement/App.xaml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmart.RecipeManagement/App.xaml.cs b/BPASmart.RecipeManagement/App.xaml.cs new file mode 100644 index 00000000..b9814a15 --- /dev/null +++ b/BPASmart.RecipeManagement/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 BPASmart.RecipeManagement +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/BPASmart.RecipeManagement/AssemblyInfo.cs b/BPASmart.RecipeManagement/AssemblyInfo.cs new file mode 100644 index 00000000..8b5504ec --- /dev/null +++ b/BPASmart.RecipeManagement/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) +)] diff --git a/BPASmart.RecipeManagement/BPASmart.RecipeManagement.csproj b/BPASmart.RecipeManagement/BPASmart.RecipeManagement.csproj new file mode 100644 index 00000000..d52552a2 --- /dev/null +++ b/BPASmart.RecipeManagement/BPASmart.RecipeManagement.csproj @@ -0,0 +1,51 @@ + + + + WinExe + net6.0-windows + enable + true + False + + + + + + + + + + + + + + + + + + + + + + Code + + + + + + $(DefaultXamlRuntime) + Designer + + + + + + Always + + + + + + + + diff --git a/BPASmart.RecipeManagement/Globle/GlobleData.cs b/BPASmart.RecipeManagement/Globle/GlobleData.cs new file mode 100644 index 00000000..c0db0770 --- /dev/null +++ b/BPASmart.RecipeManagement/Globle/GlobleData.cs @@ -0,0 +1,19 @@ +using BPASmart.Model.配方; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.RecipeManagement.Globle +{ + public class GlobleData + { + public static RecipeMaterials ChangeMaterail; + + public static Recipes ChangeRecipes; + + public static ObservableCollection orders { get; set; } = new ObservableCollection(); + } +} diff --git a/BPASmart.RecipeManagement/Image/AddGreen.png b/BPASmart.RecipeManagement/Image/AddGreen.png new file mode 100644 index 00000000..13676da2 Binary files /dev/null and b/BPASmart.RecipeManagement/Image/AddGreen.png differ diff --git a/BPASmart.RecipeManagement/Image/Delete.png b/BPASmart.RecipeManagement/Image/Delete.png new file mode 100644 index 00000000..f53eb2b3 Binary files /dev/null and b/BPASmart.RecipeManagement/Image/Delete.png differ diff --git a/BPASmart.RecipeManagement/MainWindow.xaml b/BPASmart.RecipeManagement/MainWindow.xaml new file mode 100644 index 00000000..0781e346 --- /dev/null +++ b/BPASmart.RecipeManagement/MainWindow.xaml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmart.RecipeManagement/MainWindow.xaml.cs b/BPASmart.RecipeManagement/MainWindow.xaml.cs new file mode 100644 index 00000000..f2dd0115 --- /dev/null +++ b/BPASmart.RecipeManagement/MainWindow.xaml.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +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 BPASmart.RecipeManagement +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + + } + + private void mylistview_MouseDown(object sender, MouseButtonEventArgs e) + { + this.DragMove(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + this.Close(); + } + + + private void NavButton_Click(object sender, RoutedEventArgs e) + { + try + { + if (sender is RadioButton bt) + { + Type type = Type.GetType($"BPASmart.RecipeManagement.View.{bt.Tag?.ToString()}"); + ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes); + contentRegion.Content = (FrameworkElement)cti.Invoke(null); + } + } + catch (Exception ex) + { + + } + } + } +} diff --git a/BPASmart.RecipeManagement/View/CreateOrder.xaml b/BPASmart.RecipeManagement/View/CreateOrder.xaml new file mode 100644 index 00000000..791b89f5 --- /dev/null +++ b/BPASmart.RecipeManagement/View/CreateOrder.xaml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmart.RecipeManagement/View/PowerManager.xaml.cs b/BPASmart.RecipeManagement/View/PowerManager.xaml.cs new file mode 100644 index 00000000..917d0d85 --- /dev/null +++ b/BPASmart.RecipeManagement/View/PowerManager.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 BPASmart.RecipeManagement.View +{ + /// + /// PowerManager.xaml 的交互逻辑 + /// + public partial class PowerManager : UserControl + { + public PowerManager() + { + InitializeComponent(); + } + } +} diff --git a/BPASmart.RecipeManagement/View/RecipeManager.xaml b/BPASmart.RecipeManagement/View/RecipeManager.xaml new file mode 100644 index 00000000..22f6b89d --- /dev/null +++ b/BPASmart.RecipeManagement/View/RecipeManager.xaml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmart.RecipeManagement/View/RecipeManager.xaml.cs b/BPASmart.RecipeManagement/View/RecipeManager.xaml.cs new file mode 100644 index 00000000..b0632507 --- /dev/null +++ b/BPASmart.RecipeManagement/View/RecipeManager.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 BPASmart.RecipeManagement.View +{ + /// + /// RecipeManager.xaml 的交互逻辑 + /// + public partial class RecipeManager : UserControl + { + public RecipeManager() + { + InitializeComponent(); + } + } +} diff --git a/BPASmart.RecipeManagement/View/RecipesConfigure.xaml b/BPASmart.RecipeManagement/View/RecipesConfigure.xaml new file mode 100644 index 00000000..cb9e0cd1 --- /dev/null +++ b/BPASmart.RecipeManagement/View/RecipesConfigure.xaml @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +