Browse Source

配方管理新增复制功能

样式分支
Mr_z 1 year ago
parent
commit
f2482e7a15
8 changed files with 228 additions and 10 deletions
  1. +5
    -6
      FryPot_DosingSystem/Control/DosingLogicControl.cs
  2. +6
    -1
      FryPot_DosingSystem/Model/FlowProcessModel.cs
  3. +5
    -2
      FryPot_DosingSystem/Model/MaterialType.cs
  4. +47
    -0
      FryPot_DosingSystem/View/CopyInfoView.xaml
  5. +36
    -0
      FryPot_DosingSystem/View/CopyInfoView.xaml.cs
  6. +3
    -1
      FryPot_DosingSystem/View/RecipeManageView.xaml
  7. +33
    -0
      FryPot_DosingSystem/ViewModel/CopyInfoViewModel.cs
  8. +93
    -0
      FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs

+ 5
- 6
FryPot_DosingSystem/Control/DosingLogicControl.cs View File

@@ -2123,7 +2123,7 @@ namespace FryPot_DosingSystem.Control
// throw;
}
}));
GetFryTwoData("D3302", new Action<ushort[]>(data =>
GetFryTwoData("D3301", new Action<ushort[]>(data =>
{
try
{
@@ -2245,7 +2245,7 @@ namespace FryPot_DosingSystem.Control
// throw;
}
}));
GetFryThreeData("D3303", new Action<ushort[]>(data =>
GetFryThreeData("D3301", new Action<ushort[]>(data =>
{
try
{
@@ -2367,7 +2367,7 @@ namespace FryPot_DosingSystem.Control
//throw;
}
}));
GetFryFourData("D3304", new Action<ushort[]>(data =>
GetFryFourData("D3301", new Action<ushort[]>(data =>
{
try
{
@@ -2489,7 +2489,7 @@ namespace FryPot_DosingSystem.Control
// throw;
}
}));
GetFryFiveData("D3305", new Action<ushort[]>(data =>
GetFryFiveData("D3301", new Action<ushort[]>(data =>
{
try
{
@@ -3854,7 +3854,6 @@ namespace FryPot_DosingSystem.Control
if (RTrig.GetInstance("炒锅5配方完成").Start(Convert.ToBoolean(globalVar.fryPotFive.RecipeCompleteSingle)))
{
ResetPotData(5);

Application.Current.Dispatcher.Invoke(new Action(() => { AgvViewModel.GetInstance().wokModel_5.workflows.Add(new WorkflowModel { id = globalVar.LFiveCurrentCookingStep + 1, Name = "配方制作完成!", isBool = IsBool.Yes }); }));
ActionManage.GetInstance.Send("炒锅工艺流程更新", 5);
MessageNotify.GetInstance.ShowRunLog("炒锅5配方制作完成");
@@ -6433,7 +6432,7 @@ namespace FryPot_DosingSystem.Control
WritePotData(potNum, "D4121", Convert.ToUInt16((result.FlowProcess.fpModels.ElementAt(result.FlowProcess.fpModels.Count - 1).TargeWeight*10)));//清洗目标重量
}
else
else
{
length = result.FlowProcess.fpModels.Count;
}


+ 6
- 1
FryPot_DosingSystem/Model/FlowProcessModel.cs View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;

namespace FryPot_DosingSystem.Model
{
internal class FlowProcessModel:ObservableObject
internal class FlowProcessModel:ObservableObject,ICloneable
{
///// <summary>
///// 工艺步骤对应名称
@@ -72,5 +72,10 @@ namespace FryPot_DosingSystem.Model
/// </summary>
public double StrongFirePercent { get { return _strongFilePercent; } set { _strongFilePercent = value; OnPropertyChanged(); } }
private double _strongFilePercent;

public object Clone()
{
return MemberwiseClone();
}
}
}

+ 5
- 2
FryPot_DosingSystem/Model/MaterialType.cs View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;

namespace FryPot_DosingSystem.Model
{
internal class MaterialType:ObservableObject
internal class MaterialType:ObservableObject,ICloneable
{
/// <summary>
/// 原料名称
@@ -36,6 +36,9 @@ namespace FryPot_DosingSystem.Model
private ushort _materialLoc;
public ushort MaterialLoc { get { return _materialLoc; } set { _materialLoc = value; OnPropertyChanged(); } }

public object Clone()
{
return MemberwiseClone();
}
}
}

+ 47
- 0
FryPot_DosingSystem/View/CopyInfoView.xaml View File

@@ -0,0 +1,47 @@
<Window x:Class="FryPot_DosingSystem.View.CopyInfoView"
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:vm="clr-namespace:FryPot_DosingSystem.ViewModel"
xmlns:local="clr-namespace:FryPot_DosingSystem.View"
mc:Ignorable="d"
Title="CopyInfoView" Height="250" Width="600" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/GenricStyle.xaml" />
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Window.DataContext>
<vm:CopyInfoViewModel/>
</Window.DataContext>
<Border x:Name="br" BorderThickness="1" BorderBrush="Aqua">
<Border.Background>
<SolidColorBrush Color="#FF0B2F5F"/>
</Border.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>

<!--<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
<TextBlock Text="名称:" Foreground="#FF2AB2E7" FontSize="18" VerticalAlignment="Center"/>
<TextBox Text="{Binding MaterialName}" FontSize="18" Width="300" Height="50" />
</StackPanel>-->
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center" >
<TextBlock Text="炒锅编号:" Foreground="#FF2AB2E7" FontSize="18" VerticalAlignment="Center"/>
<TextBox Text="{Binding FryNum}" FontSize="18" Width="300" Height="50"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" >
<Button Content="确定" Background="Transparent" Foreground="#FF2AB2E7" FontSize="18" Margin="40,0,20,0" Width="100" Height="50" Command="{Binding ConfimCommand}"/>
<Button Content="取消" FontSize="18" Margin="40,0,20,0" Width="100" Height="50" Click="Button_Click"/>
</StackPanel>
</Grid>

</Border>
</Window>

+ 36
- 0
FryPot_DosingSystem/View/CopyInfoView.xaml.cs View File

@@ -0,0 +1,36 @@
using BPASmartClient.Helper;
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.Shapes;

namespace FryPot_DosingSystem.View
{
/// <summary>
/// CopyInfoView.xaml 的交互逻辑
/// </summary>
public partial class CopyInfoView : Window
{
public CopyInfoView()
{
InitializeComponent();
this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); };
ActionManage.GetInstance.CancelRegister("CloseCopyInfoView");
ActionManage.GetInstance.Register(new Action(() => { this.Close(); }), "CloseCopyInfoView");
}

private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

+ 3
- 1
FryPot_DosingSystem/View/RecipeManageView.xaml View File

@@ -150,7 +150,9 @@
<TextBlock Text="操作:" Foreground="White" FontSize="18"></TextBlock>
<Button Style="{DynamicResource ButtonStyle1}" Content="编辑" Cursor="Hand" Foreground="Orange" FontSize="18" Background="Transparent" BorderThickness="0" Command="{Binding DataContext.EditRecipeCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}}"
CommandParameter="{Binding RecipeId}"/>
<Button Margin="60,0,0,0" Style="{DynamicResource ButtonStyle1}" Content="炒制工艺" Cursor="Hand" Foreground="Orange" FontSize="18" Background="Transparent" BorderThickness="0" Command="{Binding DataContext.OperateFlowProcess,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}}" CommandParameter="{Binding RecipeName}"/>
<Button Style="{DynamicResource ButtonStyle1}" Margin="15,0,0,0" Content="复制" Cursor="Hand" Foreground="Orange" FontSize="18" Background="Transparent" BorderThickness="0" Command="{Binding DataContext.CopyRecipeCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}}"
CommandParameter="{Binding RecipeId}"/>
<Button Margin="15,0,0,0" Style="{DynamicResource ButtonStyle1}" Content="炒制工艺" Cursor="Hand" Foreground="Orange" FontSize="18" Background="Transparent" BorderThickness="0" Command="{Binding DataContext.OperateFlowProcess,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}}" CommandParameter="{Binding RecipeName}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,5">
<TextBlock Text="创建时间:" FontSize="18" Foreground="White"></TextBlock>


+ 33
- 0
FryPot_DosingSystem/ViewModel/CopyInfoViewModel.cs View File

@@ -0,0 +1,33 @@

using BPASmartClient.Helper;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FryPot_DosingSystem.ViewModel
{
internal class CopyInfoViewModel:ObservableObject
{
private string _fryNum;
public string FryNum { get { return _fryNum; } set { _fryNum = value;OnPropertyChanged(); } }
public RelayCommand ConfimCommand { get; set; }
public CopyInfoViewModel()
{


ConfimCommand = new RelayCommand(() => {
if (FryNum != null && FryNum != "" && int.TryParse(FryNum.Trim(), out int Num))
{
ActionManage.GetInstance.Send("CopyPotNum",Num);
ActionManage.GetInstance.Send("CloseCopyInfoView");
}

});
}
}
}

+ 93
- 0
FryPot_DosingSystem/ViewModel/RecipeSetViewModel.cs View File

@@ -13,6 +13,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Media3D;

namespace FryPot_DosingSystem.ViewModel
{
@@ -28,6 +29,11 @@ namespace FryPot_DosingSystem.ViewModel
///// </summary>
//private string _recipeName;
//public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } }
/// <summary>
/// 复制配方的Id
/// </summary>
public static string CopyRecipeId { get; set; }

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

@@ -43,10 +49,15 @@ namespace FryPot_DosingSystem.ViewModel
/// </summary>
public RelayCommand<object> EditRecipeCommand { get; set; }
/// <summary>
/// 复制配方
/// </summary>
public RelayCommand<object> CopyRecipeCommand { get; set; }
/// <summary>
/// 删除配方
/// </summary>
public RelayCommand<object> DeleteRecipeCommand { get; set; }


public RecipeSetViewModel()
{
// Json<RecipeManage>.Read();
@@ -76,6 +87,81 @@ namespace FryPot_DosingSystem.ViewModel
}

}), "RecipeIsChange");
//复制指定炒锅配方
ActionManage.GetInstance.Register<object>(new Action<object>((Num) => {
if (Num != null&& CopyRecipeId!=null)
{
var res= Json<RecipeManage>.Data.Recipes.FirstOrDefault(p=>p.RecipeId==CopyRecipeId);
if (res != null)
{
prop: string recipeID = Guid.NewGuid().ToString();//配方唯一ID,后期根据实际要求更改
var res1 = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeID);
if (res1 == null)
{
string recipeNamec = string.Empty;
if (res.RecipeName.Contains('('))
{
recipeNamec = res.RecipeName.Split('(')[0] + $"({Num}号锅)";
}
else
{
recipeNamec= res.RecipeName+$"({Num}号锅)";
}
//复制料筒配方
ObservableCollection<MaterialType> collect = new ObservableCollection<MaterialType>();
//浅拷贝
foreach (var item in res.materialCollection)
{
var clone=(MaterialType)item.Clone();
collect.Add(clone);
}
foreach (var item in collect)
{
if (ushort.TryParse((Num.ToString() + item.MaterialLoc.ToString().Substring(1, 2)), out ushort loc))
{
item.MaterialLoc = loc;
}
else
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"复制配方失败");
return;
}
}

//复制炒锅工艺配方
FlowProcessManage FryFlow = new FlowProcessManage();
FryFlow.StirTime=res.FlowProcess.StirTime;
FryFlow.RecipeName = recipeNamec;
FryFlow.targetWeightOffset = res.FlowProcess.targetWeightOffset;
ObservableCollection<FlowProcessModel> flowCollect = new ObservableCollection<FlowProcessModel>();
//浅拷贝
foreach (var item in res.FlowProcess.fpModels)
{
var clone = (FlowProcessModel)item.Clone();
flowCollect.Add(clone);
}
foreach (var item in flowCollect)
{
if (ushort.TryParse(item.FryMaterialNum, out ushort rollerNum))
{
item.FryMaterialNum = Num.ToString() + item.FryMaterialNum.ToString().Substring(1, 2);
}
}
FryFlow.fpModels = flowCollect;
Json<RecipeManage>.Data.Recipes.Add(new NewRecipeModel { RecipeId = recipeID, DataTime = DateTime.Now.ToShortDateString(), RecipeName = recipeNamec, materialCollection = collect, FlowProcess = FryFlow });//配方添加
//Json<RecipeManage>.Save();
}
else
{
goto prop;
}
MessageNotify.GetInstance.ShowUserLog("复制配方成功");
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"复制配方成功");
}
}
}), "CopyPotNum");

NewRecipe =new RelayCommand( new Action(() =>
{
NewRecipeView nrv = new NewRecipeView();
@@ -124,6 +210,13 @@ namespace FryPot_DosingSystem.ViewModel
}
});
//复制配方
CopyRecipeCommand = new RelayCommand<object>((Id) => {
CopyInfoView copyInfoView = new CopyInfoView();
CopyRecipeId = Id.ToString() ;
copyInfoView.Show();
});

}
}
}

Loading…
Cancel
Save