为我的日程安排系统保存一些日程表后,我需要创建一个代码,如果我的其他日程安排(开始时间 + 结束时间 + 房间 + 与同一位教师)属于已从数据表中保存的其他计划的范围。
我试着写一个代码,但它有一个问题,在得到落在范围内的时间之后,即使房间和老师不一样,它也算真实......但是如果时间只应该是真的属于同一房间 + 同一位老师的时间范围。
这是我的代码:
String str1;
str1 = "select * from Scheduling where Timein = '" + DDStartTime.SelectedItem.ToString() + "' OR TimeOut = '" + DDEndTime.SelectedItem.ToString() + "' AND Day ='" + SchedDayDD.SelectedItem.ToString() + "'";
string checkuser6 = "select count(*) from Scheduling where Timein = '" + DDStartTime.SelectedItem.ToString() + "' OR TimeOut = '" + DDEndTime.SelectedItem.ToString() + "' AND Day ='" + SchedDayDD.SelectedItem.ToString() + "'AND RoomNumber = '" + RoomDDSched.SelectedItem.ToString() + "'";
SqlCommand comm6 = new SqlCommand(checkuser6, con);
temp7 = Convert.ToInt32(comm6.ExecuteScalar().ToString());
string checkuser7 = "select count(*) from Scheduling where Timein = '" + DDStartTime.SelectedItem.ToString() + "' OR TimeOut = '" + DDEndTime.SelectedItem.ToString() + "' AND Day ='" + SchedDayDD.SelectedItem.ToString() + "'AND Name = '" + SchedNameDD.SelectedItem.ToString() + "'";
SqlCommand comm7 = new SqlCommand(checkuser6, con);
temp8 = Convert.ToInt32(comm7.ExecuteScalar().ToString());
SqlCommand commms = new SqlCommand(str1, con);
SqlDataReader reads = commms.ExecuteReader();
if(temp8 != 0 )
{
num9 = 1;
}
if (temp7 == 0)
{
num10 = 0;
}
else
{
if (reads.Read())
{
tempstart = reads["Timein"].ToString();
tempend = reads["TimeOut"].ToString();
tempdays = reads["Day"].ToString();
num10 = 1;
reads.Close();
}
TimeSpan starts = TimeSpan.Parse(tempstart);
TimeSpan ends = TimeSpan.Parse(tempend);
string tempstarttime = DDStartTime.SelectedValue.ToString();
string tempsendtime = DDEndTime.SelectedValue.ToString();
TimeSpan nowstart = TimeSpan.Parse(tempstarttime.Remove(tempstarttime.Length - 3));
TimeSpan nowend = TimeSpan.Parse(tempsendtime.Remove(tempsendtime.Length - 3));
if (((nowstart > starts) || (nowstart < ends)) || ((nowend > starts) || (nowend < ends)))
{
num11 = 1;
}
}
num12 = num9 + num10 + num11;
reads.Close();
if (num12 == 3)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Range Between Time Conflict Detected')</script>");
}
else
{
//Save to database
}