Я делаю небольшую программу, в которой работник будет время в/из. У сотрудника есть идентификатор сотрудника, и это тот, который должен использоваться для того, чтобы время и время.Проверка времени (посещаемость C#)
Сроки в порядке, но моя проблема заключается в том, что сотрудник может время во много раз, не выбирая время.
То, что я пытаюсь сделать, это то, что всякий раз, когда сотрудник набирает время, ему/ей не разрешается снова заходить, если он не истечет.
Вот что я сделал до сих пор:
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);
}
}
помощь будет оценена. Спасибо!
я не понимаю. Что не так с этим кодом? BTW, вы всегда должны использовать [параметризованные запросы] (http://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/). Этот тип конкатенаций строк открыт для [SQL Injection] (http://en.wikipedia.org/wiki/SQL_injection) атак. –
Собственно, нет ничего плохого. Я только хочу достичь этого, когда сотрудник наткнется, он/она должен уйти с первого раза, если он/она снова заберет время. Но этого не происходит. И о параметризованных запросах я все еще об этом узнал. – Naomi