/// <summary> /// Gets <see cref="TimeEvent"/>'s data from database. /// </summary> /// <param name="hash"></param> /// <returns>One <see cref="TimeEvent"/> with specific hash or null if record with given hash does not exist.</returns> internal TimeEvent GetTimeEvent(string hash) { var reader = getNullReader(); try { string sql = "SELECT * FROM event WHERE hash = '" + hash + "' LIMIT 1;"; var command = getCommand(sql); reader = command.ExecuteReader(); command.Dispose(); if (reader.Read()) { return(TimeEvent.LoadTimeEvent((string)reader["hash"], (string)reader["name"], (string)reader["description"], (DateTime)reader["startDate"], (DateTime)reader["endDate"], (bool)reader["notification"], (DateTime)reader["notificationDate"])); } else { return(null); } } finally { if (reader != null) { reader.Dispose(); } } }
/// <summary> /// Gets <see cref="TimeEvent"/>s for notify purpose. It returns only TimeEvents with enabled notification and NotificationDate in given interval from notifyFrom to notifyTo. /// </summary> /// <param name="notifyFrom">Start of interval of notificationDate.</param> /// <param name="notifyTo">End of interval of notificationDate.</param> /// <returns>Enumerable <see cref="TimeEvent"/>s for notification.</returns> internal IEnumerable <TimeEvent> GetTimeEventsForNotification(DateTime notifyFrom, DateTime notifyTo) { var reader = getNullReader(); try { string sql = "SELECT * FROM event WHERE notification = 1 AND notificationDate > datetime('" + notifyFrom.ToString(Constants.DateTimeFormat) + "')" + " AND notificationDate <= datetime('" + notifyTo.ToString(Constants.DateTimeFormat) + "')" + " ORDER BY notificationDate ASC"; var command = getCommand(sql); reader = command.ExecuteReader(); command.Dispose(); foreach (var item in reader) { yield return(TimeEvent.LoadTimeEvent((string)reader["hash"], (string)reader["name"], (string)reader["description"], (DateTime)reader["startDate"], (DateTime)reader["endDate"], (bool)reader["notification"], (DateTime)reader["notificationDate"])); } } finally { if (reader != null) { reader.Dispose(); } } }
/// <summary> /// Gets Events that is in given Time Interval. /// </summary> /// <param name="from">Start of interval.</param> /// <param name="to">End of interval.</param> /// <param name="limit">How many <see cref="TimeEvent"/>s should be returned as maximal value.</param> /// <returns>Enumerable <see cref="TimeEvent"/>s ascending by StarDate. And happen in given interval.</returns> internal IEnumerable <TimeEvent> GetTimeEventsInRange(DateTime from, DateTime to, int limit = int.MaxValue) { var reader = getNullReader(); try { string sql = "SELECT * FROM event WHERE endDate >= datetime('" + from.ToString(Constants.DateTimeFormat) + "') AND startDate <= datetime('" + to.ToString(Constants.DateTimeFormat) + "') ORDER BY startDate ASC"; if (limit != int.MaxValue) { sql += " LIMIT " + limit.ToString(); } var command = getCommand(sql); reader = command.ExecuteReader(); command.Dispose(); foreach (var item in reader) { yield return(TimeEvent.LoadTimeEvent((string)reader["hash"], (string)reader["name"], (string)reader["description"], (DateTime)reader["startDate"], (DateTime)reader["endDate"], (bool)reader["notification"], (DateTime)reader["notificationDate"])); } } finally { if (reader != null) { reader.Dispose(); } } }
/// <summary> /// Gets <see cref="TimeEvent"/>s which contain string <paramref name="name"/> in Name parameter, <paramref name="description"/> in Description parameter, /// they happen sometimes after <paramref name="from"/> and before <paramref name="to"/> dates. And does notify in <paramref name="notificationDate"/> /// </summary> /// <param name="name">String contained in record in collumn name. Blank string if this parameter should not be take into account.</param> /// <param name="description">String contained in record in collumn name. Blank string if this parameter should not be take into account.</param> /// <param name="from">Start of interval. <see cref="DateTime.MinValue"/> if this parameter should not be take into account.</param> /// <param name="to">End of interval. <see cref="DateTime.MinValue"/> if this parameter should not be take into account.</param> /// <param name="notificationDate">Date, the day where notification is set. <see cref="DateTime.MinValue"/> if this parameter should not be take into account.</param> /// <returns>Enumerable <see cref="TimeEvent"/>s which have specific parameters.</returns> internal IEnumerable <TimeEvent> GetTimeEvents(string name, string description, DateTime from, DateTime to, DateTime notificationDate) { var reader = getNullReader(); try { bool addAnd = false; StringBuilder sb = new StringBuilder("SELECT * FROM event"); AppendClauseFromIfNotDefault(sb, ref addAnd, from); AppendClauseToIfNotDefault(sb, ref addAnd, to); AppendClauseNameIfNotDefault(sb, ref addAnd, name); AppendClauseDescriptionIfNotDefault(sb, ref addAnd, description); AppendClauseNotificationDateIfNotDefault(sb, ref addAnd, notificationDate); sb.Append(" ORDER BY startDate ASC LIMIT 50000"); string sql = sb.ToString(); var command = getCommand(sql); reader = command.ExecuteReader(); command.Dispose(); foreach (var item in reader) { yield return(TimeEvent.LoadTimeEvent((string)reader["hash"], (string)reader["name"], (string)reader["description"], (DateTime)reader["startDate"], (DateTime)reader["endDate"], (bool)reader["notification"], (DateTime)reader["notificationDate"])); } } finally { if (reader != null) { reader.Dispose(); } } }
/// <summary> /// Update event with specific hash and Log that change. It change all datas of event. /// </summary> /// <param name="hash">Original hash of event.</param> /// <param name="name">New name for event.</param> /// <param name="description">New description of event.</param> /// <param name="startDate">New starting date of this event.</param> /// <param name="endDate">New eding date of this event.</param> /// <param name="notification">New notification boolean.</param> /// <param name="notificationDate">New date for notification.</param> /// <returns>True if datas has been updated, false otherwise.</returns> internal bool UpdateTimeEvent(string hash, string name, string description, DateTime startDate, DateTime endDate, bool notification, DateTime notificationDate) { ChangeEdit(hash); return(updateTimeEvent(TimeEvent.LoadTimeEvent(hash, name, description, startDate, endDate, notification, notificationDate))); }