2023-05-14 23:26:08 +08:00
|
|
|
|
using System.Collections.Generic;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
2023-05-14 23:26:08 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramApp.Models;
|
2022-10-28 22:45:39 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner;
|
2023-05-14 23:26:08 +08:00
|
|
|
|
using AIStudio.Wpf.Flowchart;
|
|
|
|
|
|
using AIStudio.Wpf.Flowchart.ViewModels;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-05-14 23:26:08 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramApp.ViewModels
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-02-12 21:30:16 +08:00
|
|
|
|
public class FlowchartViewModel : PageViewModel
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2021-07-29 13:55:18 +08:00
|
|
|
|
public FlowchartViewModel(string title, string status, DiagramType diagramType) : base(title, status, diagramType)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-04-04 22:42:09 +08:00
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
2021-08-03 18:19:47 +08:00
|
|
|
|
public FlowchartViewModel(string filename, DiagramDocument diagramDocument) : base(filename, diagramDocument)
|
2021-08-06 18:12:05 +08:00
|
|
|
|
{
|
2021-08-03 18:19:47 +08:00
|
|
|
|
if (DiagramViewModel != null)
|
|
|
|
|
|
{
|
2023-04-16 12:21:51 +08:00
|
|
|
|
FlowchartService.InitData(DiagramViewModel.Items.OfType<FlowNode>().ToList(), DiagramViewModel.Items.OfType<ConnectionViewModel>().ToList(), DiagramViewModel, false);
|
2021-08-03 18:19:47 +08:00
|
|
|
|
}
|
2023-01-14 21:52:05 +08:00
|
|
|
|
_service.DrawModeViewModel.LineDrawMode = DrawMode.ConnectingLineSmooth;
|
2021-08-05 18:20:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
protected override void InitDiagramViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.InitDiagramViewModel();
|
|
|
|
|
|
|
2023-05-11 19:14:39 +08:00
|
|
|
|
DiagramViewModel.DiagramOption.LayoutOption.ShowGrid = true;
|
|
|
|
|
|
DiagramViewModel.DiagramOption.LayoutOption.GridCellSize = new Size(100, 100);
|
|
|
|
|
|
DiagramViewModel.DiagramOption.LayoutOption.CellHorizontalAlignment = CellHorizontalAlignment.Center;
|
|
|
|
|
|
DiagramViewModel.DiagramOption.LayoutOption.CellVerticalAlignment = CellVerticalAlignment.Center;
|
2023-01-14 21:52:05 +08:00
|
|
|
|
_service.DrawModeViewModel.LineDrawMode = DrawMode.ConnectingLineSmooth;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-02 22:59:22 +08:00
|
|
|
|
protected override void Init(bool initNew)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-04-02 22:59:22 +08:00
|
|
|
|
base.Init(initNew);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-03-10 12:09:13 +08:00
|
|
|
|
DesignerItemViewModelBase start = new StartFlowNode() { Left = 100, Top = 0, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString() };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(start);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-05-21 23:03:28 +08:00
|
|
|
|
DesignerItemViewModelBase middle1 = new MiddleFlowNode() { Left = 100, Top = 100, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString(), Text = "主管审批(两人或)", UserIds= new List<string> { "操作员1", "操作员2" }, ActType = "or", SimulateApprove = true };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(middle1);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-03-10 12:09:13 +08:00
|
|
|
|
DesignerItemViewModelBase decide = new DecideFlowNode() { Left = 100, Top = 200, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString(), Text = "5" };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(decide);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-05-21 23:03:28 +08:00
|
|
|
|
DesignerItemViewModelBase middle2 = new MiddleFlowNode() { Left = 200, Top = 300, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString(), Text = "分管领导(两人与)", UserIds = new List<string> { "操作员1", "操作员2" }, ActType = "and", SimulateApprove = true };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(middle2);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-03-10 12:09:13 +08:00
|
|
|
|
DesignerItemViewModelBase cobegin = new COBeginFlowNode() { Left = 100, Top = 400, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString() };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(cobegin);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-04-16 12:21:51 +08:00
|
|
|
|
DesignerItemViewModelBase middle3 = new MiddleFlowNode() { Left = 100, Top = 500, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString(), Text = "财务审批", UserIds = new List<string> { "Admin" }, ActType = "or", SimulateApprove = true };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(middle3);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-04-16 12:21:51 +08:00
|
|
|
|
DesignerItemViewModelBase middle4 = new MiddleFlowNode() { Left = 200, Top = 500, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString(), Text = "人力审批", RoleIds = new List<string> { "操作员", "管理员" }, ActType = "or", SimulateApprove = true };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(middle4);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-03-10 12:09:13 +08:00
|
|
|
|
DesignerItemViewModelBase coend = new COEndFlowNode() { Left = 100, Top = 600, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString() };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(coend);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-03-10 12:09:13 +08:00
|
|
|
|
DesignerItemViewModelBase end = new EndFlowNode() { Left = 100, Top = 700, ItemWidth = 80, ItemHeight = 40, StatusColor = Colors.Yellow.ToString() };
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(end);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector1 = new ConnectionViewModel(start.BottomConnector, middle1.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector1);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector2 = new ConnectionViewModel(middle1.BottomConnector, decide.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector2);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector3 = new ConnectionViewModel(decide.RightConnector, middle2.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector3);
|
2023-01-23 15:43:44 +08:00
|
|
|
|
connector3.AddLabel(">=3");
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector4 = new ConnectionViewModel(middle2.BottomConnector, cobegin.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector4);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector5 = new ConnectionViewModel(decide.BottomConnector, cobegin.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector5);
|
2023-01-23 15:43:44 +08:00
|
|
|
|
connector5.AddLabel("<3");
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector6 = new ConnectionViewModel(cobegin.BottomConnector, middle3.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector6);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector7 = new ConnectionViewModel(cobegin.BottomConnector, middle4.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector7);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector8 = new ConnectionViewModel(middle3.BottomConnector, coend.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector8);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector9 = new ConnectionViewModel(middle4.BottomConnector, coend.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector9);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 17:53:04 +08:00
|
|
|
|
ConnectionViewModel connector10 = new ConnectionViewModel(coend.BottomConnector, end.TopConnector, _service.DrawModeViewModel.LineDrawMode, _service.DrawModeViewModel.LineRouterMode);
|
2023-03-25 22:29:02 +08:00
|
|
|
|
DiagramViewModel.Add(connector10);
|
2021-07-27 16:15:30 +08:00
|
|
|
|
|
2023-04-16 14:56:53 +08:00
|
|
|
|
TextDesignerItemViewModel despcription = new TextDesignerItemViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = nameof(despcription),
|
2023-05-21 23:03:28 +08:00
|
|
|
|
Left = 360,
|
2023-04-16 14:56:53 +08:00
|
|
|
|
Top = 60,
|
|
|
|
|
|
ItemWidth = 300,
|
|
|
|
|
|
ItemHeight = 150,
|
|
|
|
|
|
Text = @"
|
|
|
|
|
|
一个简易的OA审批流程
|
|
|
|
|
|
1.主管审批为or审批,任意一个审批即可;
|
|
|
|
|
|
2.分管领导为and审批,需要审批两次;
|
|
|
|
|
|
3.财务审批为or审批,任意一个审批即可;
|
|
|
|
|
|
4.人力审批为or审批,任意一个审批即可;
|
|
|
|
|
|
注意:为了模拟审批,双击节点可以进行审批;请双击主管审批、分管领导、财务审批、人力审批、进行效果查看。"
|
|
|
|
|
|
};
|
|
|
|
|
|
despcription.FontViewModel.HorizontalAlignment = HorizontalAlignment.Left;
|
|
|
|
|
|
despcription.FontViewModel.VerticalAlignment = VerticalAlignment.Top;
|
|
|
|
|
|
despcription.FontViewModel.FontColor = Colors.Blue;
|
|
|
|
|
|
DiagramViewModel.Add(despcription);
|
|
|
|
|
|
|
2023-04-16 12:21:51 +08:00
|
|
|
|
FlowchartService.InitData(DiagramViewModel.Items.OfType<FlowNode>().ToList(), DiagramViewModel.Items.OfType<ConnectionViewModel>().ToList(), DiagramViewModel, true);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
2023-03-08 19:45:07 +08:00
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2021-08-03 18:19:47 +08:00
|
|
|
|
public override void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Dispose();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var viewModel in DiagramViewModels)
|
|
|
|
|
|
{
|
2023-04-15 23:42:36 +08:00
|
|
|
|
FlowchartService.Dispose(viewModel);
|
2021-08-03 18:19:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|