增强了实例工程的抽象逻辑

This commit is contained in:
fengjiayi
2024-10-07 15:15:18 +08:00
parent 7a9f7b7bf3
commit 878b1c5893
39 changed files with 1361 additions and 826 deletions

View File

@@ -31,7 +31,7 @@
this.button1 = new System.Windows.Forms.Button();
this.textBoxPlcInfo = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBoxCommand = new System.Windows.Forms.ListBox();
this.textBoxSpaceNum = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
@@ -43,7 +43,6 @@
this.button1.TabIndex = 0;
this.button1.Text = "查看状态";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBoxPlcInfo
//
@@ -61,16 +60,15 @@
this.button2.TabIndex = 2;
this.button2.Text = "触发";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// listBox1
// listBoxCommand
//
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(35, 85);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(250, 88);
this.listBox1.TabIndex = 6;
this.listBoxCommand.FormattingEnabled = true;
this.listBoxCommand.ItemHeight = 12;
this.listBoxCommand.Location = new System.Drawing.Point(35, 85);
this.listBoxCommand.Name = "listBoxCommand";
this.listBoxCommand.Size = new System.Drawing.Size(250, 88);
this.listBoxCommand.TabIndex = 6;
//
// textBoxSpaceNum
//
@@ -86,12 +84,13 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(341, 251);
this.Controls.Add(this.textBoxSpaceNum);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.listBoxCommand);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBoxPlcInfo);
this.Controls.Add(this.button1);
this.Name = "FromWorkBenchView";
this.Text = "Form1";
this.Load += new System.EventHandler(this.FromWorkBenchView_Load);
this.ResumeLayout(false);
this.PerformLayout();
@@ -102,7 +101,7 @@
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBoxPlcInfo;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBoxCommand;
private System.Windows.Forms.TextBox textBoxSpaceNum;
}
}

View File

@@ -1,4 +1,4 @@
using Net462DllTest.Device;
using Net462DllTest.Signal;
using Net462DllTest.ViewModel;
using Serein.Library.Api;
@@ -19,44 +19,36 @@ namespace Net462DllTest
{
private FromWorkBenchViewModel ViewModel;
public FromWorkBenchView(IFlowEnvironment env)
{
ViewModel = env.IOC.Instantiate<FromWorkBenchViewModel>(); // 创建对象并注入依赖项
InitializeComponent();
Init();
ViewModel = env.IOC.Get<FromWorkBenchViewModel>(); // 获取对象
if(ViewModel is null)
{
Console.WriteLine("创建对象并注入依赖项");
ViewModel = env.IOC.Instantiate<FromWorkBenchViewModel>();
}
BindData();
}
public void Init()
private void BindData()
{
listBox1.Items.Clear();
var enumValues = Enum.GetValues(typeof(CommandSignal)).Cast<CommandSignal>();
foreach (var value in enumValues)
{
listBox1.Items.Add(value.ToString());
}
textBoxPlcInfo.DataBindings.Add(nameof(textBoxPlcInfo.Text), ViewModel, nameof(ViewModel.DeviceInfo), false, DataSourceUpdateMode.OnPropertyChanged);
textBoxSpaceNum.DataBindings.Add(nameof(textBoxSpaceNum.Text), ViewModel, nameof(ViewModel.SpcaeNumber), false, DataSourceUpdateMode.OnPropertyChanged);
listBoxCommand.DataSource = Enum.GetValues(typeof(CommandSignal));
listBoxCommand.DataBindings.Add(nameof(listBoxCommand.SelectedItem), ViewModel, nameof(ViewModel.SelectedSignal), false, DataSourceUpdateMode.OnPropertyChanged);
listBoxCommand.SelectedIndexChanged += (s, e) => listBoxCommand.DataBindings[nameof(listBoxCommand.SelectedItem)].WriteValue();
button1.Click += (s, e) => ViewModel.CommandViewPlcInfo.Execute();
button2.Click += (s, e) => ViewModel.CommandGetParkingSpace.Execute();
}
private void FromWorkBenchView_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
textBoxPlcInfo.Text = ViewModel.GetDeviceInfo();
}
private void button2_Click(object sender, EventArgs e)
{
if(listBox1.SelectedItem is null)
{
return;
}
string type = listBox1.SelectedItem.ToString();
if (!string.IsNullOrEmpty(type) && Enum.TryParse(type, out CommandSignal signal) && Enum.IsDefined(typeof(CommandSignal), signal))
{
Console.WriteLine($"Trigger : {type}");
ViewModel.Trigger(signal,textBoxSpaceNum.Text);
}
}
}
}