Browse Source

1. 物料管理界面修改,2. 修改物料绑定方式 3. 加载物料修改为异步方式。

master
Nah 10 months ago
parent
commit
cff368397c
33 changed files with 1899 additions and 166 deletions
  1. +32
    -0
      BPA.Model/Table/MaterialBindTB.cs
  2. +2
    -4
      BPA.Model/Table/MaterialTB.cs
  3. +1
    -1
      BPA.Model/Table/RecipeRawMaterTB.cs
  4. +7
    -4
      BPA.SingleDevice/App.xaml.cs
  5. +6
    -1
      BPA.SingleDevice/Business/Batcher.cs
  6. +6
    -6
      BPA.SingleDevice/Business/ProcessControl.cs
  7. +36
    -0
      BPA.SingleDevice/Converters/MateialCodeConverter.cs
  8. +29
    -1
      BPA.SingleDevice/Helper/SqlHelper.cs
  9. +8
    -2
      BPA.SingleDevice/Interface/ISqlHelper.cs
  10. +99
    -0
      BPA.SingleDevice/View/AddMaterialDialogView.xaml
  11. +28
    -0
      BPA.SingleDevice/View/AddMaterialDialogView.xaml.cs
  12. +6
    -3
      BPA.SingleDevice/View/MainView.xaml
  13. +115
    -0
      BPA.SingleDevice/View/MaterialBindingView.xaml
  14. +30
    -0
      BPA.SingleDevice/View/MaterialBindingView.xaml.cs
  15. +124
    -0
      BPA.SingleDevice/View/MaterialManagementView.xaml
  16. +30
    -0
      BPA.SingleDevice/View/MaterialManagementView.xaml.cs
  17. +1
    -1
      BPA.SingleDevice/View/NewRecipeView.xaml
  18. +64
    -60
      BPA.SingleDevice/View/OrderMainView.xaml
  19. +5
    -4
      BPA.SingleDevice/View/RawMaterialManagementView.xaml
  20. +2
    -4
      BPA.SingleDevice/View/RecipeCompletView.xaml
  21. +171
    -0
      BPA.SingleDevice/View/SetBindMaterialView.xaml
  22. +28
    -0
      BPA.SingleDevice/View/SetBindMaterialView.xaml.cs
  23. +126
    -0
      BPA.SingleDevice/View/SetBindingMaterialView.xaml
  24. +28
    -0
      BPA.SingleDevice/View/SetBindingMaterialView.xaml.cs
  25. +40
    -0
      BPA.SingleDevice/ViewModel/AddMaterialViewModel.cs
  26. +4
    -1
      BPA.SingleDevice/ViewModel/MainViewModel.cs
  27. +297
    -0
      BPA.SingleDevice/ViewModel/MaterialBindingViewModel.cs
  28. +226
    -0
      BPA.SingleDevice/ViewModel/MaterialManagementViewModel.cs
  29. +29
    -20
      BPA.SingleDevice/ViewModel/NewRecipeViewModel.cs
  30. +158
    -44
      BPA.SingleDevice/ViewModel/OrderMainViewModel.cs
  31. +30
    -10
      BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs
  32. +88
    -0
      BPA.SingleDevice/ViewModel/SetBindMaterialViewModel.cs
  33. +43
    -0
      BPA.SingleDevice/ViewModel/SetBindingMaterialViewModel.cs

+ 32
- 0
BPA.Model/Table/MaterialBindTB.cs View File

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

namespace BPA.Model.Table
{
public class MaterialBindTB:SqlBase
{
/// <summary>
/// 物料名称
/// </summary>
public string MaterialName { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string MaterialCode { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public int DeviceNum { get; set; }
/// <summary>
/// 设备仓位编号
/// </summary>
public int WarehouseNum { get; set; }
/// <summary>
/// 最后修改时间
/// </summary>
public string LastModified { get; set; }
}
}

+ 2
- 4
BPA.Model/Table/MaterialTB.cs View File

@@ -23,16 +23,13 @@ namespace BPA.Model.Table
/// </summary>
public string MaterialCode { get; set; }
/// <summary>
/// 是否删除
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// 是否激活
/// </summary>
public bool IsActive { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(IsOnlyIgnoreUpdate =true)]
public string CreateTime { get; set; }

/// <summary>
@@ -42,6 +39,7 @@ namespace BPA.Model.Table
/// <summary>
/// 物料描述
/// </summary>
[SugarColumn(IsNullable =true)]
public string Description { get; set; }
}



+ 1
- 1
BPA.Model/Table/RecipeRawMaterTB.cs View File

@@ -17,7 +17,7 @@ namespace BPA.Model.Table
public string RecipeId { get; set; }

/// <summary>
/// 原料ID
/// 原料ID,后被修改为对应物料编码。
/// </summary>
public string RawMaterId { get; set; }



+ 7
- 4
BPA.SingleDevice/App.xaml.cs View File

@@ -64,14 +64,16 @@ namespace BPA.SingleDevice

//services.AddSingleton<ISqlHelper, SqlHelper>();
services.AddSingleton<ILogService, LogService>();
services.AddSingleton<IProcessControl, ProcessControl>();
services.AddSingleton<GlobalData>();

services.AddTransient<RawMaterialManagementViewModel>();
//services.AddTransient<RawMaterialManagementViewModel>();
services.AddTransient<OrderMainViewModel>();
services.AddTransient<RecipeManagementViewModel>();

//services.AddSingleton<ParamsSetViewModel>();
services.AddSingleton<RunLogViewModel>();
services.AddSingleton<AlarmLogViewModel>();
//services.AddSingleton<AlarmLogViewModel>();
services.AddSingleton<RecipeCompleteViewModel>();
services.AddSingleton<UserLogViewModel>();
services.AddSingleton<DebugLogViewModel>();
@@ -79,9 +81,10 @@ namespace BPA.SingleDevice
services.AddSingleton<DebugViewModel>();

services.AddSingleton<RecipeStatusViewModel>();
services.AddTransient<MaterialManagementViewModel>();
services.AddTransient<MaterialBindingViewModel>();

services.AddSingleton<IProcessControl, ProcessControl>();
services.AddSingleton<GlobalData>();

return services.BuildServiceProvider();
}


+ 6
- 1
BPA.SingleDevice/Business/Batcher.cs View File

@@ -58,9 +58,14 @@ namespace BPA.SingleDevice.Business

public bool WriteBatchData(ushort[] value)
{
ushort[] newValue = new ushort[value.Length];
for (int i = 0; i < value.Length; i++)
{
newValue[i] = (ushort)(value[i] * 10);
}
try
{
var result = modbus.Write<ushort[]>("LW1000".ToModbusAdd(), value);
var result = modbus.Write<ushort[]>("LW1000".ToModbusAdd(), newValue);
return result.IsSuccess;
}
catch (Exception ex)


+ 6
- 6
BPA.SingleDevice/Business/ProcessControl.cs View File

@@ -162,7 +162,11 @@ namespace BPA.SingleDevice.Business
switch (recipe.BatchStatus[stationNum])
{
case BatchStep.WaitBatch:
recipe.BatchStatus[stationNum] = BatchStep.WriteBatchParam;
if (Batchers[stationNum].ResetCompleted())
{
recipe.BatchStatus[stationNum] = BatchStep.WriteBatchParam;
logService.LogRunInfo($"配方【{recipe.Name}】工位【{stationNum}】的配料完成信号已复位。");
}
break;

case BatchStep.WriteBatchParam:
@@ -171,7 +175,7 @@ namespace BPA.SingleDevice.Business
if (Batchers[stationNum].WriteBatchData(materialList))
{
recipe.BatchStatus[stationNum] = BatchStep.StartBatch;
logService.LogRunInfo($"配方【{recipe.Name}】写入工位【{stationNum}】的下料参数【{String.Join(',', materialList)}】成功。");
logService.LogRunInfo($"配方【{recipe.Name}】写入工位【{stationNum}】的下料重量【{String.Join(',', materialList)}】成功。");
}
else
{
@@ -208,11 +212,7 @@ namespace BPA.SingleDevice.Business
break;

case BatchStep.BatchCompleted:
if (Batchers[stationNum].ResetCompleted())
{
recipe.IsMakeComplete[stationNum - 1] = true;
logService.LogRunInfo($"配方【{recipe.Name}】工位【{stationNum}】的配料完成信号已复位。");
}
break;
}
}


+ 36
- 0
BPA.SingleDevice/Converters/MateialCodeConverter.cs View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace BPA.SingleDevice.Converters
{
public class MateialCodeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not null && !String.IsNullOrEmpty(value.ToString()))
{
var code = value.ToString();
var result = SqlHelper.GetInstance.GetListAsync<MaterialTB>().Result;
if (result.IsSuccess)
{
var b= result.Content.FirstOrDefault(m => m.MaterialCode == code);
if (b is not null)
{
return b.Name;
}
}
}
return Binding.DoNothing;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

+ 29
- 1
BPA.SingleDevice/Helper/SqlHelper.cs View File

@@ -94,7 +94,7 @@ namespace BPA.SingleDevice.Helper
}
}

public async Task<OperateResult> UpdateAsync<T>(T data) where T : SqlBase, new()
public async Task<OperateResult> UpdateAsync<T>(T data) where T : class, new()
{
try
{
@@ -134,6 +134,34 @@ namespace BPA.SingleDevice.Helper
}
}


