Hridoy Paul

Hridoy Paul

  • NA
  • 1
  • 1.6k

How to avoid time conflict in datagridview using c#.net wind

Jun 15 2014 3:11 AM
Hi,

I have prepared a 'Meeting Room Booking System'. In the datagridview there are two column like StartTime and EndTime. If a person book the room 12:00 as StartTime and 13:15 as EndTime, no other person can book the room in between of that time. Not even like 11:30 to 12:30, 
not even like 12:30 to 14:00, 
not even like 11:00 to 14:00 etc.

What I mean is, I persons booking time should not conflict with the other persons booking time.

I use this following code to validate which does not work as per my above requirement.

for (int i = 0; i < dgvBookingEntry.Rows.Count - 1; i++)
{
SqlDataReader reader = GlobalInfo.GlobalInfo.returnReader("SELECT StartTime, EndTime FROM BookingEntry_Main WHERE (BookingDate = '" + GlobalInfo.GlobalInfo.SqlDateTimeF(Convert.ToDateTime(txtDate.Text)) + "') AND (ComID = '" + txtComID.Text + "') AND (Status = 'Active') AND (StartTime BETWEEN '" + Convert.ToDateTime(dgvBookingEntry.Rows[i].Cells[3].Value.ToString()) + "' AND '" + Convert.ToDateTime(dgvBookingEntry.Rows[i].Cells[4].Value.ToString()) + "')");
if (reader.HasRows)
{
MessageBox.Show("You are not allowed to take this schedule!", "Warning!");
Cursor = Cursors.Default;
return;
}
}
Please help me...
Regards,
Hridoy Paul