Add button for creating step violation rules

This commit is contained in:
sophelper 2026-11-05 23:52:48 +08:00
parent 15472311ff
commit da06e5aa77
2 changed files with 27 additions and 2 deletions

View File

@ -345,8 +345,12 @@
Text="{Binding RequiredObjects.Title}" />
<ItemsControl ItemsSource="{Binding RequiredObjects.Items}" />
<TextBlock Style="{StaticResource Title}" FontSize="13" Margin="0,10,0,6"
Text="{Binding ViolationRules.Title}" />
<DockPanel Margin="0,10,0,6">
<Button DockPanel.Dock="Right" Content="加违规规则" Style="{StaticResource Mini}"
Command="{Binding ViolationRules.AddCommand}" />
<TextBlock Style="{StaticResource Title}" FontSize="13"
Text="{Binding ViolationRules.Title}" />
</DockPanel>
<ItemsControl ItemsSource="{Binding ViolationRules.Items}" />
</StackPanel>
</ScrollViewer>

View File

@ -105,6 +105,27 @@ internal static class Program
var reopenedAgain = RecipeNode.From(SopConfigLoader.Load(savePath), "repeat-save", false);
if (reopenedAgain.SelectedStep?.Detection?.Method != ConditionMethod.TimeElapsed)
throw new Exception("保存后再次打开丢失判定方法");
var addRule = Descendants(stepView).OfType<Button>().Single(b => Equals(b.Content, "加违规规则"));
if (addRule.Command is null || !addRule.Command.CanExecute(addRule.CommandParameter))
throw new Exception("新增违规规则按钮未绑定可执行命令");
addRule.Command.Execute(addRule.CommandParameter);
stepView.UpdateLayout();
var rule = reopenedVm.Recipe.SelectedStep!.ViolationRules.Items.Single();
rule.Type = ViolationType.WrongOrder;
rule.Description = "请按顺序操作";
rule.Severity = 2;
reopenedVm.SaveCommand.Execute();
var savedRule = SopConfigLoader.Load(savePath).Sop.Steps.Single().ViolationRules.Single();
if (savedRule.Type != ViolationType.WrongOrder || savedRule.Description != "请按顺序操作" || savedRule.Severity != 2)
throw new Exception("新增违规规则未正确保存");
var removeRule = Descendants(stepView).OfType<Button>().Single(b =>
ReferenceEquals(b.DataContext, rule) && Equals(b.Content, "删"));
if (removeRule.Command is null) throw new Exception("违规规则删除按钮未绑定命令");
removeRule.Command.Execute(removeRule.CommandParameter);
reopenedVm.SaveCommand.Execute();
if (SopConfigLoader.Load(savePath).Sop.Steps.Single().ViolationRules.Count != 0)
throw new Exception("删除违规规则未正确保存");
Console.WriteLine("PASS: 界面新增违规规则、编辑字段、保存回读和删除");
reopenedVm.OnDialogClosed();
Console.WriteLine("PASS: 新增步骤和重新打开的空判定步骤,通过界面选择方法后均可保存");
}