public async Task<OperateResult<int>> DeleteMaterialByIDAsync<T>(int id) where T:MaterialTB
{
OperateResult<int> result = new();
try
{
if (Db == null)
return new OperateResult<int>("DB 实例为空");
var removeList = await Db.Queryable<T>().Where(p => p.ID == id).ToListAsync();
if (removeList != null)
{
var res = await Db.Deleteable<MaterialTB>(removeList).ExecuteCommandAsync();
//return new OperateResult<int>(res);
result.Content = res;
result.IsSuccess = true;
return result;
}
else
{
return new OperateResult<int>("未找到需要移除的信息");
}
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
return new OperateResult<int>(ex.ToString());
}
}
public async Task<OperateResult<List<T>>> GetListAsync<T>()
{
OperateResult<List<T>> result = new OperateResult<List<T>>();


+ 8
- 2
BPA.SingleDevice/Interface/ISqlHelper.cs View File

@@ -31,7 +31,7 @@ namespace BPA.SingleDevice.Interface
/// <summary>更新信息</summary>
/// <param name="data"></param>
/// <returns></returns>
Task<OperateResult> UpdateAsync<T>(T data) where T : SqlBase, new();
Task<OperateResult> UpdateAsync<T>(T data) where T : class, new();

/// <summary>移除数据</summary>
/// <param name="id"></param>
@@ -46,7 +46,13 @@ namespace BPA.SingleDevice.Interface
/// <summary>获取所有数据</summary>
/// <returns></returns>
Task<OperateResult<List<T>>> GetListAsync<T>();

/// <summary>
/// 删除物料新的物料表指定信息。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
Task<OperateResult<int>> DeleteMaterialByIDAsync<T>(int id) where T : MaterialTB;
/// <summary>通过配方ID获取物料ID集合</summary>
/// <param name="RecipeId"></param>
/// <returns></returns>


+ 99
- 0
BPA.SingleDevice/View/AddMaterialDialogView.xaml View File

@@ -0,0 +1,99 @@
<UserControl
x:Class="BPA.SingleDevice.View.AddMaterialDialogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bpa="http://BPAUIControl.io/winfx/xaml/toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPA.SingleDevice.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
d:DesignHeight="300"
d:DesignWidth="800"
mc:Ignorable="d">

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

<Grid Margin="10" bpa:PanelHelper.Spacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="物料名称:" />
<TextBox
Grid.Row="0"
Grid.Column="1"
Width="350"
Height="70"
FontSize="40"
Style="{StaticResource DarkTextBox}"
Text="{Binding MaterialInfo.Name}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="物料编码:" />
<TextBox
Grid.Row="1"
Grid.Column="1"
Width="350"
Height="70"
FontSize="40"
Style="{StaticResource DarkTextBox}"
Text="{Binding MaterialInfo.MaterialCode}" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="物料描述:" />
<TextBox
Grid.Row="2"
Grid.Column="1"
Width="350"
Height="70"
FontSize="40"
Style="{StaticResource DarkTextBox}"
Text="{Binding MaterialInfo.Description}" />

<Grid
Grid.Row="3"
Grid.ColumnSpan="2"
Height="70"
Margin="0,5"
bpa:PanelHelper.Spacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button
Grid.Column="0"
Command="{Binding SaveCommand}"
Content="确认"
FontSize="40" />
<Button
Grid.Column="1"
Command="{Binding CancelCommand}"
Content="取消"
FontSize="40" />
</Grid>
</Grid>
</UserControl>

+ 28
- 0
BPA.SingleDevice/View/AddMaterialDialogView.xaml.cs View File

@@ -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 BPA.SingleDevice.View
{
/// <summary>
/// AddMaterialDialogView.xaml 的交互逻辑
/// </summary>
public partial class AddMaterialDialogView : UserControl
{
public AddMaterialDialogView()
{
InitializeComponent();
}
}
}

+ 6
- 3
BPA.SingleDevice/View/MainView.xaml View File

@@ -89,9 +89,12 @@
bpa:ItemsControlHelper.ItemMargin="0"
bpa:ItemsControlHelper.ItemPadding="5 3"
Background="#2d2d2d"
ExpandedWidth="400" CollapsedWidth="100"
CollapsedWidth="100"
ExpandedWidth="400"
FontSize="40"
IsExpanded="False"
Foreground="{DynamicResource WhiteForeground}"
Header="菜单" FontSize="40"
Header="菜单"
ItemsSource="{Binding ViewItems}"
PaneBackground="{Binding TitleBackground, RelativeSource={RelativeSource AncestorType=bpa:BPAWindow}}"
SelectedItem="{Binding CurrentViewItem}"
@@ -102,7 +105,7 @@
x:Key="headContent"
Height="70"
x:Shared="false">
<TextBlock Text="{Binding Name}" FontSize="40" />
<TextBlock FontSize="40" Text="{Binding Name}" />
</Grid>
</bpa:HamburgerMenu.Resources>
<bpa:HamburgerMenu.ItemContainerStyle>


+ 115
- 0
BPA.SingleDevice/View/MaterialBindingView.xaml View File

@@ -0,0 +1,115 @@
<UserControl
x:Class="BPA.SingleDevice.View.MaterialBindingView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bpa="http://BPAUIControl.io/winfx/xaml/toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPA.SingleDevice.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">

<bpa:DialogContainer>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>

<!--#region 功能按钮-->
<StackPanel
Grid.Row="0"
Margin="5"
HorizontalAlignment="Right"
bpa:PanelHelper.Spacing="15"
Orientation="Horizontal">
<Button
Width="250"
HorizontalAlignment="Right"
Command="{Binding RefreshCommand}"
Content="刷新"
Style="{DynamicResource DarkButton}" />
<Button
Width="300"
HorizontalAlignment="Right"
Command="{Binding AddCommand}"
Content="物料绑定"
Style="{DynamicResource DarkButton}" />
</StackPanel>

<!--#endregion-->

<!--#region 列表-->
<bpa:ControlDisplay Grid.Row="1">
<DataGrid
Grid.Row="1"
bpa:HeaderHelper.HorizontalAlignment="Center"
AutoGenerateColumns="False"
BorderBrush="Gray"
BorderThickness="1"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
GridLinesVisibility="All"
IsReadOnly="True"
ItemsSource="{Binding MaterialBindInfos}"
RowHeight="70"
SelectionMode="Single"
Style="{StaticResource DataGridLargeScrollStyle}">
<DataGrid.Columns>
<DataGridTextColumn
Width="*"
Binding="{Binding MaterialName}"
FontSize="36"
Header="物料名称" />
<DataGridTextColumn
Width="200"
Binding="{Binding MaterialCode}"
Header="物料编码" />
<DataGridTextColumn
Width="140"
Binding="{Binding DeviceNum}"
Header="设备号" />
<DataGridTextColumn
Width="140"
Binding="{Binding WarehouseNum}"
Header="通道号" />
<DataGridTextColumn
Width="410"
Binding="{Binding LastModified}"
Header="最后修改时间" />
<DataGridTemplateColumn Width="500" Header="操作">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button
Width="300"
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:MaterialBindingView}}"
CommandParameter="{Binding Id}"
Foreground="#2196F3"
Style="{StaticResource TextButton}">
<bpa:Icon Type="Edit2Fill" />
</Button>
<Button
Width="150"
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:MaterialBindingView}}"
CommandParameter="{Binding Id}"
Style="{StaticResource TextErrorButton}">
<bpa:Icon Type="DeleteBinFill" />
</Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</bpa:ControlDisplay>
<bpa:MessageContainer Grid.Row="1" Identifier="MaterialBindingView" />
<!--#endregion-->
</Grid>
</bpa:DialogContainer>
</UserControl>

+ 30
- 0
BPA.SingleDevice/View/MaterialBindingView.xaml.cs View File

@@ -0,0 +1,30 @@
using Microsoft.Extensions.DependencyInjection;
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 BPA.SingleDevice.View
{
/// <summary>
/// MaterialBindingView.xaml 的交互逻辑
/// </summary>
public partial class MaterialBindingView : UserControl
{
public MaterialBindingView()
{
InitializeComponent();
this.DataContext = App.Current.Services.GetService<MaterialBindingViewModel>();
}
}
}

+ 124
- 0
BPA.SingleDevice/View/MaterialManagementView.xaml View File

@@ -0,0 +1,124 @@
<UserControl
x:Class="BPA.SingleDevice.View.MaterialManagementView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bpa="http://BPAUIControl.io/winfx/xaml/toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPA.SingleDevice.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">

<!--<UserControl.DataContext>
<vm:RawMaterialManagementViewModel />
</UserControl.DataContext>-->

<bpa:DialogContainer>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>

<!--#region 功能按钮-->
<StackPanel
Grid.Row="0"
Margin="5"
HorizontalAlignment="Right"
bpa:PanelHelper.Spacing="15"
Orientation="Horizontal">
<Button
Width="250"
HorizontalAlignment="Right"
Command="{Binding RefreshCommand}"
Content="刷新"
Style="{DynamicResource DarkButton}" />
<Button
Width="300"
HorizontalAlignment="Right"
Command="{Binding AddCommand}"
Content="添加原料"
Style="{DynamicResource DarkButton}" />

