📄 form1.cs
字号:
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// openFileDialog1
//
this.openFileDialog1.Filter = "(*.jfa)|*.jfa";
this.openFileDialog1.Title = "读入FA文件";
//
// saveFileDialog1
//
this.saveFileDialog1.Filter = "(*.jfa)|*.jfa";
this.saveFileDialog1.Title = "保存FA到文件";
//
// label7
//
this.label7.Location = new System.Drawing.Point(232, 56);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(112, 16);
this.label7.TabIndex = 21;
this.label7.Text = "空字符输入用$代替";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.DarkOrange;
this.ClientSize = new System.Drawing.Size(448, 361);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.comboBox3);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.label2);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.label1);
this.Controls.Add(this.listBox2);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.textBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "JDFA";
this.ResumeLayout(false);
}
#endregion
class record
{
public string status1;
public string status1_a;
public string process;
public string status2;
public string status2_a;
public record()
{
status1="";
status1_a="";
process="";
status2="";
status2_a="";
}
~record(){}
}
record[] j=new record[50];
char[] s=new char[255];
string path;
int p=0;
int position=0;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
j[p]=new record();
j[p].status1=textBox1.Text;
j[p].status1_a=comboBox1.Text;
j[p].process=comboBox3.Text;
j[p].status2=textBox2.Text;
j[p].status2_a=comboBox2.Text;
p++;
listBox1.Items.Add(textBox1.Text+"("+comboBox1.Text+")"+"---("+comboBox3.Text+")-->"+textBox2.Text+"("+comboBox2.Text+")");
}
private void button2_Click(object sender, System.EventArgs e)
{
if (listBox1.SelectedItem!=null)
{
//MessageBox.Show(listBox1.Items.IndexOf(listBox1.SelectedItem).ToString());
j[listBox1.Items.IndexOf(listBox1.SelectedItem)].status1=j[p-1].status1;
j[listBox1.Items.IndexOf(listBox1.SelectedItem)].status1_a=j[p-1].status1_a;
j[listBox1.Items.IndexOf(listBox1.SelectedItem)].process=j[p-1].process;
j[listBox1.Items.IndexOf(listBox1.SelectedItem)].status2=j[p-1].status2;
j[listBox1.Items.IndexOf(listBox1.SelectedItem)].status2_a=j[p-1].status2_a;
p--;
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
private void button3_Click(object sender, System.EventArgs e)
{
bool s=false;
bool f=false;
textBox1.Visible=false;
textBox2.Visible=false;
comboBox3.Visible=false;
comboBox1.Visible=false;
comboBox2.Visible=false;
listBox1.Visible=false;
listBox2.Visible=true;
button3.Visible=false;
button1.Visible=false;
button2.Visible=false;
label3.Visible=false;
label4.Visible=false;
label7.Visible=false;
int t=0;
while(t!=p)
{
listBox2.Items.Add(j[t].status1+"("+j[t].status1_a+")"+"---("+j[t].process+")-->"+j[t].status2+"("+j[t].status2_a+")");
if (j[t].status1_a.Equals("Start")) s=true;
if (j[t].status2_a.Equals("Final")) f=true;
t++;
}
if (s==false || f==false)
{
label1.Visible=true;
button4.Visible=true;
}
else
{
menuItem3.Enabled=false;
label2.Visible=true;
button5.Visible=true;
textBox4.Visible=true;
label6.Visible=true;
}
}
private void button4_Click(object sender, System.EventArgs e)
{
listBox2.Items.Clear();
textBox1.Visible=true;
textBox2.Visible=true;
comboBox3.Visible=true;
comboBox1.Visible=true;
comboBox2.Visible=true;
listBox1.Visible=true;
listBox2.Visible=false;
button3.Visible=true;
button1.Visible=true;
button2.Visible=true;
label1.Visible=false;
button4.Visible=false;
label3.Visible=true;
label4.Visible=true;
label7.Visible=true;
}
private void button5_Click(object sender, System.EventArgs e)
{
label2.Text="";
label6.Text="";
path="";
s=textBox4.Text.ToCharArray();
for (position=0;position<textBox4.Text.Length;position++)
{
//MessageBox.Show(textBox4.Text.Length.ToString());
int t=0;
while(t!=p)
{
//MessageBox.Show(j[t].process.ToString());
char[] c=j[t].process.ToCharArray();
if (c[0]==s[position]) break;
t++;
//MessageBox.Show("x");
if (t==p) {label2.Text="输入字符串不合法,请检查后重新输入";return;}
}
}
int i;
for (i=0;i<p;i++)
{
if (j[i].status1_a.Equals("Start"))
{
position=0;
//MessageBox.Show(i.ToString());
if (moveto(j[i])==true)
{
label2.Text="此字符串符合以上FA";
path=j[i].status1+"===>"+path;
label6.Text=path.ToString();
break;
}
}
label2.Text="此字符串不符合以上的FA";
}
}
private bool moveto (record a)
{
char[] c=a.process.ToCharArray();
if (position>=s.Length) return false;
//MessageBox.Show(a.process.Equals("$").ToString());
if (c[0]!=s[position] && (!a.process.Equals("$")) ) return false;
if (a.status2_a.Equals("Final") && (position==s.Length-1))
{
path=a.status2;
return true;
}
for (int i=0;i<p;i++)
{
if (a.status2.Equals(j[i].status1))
{
if (!a.process.Equals("$")) position++;
if (moveto(j[i])==true)
{
path=a.status2+"--->"+path;
return true;
}else if (!a.process.Equals("$")) position--;
}
}
return false;
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
openFileDialog1.ShowDialog();
if (!openFileDialog1.FileName.Equals(""))
{
System.IO.StreamReader r=new System.IO.StreamReader(openFileDialog1.FileName);
string line=r.ReadLine();
while(line!=null)
{
char[] c=new char[255];
j[p]=new record();
c=line.ToCharArray();
//MessageBox.Show(c[10].ToString());
for (int i=0;i<10;i++)
{
if (c[i].ToString()!=" ") j[p].status1+=c[i].ToString();
}
for (int i=10;i<20;i++)
{
if (c[i].ToString()!=" ") j[p].status1_a+=c[i].ToString();
}
for (int i=20;i<22;i++)
{
if (c[i].ToString()!=" ") j[p].process+=c[i].ToString();
}
for (int i=22;i<32;i++)
{
if (c[i].ToString()!=" ") j[p].status2+=c[i].ToString();
}
for (int i=32;i<c.Length;i++)
{
if (c[i].ToString()!=" ") j[p].status2_a+=c[i].ToString();
}
/*MessageBox.Show(j[p].status1.ToString());
MessageBox.Show(j[p].status1_a.ToString());
MessageBox.Show(j[p].process.ToString());
MessageBox.Show(j[p].status2.ToString());
MessageBox.Show(j[p].status2_a.ToString());*/
listBox1.Items.Add(j[p].status1+"("+j[p].status1_a+")"+"---("+j[p].process+")-->"+j[p].status2+"("+j[p].status2_a+")");
p++;
line=r.ReadLine();
}
r.Close();
}
else return;
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
saveFileDialog1.ShowDialog();
if (!saveFileDialog1.FileName.Equals(""))
{
System.IO.StreamWriter r=new System.IO.StreamWriter(saveFileDialog1.FileName);
int t=0;
while(j[t]!=null && t<p)
{
string line="";
line+=j[t].status1;
for (int i=0;i<10-j[t].status1.Length;i++)
{
line+=" ";
}
line+=j[t].status1_a;
for (int i=0;i<10-j[t].status1_a.Length;i++)
{
line+=" ";
}
line+=j[t].process;
for (int i=0;i<2-j[t].process.Length;i++)
{
line+=" ";
}
line+=j[t].status2;
for (int i=0;i<10-j[t].status2.Length;i++)
{
line+=" ";
}
line+=j[t].status2_a;
for (int i=0;i<10-j[t].status2_a.Length;i++)
{
line+=" ";
}
//MessageBox.Show(line);
t++;
r.WriteLine(line.ToCharArray());
}
r.Close();
}else return;
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Form2 joker=new Form2();
joker.ShowDialog();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -