Fixed bugs with CasesDialogView and DatetimeRangeView.
Fixed database query bugs and removed unnecessary WHERE conditions in queries.