<!--<Button
HorizontalAlignment="Right"
Command="{Binding SaveCommand}"
Content="保存修改"
Style="{DynamicResource SuccessButton}" />-->
</StackPanel>

<!--#endregion-->

<!--#region 列表-->
<bpa:ControlDisplay Grid.Row="1">
<DataGrid
Grid.Row="1"
bpa:HeaderHelper.HorizontalAlignment="Center"
AutoGenerateColumns="False"
BorderBrush="Gray"
BorderThickness="1"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
GridLinesVisibility="All"
IsReadOnly="True"
ItemsSource="{Binding MaterialInfos}"
RowHeight="70"
SelectionMode="Single"
Style="{StaticResource DataGridLargeScrollStyle}">
<DataGrid.Columns>
<!--<DataGridTextColumn
Width="100"
Binding="{Binding ID}"
Header="ID" />-->
<DataGridTextColumn
Width="*"
Binding="{Binding Name}"
Header="物料名称" />
<DataGridTextColumn
Width="200"
Binding="{Binding MaterialCode}"
Header="物料编码" />
<!--<DataGridCheckBoxColumn
Width="100"
Binding="{Binding IsActive, UpdateSourceTrigger=PropertyChanged}"
Header="启用" />-->
<DataGridTextColumn
Width="420"
Binding="{Binding LastModified}"
Header="最后修改时间" />
<DataGridTemplateColumn Width="500" Header="操作">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button
Width="300"
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:MaterialManagementView}}"
CommandParameter="{Binding ID}"
Foreground="#2196F3"
Style="{StaticResource TextButton}">
<bpa:Icon Type="Edit2Fill" />
</Button>
<Button
Width="150"
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:MaterialManagementView}}"
CommandParameter="{Binding ID}"
Style="{StaticResource TextErrorButton}">
<bpa:Icon Type="DeleteBinFill" />
</Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</bpa:ControlDisplay>
<bpa:MessageContainer Grid.Row="1" Identifier="MaterialManagementView" />
<!--#endregion-->
</Grid>
</bpa:DialogContainer>
</UserControl>

+ 30
- 0
BPA.SingleDevice/View/MaterialManagementView.xaml.cs View File

@@ -0,0 +1,30 @@
using Microsoft.Extensions.DependencyInjection;
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 BPA.SingleDevice.View
{
/// <summary>
/// MaterialManagementView.xaml 的交互逻辑
/// </summary>
public partial class MaterialManagementView : UserControl
{
public MaterialManagementView()
{
InitializeComponent();
this.DataContext = App.Current.Services.GetService<MaterialManagementViewModel>();
}
}
}

+ 1
- 1
BPA.SingleDevice/View/NewRecipeView.xaml View File

@@ -37,7 +37,7 @@
Width="950"
Height="700"
bpa:ScrollViewerHelper.ScrollBarSize="40">
<ListView ItemsSource="{Binding NewRecipeModels}">
<ListView ItemsSource="{Binding NewRecipeModels}" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2" />


+ 64
- 60
BPA.SingleDevice/View/OrderMainView.xaml View File

@@ -14,65 +14,69 @@
<!--<UserControl.DataContext>
<vm:OrderMainViewModel />
</UserControl.DataContext>-->
<Grid Margin="10">
<ListView
Style="{StaticResource LargeScrollListView}"
VerticalAlignment="Top"
bpa:ItemsControlHelper.ItemPadding="8 5 8 8"
ItemsSource="{Binding Goods}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<!--<UniformGrid Columns="5" />-->
<WrapPanel Width="1750"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<bpa:ControlDisplay Margin="5">
<Grid Width="390">
<Grid.RowDefinitions>
<RowDefinition Height="120" />
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<!-- 图片 -->
<!--<Border Width="120" Background="Gray" />-->
<bpa:Icon Width="120" Type="RestaurantFill" />
<TextBlock
Grid.Row="1"
HorizontalAlignment="Center"
FontSize="40"
Foreground="#ddd"
Text="{Binding Name}" />
<Border
Grid.Row="1"
BorderBrush="#505050"
BorderThickness="0,0,0,1" />
<Grid
Grid.Row="2"
Margin="0,5,0,0"
bpa:GridHelper.ColumnDefinitions="*,*">
<bpa:NumericBox
Width="200"
bpa:ControlHelper.FocusBorderBrush="{DynamicResource Secondary}"
BorderThickness="0"
FontSize="40"
Style="{StaticResource FrontBackNumericBox}"
Value="{Binding Count}" />
<Button
Grid.Column="1"
Margin="10,0,0,0"
Command="{Binding DataContext.DownRecipeCommand, RelativeSource={RelativeSource AncestorType=local:OrderMainView}}"
CommandParameter="{Binding Id}"
Content="开始下单"
Foreground="#ddd"
Style="{DynamicResource SecondaryButton}" />
<bpa:DialogContainer>
<Grid Margin="10">
<ListView
VerticalAlignment="Top"
bpa:ItemsControlHelper.ItemPadding="8 5 8 8"
ItemsSource="{Binding Goods}"
Style="{StaticResource LargeScrollListView}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<!--<UniformGrid Columns="5" />-->
<WrapPanel Width="1750" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<bpa:ControlDisplay Margin="5">
<Grid Width="390">
<Grid.RowDefinitions>
<RowDefinition Height="120" />
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<!-- 图片 -->
<!--<Border Width="120" Background="Gray" />-->
<bpa:Icon Width="120" Type="RestaurantFill" />
<TextBlock
Grid.Row="1"
HorizontalAlignment="Center"
FontSize="40"
Foreground="#ddd"
Text="{Binding Name}" />
<Border
Grid.Row="1"
BorderBrush="#505050"
BorderThickness="0,0,0,1" />
<Grid
Grid.Row="2"
Margin="0,5,0,0"
bpa:GridHelper.ColumnDefinitions="*,*">
<bpa:NumericBox
Width="200"
bpa:ControlHelper.FocusBorderBrush="{DynamicResource Secondary}"
BorderThickness="0"
FontSize="40"
Style="{StaticResource FrontBackNumericBox}"
Value="{Binding Count}" />
<Button
Grid.Column="1"
Margin="10,0,0,0"
Command="{Binding DataContext.DownRecipeCommand, RelativeSource={RelativeSource AncestorType=local:OrderMainView}}"
CommandParameter="{Binding Id}"
Content="开始下单"
Foreground="#ddd"
Style="{DynamicResource SecondaryButton}" />
</Grid>
</Grid>
</Grid>
</bpa:ControlDisplay>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</bpa:ControlDisplay>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<bpa:MessageContainer Grid.Row="1" Identifier="OrderMainView" />
</Grid>
</bpa:DialogContainer>


</UserControl>

+ 5
- 4
BPA.SingleDevice/View/RawMaterialManagementView.xaml View File

@@ -52,10 +52,10 @@
<!--#endregion-->

<!--#region 列表-->
<bpa:ControlDisplay Grid.Row="1" >
<bpa:ControlDisplay Grid.Row="1">
<DataGrid
bpa:HeaderHelper.HorizontalAlignment="Center"
Grid.Row="1"
bpa:HeaderHelper.HorizontalAlignment="Center"
AutoGenerateColumns="False"
BorderBrush="Gray"
BorderThickness="1"
@@ -68,8 +68,9 @@
IsReadOnly="True"
ItemsSource="{Binding RawMaterInfos}"
RowHeight="70"
SelectionMode="Single" Style="{StaticResource DataGridLargeScrollStyle}">
SelectionMode="Single"
Style="{StaticResource DataGridLargeScrollStyle}">

<!--<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Border>


+ 2
- 4
BPA.SingleDevice/View/RecipeCompletView.xaml View File

@@ -27,7 +27,6 @@
<StackPanel Orientation="Horizontal" Visibility="{Binding ElementName=IsShowHistory, Path=IsChecked, Converter={StaticResource BooleanToVisibleConverter}}">
<TextBlock Margin="5,0" Text="开始日期:" />
<DatePicker
bpa:ControlHelper.FocusBorderBrush="{DynamicResource Accent}"
bpa:ControlHelper.MouseOverBrush="{DynamicResource Accent}"
bpa:InputBoxHelper.IsClearable="False"
@@ -36,7 +35,6 @@
SelectedDateFormat="Short" />
<TextBlock Margin="5,0" Text="结束日期:" />
<DatePicker
bpa:ControlHelper.FocusBorderBrush="{DynamicResource Accent}"
bpa:ControlHelper.MouseOverBrush="{DynamicResource Accent}"
bpa:InputBoxHelper.IsClearable="False"
@@ -63,7 +61,6 @@
<!--#region 列表-->
<bpa:ControlDisplay Grid.Row="1">
<DataGrid
Style="{StaticResource DataGridLargeScrollStyle}"
Grid.Row="1"
AutoGenerateColumns="False"
BorderBrush="Gray"
@@ -78,7 +75,8 @@
IsReadOnly="True"
ItemsSource="{Binding Logs}"
RowHeight="50"
SelectionMode="Single">
SelectionMode="Single"
Style="{StaticResource DataGridLargeScrollStyle}">
<DataGrid.Columns>
<DataGridTextColumn
Width="150"


+ 171
- 0
BPA.SingleDevice/View/SetBindMaterialView.xaml View File

