示例#1
0
 internal static void SaveNoteSchedule(PNote note)
 {
     try
     {
         var ac = new AlarmAfterValuesConverter();
         var mc = new MonthDayConverter();
         var dc = new DaysOfWeekConverter();
         var sb = new StringBuilder();
         DeleteNoteSchedule(note);
         sb.Append("INSERT INTO NOTES_SCHEDULE (NOTE_ID,SCHEDULE_TYPE,ALARM_DATE,START_DATE,LAST_RUN,SOUND,STOP_AFTER,TRACK,REPEAT_COUNT,SOUND_IN_LOOP,USE_TTS,START_FROM,MONTH_DAY,ALARM_AFTER,WEEKDAYS,PROG_TO_RUN,CLOSE_ON_NOTIFICATION,MULTI_ALERTS,TIME_ZONE) VALUES('");
         sb.Append(note.ID);
         sb.Append("',");
         sb.Append(Convert.ToInt32(note.Schedule.Type));
         sb.Append(",'");
         sb.Append(note.Schedule.AlarmDate.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
         sb.Append("','");
         sb.Append(note.Schedule.StartDate.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
         sb.Append("','");
         sb.Append(note.Schedule.LastRun.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
         sb.Append("','");
         sb.Append(note.Schedule.Sound);
         sb.Append("',");
         sb.Append(note.Schedule.StopAfter);
         sb.Append(",");
         sb.Append(Convert.ToInt32(note.Schedule.Track));
         sb.Append(",");
         sb.Append(note.Schedule.RepeatCount);
         sb.Append(",");
         sb.Append(Convert.ToInt32(note.Schedule.SoundInLoop));
         sb.Append(",");
         sb.Append(Convert.ToInt32(note.Schedule.UseTts));
         sb.Append(",");
         sb.Append(Convert.ToInt32(note.Schedule.StartFrom));
         sb.Append(",'");
         sb.Append(mc.ConvertToString(note.Schedule.MonthDay));
         sb.Append("','");
         sb.Append(ac.ConvertToString(note.Schedule.AlarmAfter));
         sb.Append("','");
         sb.Append(dc.ConvertToString(note.Schedule.Weekdays));
         sb.Append("','");
         sb.Append(note.Schedule.ProgramToRunOnAlert);
         sb.Append("',");
         sb.Append(Convert.ToInt32(note.Schedule.CloseOnNotification));
         //MULTI_ALERTS
         if (note.Schedule.MultiAlerts.Any())
         {
             var temp = new StringBuilder();
             foreach (var ma in note.Schedule.MultiAlerts)
             {
                 temp.Append(ma.Raised);
                 temp.Append("|");
                 temp.Append(ma.Date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                 temp.Append("^");
             }
             sb.Append(",'");
             sb.Append(temp);
             sb.Append("'");
         }
         else
         {
             sb.Append(",NULL");
         }
         //TIME_ZONE
         if (note.Schedule.TimeZone != null)
         {
             sb.Append(",'");
             sb.Append(note.Schedule.TimeZone.ToSerializedString());
             sb.Append("'");
         }
         else
         {
             sb.Append(",NULL");
         }
         sb.Append(")");
         using (var oData = new SQLiteDataObject(PNData.ConnectionString))
         {
             oData.Execute(sb.ToString());
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
示例#2
0
        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;
            }
        }
示例#3
0
        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);
        }
示例#4
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                if (value == null)
                {
                    return "";
                }
                var sch = value as PNNoteSchedule;
                if (sch != null)
                {
                    var dwc = new DaysOfWeekConverter();
                    var mc = new MonthDayConverter();
                    var avc = new AlarmAfterValuesConverter();
                    var dtc = new DateTimeConverter();

                    var sb = new StringBuilder();
                    sb.Append(avc.ConvertToString(sch.AlarmAfter));
                    sb.Append(DEL_INNER);
                    sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, sch.AlarmDate));
                    sb.Append(DEL_INNER);
                    sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, sch.LastRun));
                    sb.Append(DEL_INNER);
                    sb.Append(mc.ConvertToString(sch.MonthDay));
                    sb.Append(DEL_INNER);
                    sb.Append(sch.RepeatCount);
                    sb.Append(DEL_INNER);
                    sb.Append(sch.Sound);
                    sb.Append(DEL_INNER);
                    sb.Append(sch.SoundInLoop);
                    sb.Append(DEL_INNER);
                    sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, sch.StartDate));
                    sb.Append(DEL_INNER);
                    sb.Append((int)sch.StartFrom);
                    sb.Append(DEL_INNER);
                    sb.Append(sch.StopAfter);
                    sb.Append(DEL_INNER);
                    sb.Append(sch.Track);
                    sb.Append(DEL_INNER);
                    sb.Append((int)sch.Type);
                    sb.Append(DEL_INNER);
                    sb.Append(sch.UseTts);
                    sb.Append(DEL_INNER);
                    sb.Append(dwc.ConvertToString(sch.Weekdays));
                    sb.Append(DEL_INNER);
                    sb.Append(sch.ProgramToRunOnAlert);
                    sb.Append(DEL_INNER);
                    sb.Append(sch.CloseOnNotification);
                    return sb.ToString();
                }
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
        private bool addNewNote(string id, NOTE_DATA data, SCHEDULE_TYPE schedule, NOTE_REL_POSITION relPos,
            ADDITIONAL_NAPP addApp, SYSTEMTIME creation, SYSTEMTIME deletion, NOTE_APPEARANCE appearance, NOTE_PIN pin,
            SEND_REC_STATUS sendrec, StringBuilder tags, StringBuilder links, Dictionary<int, int> groupIds, bool hide)
        {
            try
            {
                var sqlList = new List<string>();
                var sb = new StringBuilder();
                var afv = new AlarmAfterValues();
                var md = new MonthDay();
                var dw = new List<DayOfWeek>();
                var sc = new SizeConverter();
                var pc = new PointConverter();
                var ac = new AlarmAfterValuesConverter();
                var mdc = new MonthDayConverter();
                var dwc = new DaysOfWeekConverter();
                var lfc = new LogFontConverter();

                if (PNStatic.Notes.Any(n => n.ID == id))
                {
                    string message = PNLang.Instance.GetMessageText("id_exists",
                        "The note with the same ID already exists.");
                    message += '\n';
                    message += PNLang.Instance.GetMessageText("continue_anyway", "Continue anyway?");
                    if (
                        PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) ==
                        MessageBoxResult.No)
                    {
                        return false;
                    }
                }
                sqlList.Add("DELETE FROM NOTES WHERE ID = '" + id + "'");
                sb.Append(
                    "INSERT INTO NOTES (ID, NAME, GROUP_ID, PREV_GROUP_ID, OPACITY, VISIBLE, FAVORITE, PROTECTED, COMPLETED, PRIORITY, PASSWORD_STRING, PINNED, TOPMOST, ROLLED, DOCK_STATUS, DOCK_ORDER, SEND_RECEIVE_STATUS, DATE_CREATED, DATE_SAVED, DATE_SENT, DATE_RECEIVED, DATE_DELETED, SIZE, LOCATION, EDIT_SIZE, REL_X, REL_Y, SENT_TO, RECEIVED_FROM, PIN_CLASS, PIN_TEXT, RECEIVED_IP) VALUES(");
                // ID
                sb.Append("'");
                sb.Append(id);
                sb.Append("', ");
                // NAME
                sb.Append("'");
                sb.Append(data.szName.Replace("'", "''"));
                sb.Append("', ");
                // GROUP_ID
                if (groupIds.Keys.Contains(data.idGroup))
                {
                    sb.Append(groupIds[data.idGroup]);
                }
                else
                {
                    if (PNStatic.Groups.Any(g => g.ID == data.idGroup))
                    {
                        if (data.idGroup == GROUP_INCOMING)
                            sb.Append((int)SpecialGroups.Incoming);
                        else
                            sb.Append(data.idGroup);
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
                sb.Append(", ");
                // PREV_GROUP_ID
                sb.Append("0");
                sb.Append(", ");
                // OPACITY
                sb.Append(addApp.transValue != 0 ? (addApp.transValue / 255.0).ToString(PNStatic.CultureInvariant) : "1.0");
                sb.Append(", ");
                // VISIBLE
                sb.Append(!hide ? Convert.ToInt32(data.visible) : 0);
                sb.Append(", ");
                // FAVORITE
                sb.Append("0, ");
                // PROTECTED
                sb.Append(Convert.ToInt32(PNStatic.IsBitSet(data.res1, NB_PROTECTED)));
                sb.Append(", ");
                // COMPLETED
                sb.Append(Convert.ToInt32(PNStatic.IsBitSet(data.res1, NB_COMPLETED)));
                sb.Append(", ");
                // PRIORITY
                sb.Append(Convert.ToInt32(PNStatic.IsBitSet(data.res1, NB_HIGH_PRIORITY)));
                sb.Append(", ");
                // PASSWORD_STRING
                sb.Append("'',");
                // PINNED
                sb.Append(
                    Convert.ToInt32((pin.className != null && pin.text != null && pin.className != "" && pin.text != "")));
                sb.Append(", ");
                // TOPMOST
                sb.Append(Convert.ToInt32(data.onTop));
                sb.Append(", ");
                // ROLLED
                sb.Append(Convert.ToInt32(data.rolled));
                sb.Append(", ");
                // DOCK_STATUS
                int ddata = loWord(data.dockData);
                if (ddata < (int)DockStatus.None || ddata > (int)DockStatus.Bottom)
                    sb.Append((int)DockStatus.None);
                else
                    sb.Append(ddata);
                sb.Append(", ");
                // DOCK_ORDER
                var dorder = -1;
                switch ((DockStatus)ddata)
                {
                    case DockStatus.Left:
                    case DockStatus.Top:
                    case DockStatus.Right:
                    case DockStatus.Bottom:
                        if (PNStatic.DockedNotes[(DockStatus)ddata].Count > 0)
                        {
                            dorder = PNStatic.DockedNotes[(DockStatus)ddata].Max(n => n.DockOrder) + 1;
                            dorder += m_DockedNotes[(DockStatus)ddata];
                            m_DockedNotes[(DockStatus)ddata]++;
                        }
                        else
                            dorder = 0;
                        break;
                }
                sb.Append(dorder);
                sb.Append(", ");
                // SEND_RECEIVE_STATUS
                if (sendrec.sentTo != null && sendrec.recFrom != null && sendrec.sentTo != "" && sendrec.recFrom != "")
                    sb.Append((int)(SendReceiveStatus.Both));
                else if (!string.IsNullOrEmpty(sendrec.sentTo))
                    sb.Append((int)SendReceiveStatus.Sent);
                else if (!string.IsNullOrEmpty(sendrec.recFrom))
                    sb.Append((int)SendReceiveStatus.Received);
                else
                    sb.Append("0");
                sb.Append(", ");
                // DATE_CREATED
                DateTime date = new DateTime(creation.wYear != 0 ? creation.wYear : 1,
                    creation.wMonth != 0 ? creation.wMonth : 1, creation.wDay != 0 ? creation.wDay : 1, creation.wHour,
                    creation.wMinute, creation.wSecond);
                sb.Append("'");
                sb.Append(date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', ");
                // DATE_SAVED
                date = new DateTime(data.stChanged.wYear != 0 ? data.stChanged.wYear : 1,
                    data.stChanged.wMonth != 0 ? data.stChanged.wMonth : 1,
                    data.stChanged.wDay != 0 ? data.stChanged.wDay : 1, data.stChanged.wHour, data.stChanged.wMinute,
                    data.stChanged.wSecond);
                sb.Append("'");
                sb.Append(date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', ");
                // DATE_SENT
                date = new DateTime(sendrec.lastSent.wYear != 0 ? sendrec.lastSent.wYear : 1,
                    sendrec.lastSent.wMonth != 0 ? sendrec.lastSent.wMonth : 1,
                    sendrec.lastSent.wDay != 0 ? sendrec.lastSent.wDay : 1, sendrec.lastSent.wHour,
                    sendrec.lastSent.wMinute, sendrec.lastSent.wSecond);
                sb.Append("'");
                sb.Append(date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', ");
                // DATE_RECEIVED
                date = new DateTime(sendrec.lastRec.wYear != 0 ? sendrec.lastRec.wYear : 1,
                    sendrec.lastRec.wMonth != 0 ? sendrec.lastRec.wMonth : 1,
                    sendrec.lastRec.wDay != 0 ? sendrec.lastRec.wDay : 1, sendrec.lastRec.wHour, sendrec.lastRec.wMinute,
                    sendrec.lastRec.wSecond);
                sb.Append("'");
                sb.Append(date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', ");
                // DATE_DELETED
                date = new DateTime(deletion.wYear != 0 ? deletion.wYear : 1, deletion.wMonth != 0 ? deletion.wMonth : 1,
                    deletion.wDay != 0 ? deletion.wDay : 1, deletion.wHour, deletion.wMinute, deletion.wSecond);
                sb.Append("'");
                sb.Append(date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', ");
                // SIZE
                Size size = new Size(data.rcp.right - data.rcp.left, data.rcp.bottom - data.rcp.top);
                sb.Append("'");
                sb.Append(sc.ConvertToString(null, PNStatic.CultureInvariant, size));
                sb.Append("', ");
                // LOCATION
                Point location = new Point(data.rcp.left, data.rcp.top);
                sb.Append("'");
                sb.Append(pc.ConvertToString(null, PNStatic.CultureInvariant, location));
                sb.Append("', ");
                // EDIT_SIZE - just copy note size, there is no way to get the edit size of note
                sb.Append("'");
                sb.Append(sc.ConvertToString(null, PNStatic.CultureInvariant, size));
                sb.Append("', ");
                // REL_X
                sb.Append(Math.Abs(relPos.left - 0) > double.Epsilon
                    ? relPos.left.ToString(PNStatic.CultureInvariant)
                    : "1.0");
                sb.Append(", ");
                // REL_Y
                sb.Append(Math.Abs(relPos.top - 0) > double.Epsilon
                    ? relPos.top.ToString(PNStatic.CultureInvariant)
                    : "1.0");
                sb.Append(", ");
                // SENT_TO
                sb.Append("'");
                sb.Append(!string.IsNullOrEmpty(sendrec.sentTo) ? sendrec.sentTo.Replace("'", "''") : "");
                sb.Append("', ");
                // RECEIVED_FROM
                sb.Append("'");
                sb.Append(!string.IsNullOrEmpty(sendrec.recFrom) ? sendrec.recFrom.Replace("'", "''") : "");
                sb.Append("', ");
                // PIN_CLASS
                sb.Append("'");
                sb.Append(!string.IsNullOrEmpty(pin.className) ? pin.className.Replace("'", "''") : "");
                sb.Append("', ");
                // PIN_TEXT
                sb.Append("'");
                sb.Append(!string.IsNullOrEmpty(pin.text) ? pin.text.Replace("'", "''") : "");
                //RECEIVED_IP
                sb.Append("', ''");
                
                sb.Append(")");
                sqlList.Add(sb.ToString());

                // schedule
                // SCHEDULE_TYPE
                if (schedule.scType > 0)
                {
                    ScheduleType sctype;
                    if (schedule.scType > START_PROG)
                    {
                        sctype = (ScheduleType)(schedule.scType - START_PROG);
                    }
                    else
                    {
                        sctype = (ScheduleType)schedule.scType;
                    }
                    var doInsert = true;
                    if (sctype == ScheduleType.RepeatEvery || sctype == ScheduleType.After)
                    {
                        if (schedule.scDate.wYear == 0 &&
                            schedule.scDate.wMonth == 0 &&
                            schedule.scDate.wDayOfWeek == 0 &&
                            schedule.scDate.wDay == 0 &&
                            schedule.scDate.wHour == 0 &&
                            schedule.scDate.wMinute == 0 &&
                            schedule.scDate.wSecond == 0)
                        {
                            doInsert = false;
                        }
                    }
                    if (doInsert)
                    {
                        sb = new StringBuilder();
                        sb.Append(
                            "INSERT INTO NOTES_SCHEDULE (NOTE_ID, SCHEDULE_TYPE, ALARM_DATE, START_DATE, LAST_RUN, SOUND, STOP_AFTER, TRACK, REPEAT_COUNT, SOUND_IN_LOOP, USE_TTS, START_FROM, MONTH_DAY, ALARM_AFTER, WEEKDAYS, PROG_TO_RUN, CLOSE_ON_NOTIFICATION, MULTI_ALERTS, TIME_ZONE) VALUES(");
                        // NOTE_ID
                        sb.Append("'");
                        sb.Append(id);
                        sb.Append("', ");
                        sb.Append((int)sctype);
                        sb.Append(", ");
                        // ALARM_DATE
                        date = new DateTime(schedule.scDate.wYear != 0 ? schedule.scDate.wYear : 1,
                            schedule.scDate.wMonth != 0 ? schedule.scDate.wMonth : 1,
                            schedule.scDate.wDay != 0 ? schedule.scDate.wDay : 1, schedule.scDate.wHour,
                            schedule.scDate.wMinute, schedule.scDate.wSecond);
                        sb.Append("'");
                        sb.Append(date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant)
                            .Replace("'", "''"));
                        sb.Append("', ");
                        // START_DATE
                        date = new DateTime(schedule.scStart.wYear != 0 ? schedule.scStart.wYear : 1,
                            schedule.scStart.wMonth != 0 ? schedule.scStart.wMonth : 1,
                            schedule.scStart.wDay != 0 ? schedule.scStart.wDay : 1, schedule.scStart.wHour,
                            schedule.scStart.wMinute, schedule.scStart.wSecond);
                        sb.Append("'");
                        sb.Append(date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant)
                            .Replace("'", "''"));
                        sb.Append("', ");
                        // LAST_RUN
                        date = new DateTime(schedule.scLastRun.wYear != 0 ? schedule.scLastRun.wYear : 1,
                            schedule.scLastRun.wMonth != 0 ? schedule.scLastRun.wMonth : 1,
                            schedule.scLastRun.wDay != 0 ? schedule.scLastRun.wDay : 1, schedule.scLastRun.wHour,
                            schedule.scLastRun.wMinute, schedule.scLastRun.wSecond);
                        sb.Append("'");
                        sb.Append(date.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant)
                            .Replace("'", "''"));
                        sb.Append("', ");
                        // SOUND
                        sb.Append("'");
                        sb.Append(schedule.szSound != null && schedule.szSound.Trim().Length > 0
                            ? schedule.szSound.Replace("'", "''")
                            : PNSchedule.DEF_SOUND);
                        sb.Append("', ");
                        // STOP_AFTER
                        sb.Append(schedule.stopLoop);
                        sb.Append(", ");
                        // TRACK
                        sb.Append(Convert.ToInt32(!PNStatic.IsBitSet(data.res1, NB_NOT_TRACK)));
                        sb.Append(", ");
                        // REPEAT_COUNT - no way to get repeat count
                        sb.Append(0);
                        sb.Append(", ");
                        // SOUND_IN_LOOP
                        sb.Append(Convert.ToInt32(PNStatic.IsBitSet(schedule.parameters, SP_SOUND_IN_LOOP)));
                        sb.Append(", ");
                        // USE_TTS
                        sb.Append(Convert.ToInt32(PNStatic.IsBitSet(schedule.parameters, SP_USE_TTS)));
                        sb.Append(", ");
                        // START_FROM
                        if (schedule.scType > START_PROG)
                            sb.Append((int)ScheduleStart.ProgramStart);
                        else
                            sb.Append((int)ScheduleStart.ExactTime);
                        sb.Append(", ");
                        // MONTH_DAY
                        if (sctype == ScheduleType.MonthlyDayOfWeek)
                        {
                            md.WeekDay = (DayOfWeek)schedule.scDate.wDayOfWeek;
                            md.OrdinalNumber = (DayOrdinal)schedule.scDate.wMilliseconds;
                        }
                        sb.Append("'");
                        var convertToString = mdc.ConvertToString(md);
                        if (convertToString != null) sb.Append(convertToString.Replace("'", "''"));
                        sb.Append("', ");
                        // ALARM_AFTER
                        if (sctype == ScheduleType.RepeatEvery || sctype == ScheduleType.After)
                        {
                            afv.Years = schedule.scDate.wYear;
                            afv.Months = schedule.scDate.wMonth;
                            afv.Weeks = schedule.scDate.wDayOfWeek;
                            afv.Days = schedule.scDate.wDay;
                            afv.Hours = schedule.scDate.wHour;
                            afv.Minutes = schedule.scDate.wMinute;
                            afv.Seconds = schedule.scDate.wSecond;
                        }
                        sb.Append("'");
                        sb.Append(ac.ConvertToString(afv).Replace("'", "''"));
                        sb.Append("', ");
                        // WEEKDAYS
                        if (sctype == ScheduleType.Weekly)
                        {
                            if (PNStatic.IsBitSet(schedule.scDate.wDayOfWeek, 1))
                                dw.Add(DayOfWeek.Sunday);
                            if (PNStatic.IsBitSet(schedule.scDate.wDayOfWeek, 2))
                                dw.Add(DayOfWeek.Monday);
                            if (PNStatic.IsBitSet(schedule.scDate.wDayOfWeek, 3))
                                dw.Add(DayOfWeek.Tuesday);
                            if (PNStatic.IsBitSet(schedule.scDate.wDayOfWeek, 4))
                                dw.Add(DayOfWeek.Wednesday);
                            if (PNStatic.IsBitSet(schedule.scDate.wDayOfWeek, 5))
                                dw.Add(DayOfWeek.Thursday);
                            if (PNStatic.IsBitSet(schedule.scDate.wDayOfWeek, 6))
                                dw.Add(DayOfWeek.Friday);
                            if (PNStatic.IsBitSet(schedule.scDate.wDayOfWeek, 7))
                                dw.Add(DayOfWeek.Saturday);
                        }
                        sb.Append("'");
                        sb.Append(dwc.ConvertToString(dw));
                        sb.Append("','");
                        //PROG_TO_RUN
                        sb.Append("',");
                        //CLOSE_ON_NOTIFICATION
                        sb.Append(0);
                        //MULTI_ALERTS
                        sb.Append(", NULL");
                        //TIME_ZONE
                        sb.Append(", NULL");
                        sb.Append(")");
                        sqlList.Add(sb.ToString());
                    }
                }
                // custom note settings
                sb = new StringBuilder();
                sb.Append(
                    "INSERT INTO CUSTOM_NOTES_SETTINGS (NOTE_ID, BACK_COLOR, CAPTION_FONT_COLOR, CAPTION_FONT, SKIN_NAME, CUSTOM_OPACITY) VALUES(");
                // NOTE_ID
                sb.Append("'");
                sb.Append(id);
                sb.Append("', ");
                // BACK_COLOR
                if (appearance.crWindow != 0 && (appearance.nPrivate & F_B_COLOR) == F_B_COLOR)
                {
                    sb.Append("'");
                    var colorString = PNStatic.FromIntToColorString(appearance.crWindow);
                    sb.Append(colorString);
                    sb.Append("', ");
                }
                else
                {
                    sb.Append("NULL, ");
                }
                // CAPTION_FONT_COLOR
                if (appearance.crCaption != 0 && (appearance.nPrivate & F_C_COLOR) == F_C_COLOR)
                {
                    sb.Append("'");
                    var colorString = PNStatic.FromIntToColorString(appearance.crCaption);
                    sb.Append(colorString);
                    sb.Append("', ");
                }
                else
                {
                    sb.Append("NULL, ");
                }
                // CAPTION_FONT
                if (appearance.lfCaption.lfFaceName != null && appearance.lfCaption.lfFaceName.Trim().Length > 0 &&
                    (appearance.nPrivate & F_C_FONT) == F_C_FONT)
                {
                    var lf = new LOGFONT
                    {
                        lfCharSet = appearance.lfCaption.lfCharSet,
                        lfClipPrecision = appearance.lfCaption.lfClipPrecision,
                        lfEscapement = appearance.lfCaption.lfEscapement,
                        lfFaceName = appearance.lfCaption.lfFaceName.Trim(),
                        lfHeight = appearance.lfCaption.lfHeight,
                        lfItalic = appearance.lfCaption.lfItalic,
                        lfOrientation = appearance.lfCaption.lfOrientation,
                        lfOutPrecision = appearance.lfCaption.lfOutPrecision,
                        lfPitchAndFamily = appearance.lfCaption.lfPitchAndFamily,
                        lfQuality = appearance.lfCaption.lfQuality,
                        lfStrikeOut = appearance.lfCaption.lfStrikeOut,
                        lfUnderline = appearance.lfCaption.lfUnderline,
                        lfWeight = appearance.lfCaption.lfWeight,
                        lfWidth = appearance.lfCaption.lfWidth
                    };
                    sb.Append("'");
                    sb.Append(lfc.ConvertToString(lf));
                    sb.Append("', ");
                }
                else
                {
                    sb.Append("NULL, ");
                }
                // SKIN_NAME
                if (appearance.szSkin != null && appearance.szSkin.Trim().Length > 0 &&
                    (appearance.nPrivate & F_SKIN) == F_SKIN)
                {
                    sb.Append("'");
                    sb.Append(appearance.szSkin.Trim().Replace("'", "''"));
                    sb.Append("', ");
                }
                else
                {
                    sb.Append("NULL, ");
                }
                // CUSTOM_OPACITY
                sb.Append(addApp.transValue != 0 ? 1 : 0);
                sb.Append(")");
                sqlList.Add(sb.ToString());

                // linked notes
                if (links.Length > 0)
                {
                    var arr = links.ToString().Split('|');
                    foreach (var s in arr)
                    {
                        if (s.Trim().Length > 0)
                        {
                            sb = new StringBuilder();
                            sb.Append("INSERT INTO LINKED_NOTES (NOTE_ID, LINK_ID) VALUES(");
                            // NOTE_ID
                            sb.Append("'");
                            sb.Append(id);
                            sb.Append("', ");
                            // LINK_ID
                            sb.Append("'");
                            sb.Append(s);
                            sb.Append("'");
                            sb.Append(")");
                            sqlList.Add(sb.ToString());
                        }
                    }
                }

                // tags
                if (tags.Length > 0)
                {
                    var arr = tags.ToString().Split(',');
                    foreach (var s in arr)
                    {
                        if (s.Trim().Length > 0)
                        {
                            sb = new StringBuilder();
                            sb.Append("INSERT INTO NOTES_TAGS (NOTE_ID, TAG) VALUES(");
                            // NOTE_ID
                            sb.Append("'");
                            sb.Append(id);
                            sb.Append("', ");
                            // TAG
                            sb.Append("'");
                            sb.Append(s.Replace("'", "''"));
                            sb.Append("'");
                            sb.Append(") ");
                            sqlList.Add(sb.ToString());
                        }
                    }
                }

                if (!removeNote(id))
                    return false;
                if (!PNData.ExecuteTransactionForList(sqlList, PNData.ConnectionString))
                    return false;
                return true;
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return false;
            }
        }