0

従業員が出入りする小さなプログラムを作成しています。従業員には従業員 ID があり、それはタイムアウトするために使用する必要がある ID です。

タイミングは問題ありませんが、ここでの問題は、従業員がタイムアウトせずに何度も時間を計ることができることです。

私がやろうとしているのは、従業員がタイムアウトしない限り、従業員がタイムインするたびに再びタイムインすることを許可しないということです。

これまでに行ったことは次のとおりです。

private void TimeIN()
    {
        //check if Employee ID belongs to the tbl_humans table

        Connection();
        sql_connect.Close();
        sql_connect.Open();
        sql_command = new MySqlCommand("Select * from tbl_humans where ID = '" + textBox1.Text + "' ;", sql_connect);

        sql_reader = sql_command.ExecuteReader();

        string username;
        //string password;

        username = (textBox1.Text);
        // password = (textBox2.Text);

        int count = 0;

        while (sql_reader.Read())
        {
            count = count + 1;
        }


        //checks if the Employee ID has been already timed in on tbl_loginout
        // if it's already timed in, it will display "You time out first"
        // but unfortunately, it's not working and still continues to time in the employee even if the employee is already timed in

        if (count == 0) 
        {
           try
           {
               Connection();
               sql_connect.Close();
               sql_connect.Open();


               sql_command = new MySqlCommand
                   ("Select * from tbl_loginout where ID = '" + textBox1.Text +
                   "' and timein_date = '" + DateTime.Today.ToString() + // checks if the employee is timed in on that day(today)
                   "' and timeout_time = '" + DateTime.Now.ToString("00:00:00") + // checks if the employee is still not time out
                   "';", sql_connect);
               sql_reader = sql_command.ExecuteReader();

               MessageBox.Show("You Time Out first");
           }

           catch (Exception aa)
           {
               MessageBox.Show(aa.Message);
           }
       }

助けていただければ幸いです。ありがとうございました!

4

1 に答える 1

0

"' and timeout_time = '" + DateTime.Now.ToString("00:00:00") + "';"クエリから削除するか、に置き換えてみてください"' and timeout_time = null;"

一般に、使用したい SQL を手動で作成し、それを直接実行して、必要なものが確実に返されるようにする必要があります。

もう 1 つのコメント: リーダーを実行sql_reader = sql_command.ExecuteReader();し、結果に対して何もしません。実際の結果が何であれ、メッセージ ボックスを表示するだけです。

于 2016-01-14T13:21:57.937 に答える