@@ -0,0 +1,171 @@
<UserControl
x:Class="BPA.SingleDevice.View.SetBindMaterialView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bpa="http://BPAUIControl.io/winfx/xaml/toolkit"
xmlns:conv="clr-namespace:BPA.SingleDevice.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPA.SingleDevice.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
d:DesignHeight="300"
d:DesignWidth="800"
mc:Ignorable="d">

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

<UserControl.Resources>
<conv:MateialCodeConverter x:Key="MateialCodeConverter" />
</UserControl.Resources>

<Grid Margin="10" bpa:PanelHelper.Spacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="320" />
<ColumnDefinition />
<ColumnDefinition Width="320" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="物料编码:" />
<TextBox
Grid.Row="0"
Grid.Column="1"
Height="70"
FontSize="40"
IsReadOnly="True"
Style="{StaticResource DarkTextBox}"
Text="{Binding ElementName=MaterialSelectList, Path=SelectedItem.MaterialCode}" />

<TextBlock
Grid.Row="0"
Grid.Column="2"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="对应物料名称:" />
<TextBox
Grid.Row="0"
Grid.Column="3"
Height="70"
FontSize="40"
IsReadOnly="True"
Style="{StaticResource DarkTextBox}"
Text="{Binding ElementName=MaterialSelectList, Path=SelectedItem.Name}" />

<TextBlock
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="设备对应工位:" />
<ComboBox
Grid.Row="1"
Grid.Column="1"
Height="70"
FontSize="40"
ItemsSource="{Binding DeviceNums}"
SelectedIndex="0"
Text="{Binding RawMaterResultInfo.DeviceNum}" />

<TextBlock
Grid.Row="1"
Grid.Column="2"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="设备通道编号:" />
<ComboBox
Grid.Row="1"
Grid.Column="3"
Height="70"
FontSize="40"
ItemsSource="{Binding ChNum}"
SelectedIndex="0"
Style="{StaticResource LargeScrollComboBoxStyle}"
Text="{Binding RawMaterResultInfo.WarehouseNum}" />

<bpa:ControlDisplay
Grid.Row="2"
Grid.RowSpan="4"
Grid.Column="0"
Grid.ColumnSpan="4">
<!--<ScrollViewer bpa:ScrollViewerHelper.ScrollBarSize="40">-->
<ListView
x:Name="MaterialSelectList"
Margin="10"
ItemsSource="{Binding MaterialInfos}"
SelectedItem="{Binding SelectedItem}"
SelectionMode="Single"
bpa:ItemsControlHelper.ItemMargin="5"
Style="{StaticResource LargeScrollListView}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<!--<RadioButton FontSize="32" GroupName="MaterialGroup">
<RadioButton.Content>-->
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" MinWidth="190" />
</Grid.ColumnDefinitions>
<TextBlock FontSize="32" Text="{Binding Name}" />
<TextBlock
Grid.Column="1"
Margin="10,0,0,0"
FontSize="32"
Text="{Binding MaterialCode, StringFormat=({0})}" />
</Grid>
<!--</RadioButton.Content>
</RadioButton>-->
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!--</ScrollViewer>-->
</bpa:ControlDisplay>


<Grid
Grid.Row="6"
Grid.ColumnSpan="4"
Height="70"
Margin="0,5"
bpa:PanelHelper.Spacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button
Grid.Column="0"
Command="{Binding SaveCommand}"
Content="确认"
FontSize="40" />
<Button
Grid.Column="1"
Command="{Binding CancelCommand}"
Content="取消"
FontSize="40" />
</Grid>
</Grid>
</UserControl>

+ 28
- 0
BPA.SingleDevice/View/SetBindMaterialView.xaml.cs View File

@@ -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 BPA.SingleDevice.View
{
/// <summary>
/// SetBindMaterialView.xaml 的交互逻辑
/// </summary>
public partial class SetBindMaterialView : UserControl
{
public SetBindMaterialView()
{
InitializeComponent();
}
}
}

+ 126
- 0
BPA.SingleDevice/View/SetBindingMaterialView.xaml View File

@@ -0,0 +1,126 @@
<UserControl
x:Class="BPA.SingleDevice.View.SetBindingMaterialView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bpa="http://BPAUIControl.io/winfx/xaml/toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPA.SingleDevice.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
xmlns:conv="clr-namespace:BPA.SingleDevice.Converters"
d:DesignHeight="300"
d:DesignWidth="500"
mc:Ignorable="d">

<UserControl.DataContext>
<vm:SetBindingMaterialViewModel />
</UserControl.DataContext>
<UserControl.Resources>
<conv:MateialCodeConverter x:Key="MateialCodeConverter"/>
</UserControl.Resources>
<Grid Margin="10" bpa:PanelHelper.Spacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="320" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="物料编码:" />
<TextBox
Grid.Row="0"
Grid.Column="1"
Width="350"
Height="70"
FontSize="40"
Style="{StaticResource DarkTextBox}"
Text="{Binding RawMaterResultInfo.MaterialCode}" />

<TextBlock
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="对应物料名称:" />
<TextBox
Grid.Row="1"
Grid.Column="1"
Width="350"
Height="70"
FontSize="40"
IsEnabled="False"
IsReadOnly="True"
Style="{StaticResource DarkTextBox}"
Text="{Binding RawMaterResultInfo.MaterialCode, Converter={StaticResource MateialCodeConverter}}" />

<TextBlock
Grid.Row="2"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="设备对应工位:" />
<ComboBox
Grid.Row="2"
Grid.Column="1"
Height="70"
FontSize="40"
ItemsSource="{Binding DeviceNums}"
SelectedIndex="0"
Text="{Binding RawMaterResultInfo.DeviceNum}" />

<TextBlock
Grid.Row="3"
Grid.Column="0"
HorizontalAlignment="Right"
FontSize="40"
Foreground="#ddd"
Text="设备通道编号:" />
<ComboBox
Grid.Row="3"
Grid.Column="1"
Height="70"
FontSize="40"
ItemsSource="{Binding ChNum}"
SelectedIndex="0"
Style="{StaticResource LargeScrollComboBoxStyle}"
Text="{Binding RawMaterResultInfo.WarehouseNum}" />

<Grid
Grid.Row="4"
Grid.ColumnSpan="2"
Height="70"
Margin="0,5"
bpa:PanelHelper.Spacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button
Grid.Column="0"
Command="{Binding SaveCommand}"
Content="确认"
FontSize="40" />
<Button
Grid.Column="1"
Command="{Binding CancelCommand}"
Content="取消"
FontSize="40" />
</Grid>
</Grid>
</UserControl>

+ 28
- 0
BPA.SingleDevice/View/SetBindingMaterialView.xaml.cs View File

@@ -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 BPA.SingleDevice.View
{
/// <summary>
/// SetBindingMaterialView.xaml 的交互逻辑
/// </summary>
public partial class SetBindingMaterialView : UserControl
{
public SetBindingMaterialView()
{
InitializeComponent();
}
}
}

+ 40
- 0
BPA.SingleDevice/ViewModel/AddMaterialViewModel.cs View File

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

namespace BPA.SingleDevice.ViewModel
{
public class AddMaterialViewModel : NotifyBase, IDialogDataContext
{

public AddMaterialViewModel()
{

SaveCommand = new BPARelayCommand(() =>
{
RequestClose?.Invoke(MaterialInfo);
});
CancelCommand = new BPARelayCommand(() => { RequestClose?.Invoke(null); });
}

public string Title => "添加物料";

public event Action<object> RequestClose;

public void OnDialogOpened(object parameters)
{
if (parameters is MaterialTB material)
{
MaterialInfo = material;
}
}

public MaterialTB MaterialInfo { get => materialInfo; set { materialInfo = value; OnPropertyChanged(); } }
private MaterialTB materialInfo = new();
public BPARelayCommand SaveCommand { get; set; }
public BPARelayCommand CancelCommand { get; set; }
}
}

+ 4
- 1
BPA.SingleDevice/ViewModel/MainViewModel.cs View File

