0

我正在制作一个小程序,员工将在其中超时。员工有一个员工 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 并直接执行它,以确保它返回你想要的。

还有一条评论:您执行阅读器sql_reader = sql_command.ExecuteReader();并且不对结果做任何事情,无论实际结果是什么,您都只是显示消息框。

于 2016-01-14T13:21:57.937 回答