0
<DatePicker HorizontalAlignment="Left"  Date="{Binding CzechzIn,UpdateSourceTrigger=PropertyChanged , Mode=TwoWay}"  Height="35" Margin="785,265,0,0" VerticalAlignment="Top" Width="265"/>

<DatePicker HorizontalAlignment="Left"  SelectedDate="{Binding CzechOut, Mode = TwoWay}" Height="35" Margin="785,328,0,0" VerticalAlignment="Top" Width="286"/>

EDIT:

The error was in the binding.Apparently DatePicker boxes are messed up and the "Page" property doesnt do anything(?).

THe first line of code was the original, it does nothing. After a google search people reccomended to use SelectedDate but it says Error The property 'SelectedDate' was not found in type 'DatePicker'. how to fix this?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Margarin
  • 3
  • 2
  • Possible duplicate of [Algorithm to detect overlapping periods](http://stackoverflow.com/questions/13513932/algorithm-to-detect-overlapping-periods) – Lukas Kabrt Dec 12 '15 at 18:46
  • `CheckIn > DateTime.Now` Checkin cannot possibly ever be greater than `DateTime.Now`. Also realize that a `DateTime` object is always a date and time, and it is down to the millisecond. I.E. `CheckIn = DateTime.Now; ` then in the next statement, examine equality: `CheckIn == DateTime.Now;` They might be different, if only by a millisecond. Or they might not. And you might get different answers in subsequent executions. – radarbob Dec 12 '15 at 20:51
  • CheckIn is supposed to be in the future. Im supposed to be bound to a datepicker. – Margarin Dec 12 '15 at 20:59

2 Answers2

0

Your overlap logic is wrong. The correct algorithm can be seen in the accepted answer here:Algorithm to detect overlapping periods

DateCalc looks correct, how is it failing? You should consider using DateTime.Today over .Now in such code to avoid nasty off by one errors caused by the time component of .Now - but it is unclear whether booking from the current date should be possible, I guess.

Community
  • 1
  • 1
Jonas Høgh
  • 10,358
  • 1
  • 26
  • 46
  • Thanks! That algorithm makes much more sense, however it just produces the opposite result, leading me to believe that the reason it doesnt work is somewhere else in the code. – Margarin Dec 12 '15 at 19:51
  • And DateCalc is mysteriously not working still. I have no idea why. – Margarin Dec 12 '15 at 19:52
0

Try this: (ps. I changed (and assumed) your function name for my own sanity :D I think you should too)

DateCalc (your code should be correct, but here's a shorter version):

public bool isCheckInOutOk() 
{
    return (CheckIn < CheckOut) && (CheckIn > DateTime.Now);
}

DateCalc2:

public bool isOverlapping()
{
    foreach (Booking book in Books) 
    {
        if (book.CheckInDateTime < CheckOut && CheckIn < book.CheckOutDateTime)
            return true;
        }
    }
    return false;
}

so, you can use:

if (IsConfirmed && isCheckInOutOk() && !isOverlapping())

PS. off the top of my head, so didn't really tested. isOverlapping credit to Rawling (https://stackoverflow.com/a/13513973/189554)

Community
  • 1
  • 1
antony
  • 123
  • 1
  • 5