@@ -11,7 +11,10 @@ namespace BPA.SingleDevice.ViewModel
{
new ViewItem("点单主页", new OrderMainView(), IconType.Home3Fill),
new ViewItem("配方管理", new RecipeManagementView(), IconType.NewspaperFill),
new ViewItem("原料管理", new RawMaterialManagementView(), IconType.ReservedFill),
//new ViewItem("原料管理", new RawMaterialManagementView(), IconType.ReservedFill),
new ViewItem("设备物料绑定", new MaterialBindingView(), IconType.ReservedFill),

new ViewItem("物料管理", new MaterialManagementView(), IconType.BookLine),
new ViewItem("运行日志",new RunLogView(),IconType.FileTextLine),
new ViewItem("操作日志",new UserLogView(),IconType.AccountPinCircleLine),
//new ViewItem("报警日志",new AlarmLogView(),IconType.AlarmWarningLine),


+ 297
- 0
BPA.SingleDevice/ViewModel/MaterialBindingViewModel.cs View File

@@ -0,0 +1,297 @@
using BPA.Model;
using BPA.SingleDevice.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SingleDevice.ViewModel
{
public class MaterialBindingViewModel:NotifyBase
{
private readonly ILogService logService;

public MaterialBindingViewModel(ILogService logService)
{
this.logService = logService;

GetMaterialBindInfos();

#region 修改物料绑定对话框之前的。
//AddCommand = new(async () =>
// {
// var content = new SetBindingMaterialView();
// var para = await Dialog.Show(content, new Parameters(), "绑定物料", (d) => { }, async (d, o) =>
// {
// if (o is MaterialBindTB rm)
// {
// if (!IsEmploy(rm.DeviceNum, rm.WarehouseNum))
// {
// string id = Guid.NewGuid().ToString();
// string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// var materialName = await GetMaterialNameAsync(rm.MaterialCode);
// if (materialName is not null)
// {
// var materialbd = new MaterialBindTB()
// {
// Id = id,
// MaterialName = materialName,
// MaterialCode = rm.MaterialCode,
// DeviceNum = rm.DeviceNum,
// WarehouseNum = rm.WarehouseNum,
// LastModified = time
// };
// SqlHelper.GetInstance.AddAsync(materialbd).Result.OnSuccess(() =>
// {
// GetMaterialBindInfos();
// Message.Success("MaterialBindingView", $"绑定物料【{materialName}】成功。");
// logService.LogUserInfo($"成功绑定物料【{materialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】。");
// }).OnFail(s =>
// {
// logService.LogDebugInfo($"绑定物料【{materialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】失败,信息【{s}】");
// Message.Error("MaterialBindingView", $"绑定物料【{materialName}】失败。");
// });
// }
// else
// {
// Message.Error("MaterialBindingView", $"绑定物料失败,未找到【{rm.MaterialCode}】对应的物料。");
// }
// }
// else
// {
// Message.Error("MaterialBindingView", $"绑定物料失败,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】已经被占用。");
// }
// }
// });
// });



//EditCommand = new(async (o) =>
//{
// if (o != null && !string.IsNullOrEmpty(o.ToString()))
// {
// var index = MaterialBindInfos.ToList().FindIndex(p => p.Id == o.ToString());
// if (index >= 0)
// {
// var para = await Dialog.Show(new SetBindingMaterialView(), new MaterialBindTB()
// {
// MaterialName = MaterialBindInfos[index].MaterialName,
// MaterialCode = MaterialBindInfos[index].MaterialCode,
// DeviceNum = MaterialBindInfos[index].DeviceNum,
// WarehouseNum = MaterialBindInfos[index].WarehouseNum,
// Id = MaterialBindInfos[index].Id,
// }, "物料绑定编辑", (d) => { }, async (d, o) =>
// {
// if (o is MaterialBindTB rm)
// {
// var list = MaterialBindInfos.Where(m => m.DeviceNum == rm.DeviceNum && m.WarehouseNum == rm.WarehouseNum);
// foreach (var item in list)
// {
// if (item.Id != rm.Id)
// {
// Message.Error("MaterialBindingView", $"修改绑定物料【{rm.MaterialName}】失败,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】已被占用。");
// return;
// }
// }
// string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// var mbtb = new MaterialBindTB()
// {
// Id = MaterialBindInfos[index].Id,
// MaterialName = await GetMaterialNameAsync(rm.MaterialCode),
// MaterialCode = rm.MaterialCode,
// DeviceNum = rm.DeviceNum,
// WarehouseNum = rm.WarehouseNum,
// LastModified = time
// };
// SqlHelper.GetInstance.UpdateAsync(mbtb).Result.OnSuccess(() =>
// {
// GetMaterialBindInfos();
// Message.Success("MaterialBindingView", $"修改绑定物料【{rm.MaterialName}】成功。");
// logService.LogUserInfo($"成功修改绑定物料【{rm.MaterialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】。");
// }).OnFail(s => {
// logService.LogDebugInfo($"修改绑定物料【{rm.MaterialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】失败,信息:【{s}】。");
// Message.Error("MaterialBindingView", $"修改绑定物料【{rm.MaterialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】失败。");
// });
// }
// });
// }
// }
//});
#endregion

#region 修改物料绑定对话框之后的。
AddCommand = new(async () =>
{
var content = new SetBindMaterialView();
var para = await Dialog.Show(content, new Parameters(),
"绑定物料", (d) => { },
(d, o) =>
{
if (o is MaterialBindTB rm)
{
if (!IsEmploy(rm.DeviceNum, rm.WarehouseNum))
{
string id = Guid.NewGuid().ToString();
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

var materialName = rm.MaterialName;
var materialbd = new MaterialBindTB()
{
Id = id,
MaterialName = materialName,
MaterialCode = rm.MaterialCode,
DeviceNum = rm.DeviceNum,
WarehouseNum = rm.WarehouseNum,
LastModified = time
};
SqlHelper.GetInstance.AddAsync(materialbd).Result.OnSuccess(() =>
{
GetMaterialBindInfos();
Message.Success("MaterialBindingView", $"绑定物料【{materialName}】成功。");
logService.LogUserInfo($"成功绑定物料【{materialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】。");
}).OnFail(s =>
{
logService.LogDebugInfo($"绑定物料【{materialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】失败,信息【{s}】");
Message.Error("MaterialBindingView", $"绑定物料【{materialName}】失败。");
});
}
else
{
Message.Error("MaterialBindingView", $"绑定物料失败,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】已经被占用。");
}
}
});
});

EditCommand = new(async (o) =>
{
if (o != null && !string.IsNullOrEmpty(o.ToString()))
{
var index = MaterialBindInfos.ToList().FindIndex(p => p.Id == o.ToString());
if (index >= 0)
{
var para = await Dialog.Show(new SetBindMaterialView(), new MaterialBindTB()
{
MaterialName = MaterialBindInfos[index].MaterialName,
MaterialCode = MaterialBindInfos[index].MaterialCode,
DeviceNum = MaterialBindInfos[index].DeviceNum,
WarehouseNum = MaterialBindInfos[index].WarehouseNum,
Id = MaterialBindInfos[index].Id,
}, "物料绑定编辑", (d) => { }, (d, o) =>
{
if (o is MaterialBindTB rm)
{
var list = MaterialBindInfos.Where(m => m.DeviceNum == rm.DeviceNum && m.WarehouseNum == rm.WarehouseNum);
foreach (var item in list)
{
if (item.Id != rm.Id)
{
Message.Error("MaterialBindingView", $"修改绑定物料【{rm.MaterialName}】失败,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】已被占用。");
return;
}
}
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var mbtb = new MaterialBindTB()
{
Id = MaterialBindInfos[index].Id,
MaterialName =rm.MaterialName,
MaterialCode = rm.MaterialCode,
DeviceNum = rm.DeviceNum,
WarehouseNum = rm.WarehouseNum,
LastModified = time
};
SqlHelper.GetInstance.UpdateAsync(mbtb).Result.OnSuccess(() =>
{
GetMaterialBindInfos();
Message.Success("MaterialBindingView", $"修改绑定物料【{rm.MaterialName}】成功。");
logService.LogUserInfo($"成功修改绑定物料【{rm.MaterialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】。");
}).OnFail(s => {
logService.LogDebugInfo($"修改绑定物料【{rm.MaterialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】失败,信息:【{s}】。");
Message.Error("MaterialBindingView", $"修改绑定物料【{rm.MaterialName}】,设备号【{rm.DeviceNum}】,通道号【{rm.WarehouseNum}】失败。");
});
}
});
}
}
});
#endregion




RemoveCommand = new(async (o) =>
{
if (o != null && !string.IsNullOrEmpty(o.ToString()))
{
var index = MaterialBindInfos.ToList().FindIndex(p => p.Id == o.ToString());
if (index >= 0)
{
var result = await MessageBoxR.Confirm("是否删除该数据?");
if (result == System.Windows.MessageBoxResult.Yes)
{
SqlHelper.GetInstance.DeleteAsync<MaterialBindTB>(o.ToString()).OnSuccess(() =>
{
var code = MaterialBindInfos[index].MaterialCode;
GetMaterialBindInfos();
Message.Success("MaterialBindingView", $"删除物料【{code}】成功。");
logService.LogUserInfo($"成功移除物料【{code}】。");
}).OnFail(s => {
logService.LogDebugInfo($"删除物料失败,信息:【{s}】");
Message.Error("MaterialBindingView", $"删除物料失败。"); });
}
}
}
});

RefreshCommand = new(() => GetMaterialBindInfos());
}

private async Task<string> GetMaterialNameAsync(string code)
{
if (string.IsNullOrEmpty(code))
{
throw new ArgumentNullException(code, "MaterialCode为null");
}
var result = await SqlHelper.GetInstance.GetListAsync<MaterialTB>();
if (result.IsSuccess)
{
var b= result.Content.FirstOrDefault(m => m.MaterialCode == code);
if (b is not null)
{
return b.Name;
}
}
return null;
}

private async void GetMaterialBindInfos()
{
var result= await SqlHelper.GetInstance.GetListAsync<MaterialBindTB>();
result.OnSuccess((s) =>
{
MaterialBindInfos.Clear();
var list = s.OrderBy(m => m.DeviceNum).ThenBy(m => m.WarehouseNum);
foreach (var item in list)
{
MaterialBindInfos.Add(item);
}
});
}

private bool IsEmploy(int deviceNum,int chNum)
{
return MaterialBindInfos.Any(m => m.DeviceNum == deviceNum && m.WarehouseNum == chNum);
}

public ObservableCollection<MaterialBindTB> MaterialBindInfos { get; set; } = new();

public BPARelayCommand AddCommand { get; set; }
public BPARelayCommand<object> EditCommand { get; set; }
public BPARelayCommand<object> RemoveCommand { get; set; }

public BPARelayCommand RefreshCommand { get; set; }
}
}

+ 226
- 0
BPA.SingleDevice/ViewModel/MaterialManagementViewModel.cs View File

@@ -0,0 +1,226 @@
using BPA.Model;
using BPA.Model.Table;
using BPA.SingleDevice.Services;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Media3D;

namespace BPA.SingleDevice.ViewModel
{
public class MaterialManagementViewModel : NotifyBase
{
private readonly ILogService logService;

public MaterialManagementViewModel(ILogService logService)
{
this.logService = logService;
MaterialInfos = new();

GetAllMaterialAsync();
AddCommand = new BPARelayCommand(async () =>
{
var content = new AddMaterialDialogView();
var para = await Dialog.Show(content, new Parameters(), "添加物料", (d) => { }, async (d, o) =>
{
if (o is MaterialTB rm)
{
//string id = Guid.NewGuid().ToString();
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var material = new MaterialTB()
{
Name = rm.Name,
MaterialCode = rm.MaterialCode,
IsActive = true,

CreateTime = time,
LastModified = time,
Description = rm.Description
};
bool isExist = true;
var queryResult = await SqlHelper.GetInstance.GetListAsync<MaterialTB>();
if (queryResult.IsSuccess)
{
isExist= queryResult.Content.Where(m => m.MaterialCode == material.MaterialCode || m.Name == material.Name).Any();
}
if (isExist)
{
Message.Error("MaterialManagementView", $"添加物料【{rm.Name}】失败,已有物料编码或名称相同的物料。");

}
else
{
var result = await SqlHelper.GetInstance.AddAsync(material);
result.OnSuccess(() =>
{
//MaterialInfos.Add(material);
Message.Success("MaterialManagementView", $"添加物料【{rm.Name}】成功。");
logService.LogUserInfo($"成功添加物料【{rm.Name}】,物料编码【{rm.MaterialCode}】。");
GetAllMaterialAsync();
}).OnFail(s => {
Message.Error("MaterialManagementView", $"添加物料【{rm.Name}】,物料编码【{rm.MaterialCode}】失败。");
logService.LogDebugInfo($"添加物料【{rm.Name}】失败,信息:{s}"); });
}
}
});
});

EditCommand = new(async (o) =>
{
if (o is int id)
{
var index = MaterialInfos.ToList().FindIndex(p => p.ID == id);
if (index >= 0)
{
var material = MaterialInfos[index];
if (await GetIsOccupyAsunc(material.MaterialCode))
{
Message.Error("MaterialManagementView", $"修改物料【{material.Name}】,物料编码【{material.MaterialCode}】失败,该物料已被绑定到设备,请解绑后重试。");
return;
}
var para = await Dialog.Show(new AddMaterialDialogView(), new MaterialTB()
{
ID = MaterialInfos[index].ID,
Name = MaterialInfos[index].Name,
MaterialCode = MaterialInfos[index].MaterialCode,
Description = MaterialInfos[index].Description,
}, "物料编辑", (d) => { }, async (d, o) =>
{
if (o is MaterialTB rm)
{
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

var material = new MaterialTB()
{
ID= MaterialInfos[index].ID,
Name=rm.Name,
MaterialCode=rm.MaterialCode,
IsActive= MaterialInfos[index].IsActive,
//CreateTime = MaterialInfos[index].CreateTime,
LastModified =time,
Description = rm.Description,
};

bool isExist = false;
var queryResult = await SqlHelper.GetInstance.GetListAsync<MaterialTB>();
if (queryResult.IsSuccess)
{
var existList = queryResult.Content.Where(m => m.MaterialCode == material.MaterialCode);
foreach (var item in existList)
{
if (item.ID!=material.ID)
{
isExist = true;
break;
}
}
}
if (isExist)
{
Message.Error("MaterialManagementView", $"修改物料【{rm.Name}】失败,已有物料编码或名称相同的物料。");

}
else
{
SqlHelper.GetInstance.UpdateAsync(material).Result.OnSuccess(() =>
{
Message.Success("MaterialManagementView", $"修改物料【{rm.Name}】,物料编码【{rm.MaterialCode}】成功。");
logService.LogUserInfo($"成功修改物料【{rm.Name}】,物料编码【{rm.MaterialCode}】。");
GetAllMaterialAsync();
}).OnFail(s => {
Message.Error("MaterialManagementView", $"修改物料【{rm.Name}】,物料编码【{rm.MaterialCode}】失败。");
logService.LogDebugInfo( $"修改物料【{rm.Name}】,物料编码【{rm.MaterialCode}】失败:{s}"); });
}
}
});
}
}
});

RemoveCommand = new(async (o) =>
{
if (o is int id)
{
var index = MaterialInfos.ToList().FindIndex(p => p.ID == id);
if (index >= 0)
{
var material = MaterialInfos[index];
if (await GetIsOccupyAsunc(material.MaterialCode))
{
Message.Error("MaterialManagementView", $"删除物料【{material.Name}】,物料编码【{material.MaterialCode}】失败,该物料已被绑定到设备,请解绑后重试。");
return;
}
var result = await MessageBoxR.Confirm("是否删除该数据?");
if (result == System.Windows.MessageBoxResult.Yes)
{
SqlHelper.GetInstance.DeleteMaterialByIDAsync<MaterialTB>(id).OnSuccess((result) =>
{
//MaterialInfos.RemoveAt(index);
Message.Success("MaterialManagementView", $"删除物料【{material.Name}】,物料编码【{material.MaterialCode}】成功。");
logService.LogUserInfo($"删除物料【{material.Name}】,物料编码【{material.MaterialCode}】成功。");
GetAllMaterialAsync();
}).OnFail(s => { Message.Error("MaterialManagementView", $"删除物料【{material.Name}】,物料编码【{material.MaterialCode}】失败。");
logService.LogDebugInfo($"删除物料【{material.Name}】,物料编码【{material.MaterialCode}】失败,信息【{s}】。");
});
}
}
}
});

RefreshCommand = new(() => GetAllMaterialAsync());
}

public ObservableCollection<MaterialTB> MaterialInfos { get; set; }

public BPARelayCommand AddCommand { get; set; }

public BPARelayCommand RefreshCommand { get; set; }
public BPARelayCommand<object> EditCommand { get; set; }
public BPARelayCommand<object> RemoveCommand { get; set; }

private async void GetAllMaterialAsync(CancellationToken? cancellationToken=null)
{
var token = cancellationToken ?? CancellationToken.None;
try
{
var result = await SqlHelper.GetInstance.GetListAsync<MaterialTB>();
if (result.IsSuccess)
{
MaterialInfos.Clear();
var list = result.Content.OrderBy(m => m.MaterialCode);
foreach (var item in list)
{
MaterialInfos.Add(item);
}
}
}
catch (Exception e)
{
logService.LogDebugInfo(e.ToString());
}
}
/// <summary>
/// 查找该物料编码是否已经被绑定到设备了。
/// </summary>
/// <param name="materialCode"></param>
/// <returns></returns>
private async Task<bool> GetIsOccupyAsunc(string materialCode)
{
if (String.IsNullOrEmpty(materialCode))
{
return true;
}
var getAllBindedMaterial = await SqlHelper.GetInstance.GetListAsync<MaterialBindTB>();
if (getAllBindedMaterial.IsSuccess)
{
return getAllBindedMaterial.Content.Any(m => m.MaterialCode == materialCode);
}
return true;
}
}
}

+ 29
- 20
BPA.SingleDevice/ViewModel/NewRecipeViewModel.cs View File

@@ -6,29 +6,23 @@ namespace BPA.SingleDevice.ViewModel
{
public NewRecipeViewModel()
{
//Task.Run(() =>
//SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.OnSuccess(s =>
//{
// SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.OnSuccess(s =>
// var result = s.OrderBy(r => r.DeviceNum).ThenBy(r => r.WarehouseNum);
// foreach (var item in result)
// {
// App.Current.Dispatcher.Invoke(() =>
// {
// s.ForEach(item =>
// {
// NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.Id });

// });
// });
// });
// NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.Id });
// }
//});

SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.OnSuccess(s =>
{
var result = s.OrderBy(r => r.DeviceNum).ThenBy(r => r.WarehouseNum);
foreach (var item in result)
{
NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.Id });
}
});
//SqlHelper.GetInstance.GetListAsync<MaterialTB>().Result.OnSuccess(s =>
//{
// foreach (var item in s)
// {
// NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.MaterialCode });
// }
//});
//GetAllRecipeModel();

SaveCommand = new BPARelayCommand(() =>
{
@@ -44,13 +38,15 @@ namespace BPA.SingleDevice.ViewModel

public event Action<object> RequestClose;

public void OnDialogOpened(object parameters)
public async void OnDialogOpened(object parameters)
{
await GetAllRecipeModel();
if (parameters is Parameters par)
{
if (par.TryGetValue("Name", out string name) && par.TryGetValue("RawMater", out List<NewRecipeModel> rms))
{
RecipeName = name;
rms.ForEach(item =>
{
var res = NewRecipeModels.FirstOrDefault(p => p.Id == item.Id);
@@ -66,6 +62,19 @@ namespace BPA.SingleDevice.ViewModel

public ObservableCollection<NewRecipeModel> NewRecipeModels { get; set; } = new ObservableCollection<NewRecipeModel>();

private async Task GetAllRecipeModel()
{
var result= await SqlHelper.GetInstance.GetListAsync<MaterialTB>();
if (result.IsSuccess)
{
NewRecipeModels.Clear();
foreach (var item in result.Content)
{
NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.MaterialCode });
}
}
}

public string RecipeName
{ get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
private string _mRecipeName;


+ 158
- 44
BPA.SingleDevice/ViewModel/OrderMainViewModel.cs View File

@@ -1,5 +1,7 @@
using BPA.Model.Recipe;
using BPA.SingleDevice.Services;
using System.Collections.Immutable;
using System.Linq;
using System.Windows;

namespace BPA.SingleDevice.ViewModel
@@ -27,9 +29,10 @@ namespace BPA.SingleDevice.ViewModel
});
});
});

RawMaters = SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.Content;

//RawMaters = SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.Content;
//RawMaters = SqlHelper.GetInstance.GetListAsync<MaterialTB>().Result.Content;

DownRecipeCommand = new BPARelayCommand<object>(o =>
{
@@ -42,27 +45,105 @@ namespace BPA.SingleDevice.ViewModel
{
if (MessageBoxR.ConfirmGlobal("是否下发配方?", "提示") == MessageBoxResult.Yes)
{
GenerateRecipe(o.ToString()!);
//GenerateRecipe(o.ToString()!);
GenerateRecipeAsync(o.ToString()!);
}
}
else
{
Message.ErrorGlobal("下发配方失败,输入的配方ID为Null或空,请联系人员检查后。");
Message.Error("OrderMainView", "下发配方失败,输入的配方ID为Null或空,请联系人员检查后。");
}
}
else
{
Message.ErrorGlobal("下发配方失败,当前有配方在执行工位【1】的配料流程,请检查后重试。");
Message.Error("OrderMainView", "下发配方失败,当前有配方在执行工位【1】的配料流程,请检查后重试。");
}
});
}

