我正在開發一個考勤管理系統,我希望它提示用戶每天進/出一次。我在想的是它會從數據庫中選擇employeeID和Indate,timetime和outtime,如果indate和intime有價值,它會顯示每天一次的時間obth相同thig w/timeout選擇indate,outtime等。這是我的代碼提示用戶每天進行一次時間/超時?
private void button1_Click(object sender, EventArgs e)
{
try
{
//VALIDATION
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = @" SELECT EmployeeID, Firstname, Lastname
FROM tblEmployee
WHERE EmployeeID = @1";
command.Parameters.AddWithValue("@1", textBox1.Text);
reader = command.ExecuteReader();
if (reader.Read())
{
dataGridView1.Rows[0].Cells[0].Value = reader[0].ToString();
dataGridView1.Rows[0].Cells[1].Value = reader[1].ToString();
dataGridView1.Rows[0].Cells[2].Value = reader[2].ToString();
dataGridView1.Rows[0].Cells[3].Value = dateTimePicker1.Value.ToString();
savetimein();
}
else
{
MessageBox.Show("No Employee ID");
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//SAVE TO DATABASE
private void savetimein()
{
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "INSERT INTO [TimeinTimeout](EmployeeID, Firstname, Lastname, InDate, InTime) VALUES (@1,@2,@3,@4,@5)";
command.Parameters.Clear();
command.Parameters.AddWithValue("@1", textBox1.Text);
command.Parameters.AddWithValue("@2", dataGridView1.Rows[0].Cells[1].Value);
command.Parameters.AddWithValue("@3", dataGridView1.Rows[0].Cells[2].Value);
command.Parameters.AddWithValue("@4", DateTime.Now.ToShortDateString());
command.Parameters.AddWithValue("@5", DateTime.Now.ToLongTimeString());
command.ExecuteNonQuery();
MessageBox.Show("Data Saved!");
this.Hide();
Form1 Mm = new Form1();
Mm.ShowDialog();
}
你在哪裏查詢他們上次登錄的時間是?你似乎知道你必須做什麼 - 你的問題是什麼? –
我想限制用戶的登錄,但我想知道是什麼代碼來確定,如果某列有價值的東西那樣 –
如果數據庫列沒有價值它會違反,但如果它有價值,它會而不是 –