从组合框中分配不同的词典

Assigning different dictionaries from a combobox

我有一个线性决策树,用户可以在其中 select 不同的组合框,这些组合框以他们收到的形式创建不同的可能结果。在这种情况下,有两个因素发挥作用,我需要创造一个结果。根据在 textbox3 中输入的数字和 combobox3 的 selection,用户会在 textbox1 规定的目录中收到不同的表格。

我绝对不是一个强大的 C# 程序员,但是,我觉得其中大部分都相当合理,因为唯一不起作用的项目是 combobox3.Text 和文本框之间的 link .3 词典。

 public Form(){

    InitializeComponent();
    button2.Click += mainPageRule;
    button2.Click += mainPageCheck1;
    button2.Click += mainPageCheck2;
    button2.Click += mainPageSwitch;
    button2.Click += mainPageActivator;
}  
    protected void mainPageRule(object sender, EventArgs e){
    this.timer1.Start();
    string destination = textBox1.Text;
    string source = textBox2.Text;
    if (textBox1.Text == "")
    {
        MessageBox.Show("You forgot to set a destination!");
    }
    else if (mapping.ContainsKey(source))
    {
        string directoryName = mapping[source];
        foreach (var f in Directory.GetFiles(directoryName))
        {
            File.Copy(f, Path.Combine(destination, Path.GetFileName(f)));
            GC.Collect();
            GC.WaitForPendingFinalizers();
            progressBar1.Value = 0;
        }
    }
    else
    {
        MessageBox.Show("Oh No! The output code is incorrect or something went wrong! Please Try Again! -Love Joe");
    }
    if (progressBar1.Value == 100)
    {
        this.timer1.Stop();
        progressBar1.Value = 0;
    }}
protected void mainPageSwitch(object sender, EventArgs e){
    if (comboBox3.Text == "Hybrid")
    { 
        string payout = "hybridMain";
    }
    else if (comboBox3.Text == "Corporate")
    {
        string payout = "swagMain";
    }
    else 
    {
        MessageBox.Show("You Forgot to set your platform");
    }}
protected void mainPageActivator(object sender, EventArgs e){
    string destination = textBox1.Text;
    string source = textBox3.Text;

    if (payout.ContainsKey(source))
    {
        string directoryName = payout[source];
        foreach (var f in Directory.GetFiles(directoryName));
        }}
        private Dictionary<string, string> hybridMain = new Dictionary<string, string>{
             //THIS SECTION CALLS TO 1KN3 NEW ADVISORS
             { "0000", @"\Server\A.L.E.X.A DATABASEKN3\New Advisor\NC0"},
         };
private Dictionary<string, string> mapping = new Dictionary<string, string>{
             //THIS SECTION CALLS TO 1KN3 NEW ADVISORS
             { "0000", @"\FSN-SERVER\Server\A.L.E.X.A DATABASEKN3\New Advisor\NC0"},
             { "0001", @"\FSN-SERVER\Server\A.L.E.X.A DATABASEKN3\New Advisor\NCRA" },
             { "0002", @"\FSN-SERVER\Server\A.L.E.X.A DATABASEKN3\New Advisor\NCUA" },
             { "0003", @"\FSN-SERVER\Server\A.L.E.X.A DATABASEKN3\New Advisor\NCB" },
             { "0010", @"\FSN-SERVER\Server\A.L.E.X.A DATABASEKN3\New Advisor\NH0" },
             { "0011", @"\FSN-SERVER\Server\A.L.E.X.A DATABASEKN3\New Advisor\NHRA" },
             { "0012", @"\FSN-SERVER\Server\A.L.E.X.A DATABASEKN3\New Advisor\NHUA" },
             { "0013", @"\FSN-SERVER\Server\A.L.E.X.A DATABASEKN3\New Advisor\NHB" },
         }

与其让所有事件都在一个处理程序上触发,不如将它们分解,让特定控件触发的事件最适合更改事件处理程序。即 ComboBox.OnSelectedIndexChanged 或任何一个。随着每个控件更改下一个控件,效果会级联直到完成。

按特定顺序将多个事件方法分配给处理程序并不能保证它们会按该顺序执行。您最好重构以更具体地执行顺序。

另一种方法是在每个先前排序的方法的末尾链接方法调用,如果您只希望在单击按钮时触发所有事件,这将保证所有事件按顺序触发。

加法:

我的意思是,如果所有这些方法都需要以特定顺序可靠地执行,您应该有类似于以下内容的内容:

public partial class TestForm : Form
{
    public TestForm()
    {
        btnSubmit.Click += new System.EventHandler(button_click);
    }
    public void button_click(object sender, EventArgs e)
    {
        // do some code
        SecondMethod();
    }
    public void SecondMethod()
    {
        // Do some more code that has to wait until first method is done.
        ThirdMethod()
    }
    public void ThirdMethod()
    {
        // Do your final code.
    }
}