private List<RawMaterTB> RawMaters { get; set; } = new List<RawMaterTB>();
//private List<MaterialTB> RawMaters = new List<MaterialTB>();
//private List<RawMaterTB> RawMaters { get; set; } = new List<RawMaterTB>();
/// <summary>
/// 被启用的配方列表。
/// </summary>
public ObservableCollection<RecipeModel> Goods { get; set; } = new ObservableCollection<RecipeModel>();

public BPARelayCommand<object> DownRecipeCommand { get; set; }

private void GenerateRecipe(string recipeID)
//private void GenerateRecipe(string recipeID)
//{
// if (string.IsNullOrEmpty(recipeID))
// {
// logService.LogDebugInfo($"解析配方数据失败,参数<recipeID>是Null或者Empty,在<OrderMainViewModel.GenerateRecipe()>中。");
// }
// else
// {
// //验证指定的配方号是否在配方列表中。
// var res = Goods.FirstOrDefault(p => p.Id == recipeID);
// var recipeName = res?.Name;
// if (res != null)
// {
// //该配方所有物料集合。
// List<RawMaterModel> allMaterial = new List<RawMaterModel>();
// //根据配方号获取所有的物料。
// SqlHelper.GetInstance.GetRawMaterIds(res.Id).Result.OnSuccess(s =>
// {
// s.ForEach(item =>
// {
// var rmtb = RawMaters.FirstOrDefault(p => p.Id == item.RawMaterId);
// if (rmtb != null)
// {
// allMaterial.Add(new RawMaterModel()
// {
// Weight = item.Weight,
// DeviceNum = rmtb.DeviceNum,
// Id = rmtb.Id,
// LastModified = rmtb.LastModified,
// Name = rmtb.Name,
// WarehouseNum = rmtb.WarehouseNum,
// });
// }
// });
// });
// Dictionary<int, ushort[]> materialData = new();
// //根据设备和通道分类。
// var temp = allMaterial.GroupBy(p => p.DeviceNum);
// foreach (var device in temp)
// {
// ushort[] channelWeight = new ushort[14];
// //根据通道排序后的物料设备分组表。
// var orderedMaterial = device.OrderBy(p => p.WarehouseNum);
// for (int i = 0; i < 14; i++)
// {
// var channel = orderedMaterial.FirstOrDefault(p => p.WarehouseNum == (i + 1));
// if (channel is not null)
// {
// channelWeight[i] = (channel.Weight);
// }
// else
// {
// channelWeight[i] = 0;
// }
// }
// materialData.Add(device.Key, channelWeight);
// }
// RecipeData recipeData = new(recipeID, recipeName, materialData);
// var str = recipeData.ToJson();
// for (int i = 0; i < res.Count; i++)
// {
// global.RecipeQueue.Enqueue(str.FromJSON<RecipeData>());
// }
// Message.SuccessGlobal($"下发配方【{recipeName}】,份数【{res.Count}】成功。");
// logService.LogUserInfo($"下发配方【{recipeName}】,份数【{res.Count}】成功。");
// }
// else
// {
// logService.LogRunInfo($"解析配方数据失败,未找到【{recipeID}】对应的配方。");
// }
// }
//}

