internal static void NormalizeCustomNotesTable(SQLiteDataObject oData) { try { var listSql = new List<string>(); var lfc = new LogFontConverter(); var wfc = new WPFFontConverter(); var drawingColorConverter = new System.Drawing.ColorConverter(); var mediaColorConverter = new ColorConverter(); using ( var t = oData.FillDataTable( "SELECT NOTE_ID, CAPTION_FONT FROM CUSTOM_NOTES_SETTINGS WHERE CAPTION_FONT LIKE '%^%'")) { foreach (DataRow r in t.Rows) { var lf = lfc.ConvertFromString((string)r["CAPTION_FONT"]); var fnt = PNStatic.FromLogFont(lf); var sb = new StringBuilder("UPDATE CUSTOM_NOTES_SETTINGS SET CAPTION_FONT = '"); sb.Append(wfc.ConvertToString(null, PNStatic.CultureInvariant, fnt)); sb.Append("' WHERE NOTE_ID = "); sb.Append(r["NOTE_ID"]); listSql.Add(sb.ToString()); } } using (var t = oData.FillDataTable("SELECT NOTE_ID, BACK_COLOR, CAPTION_FONT_COLOR FROM CUSTOM_NOTES_SETTINGS")) { var backColors = new List<TempColor>(); var capColors = new List<TempColor>(); foreach (DataRow r in t.Rows) { if (!IsDBNull(r["BACK_COLOR"])) backColors.Add(new TempColor { Color = Convert.ToString(r["BACK_COLOR"]), Id = Convert.ToString(r["NOTE_ID"]) }); if (!IsDBNull(r["CAPTION_FONT_COLOR"])) capColors.Add(new TempColor { Color = Convert.ToString(r["CAPTION_FONT_COLOR"]), Id = Convert.ToString(r["NOTE_ID"]) }); } foreach (var cr in backColors.Where(c => !IsMediaColor(c.Color))) { var convertFromString = drawingColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, cr.Color); if (convertFromString == null) continue; var clr = (System.Drawing.Color)convertFromString; var color = Color.FromArgb(clr.A, clr.R, clr.G, clr.B); var sb = new StringBuilder("UPDATE CUSTOM_NOTES_SETTINGS SET BACK_COLOR = '"); sb.Append(mediaColorConverter.ConvertToString(null, PNStatic.CultureInvariant, color)); sb.Append("' WHERE NOTE_ID = "); sb.Append(cr.Id); listSql.Add(sb.ToString()); } foreach (var cr in capColors.Where(c => !IsMediaColor(c.Color))) { var convertFromString = drawingColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, cr.Color); if (convertFromString == null) continue; var clr = (System.Drawing.Color)convertFromString; var color = Color.FromArgb(clr.A, clr.R, clr.G, clr.B); var sb = new StringBuilder("UPDATE CUSTOM_NOTES_SETTINGS SET CAPTION_FONT_COLOR = '"); sb.Append(mediaColorConverter.ConvertToString(null, PNStatic.CultureInvariant, color)); sb.Append("' WHERE NOTE_ID = "); sb.Append(cr.Id); listSql.Add(sb.ToString()); } } if (listSql.Count == 0) return; ExecuteTransactionForList(listSql, ConnectionString); } catch (Exception ex) { PNStatic.LogException(ex); } }
internal static void InsertNewGroup(PNGroup group) { try { var c = new ColorConverter(); var drcc = new System.Drawing.ColorConverter(); var wfc = new WPFFontConverter(); var lfc = new LogFontConverter(); var sb = new StringBuilder(); sb.Append("INSERT INTO GROUPS (GROUP_ID, PARENT_ID, GROUP_NAME, ICON, BACK_COLOR, CAPTION_FONT_COLOR, CAPTION_FONT, SKIN_NAME, PASSWORD_STRING, FONT, FONT_COLOR, IS_DEFAULT_IMAGE) VALUES("); sb.Append(group.ID); sb.Append(","); sb.Append(group.ParentID); sb.Append(",'"); sb.Append(group.Name.Replace("'", "''")); sb.Append("','"); if (!group.IsDefaultImage) { var base64String = Convert.ToBase64String(group.Image.ToBytes()); sb.Append(base64String); } else { sb.Append(group.ImageName); sb.Append(".png"); } //using (var ms = new MemoryStream(1)) //{ // group.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // ms.Position = 0; // string base64String = Convert.ToBase64String(ms.ToArray()); // sb.Append(base64String); //} sb.Append("','"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, group.Skinless.BackColor)); sb.Append("','"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, group.Skinless.CaptionColor)); sb.Append("','"); sb.Append(wfc.ConvertToString(group.Skinless.CaptionFont)); sb.Append("','"); sb.Append(group.Skin.SkinName); sb.Append("','"); sb.Append(group.PasswordString); sb.Append("','"); sb.Append(lfc.ConvertToString(group.Font)); sb.Append("','"); sb.Append(drcc.ConvertToString(null, PNStatic.CultureInvariant, group.FontColor)); sb.Append("', "); sb.Append(Convert.ToInt32(group.IsDefaultImage)); sb.Append("); "); if (ExecuteTransactionForStringBuilder(sb, ConnectionString)) { sb = new StringBuilder(); var id = HK_START; using (var oData = new SQLiteDataObject(ConnectionString)) { var o = oData.GetScalar("SELECT MAX(ID) FROM HOT_KEYS"); if (o != null && !DBNull.Value.Equals(o)) { id = (int)(long)o + 1; } } var prefix = group.ID + "_show"; sb.Append("INSERT INTO HOT_KEYS (HK_TYPE, MENU_NAME, ID, SHORTCUT) VALUES("); sb.Append(((int)HotkeyType.Group).ToString(PNStatic.CultureInvariant)); sb.Append(",'"); sb.Append(prefix); sb.Append("',"); sb.Append(id.ToString(PNStatic.CultureInvariant)); sb.Append(",'');"); if (ExecuteTransactionForStringBuilder(sb, ConnectionString)) { PNStatic.HotKeysGroups.Add(new PNHotKey { MenuName = prefix, ID = id, Type = HotkeyType.Group }); } sb = new StringBuilder(); id++; prefix = group.ID + "_hide"; sb.Append("INSERT INTO HOT_KEYS (HK_TYPE, MENU_NAME, ID, SHORTCUT) VALUES("); sb.Append(((int)HotkeyType.Group).ToString(PNStatic.CultureInvariant)); sb.Append(",'"); sb.Append(prefix); sb.Append("',"); sb.Append(id.ToString(PNStatic.CultureInvariant)); sb.Append(",'');"); if (ExecuteTransactionForStringBuilder(sb, ConnectionString)) { PNStatic.HotKeysGroups.Add(new PNHotKey { MenuName = prefix, ID = id, Type = HotkeyType.Group }); } } } catch (Exception ex) { PNStatic.LogException(ex); } }
internal static void NormalizeGroupsTable(SQLiteDataObject oData, bool updateIcons = true) { try { var listSql = new List<string>(); var lfc = new LogFontConverter(); var wfc = new WPFFontConverter(); var drawingColorConverter = new System.Drawing.ColorConverter(); var mediaColorConverter = new ColorConverter(); if (updateIcons) { using ( var t = oData.FillDataTable( "SELECT GROUP_ID, ICON FROM GROUPS WHERE ICON NOT LIKE '%.png' OR ICON LIKE 'resource.%'") ) { foreach (DataRow r in t.Rows) { var sb = new StringBuilder("UPDATE GROUPS SET "); var icon = Convert.ToString(r["ICON"]); if (icon.StartsWith("resource.")) { var imageName = icon.Substring("resource.".Length); imageName = imageName + ".png"; sb.Append("ICON = '"); sb.Append(imageName); sb.Append("'"); } else { sb.Append("IS_DEFAULT_IMAGE = 0"); } sb.Append(" WHERE GROUP_ID = "); sb.Append(r["GROUP_ID"]); listSql.Add(sb.ToString()); } } } using ( var t = oData.FillDataTable( "SELECT GROUP_ID, CAPTION_FONT FROM GROUPS WHERE CAPTION_FONT LIKE '%^%'")) { foreach (DataRow r in t.Rows) { var lf = lfc.ConvertFromString((string)r["CAPTION_FONT"]); var fnt = PNStatic.FromLogFont(lf); var sb = new StringBuilder("UPDATE GROUPS SET CAPTION_FONT = '"); sb.Append(wfc.ConvertToString(null, PNStatic.CultureInvariant, fnt)); sb.Append("' WHERE GROUP_ID = "); sb.Append(r["GROUP_ID"]); listSql.Add(sb.ToString()); } } using (var t = oData.FillDataTable("SELECT GROUP_ID, BACK_COLOR, CAPTION_FONT_COLOR FROM GROUPS")) { var backColors = new List<TempColor>(); var capColors = new List<TempColor>(); foreach (DataRow r in t.Rows) { if (!IsDBNull(r["BACK_COLOR"])) backColors.Add(new TempColor { Color = Convert.ToString(r["BACK_COLOR"]), Id = Convert.ToString(r["GROUP_ID"]) }); if (!IsDBNull(r["CAPTION_FONT_COLOR"])) capColors.Add(new TempColor { Color = Convert.ToString(r["CAPTION_FONT_COLOR"]), Id = Convert.ToString(r["GROUP_ID"]) }); } foreach (var cr in backColors.Where(c => !IsMediaColor(c.Color))) { var convertFromString = drawingColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, cr.Color); if (convertFromString == null) continue; var clr = (System.Drawing.Color)convertFromString; var color = Color.FromArgb(clr.A, clr.R, clr.G, clr.B); var sb = new StringBuilder("UPDATE GROUPS SET BACK_COLOR = '"); sb.Append(mediaColorConverter.ConvertToString(null, PNStatic.CultureInvariant, color)); sb.Append("' WHERE GROUP_ID = "); sb.Append(cr.Id); listSql.Add(sb.ToString()); } foreach (var cr in capColors.Where(c => !IsMediaColor(c.Color))) { var convertFromString = drawingColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, cr.Color); if (convertFromString == null) continue; var clr = (System.Drawing.Color)convertFromString; var color = Color.FromArgb(clr.A, clr.R, clr.G, clr.B); var sb = new StringBuilder("UPDATE GROUPS SET CAPTION_FONT_COLOR = '"); sb.Append(mediaColorConverter.ConvertToString(null, PNStatic.CultureInvariant, color)); sb.Append("' WHERE GROUP_ID = "); sb.Append(cr.Id); listSql.Add(sb.ToString()); } } if (listSql.Count == 0) return; ExecuteTransactionForList(listSql, ConnectionString); } catch (Exception ex) { PNStatic.LogException(ex); } }
internal static void SaveGroupChanges(PNGroup group) { try { var c = new ColorConverter(); var dcc = new System.Drawing.ColorConverter(); var lfc = new LogFontConverter(); var wfc = new WPFFontConverter(); var sb = new StringBuilder(); sb.Append("UPDATE GROUPS SET GROUP_NAME = '"); sb.Append(group.Name.Replace("'", "''")); sb.Append("', PARENT_ID = "); sb.Append(group.ParentID); sb.Append(", ICON = "); if (group.Image != null) { sb.Append("'"); if (!group.IsDefaultImage) { var base64String = Convert.ToBase64String(group.Image.ToBytes()); sb.Append(base64String); } else { sb.Append(group.ImageName); sb.Append(".png"); } //using (var ms = new MemoryStream(1)) //{ // group.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // ms.Position = 0; // string base64String = Convert.ToBase64String(ms.ToArray()); // sb.Append(base64String); //} sb.Append("',"); } else { sb.Append("NULL,"); } sb.Append(" BACK_COLOR = '"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, group.Skinless.BackColor)); sb.Append("', CAPTION_FONT_COLOR = '"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, group.Skinless.CaptionColor)); sb.Append("', CAPTION_FONT = '"); sb.Append(wfc.ConvertToString(group.Skinless.CaptionFont)); sb.Append("', SKIN_NAME = '"); sb.Append(group.Skin.SkinName.Replace("'", "''")); sb.Append("', FONT_COLOR = '"); sb.Append(dcc.ConvertToString(null, PNStatic.CultureInvariant, group.FontColor)); sb.Append("', FONT = '"); sb.Append(lfc.ConvertToString(group.Font)); sb.Append("', IS_DEFAULT_IMAGE = "); sb.Append(Convert.ToInt32(group.IsDefaultImage)); sb.Append(" WHERE GROUP_ID = "); sb.Append(group.ID); ExecuteTransactionForStringBuilder(sb, ConnectionString); } catch (Exception ex) { PNStatic.LogException(ex); } }
private void fillGroup(PNGroup gr, DataRow r) { try { var c = new ColorConverter(); var wfc = new WPFFontConverter(); var lfc = new LogFontConverter(); var dcc = new System.Drawing.ColorConverter(); gr.ID = (int)r["GROUP_ID"]; gr.ParentID = (int)r["PARENT_ID"]; gr.Name = (string)r["GROUP_NAME"]; gr.PasswordString = (string)r["PASSWORD_STRING"]; gr.IsDefaultImage = (bool)r["IS_DEFAULT_IMAGE"]; if (!PNData.IsDBNull(r["ICON"])) { var base64String = (string)r["ICON"]; if (!base64String.EndsWith(PNStrings.PNG_EXT)) { try { var buffer = Convert.FromBase64String(base64String); if (gr.ID.In((int)SpecialGroups.AllGroups, 0, (int)SpecialGroups.Diary, (int)SpecialGroups.Backup, (int)SpecialGroups.SearchResults, (int)SpecialGroups.Favorites, (int)SpecialGroups.Incoming, (int)SpecialGroups.Docking, (int)SpecialGroups.RecycleBin) || base64String.StartsWith("resource.")) { //possible image data stored as string when data directory just copied into new edition folder upgradeGroupIcon(gr, gr.ID, (string)r["ICON"]); } else { using (var ms = new MemoryStream(buffer)) { ms.Position = 0; gr.Image = new BitmapImage(); gr.Image.BeginInit(); gr.Image.CacheOption = BitmapCacheOption.OnLoad; gr.Image.StreamSource = ms; gr.Image.EndInit(); } if (gr.IsDefaultImage) { gr.IsDefaultImage = false; var sb = new StringBuilder("UPDATE GROUPS SET IS_DEFAULT_IMAGE = 0"); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } } } catch (FormatException) { //possible exception when data directory just copied into new edition folder upgradeGroupIcon(gr, gr.ID, (string)r["ICON"]); } } else { gr.Image = TryFindResource(Path.GetFileNameWithoutExtension(base64String)) as BitmapImage;// new BitmapImage(new Uri(base64String)); } } try { var clr = c.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["BACK_COLOR"]); if (clr != null) gr.Skinless.BackColor = (Color)clr; } catch (FormatException) { //possible FormatException after synchronization with old database var clr = dcc.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["BACK_COLOR"]); if (clr != null) { var drawingColor = (System.Drawing.Color)clr; gr.Skinless.BackColor = Color.FromArgb(drawingColor.A, drawingColor.R, drawingColor.G, drawingColor.B); var sb = new StringBuilder("UPDATE GROUPS SET BACK_COLOR = '"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, gr.Skinless.BackColor)); sb.Append("' WHERE GROUP_ID = "); sb.Append(gr.ID); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } } try { var clr = c.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["CAPTION_FONT_COLOR"]); if (clr != null) gr.Skinless.CaptionColor = (Color)clr; } catch (FormatException) { //possible FormatException after synchronization with old database var clr = dcc.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["CAPTION_FONT_COLOR"]); if (clr != null) { var drawingColor = (System.Drawing.Color)clr; gr.Skinless.CaptionColor = Color.FromArgb(drawingColor.A, drawingColor.R, drawingColor.G, drawingColor.B); var sb = new StringBuilder("UPDATE GROUPS SET CAPTION_FONT_COLOR = '"); sb.Append(c.ConvertToString(null, PNStatic.CultureInvariant, gr.Skinless.CaptionColor)); sb.Append("' WHERE GROUP_ID = "); sb.Append(gr.ID); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } } var fontString = (string)r["CAPTION_FONT"]; //try //{ var fonts = new InstalledFontCollection(); var arr = fontString.Split(','); if (fontString.Any(ch => ch == '^')) { //old format font string var lf = lfc.ConvertFromString(fontString); gr.Skinless.CaptionFont = PNStatic.FromLogFont(lf); var sb = new StringBuilder("UPDATE GROUPS SET CAPTION_FONT = '"); sb.Append(wfc.ConvertToString(null, PNStatic.CultureInvariant, gr.Skinless.CaptionFont)); sb.Append("' WHERE GROUP_ID = "); sb.Append(gr.ID); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } else if (fonts.Families.Any(ff => ff.Name == arr[0])) { //normal font string gr.Skinless.CaptionFont = (PNFont)wfc.ConvertFromString(fontString); } else { //possible not existing font name arr[0] = PNStrings.DEF_CAPTION_FONT; fontString = string.Join(",", arr); gr.Skinless.CaptionFont = (PNFont)wfc.ConvertFromString(fontString); var sb = new StringBuilder("UPDATE GROUPS SET CAPTION_FONT = '"); sb.Append(fontString); sb.Append("' WHERE GROUP_ID = "); sb.Append(gr.ID); PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); } //} //catch (IndexOutOfRangeException) //{ // //possible IndexOutOfRangeException after synchronization with old database // var lf = lfc.ConvertFromString(fontString); // gr.Skinless.CaptionFont = PNStatic.FromLogFont(lf); // var sb = new StringBuilder("UPDATE GROUPS SET CAPTION_FONT = '"); // sb.Append(wfc.ConvertToString(null, PNStatic.CultureInvariant, gr.Skinless.CaptionFont)); // sb.Append("' WHERE GROUP_ID = "); // sb.Append(gr.ID); // PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString); //} var skinName = (string)r["SKIN_NAME"]; if (skinName != PNSkinDetails.NO_SKIN) { gr.Skin.SkinName = skinName; //load skin var path = Path.Combine(PNPaths.Instance.SkinsDir, gr.Skin.SkinName) + ".pnskn"; if (File.Exists(path)) { PNSkinsOperations.LoadSkin(path, gr.Skin); } } if (!PNData.IsDBNull(r["FONT"])) { gr.Font = lfc.ConvertFromString((string)r["FONT"]); } if (!PNData.IsDBNull(r["FONT_COLOR"])) { var clr = dcc.ConvertFromString(null, PNStatic.CultureInvariant, (string)r["FONT_COLOR"]); if (clr != null) gr.FontColor = (System.Drawing.Color)clr; } } catch (Exception ex) { PNStatic.LogException(ex); } }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var str = value as string; if (str == null) return base.ConvertFrom(context, culture, value); var skl = new PNSkinlessDetails(); var values = str.Split(DEL_INNER); if (values.Length != 3) return skl; var cr = new ColorConverter(); var wpfFontConverter = new WPFFontConverter(); var lfc = new LogFontConverter(); object convertFromString; try { convertFromString = cr.ConvertFromString(null, PNStatic.CultureInvariant, values[0]); if (convertFromString != null) skl.BackColor = (Color)convertFromString; } catch (FormatException) { var drawingColorConverter = new System.Drawing.ColorConverter(); convertFromString = drawingColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, values[0]); if (convertFromString != null) { var clr = (System.Drawing.Color)convertFromString; skl.BackColor = Color.FromArgb(clr.A, clr.R, clr.G, clr.B); } } try { convertFromString = cr.ConvertFromString(null, PNStatic.CultureInvariant, values[1]); if (convertFromString != null) skl.CaptionColor = (Color)convertFromString; } catch (FormatException) { var drawingColorConverter = new System.Drawing.ColorConverter(); convertFromString = drawingColorConverter.ConvertFromString(null, PNStatic.CultureInvariant, values[1]); if (convertFromString != null) { var clr = (System.Drawing.Color)convertFromString; skl.CaptionColor = Color.FromArgb(clr.A, clr.R, clr.G, clr.B); } } if (values[2].Any(c => c == '^')) { var logFont = lfc.ConvertFromString(values[2]); skl.CaptionFont = PNStatic.FromLogFont(logFont); } else { skl.CaptionFont = (PNFont) wpfFontConverter.ConvertFromString(values[2]); } return skl; }
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; } }