Click here to Skip to main content
15,918,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating emp_attendance register. In my form two command button Time-in and Time-out . I want employees to be able to click on timein and timeout buttons once a day.
Is it possible ... if yes then how.
Posted

Yes, before saving the value in table, check if the employee already have Time-In or Time-Out Value for that particular day? When he click on time in check for time in value for same day and if Time-out check for timeout value in database for the day. Thus you can validate your form?
If you need more help, let me know!
 
Share this answer
 
Comments
guru14 8-Apr-14 2:36am    
Mr Puneet Thanks for reply. could you please explain this process thru example so i can easily understand.
it's my code...
private void checkin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source.........");
conn.Open();
SqlCommand comm = new SqlCommand();
comm.CommandText = "insert into timeatten (id,name,timein)values('" +comboBox1.Text+"','"+textBox1.Text+"','"+textBox2.Text+"' )";
comm.Connection = conn;
comm.ExecuteNonQuery();
MessageBox.Show("Successfully check in");
}

private void checkout_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source.........");
conn.Open();
SqlCommand comm = new SqlCommand();
comm.CommandText = "update timeatten set timeout='" + textBox2.Text + "' where id='" + comboBox1.Text +"'";
comm.Connection = conn;
comm.ExecuteNonQuery();
MessageBox.Show("Successfully Checkout");
}

private void timer1_Tick(object sender, EventArgs e)
{
textBox2.Text = DateTime.Now.ToString();

}
Er. Puneet Goel 8-Apr-14 3:07am    
Before saving the value to the record run this kind of query:

select * from timeatten where DATEADD(dd, 0, DATEDIFF(dd, 0, timein)) = 'Date for whichtime in'

if this return any record, means user has already timein for the day. Similary add check for timeout before saving time out value.
Yes, it is.

You need to check first if employee has been registered yet.

SQL
IF EXISTS(SELECT Emp_ID FROM Table1 Where DateTimeIn = @date)



For further information, please see: EXISTS (Transact-SQL)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900