using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeletStateMode
{
public delegate int DeletAction();
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
checkBox1.Checked = MyWs.bStep;
checkBox2.Checked= MyWs.bquit;
}
WorkStation MyWs = new WorkStation("测试工站");
private void button1_Click(object sender, EventArgs e)
{
MyWs.Func();
}
private void button2_Click(object sender, EventArgs e)
{
MyWs.bquit = false;
MyWs.Func();
}
private void button3_Click(object sender, EventArgs e)
{
MyWs.InitStep();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
MyWs.bStep = checkBox1.Checked;
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
MyWs.bquit = checkBox2.Checked;
}
}
public class WorkStation
{
public string Name;
public DeletAction CurAct;
public bool bquit = true;
public bool bStep = true;
public WorkStation(string name)
{
Name = name;
CurAct = FirstStep;
}
public void Func()
{
int ret = 0;
if (CurAct == null)
{
MessageBox.Show(Name + "已经工作完成!");return;
}
while (CurAct!=null)
{
ret= CurAct();
if (ret != 0)
{
if (ret == 1) return;
MessageBox.Show(Name + "工作失败!");
return;
}
if (bStep) return;
}
MessageBox.Show(Name + "工作成功!");
}
public void InitStep()
{
CurAct = FirstStep;
}
private int FirstStep()
{
MessageBox.Show("第1步完成");
CurAct = SecondStep;
return 0;
}
private int SecondStep()
{
MessageBox.Show("第2步完成");
CurAct = ThirdStep;
return 0;
}
private int ThirdStep()
{
if (bquit)
{
MessageBox.Show("第3步失败");
return -1;
}
MessageBox.Show("第3步完成");
CurAct = LastStep;
return 0;
}
private int LastStep()
{
MessageBox.Show("第4步完成");
CurAct = null;
return 0;
}
}
}
动态委托流程
最新推荐文章于 2021-08-24 15:39:54 发布