private static bool loadNoteSchedule(PNote note) { try { var sqlQuery = "SELECT * FROM NOTES_SCHEDULE WHERE NOTE_ID = '" + note.ID + "'"; using (var oData = new SQLiteDataObject(PNData.ConnectionString)) { using (var t = oData.FillDataTable(sqlQuery)) { if (t.Rows.Count > 0) { var mc = new MonthDayConverter(); var ac = new AlarmAfterValuesConverter(); var dw = new DaysOfWeekConverter(); var r = t.Rows[0]; note.Schedule.Type = (ScheduleType)Convert.ToInt32(r["SCHEDULE_TYPE"]); note.Schedule.AlarmDate = DateTime.Parse((string)r["ALARM_DATE"], PNStatic.CultureInvariant); note.Schedule.StartDate = DateTime.Parse((string)r["START_DATE"], PNStatic.CultureInvariant); note.Schedule.LastRun = DateTime.Parse((string)r["LAST_RUN"], PNStatic.CultureInvariant); note.Schedule.Sound = (string)r["SOUND"]; note.Schedule.StopAfter = Convert.ToInt32(r["STOP_AFTER"]); note.Schedule.Track = Convert.ToBoolean(r["TRACK"]); note.Schedule.RepeatCount = Convert.ToInt32(r["REPEAT_COUNT"]); note.Schedule.SoundInLoop = Convert.ToBoolean(r["SOUND_IN_LOOP"]); note.Schedule.UseTts = Convert.ToBoolean(r["USE_TTS"]); note.Schedule.StartFrom = (ScheduleStart)Convert.ToInt32(r["START_FROM"]); note.Schedule.MonthDay = (MonthDay)mc.ConvertFromString((string)r["MONTH_DAY"]); note.Schedule.AlarmAfter = (AlarmAfterValues)ac.ConvertFromString((string)r["ALARM_AFTER"]); note.Schedule.Weekdays = (List<DayOfWeek>)dw.ConvertFromString((string)r["WEEKDAYS"]); if (!DBNull.Value.Equals(r["PROG_TO_RUN"])) note.Schedule.ProgramToRunOnAlert = Convert.ToString(r["PROG_TO_RUN"]); if (!DBNull.Value.Equals(r["CLOSE_ON_NOTIFICATION"])) note.Schedule.CloseOnNotification = Convert.ToBoolean(r["CLOSE_ON_NOTIFICATION"]); if (!PNData.IsDBNull(r["MULTI_ALERTS"])) { var arr1 = ((string)r["MULTI_ALERTS"]).Split(new[] { '^' }, StringSplitOptions.RemoveEmptyEntries); foreach (var ma in arr1.Select(s => s.Split('|')).Select(arr2 => new MultiAlert { Raised = Convert.ToBoolean(arr2[0]), Date = DateTime.Parse(arr2[1], PNStatic.CultureInvariant) })) { note.Schedule.MultiAlerts.Add(ma); } } if (!PNData.IsDBNull(r["TIME_ZONE"])) { note.Schedule.TimeZone = TimeZoneInfo.FromSerializedString((string)r["TIME_ZONE"]); } if (note.Schedule.Type != ScheduleType.None) { note.Timer.Start(); } } } } return true; } catch (Exception ex) { PNStatic.LogException(ex); return false; } }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var str = value as string; if (str != null) { var dwc = new DaysOfWeekConverter(); var mc = new MonthDayConverter(); var avc = new AlarmAfterValuesConverter(); var dtc = new DateTimeConverter(); var sch = new PNNoteSchedule(); var values = str.Split(DEL_INNER); if (values.Length == Enum.GetValues(typeof(Fields)).Length) { sch.AlarmAfter = (AlarmAfterValues)avc.ConvertFromString(values[(int)Fields.AlarmAfter]); var dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.AlarmDate]); if (dateFromString != null) sch.AlarmDate = (DateTime)dateFromString; dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.LastRun]); if (dateFromString != null) sch.LastRun = (DateTime)dateFromString; sch.MonthDay = (MonthDay)mc.ConvertFromString(values[(int)Fields.MonthDay]); sch.RepeatCount = Convert.ToInt32(values[(int)Fields.RepeatCount]); sch.Sound = values[(int)Fields.Sound]; sch.SoundInLoop = Convert.ToBoolean(values[(int)Fields.SoundInLoop]); dateFromString = dtc.ConvertFromString(null, PNStatic.CultureInvariant, values[(int)Fields.StartDate]); if (dateFromString != null) sch.StartDate = (DateTime)dateFromString; sch.StartFrom = (ScheduleStart)Convert.ToInt32(values[(int)Fields.StartFrom]); sch.StopAfter = Convert.ToInt32(values[(int)Fields.StopAfter]); sch.Track = Convert.ToBoolean(values[(int)Fields.Track]); sch.Type = (ScheduleType)Convert.ToInt32(values[(int)Fields.Type]); sch.UseTts = Convert.ToBoolean(values[(int)Fields.UseTTS]); sch.Weekdays = (List<DayOfWeek>)dwc.ConvertFromString(values[(int)Fields.Weekdays]); sch.ProgramToRunOnAlert = values[(int)Fields.ExtRun]; sch.CloseOnNotification = Convert.ToBoolean(values[(int)Fields.CloseOnNotify]); } return sch; } return base.ConvertFrom(context, culture, value); }