private async void GenerateRecipeAsync(string recipeID)
{
if (string.IsNullOrEmpty(recipeID))
{
@@ -72,61 +153,94 @@ namespace BPA.SingleDevice.ViewModel
{
//验证指定的配方号是否在配方列表中。
var res = Goods.FirstOrDefault(p => p.Id == recipeID);
var recipeName = res.Name;
var recipeName = res?.Name;
if (res != null)
{
//该配方所有物料集合。
List<RawMaterModel> allMaterial = new List<RawMaterModel>();
//根据配方号获取所有的物料。
SqlHelper.GetInstance.GetRawMaterIds(res.Id).Result.OnSuccess(s =>
var getMaterialList= await SqlHelper.GetInstance.GetRawMaterIds(res.Id);
#region 判断所有需要的物料都已经被绑定在设备通道了
List<string> allNeedMaterialCode = new();
getMaterialList.OnSuccess((s) =>
{
s.ForEach(item =>
allNeedMaterialCode.Clear();
foreach (var item in s)
{
var rmtb = RawMaters.FirstOrDefault(p => p.Id == item.RawMaterId);
if (rmtb != null)
{
allMaterial.Add(new RawMaterModel()
{
Weight = item.Weight,
DeviceNum = rmtb.DeviceNum,
Id = rmtb.Id,
LastModified = rmtb.LastModified,
Name = rmtb.Name,
WarehouseNum = rmtb.WarehouseNum,
});
}
});
allNeedMaterialCode.Add(item.RawMaterId);
}
});
Dictionary<int, ushort[]> materialData = new();
//根据设备和通道分类。
var temp = allMaterial.GroupBy(p => p.DeviceNum);
foreach (var device in temp)
//确保所有的物料都已经绑定在设备列表。
List<string> allbindedMaterialCode = new();
var bindedMaterials = await SqlHelper.GetInstance.GetListAsync<MaterialBindTB>();
bindedMaterials.OnSuccess((s) =>
{
ushort[] channelWeight = new ushort[14];
//根据通道排序后的物料设备分组表。
var orderedMaterial = device.OrderBy(p => p.WarehouseNum);
for (int i = 0; i < 14; i++)
allbindedMaterialCode.Clear();
foreach (var item in s)
{
var channel = orderedMaterial.FirstOrDefault(p => p.WarehouseNum == (i + 1));
if (channel is not null)
allbindedMaterialCode.Add(item.MaterialCode);
}
});

var isAllHave = allNeedMaterialCode.All(allbindedMaterialCode.Contains);
#endregion

if (getMaterialList.IsSuccess&& bindedMaterials.IsSuccess && isAllHave)
{
if (getMaterialList.IsSuccess)
{
foreach (var item in getMaterialList.Content)
{
channelWeight[i] = (channel.Weight);
var rmtb = bindedMaterials.Content.FirstOrDefault(m => m.MaterialCode == item.RawMaterId);
if (rmtb != null)
{
allMaterial.Add(new RawMaterModel()
{
DeviceNum = rmtb.DeviceNum,
WarehouseNum = rmtb.WarehouseNum,
Name = rmtb.MaterialName,
Weight = item.Weight
});
}
}
else
}

Dictionary<int, ushort[]> materialData = new();
//根据设备和通道分类。
var temp = allMaterial.GroupBy(p => p.DeviceNum);
foreach (var device in temp)
{
ushort[] channelWeight = new ushort[14];
//根据通道排序后的物料设备分组表。
var orderedMaterial = device.OrderBy(p => p.WarehouseNum);
for (int i = 0; i < 14; i++)
{
channelWeight[i] = 0;
var channel = orderedMaterial.FirstOrDefault(p => p.WarehouseNum == (i + 1));
if (channel is not null)
{
channelWeight[i] = (channel.Weight);
}
else
{
channelWeight[i] = 0;
}
}
materialData.Add(device.Key, channelWeight);
}
materialData.Add(device.Key, channelWeight);
RecipeData recipeData = new(recipeID, recipeName, materialData);
var str = recipeData.ToJson();
for (int i = 0; i < res.Count; i++)
{
global.RecipeQueue.Enqueue(str.FromJSON<RecipeData>());
}
Message.Success("OrderMainView", $"下发配方【{recipeName}】,份数【{res.Count}】成功。");
logService.LogUserInfo($"下发配方【{recipeName}】,份数【{res.Count}】成功。");
}
RecipeData recipeData = new(recipeID, recipeName, materialData);
var str = recipeData.ToJson();
for (int i = 0; i < res.Count; i++)
else
{
global.RecipeQueue.Enqueue(str.FromJSON<RecipeData>());
Message.Error("OrderMainView", $"下发配方【{recipeName}】失败,获取物料集合失败或非所有物料都绑定到设备中。");
}
Message.SuccessGlobal($"下发配方【{recipeName}】,份数【{res.Count}】成功。");
logService.LogUserInfo($"下发配方【{recipeName}】,份数【{res.Count}】成功。");
}
else
{


+ 30
- 10
BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs View File

@@ -10,6 +10,7 @@ namespace BPA.SingleDevice.ViewModel

public RecipeManagementViewModel(ILogService logService)
{
this.logService = logService;
Task.Run(() =>
{
SqlHelper.GetInstance.GetListAsync<RecipeTB>().Result.OnSuccess(s =>
@@ -55,15 +56,16 @@ namespace BPA.SingleDevice.ViewModel
SqlHelper.GetInstance.AddAsync(rrmtb).Result.OnSuccess(() =>
{
RecipeInfos.Add(new RecipeInfo() { Id = id, IsEnable = true, LastModified = time, Name = name });
Message.Success("RecipeManagementView", $"新增配方【{name}】信息成功。");
logService.LogUserInfo($"新增配方【{name}】的物料信息成功。");
}).OnFail(s =>
{
Message.Error("RecipeManagementView", $"添加失败:{s}");
Message.Error("RecipeManagementView", $"新增配方失败。");
logService.LogDebugInfo($"新增配方【{name}】的物料信息失败,信息:【{s}】。");
});
}).OnFail(s =>
{
Message.Error("RecipeManagementView", $"添加失败:{s}");
Message.Error("RecipeManagementView", $"新增配方失败。");
logService.LogDebugInfo($"新增配方【{name}】失败,信息:【{s}】。");
});
}
@@ -118,10 +120,19 @@ namespace BPA.SingleDevice.ViewModel
RecipeInfos[index].Name = name;
RecipeInfos[index].LastModified = time;
logService.LogUserInfo($"修改配方【{name}】成功。");
Message.Success("RecipeManagementView", $"修改配方成功。");
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新添加失败:{s}"); });
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新时删除失败:{s}"); });
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新失败:{s}"); });
Message.Success("RecipeManagementView", $"修改配方【{name}】成功。");
}).OnFail(s => { Message.Error("RecipeManagementView", $"修改配方【{name}】失败。");
Message.Error("RecipeManagementView", $"修改配方【{name}】失败。");
logService.LogDebugInfo($"修改配方【{name}】失败,信息【{s}】");
});
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新时删除失败:{s}");
Message.Error("RecipeManagementView", $"修改配方【{name}】更新时删除失败。");
logService.LogDebugInfo($"更新配方【{name}】时删除失败,信息【{s}】");
});
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新失败:{s}");
Message.Error("RecipeManagementView", $"更新配方【{name}】失败。");
logService.LogDebugInfo($"更新配方【{name}】失败,信息【{s}】");
});
}
}
});
@@ -136,6 +147,7 @@ namespace BPA.SingleDevice.ViewModel
var index = RecipeInfos.ToList().FindIndex(p => p.Id == o.ToString());
if (index >= 0)
{
var name = RecipeInfos[index].Name;
var result = await MessageBoxR.Confirm("是否删除该数据?");
if (result == System.Windows.MessageBoxResult.Yes)
{
@@ -143,10 +155,18 @@ namespace BPA.SingleDevice.ViewModel
{
SqlHelper.GetInstance.DeleteRawMaterAsync(o.ToString()).OnSuccess(() =>
{
RecipeInfos.RemoveAt(index);
logService.LogUserInfo($"删除配方【{o.ToString()}】成功。");
}).OnFail(s => { Message.Error("RawMaterialManagementView", $"删除失败:{s}"); });
}).OnFail(s => { Message.Error("RawMaterialManagementView", $"删除失败:{s}"); });
Message.Success("RecipeManagementView", $"删除配方【{name}】成功。");
logService.LogUserInfo($"删除配方【{name}】成功。");
}).OnFail(s => { Message.Error("RecipeManagementView", $"删除配方【{name}】的物料失败。");
Message.Error("RecipeManagementView", $"删除配方【{name}】的物料失败。");
logService.LogDebugInfo($"删除配方【{name}】的物料失败,信息【{s}】");
});
}).OnFail(s => { Message.Error("RecipeManagementView", $"删除配方【{name}】失败。");
Message.Error("RecipeManagementView", $"删除配方【{name}】失败。");
logService.LogDebugInfo($"删除配方{name}失败,信息【{s}】");
});
}
}
}
@@ -170,7 +190,7 @@ namespace BPA.SingleDevice.ViewModel
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新失败:{s}"); });
}
});
this.logService = logService;
}

