单击第一个按钮后忽略代码

时间:2014-07-08 16:22:31

标签: c# button

此按钮(loginButton)执行首次点击时应该执行的所有操作。然后,在所有后续点击中,它拒绝在方法的开头和结尾更改loginStatusLabel的文本...为什么?好像代码被完全跳过,没有任何解释。之前和之后的调试消息都很好,loginStatusLabel在其他任何地方都没有被引用。

我是白痴吗?

    private void loginButton_Click(object sender, EventArgs e)
    {
        Debug.Write("Changing label...");
        loginStatusLabel.Text = "STATUS: Running..."; //this line is ignored after the first iteration
        Debug.WriteLine("label changed.");
        loginButton.Enabled = false;
        try
        {
            string LDS01_start = "select count(*) from BBLEARN.AUTH_PROVIDER_LOG where AUTH_PROVIDER_PK1 = 103 ";
            string LDAPS_start = "select count(*) from BBLEARN.AUTH_PROVIDER_LOG where AUTH_PROVIDER_PK1 = 106 ";
            string middle = "and log_date >= '" + GetDate(loginStartDate) + @"' 
                         and log_date < '" + GetDate(loginEndDate) + @"' ";

            string LDS01_0 = LDS01_start + middle + "and event_type = 0";
            string LDS01_1 = LDS01_start + middle + "and event_type = 1";
            string LDS01_2 = LDS01_start + middle + "and event_type = 2";
            string LDS01_5 = LDS01_start + middle + "and event_type = 5";
            string LDS01_6 = LDS01_start + middle + "and event_type = 6";

            string LDAPS_0 = LDAPS_start + middle + "and event_type = 0";
            string LDAPS_1 = LDAPS_start + middle + "and event_type = 1";
            string LDAPS_2 = LDAPS_start + middle + "and event_type = 2";
            string LDAPS_5 = LDAPS_start + middle + "and event_type = 5";
            string LDAPS_6 = LDAPS_start + middle + "and event_type = 6";

            GetData(LDS01_0, LDS01_LB0);
            GetData(LDS01_1, LDS01_LB1);
            GetData(LDS01_2, LDS01_LB2);
            GetData(LDS01_5, LDS01_LB5);
            GetData(LDS01_6, LDS01_LB6);

            GetData(LDAPS_0, LDAPS_LB0);
            GetData(LDAPS_1, LDAPS_LB1);
            GetData(LDAPS_2, LDAPS_LB2);
            GetData(LDAPS_5, LDAPS_LB5);
            GetData(LDAPS_6, LDAPS_LB6);
        }
        catch (Exception exception)
        {
            Debug.WriteLine(exception);
        }
        loginButton.Enabled = true;

        Debug.Write("Changing label...");
        loginStatusLabel.Text = "STATUS: Complete";
        Debug.WriteLine("label changed.");
    }

    private void GetData(string selectCommand, Label label)
    {
        Debug.WriteLine("Getting data for " + label.Name + "...");
        //open the connection
        OracleConnection conn = new OracleConnection(connectString);
        conn.Open();
        Debug.WriteLine("Connection open...");           

        //define the command
        selectCommand = selectCommand.Replace(Environment.NewLine, " ");
        OracleDataAdapter dataAdapter = new OracleDataAdapter(selectCommand, conn);
        OracleCommandBuilder commandBuilder = new OracleCommandBuilder(dataAdapter);

        //run the command
        Debug.WriteLine("Running command...");
        DataTable table = new DataTable();
        table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        dataAdapter.Fill(table);
        Debug.WriteLine("Command complete.");
        //close the connection
        conn.Close();

        Invoke(new Action(() => RenderData(label, table.Rows[0][0].ToString())));
    }

    private void RenderData(Label label, string text)
    {
        label.Text = text;
    }

1 个答案:

答案 0 :(得分:0)

首先忘记创建新主题。我很蠢。