Example #1
0
        internal static void SaveNoteLocation(PNote note, Point location)
        {
            try
            {
                note.NoteLocation = location;
                var factors = getRelationalFactors(note);
                note.XFactor = factors[0];
                note.YFactor = factors[1];

                if (note.FromDB)
                {
                    var pc = new PointConverter();
                    var sb = new StringBuilder();
                    sb.Append("UPDATE NOTES SET LOCATION = '");
                    sb.Append(pc.ConvertToString(null, PNStatic.CultureInvariant, note.NoteLocation));
                    sb.Append("', REL_X = ");
                    sb.Append(factors[0].ToString(PNStatic.CultureInvariant));
                    sb.Append(", REL_Y = ");
                    sb.Append(factors[1].ToString(PNStatic.CultureInvariant));
                    sb.Append(" WHERE ID = '");
                    sb.Append(note.ID);
                    sb.Append("'");
                    using (var oData = new SQLiteDataObject(PNData.ConnectionString))
                    {
                        oData.Execute(sb.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
Example #2
0
        internal static bool SaveNewNote(PNote note)
        {
            try
            {
                var sb = new StringBuilder();
                note.DateSaved = DateTime.Now;

                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, SCRAMBLED, RECEIVED_IP) VALUES('");
                sb.Append(note.ID);
                sb.Append("', '");
                sb.Append(note.Name.Replace("'", "''"));
                sb.Append("', ");
                sb.Append(note.GroupID);
                sb.Append(", ");
                sb.Append(note.GroupID);   //as prev png
                sb.Append(", ");
                sb.Append(note.Opacity.ToString(PNStatic.CultureInvariant));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.Visible));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.Favorite));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.Protected));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.Completed));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.Priority));
                sb.Append(", '");
                sb.Append(note.PasswordString.Replace("'", "''"));
                sb.Append("', ");
                sb.Append(Convert.ToInt32(note.Pinned));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.Topmost));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.Rolled));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.DockStatus));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.DockOrder));
                sb.Append(", ");
                sb.Append(Convert.ToInt32(note.SentReceived));
                sb.Append(", '");
                sb.Append(note.DateCreated.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', '");
                sb.Append(note.DateSaved.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', '");
                sb.Append(note.DateSent.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', '");
                sb.Append(note.DateReceived.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', '");
                sb.Append(note.DateDeleted.ToString(PNStrings.DATE_TIME_FORMAT, PNStatic.CultureInvariant).Replace("'", "''"));
                sb.Append("', '");
                var sc = new SizeConverter();
                sb.Append(sc.ConvertToString(null, PNStatic.CultureInvariant, note.NoteSize));
                sb.Append("', '");
                var pc = new PointConverter();
                sb.Append(pc.ConvertToString(null, PNStatic.CultureInvariant, note.NoteLocation));
                sb.Append("', '");
                var scd = new System.Drawing.SizeConverter();
                sb.Append(scd.ConvertToString(null, PNStatic.CultureInvariant, note.EditSize));
                sb.Append("', ");
                var factors = getRelationalFactors(note);
                sb.Append(factors[0].ToString(PNStatic.CultureInvariant));
                sb.Append(", ");
                sb.Append(factors[1].ToString(PNStatic.CultureInvariant));
                sb.Append(", '");
                sb.Append(note.SentTo.Replace("'", "''"));
                sb.Append("', '");
                sb.Append(note.ReceivedFrom.Replace("'", "''"));
                sb.Append("', '");
                sb.Append(note.PinClass);
                sb.Append("', '");
                sb.Append(note.PinText);
                sb.Append("', ");
                sb.Append(Convert.ToInt32(note.Scrambled));
                sb.Append(", '");
                sb.Append(note.ReceivedIp);
                sb.Append("'");
                sb.Append(")");
                using (var oData = new SQLiteDataObject(PNData.ConnectionString))
                {
                    oData.Execute(sb.ToString());
                }
                note.FromDB = true;
                if (note.Skinless != null)
                {
                    SaveNoteSkinless(note);
                }
                return true;
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return false;
            }
        }
Example #3
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType != typeof (string)) return base.ConvertTo(context, culture, value, destinationType);
            var note = value as PNote;
            if (note == null) return "";
            var bt = new StringBuilder();
            var dtc = new DateTimeConverter();
            var szc = new SizeConverter();
            var scd = new System.Drawing.SizeConverter();
            var ptc = new PointConverter();
            var scv = new ScheduleConverter();
            var skc = new SkinlessConverter();
            var sb = new StringBuilder();

            sb.Append(note.Changed);
            sb.Append(DEL_NOTE);
            sb.Append(note.Completed);
            sb.Append(DEL_NOTE);
            sb.Append(note.CustomOpacity);
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateCreated));
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateDeleted));
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateReceived));
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateSaved));
            sb.Append(DEL_NOTE);
            sb.Append(dtc.ConvertToString(null, PNStatic.CultureInvariant, note.DateSent));
            sb.Append(DEL_NOTE);
            sb.Append((int)note.DockStatus);
            sb.Append(DEL_NOTE);
            sb.Append(scd.ConvertToString(null, PNStatic.CultureInvariant, note.EditSize));
            sb.Append(DEL_NOTE);
            sb.Append(note.Favorite);
            sb.Append(DEL_NOTE);
            sb.Append(note.FromDB);
            sb.Append(DEL_NOTE);
            sb.Append(note.GroupID);
            sb.Append(DEL_NOTE);
            sb.Append(note.ID);
            sb.Append(DEL_NOTE);
            foreach (var s in note.LinkedNotes)
            {
                bt.Append(s);
                bt.Append(DEL_INNER);
            }
            if (bt.Length > 0)
                bt.Length -= 1;
            sb.Append(bt);
            sb.Append(DEL_NOTE);
            sb.Append(note.Name);
            sb.Append(DEL_NOTE);
            sb.Append(ptc.ConvertToString(null, PNStatic.CultureInvariant, note.NoteLocation));
            sb.Append(DEL_NOTE);
            sb.Append(szc.ConvertToString(null, PNStatic.CultureInvariant, note.NoteSize));
            sb.Append(DEL_NOTE);
            sb.Append(note.Opacity.ToString(PNStatic.CultureInvariant));
            sb.Append(DEL_NOTE);
            sb.Append(note.PasswordString);
            sb.Append(DEL_NOTE);
            sb.Append(note.Pinned);
            sb.Append(DEL_NOTE);
            sb.Append(note.PrevGroupID);
            sb.Append(DEL_NOTE);
            sb.Append(note.Priority);
            sb.Append(DEL_NOTE);
            sb.Append(note.Protected);
            sb.Append(DEL_NOTE);
            sb.Append(note.ReceivedFrom);
            sb.Append(DEL_NOTE);
            sb.Append(note.Rolled);
            sb.Append(DEL_NOTE);
            sb.Append(scv.ConvertToString(note.Schedule));
            sb.Append(DEL_NOTE);
            sb.Append((int)note.SentReceived);
            sb.Append(DEL_NOTE);
            sb.Append(note.SentTo);
            sb.Append(DEL_NOTE);
            sb.Append(note.Skin != null ? note.Skin.SkinName : "");
            sb.Append(DEL_NOTE);
            sb.Append(note.Skinless != null ? skc.ConvertToString(note.Skinless) : "");
            sb.Append(DEL_NOTE);
            bt = new StringBuilder();
            foreach (var s in note.Tags)
            {
                bt.Append(s);
                bt.Append(DEL_INNER);
            }
            if (bt.Length > 0)
                bt.Length -= 1;
            sb.Append(bt);
            sb.Append(DEL_NOTE);
            sb.Append(note.Topmost);
            sb.Append(DEL_NOTE);
            sb.Append(note.Visible);
            sb.Append(DEL_NOTE);
            sb.Append(note.XFactor.ToString(PNStatic.CultureInvariant));
            sb.Append(DEL_NOTE);
            sb.Append(note.YFactor.ToString(PNStatic.CultureInvariant));
            sb.Append(DEL_NOTE);
            sb.Append(note.PinClass);
            sb.Append(DEL_NOTE);
            sb.Append(note.PinText);
            return sb.ToString();
        }