public ObservableCollection<RecipeInfo> RecipeInfos { get; set; } = new ObservableCollection<RecipeInfo>();


+ 88
- 0
BPA.SingleDevice/ViewModel/SetBindMaterialViewModel.cs View File

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

namespace BPA.SingleDevice.ViewModel
{
public class SetBindMaterialViewModel : NotifyBase, IDialogDataContext
{
public SetBindMaterialViewModel()
{
for (int i = 1; i <= 2; i++)
{ DeviceNums.Add(i); }
for (int i = 4; i <= 5; i++)
{ DeviceNums.Add(i); }
for (int i = 1; i <= 14; i++)
{ ChNum.Add(i); }


SaveCommand = new BPARelayCommand(() => {
RawMaterResultInfo.MaterialName = SelectedItem.Name;
RawMaterResultInfo.MaterialCode = SelectedItem.MaterialCode;
RequestClose?.Invoke(RawMaterResultInfo);
});
CancelCommand = new BPARelayCommand(() => { RequestClose?.Invoke(null); });
}

public string Title => "绑定物料";

public event Action<object> RequestClose;

public async void OnDialogOpened(object parameters)
{
await GetAllMaterials();
if (parameters is MaterialBindTB rm)
{
RawMaterResultInfo = rm;
//SelectedItem.Name = rm.MaterialName;
//SelectedItem.MaterialCode = rm.MaterialCode;
if (rm.MaterialCode!=null)
{
var isSelect = MaterialInfos.FirstOrDefault(m => m.MaterialCode == rm.MaterialCode);
if (isSelect != null)
{
SelectedItem = isSelect;
}
}
}
}

public ObservableCollection<int> DeviceNums { get; set; } = new ObservableCollection<int>();
public ObservableCollection<int> ChNum { get; set; } = new ObservableCollection<int>();
public ObservableCollection<MaterialTB> MaterialInfos { get; set; } = new();
public MaterialBindTB RawMaterResultInfo
{ get { return _mRawMaterResultInfo; } set { _mRawMaterResultInfo = value; OnPropertyChanged(); } }
private MaterialBindTB _mRawMaterResultInfo = new MaterialBindTB();

private MaterialTB _SelectedItem=new();

public MaterialTB SelectedItem
{
get { return _SelectedItem; }
set { _SelectedItem = value; OnPropertyChanged(); }
}


public BPARelayCommand SaveCommand { get; set; }
public BPARelayCommand CancelCommand { get; set; }

private async Task GetAllMaterials()
{
var result = await SqlHelper.GetInstance.GetListAsync<MaterialTB>();
if (result.IsSuccess)
{
MaterialInfos.Clear();
var list = result.Content.OrderBy(m => m.MaterialCode);
foreach (var item in list)
{
MaterialInfos.Add(item);
}
}
}
}
}

+ 43
- 0
BPA.SingleDevice/ViewModel/SetBindingMaterialViewModel.cs View File

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

namespace BPA.SingleDevice.ViewModel
{
public class SetBindingMaterialViewModel : NotifyBase, IDialogDataContext
{
public SetBindingMaterialViewModel()
{
for (int i = 1; i <= 2; i++)
{ DeviceNums.Add(i); }
for (int i = 4; i <= 5; i++)
{ DeviceNums.Add(i); }
for (int i = 1; i <= 14; i++)
{ ChNum.Add(i); }
SaveCommand = new BPARelayCommand(() => { RequestClose?.Invoke(RawMaterResultInfo); });
CancelCommand = new BPARelayCommand(() => { RequestClose?.Invoke(null); });
}

public string Title => "绑定物料";

public event Action<object> RequestClose;

public void OnDialogOpened(object parameters)
{
if (parameters is MaterialBindTB rm)
RawMaterResultInfo = rm;
}

public ObservableCollection<int> DeviceNums { get; set; } = new ObservableCollection<int>();
public ObservableCollection<int> ChNum { get; set; } = new ObservableCollection<int>();

public MaterialBindTB RawMaterResultInfo
{ get { return _mRawMaterResultInfo; } set { _mRawMaterResultInfo = value; OnPropertyChanged(); } }
private MaterialBindTB _mRawMaterResultInfo = new MaterialBindTB();

public BPARelayCommand SaveCommand { get; set; }
public BPARelayCommand CancelCommand { get; set; }
}
}

Loading…
Cancel
Save