>wait window "Checking for time conflicts..." nowait noclear > text TO lcSQL TEXTMERGE noshow > select COUNT(ID) as conflicts > from dbo.max4sale where type = <<VFP2SQL(type)>> > and <<thisform.cWhere>> > AND Start_Time >= <<VFP2SQL(Start_Time)>> > and Start_time <= <<VFP2SQL(End_Time)>> > and ID <> <<VFP2SQL(Id)>> > ENDTEXT > > * _cliptext = m.lcSQL > > mysqlexec(m.lcSQL, 'csrTemp', program())>
// Set the initial query to find overlapping times. var query = dbContext.max4sale.Where(m4s => m4s.Start_Time < this.End_Time && m4s.End_Time > this.Start_Time && m4s.ID != this.ID); // Add additional filters based on the type switch(type) { case 1: query = query.Where(m4s => m4s.Type == 1); break; case 2: query = query.Where(m4s => m4s.Type == 1 || m4s.Type == 2); break; } // Get the count of conflicts var conflicts = query.Count(); // Or .Any() if you just need to know if there is conflicts.You could also implement this as a validation attribute (https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.validationattribute%28v=vs.110%29.aspx). See http://blogs.microsoft.co.il/shimmy/2012/01/23/uniqueattribute-that-validates-a-unique-field-against-its-fellow-rows-in-the-database-inherits-dataannotationsvalidationattribute/ for an example of a validation attribute that compares against other records.