Example #4
0
        internal static void SaveCPProperties()
        {
            try
            {
                var crc = new ColorConverter();
                var sb = new StringBuilder();
                var sc = new SizeConverter();
                var pc = new PointConverter();

                var pcf = PNStatic.Settings.Config;
                sb.Append("UPDATE CONFIG SET CP_LAST_GROUP = ");
                sb.Append(pcf.CPLastGroup);
                sb.Append(",CP_PVW_COLOR = '");
                sb.Append(crc.ConvertToString(null, PNStatic.CultureInvariant, pcf.CPPvwColor));
                sb.Append("',CP_USE_CUST_PVW_COLOR = ");
                sb.Append(Convert.ToInt32(pcf.CPUseCustPvwColor));
                sb.Append(",CP_SIZE = '");
                sb.Append(sc.ConvertToString(null, PNStatic.CultureInvariant, pcf.CPSize));
                sb.Append("',CP_LOCATION = '");
                sb.Append(pc.ConvertToString(null, PNStatic.CultureInvariant, pcf.CPLocation));
                sb.Append("',CP_PVW_RIGHT = ");
                sb.Append(Convert.ToInt32(pcf.CPPvwRight));
                sb.Append(",CP_PVW_SHOW = ");
                sb.Append(Convert.ToInt32(pcf.CPPvwShow));
                sb.Append(",CP_GROUPS_SHOW = ");
                sb.Append(Convert.ToInt32(pcf.CPGroupsShow));
                ExecuteTransactionForStringBuilder(sb, SettingsConnectionString);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
        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;
            }
        }