mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
流程图审批完成
This commit is contained in:
@@ -128,6 +128,7 @@
|
||||
<PackageReference Include="MahApps.Metro.IconPacks" Version="4.8.0" />
|
||||
<PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="4.8.0" />
|
||||
<PackageReference Include="MahApps.Metro.IconPacks.VaadinIcons" Version="4.8.0" />
|
||||
<PackageReference Include="MathParser.org-mXparser" Version="4.4.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Util.Svg2XamlTestExtension" Version="1.2.5" />
|
||||
<PackageReference Include="WpfAnimatedGif" Version="2.0.0" />
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Util.DiagramDesigner;
|
||||
using Expression = org.mariuszgromada.math.mxparser.Expression;
|
||||
|
||||
namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
{
|
||||
@@ -48,7 +47,9 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 流程数据
|
||||
/// </summary>
|
||||
public static List<FlowNode> FlowNodes { get; set; }
|
||||
|
||||
|
||||
@@ -108,7 +109,7 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
nextstep.PreStepId = new List<string>();
|
||||
nextstep.PreStepId.Add(step.Id.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var oAStartStep = oASteps.Single(p => p.Kind == NodeKinds.Start);
|
||||
@@ -126,7 +127,7 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取下一个节点
|
||||
/// 初始化步骤
|
||||
/// </summary>
|
||||
/// <param name="oASteps"></param>
|
||||
/// <param name="nextstepid"></param>
|
||||
@@ -161,13 +162,55 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
return outsteps;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 审批动作,因为是客户端模拟,假设每次都是该节点的审批人进行的操作
|
||||
/// </summary>
|
||||
/// <param name="flowNode"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="remark"></param>
|
||||
public static void Approve(FlowNode flowNode, int status, string remark = null)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case 100:
|
||||
if (flowNode is MiddleFlowNode middleFlowNode)
|
||||
{
|
||||
if (string.IsNullOrEmpty(flowNode.Remark))
|
||||
{
|
||||
remark = "审批人:" + remark;
|
||||
}
|
||||
else
|
||||
{
|
||||
remark = flowNode.Remark + "\r审批人:" + remark;
|
||||
}
|
||||
|
||||
if (middleFlowNode.ActType == "and")//如果是与签,那么要都审批通过
|
||||
{
|
||||
if (middleFlowNode.UserIds != null && middleFlowNode.UserIds.Count > 1)
|
||||
{
|
||||
//实际情况不是这样的,这里只是演示,简化。
|
||||
int count = remark.Split("审批人:", StringSplitOptions.RemoveEmptyEntries).Length;
|
||||
if (middleFlowNode.UserIds.Count != count)
|
||||
{
|
||||
SetStatus(flowNode, 1, remark);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (middleFlowNode.RoleIds != null && middleFlowNode.RoleIds.Count > 1)
|
||||
{
|
||||
//实际情况不是这样的,这里只是演示,简化。
|
||||
int count = remark.Split("审批人:", StringSplitOptions.RemoveEmptyEntries).Length;
|
||||
if (middleFlowNode.RoleIds.Count != count)
|
||||
{
|
||||
SetStatus(flowNode, 1, remark);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SetStatus(flowNode, status, remark);
|
||||
flowNode.Color = Colors.Green.ToString();
|
||||
if (!string.IsNullOrEmpty(flowNode.NextStepId))
|
||||
{
|
||||
Next(flowNode.NextStepId);
|
||||
@@ -180,7 +223,7 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 2:
|
||||
if (Pre(flowNode))
|
||||
{
|
||||
SetStatus(flowNode, status, remark);
|
||||
@@ -203,6 +246,10 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 流向下一个节点
|
||||
/// </summary>
|
||||
/// <param name="stepid"></param>
|
||||
public static void Next(string stepid)
|
||||
{
|
||||
FlowNode nextNode = FlowNodes.FirstOrDefault(p => p.Id.ToString() == stepid);
|
||||
@@ -210,31 +257,37 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
|
||||
switch (nextNode.Kind)
|
||||
{
|
||||
case NodeKinds.Start:
|
||||
SetStatus(nextNode, 100);
|
||||
Next(nextNode.NextStepId);
|
||||
case NodeKinds.Start:
|
||||
SetStatus(nextNode, 100);
|
||||
Next(nextNode.NextStepId);
|
||||
break;
|
||||
case NodeKinds.End:
|
||||
SetStatus(nextNode, 100);
|
||||
MessageBox.Show("流程完成");
|
||||
case NodeKinds.End:
|
||||
SetStatus(nextNode, 100);
|
||||
MessageBox.Show("流程完成");
|
||||
break;
|
||||
case NodeKinds.Decide:
|
||||
foreach (var step in nextNode.SelectNextStep)
|
||||
{
|
||||
try
|
||||
{
|
||||
//暂未实现表达式比较
|
||||
step.Value.Replace("data.Flag", nextNode.Text);
|
||||
//先按第一个表达式成立处理。
|
||||
SetStatus(nextNode, 100);
|
||||
Next(step.Key);
|
||||
break;
|
||||
//按条件选择一个分支
|
||||
string express = step.Value.Replace("data.Flag", nextNode.Text);
|
||||
Expression e = new Expression(express);
|
||||
var result = e.calculate();
|
||||
if (result == 1)
|
||||
{
|
||||
SetStatus(nextNode, 100);
|
||||
Next(step.Key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
//如果表达式错了,就按第一个处理
|
||||
Next(nextNode.SelectNextStep.FirstOrDefault().Key);
|
||||
break;
|
||||
case NodeKinds.COBegin:
|
||||
foreach (var step in nextNode.SelectNextStep)
|
||||
foreach (var step in nextNode.SelectNextStep)//启动各个分支
|
||||
{
|
||||
SetStatus(nextNode, 100);
|
||||
Next(step.Key);
|
||||
@@ -244,7 +297,7 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
foreach (var prestep in nextNode.PreStepId)
|
||||
{
|
||||
var step = FlowNodes.FirstOrDefault(p => p.Id.ToString() == prestep);
|
||||
if (step.Status != 100)
|
||||
if (step.Status != 100)//如果并行分支没有都完成,那么并行结束节点也未完成
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -255,6 +308,11 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 流向上一个节点
|
||||
/// </summary>
|
||||
/// <param name="flowNode"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Pre(FlowNode flowNode)
|
||||
{
|
||||
if (flowNode.PreStepId != null && flowNode.PreStepId.Count == 1)
|
||||
@@ -270,6 +328,12 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置颜色
|
||||
/// </summary>
|
||||
/// <param name="flowNode"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="remark"></param>
|
||||
public static void SetStatus(FlowNode flowNode, int status, string remark = null)
|
||||
{
|
||||
flowNode.Status = status;
|
||||
|
||||
@@ -39,22 +39,22 @@ namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
DesignerItemViewModelBase start = new StartFlowNode() { Left = 100, Top = 0, Color = Colors.Yellow.ToString() };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(start);
|
||||
|
||||
DesignerItemViewModelBase middle1 = new MiddleFlowNode() { Left = 100, Top = 100, Color = Colors.Yellow.ToString(), Text = "主管审批" };
|
||||
DesignerItemViewModelBase middle1 = new MiddleFlowNode() { Left = 100, Top = 100, Color = Colors.Yellow.ToString(), Text = "主管审批", UserIds= new List<string> { "操作员1", "操作员2" }, ActType = "or" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(middle1);
|
||||
|
||||
DesignerItemViewModelBase decide = new DecideFlowNode() { Left = 100, Top = 200, Color = Colors.Yellow.ToString(), Text = "5" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(decide);
|
||||
|
||||
DesignerItemViewModelBase middle2 = new MiddleFlowNode() { Left = 200, Top = 300, Color = Colors.Yellow.ToString(), Text = "分管领导" };
|
||||
DesignerItemViewModelBase middle2 = new MiddleFlowNode() { Left = 200, Top = 300, Color = Colors.Yellow.ToString(), Text = "分管领导", UserIds = new List<string> { "操作员1", "操作员2" }, ActType = "and" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(middle2);
|
||||
|
||||
DesignerItemViewModelBase cobegin = new COBeginFlowNode() { Left = 100, Top = 400, Color = Colors.Yellow.ToString() };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(cobegin);
|
||||
|
||||
DesignerItemViewModelBase middle3 = new MiddleFlowNode() { Left = 100, Top = 500, Color = Colors.Yellow.ToString(), Text = "财务审批" };
|
||||
DesignerItemViewModelBase middle3 = new MiddleFlowNode() { Left = 100, Top = 500, Color = Colors.Yellow.ToString(), Text = "财务审批", UserIds = new List<string> { "Admin" }, ActType = "or" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(middle3);
|
||||
|
||||
DesignerItemViewModelBase middle4 = new MiddleFlowNode() { Left = 200, Top = 500, Color = Colors.Yellow.ToString(), Text = "人力审批" };
|
||||
DesignerItemViewModelBase middle4 = new MiddleFlowNode() { Left = 200, Top = 500, Color = Colors.Yellow.ToString(), Text = "人力审批", RoleIds = new List<string> { "操作员", "管理员" }, ActType = "or" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(middle4);
|
||||
|
||||
DesignerItemViewModelBase coend = new COEndFlowNode() { Left = 100, Top = 600, Color = Colors.Yellow.ToString() };
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
</Grid>
|
||||
</Border>
|
||||
<TextBlock Text="{Binding Remark}" FontSize="9" RenderTransformOrigin="1,0.5" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2">
|
||||
<TextBlock Text="{Binding Remark}" FontSize="9" RenderTransformOrigin="1,0.5" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2">
|
||||
<TextBlock.RenderTransform>
|
||||
<TranslateTransform X="{Binding ItemWidth}"/>
|
||||
</TextBlock.RenderTransform>
|
||||
|
||||
@@ -209,22 +209,31 @@ namespace Util.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
var text = _text;
|
||||
if (OutTextItem != null)
|
||||
{
|
||||
text = OutTextItem._text;
|
||||
}
|
||||
if (FontViewModel.FontCase == FontCase.Upper)
|
||||
{
|
||||
return _text?.ToUpper();
|
||||
return text?.ToUpper();
|
||||
}
|
||||
else if (FontViewModel.FontCase == FontCase.Lower)
|
||||
{
|
||||
return _text?.ToLower();
|
||||
return text?.ToLower();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _text;
|
||||
return text;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _text, value))
|
||||
if (OutTextItem != null)
|
||||
{
|
||||
OutTextItem.Text = value;
|
||||
}
|
||||
else if (SetProperty(ref _text, value))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_text))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user