コード例 #1
0
 internal WndNewGroup(PNGroup group, PNTreeItem treeItem)
     : this()
 {
     if (group != null)
     {
         m_Group = (PNGroup)group.Clone();
         m_Mode = AddEditMode.Edit;
     }
     else
     {
         m_Group = new PNGroup {IsDefaultImage = true};
     }
     _TreeItem=treeItem;
 }
コード例 #2
0
 private static void groupShowHide(PNGroup group, bool show)
 {
     try
     {
         ShowHideSpecificGroup(group.ID, show);
         foreach (var g in group.Subgroups)
         {
             groupShowHide(g, show);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #3
0
ファイル: WndCP.xaml.cs プロジェクト: hyrmedia/PNotes.NET
 private void updateNotesAfterGroupPasswordChange(PNGroup group)
 {
     try
     {
         var notes = PNStatic.Notes.Where(n => n.GroupID == group.ID).ToArray();
         foreach (var note in notes)
         {
             var cpn = _Notes.FirstOrDefault(n => n.Id == note.ID);
             if (cpn == null) continue;
             cpn.Password = note.PasswordString != ""
                     ? PasswordProtectionMode.Note
                     : (group.PasswordString != ""
                         ? PasswordProtectionMode.Group
                         : PasswordProtectionMode.None);
             cpn.Content = getNoteContent(note);
             var selectedNote = getSelectedNote();
             if (selectedNote != null && selectedNote.ID == cpn.Id)
             {
                 loadNotePreview(selectedNote);
             }
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #4
0
 internal static void ChangeNoteLookOnGroupChange(WndNote wnd, PNGroup group)
 {
     try
     {
         if (!PNStatic.Settings.GeneralSettings.UseSkins)
         {
             wnd.Background =
                 new SolidColorBrush(group.Skinless.BackColor);
             wnd.PHeader.SetPNFont(group.Skinless.CaptionFont);
             wnd.Foreground =
                 new SolidColorBrush(group.Skinless.CaptionColor);
         }
         else
         {
             var note = PNStatic.Notes.Note(wnd.Handle);
             if (note != null && note.Skin == null)
             {
                 PNSkinsOperations.ApplyNoteSkin(wnd, note);
             }
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #5
0
        private void addGroupToTree(PNGroup group, PNTreeItem node)
        {
            try
            {
                var temp = (PNGroup)group.Clone();
                group.CopyTo(temp);

                var n = new PNTreeItem(temp.Image, temp.Name, temp);
                if (node == null)
                {
                    tvwGroups.Items.Add(n);
                }
                else
                {
                    node.Items.Add(n);
                }
                foreach (var g in group.Subgroups.OrderBy(gr => gr.Name))
                {
                    addGroupToTree(g, n);
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #6
0
ファイル: PNData.cs プロジェクト: hyrmedia/PNotes.NET
 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);
     }
 }
コード例 #7
0
ファイル: PNData.cs プロジェクト: hyrmedia/PNotes.NET
 internal static void SaveGroupNewParent(PNGroup group)
 {
     try
     {
         var sb = new StringBuilder();
         sb.Append("UPDATE GROUPS SET PARENT_ID = ");
         sb.Append(group.ParentID);
         sb.Append(" WHERE GROUP_ID = ");
         sb.Append(group.ID);
         ExecuteTransactionForStringBuilder(sb, ConnectionString);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #8
0
ファイル: WndMain.xaml.cs プロジェクト: hyrmedia/PNotes.NET
 private void upgradeGroupIcon(PNGroup gr, int groupId, string iconString)
 {
     try
     {
         var sb = new StringBuilder("UPDATE GROUPS SET ICON = ");
         string groupIcon;
         switch (groupId)
         {
             case (int)SpecialGroups.AllGroups:
                 groupIcon = "gr_all.png";
                 break;
             case 0:
                 groupIcon = "gr.png";
                 break;
             case (int)SpecialGroups.Diary:
                 groupIcon = "gr_diary.png";
                 break;
             case (int)SpecialGroups.SearchResults:
                 groupIcon = "gr_search.png";
                 break;
             case (int)SpecialGroups.Backup:
                 groupIcon = "gr_back.png";
                 break;
             case (int)SpecialGroups.Favorites:
                 groupIcon = "gr_fav.png";
                 break;
             case (int)SpecialGroups.Incoming:
                 groupIcon = "gr_inc.png";
                 break;
             case (int)SpecialGroups.Docking:
                 groupIcon = "dockall.png";
                 break;
             case (int)SpecialGroups.RecycleBin:
                 groupIcon = "gr_bin.png";
                 break;
             default:
                 if (iconString.StartsWith("resource."))
                 {
                     groupIcon = iconString.Substring("resource.".Length);
                     groupIcon += ".png";
                 }
                 else
                 {
                     return;
                 }
                 break;
         }
         sb.Append("'");
         sb.Append(groupIcon);
         sb.Append("', IS_DEFAULT_IMAGE = 1");
         sb.Append(" WHERE GROUP_ID = ");
         sb.Append(groupId);
         PNData.ExecuteTransactionForStringBuilder(sb, PNData.ConnectionString);
         gr.Image = TryFindResource(Path.GetFileNameWithoutExtension(groupIcon)) as BitmapImage;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #9
0
ファイル: PNClasses.cs プロジェクト: hyrmedia/PNotes.NET
        internal void CopyTo(PNGroup pg)
        {
            var changed = (pg._Skinless != _Skinless);
            var changedBackColor = (pg._Skinless.BackColor != _Skinless.BackColor);
            var changedCaptionFont = (!pg._Skinless.CaptionFont.Equals(_Skinless.CaptionFont));
            var changedCaptionColor = (pg._Skinless.CaptionColor != _Skinless.CaptionColor);

            pg._Skinless = (PNSkinlessDetails)_Skinless.Clone();
            if (changed && pg.GroupPropertyChanged != null)
            {
                if (changedBackColor)
                {
                    pg.GroupPropertyChanged(pg, new GroupPropertyChangedEventArgs(pg._Skinless.BackColor, GroupChangeType.BackColor));
                }
                if (changedCaptionFont)
                {
                    pg.GroupPropertyChanged(pg, new GroupPropertyChangedEventArgs(pg._Skinless.CaptionFont, GroupChangeType.CaptionFont));
                }
                if (changedCaptionColor)
                {
                    pg.GroupPropertyChanged(pg, new GroupPropertyChangedEventArgs(pg._Skinless.CaptionColor, GroupChangeType.CaptionColor));
                }
            }
            changed = (pg._Skin.SkinName != _Skin.SkinName);
            pg._Skin.Dispose();
            pg._Skin = _Skin.PNClone();
            if (changed && pg.GroupPropertyChanged != null)
            {
                pg.GroupPropertyChanged(pg, new GroupPropertyChangedEventArgs(pg._Skin.SkinName, GroupChangeType.Skin));
            }
            changed = (!pg._Font.Equals(_Font));
            pg._Font = _Font;
            if (changed && pg.GroupPropertyChanged != null)
            {
                pg.GroupPropertyChanged(pg, new GroupPropertyChangedEventArgs(pg._Font, GroupChangeType.Font));
            }
            changed = (pg._FontColor != _FontColor);
            pg._FontColor = _FontColor;
            if (changed && pg.GroupPropertyChanged != null)
            {
                pg.GroupPropertyChanged(pg, new GroupPropertyChangedEventArgs(pg._FontColor, GroupChangeType.FontColor));
            }
            changed = (!pg.Image.Equals(Image));
            pg.Image = Image.Clone();
            pg.IsDefaultImage = IsDefaultImage;
            if (changed && pg.GroupPropertyChanged != null)
            {
                pg.GroupPropertyChanged(pg, new GroupPropertyChangedEventArgs(pg.Image, GroupChangeType.Image));
            }
        }
コード例 #10
0
ファイル: PNClasses.cs プロジェクト: hyrmedia/PNotes.NET
 private PNGroup subGroupByID(PNGroup parent, int id)
 {
     foreach (var g in parent._Subgroups)
     {
         if (g._Id == id)
         {
             return g;
         }
         var result = subGroupByID(g, id);
         if (result != null)
         {
             return result;
         }
     }
     return null;
 }
コード例 #11
0
ファイル: PNClasses.cs プロジェクト: hyrmedia/PNotes.NET
 public object Clone()
 {
     var g = new PNGroup
     {
         _Skinless = (PNSkinlessDetails)_Skinless.Clone(),
         _Skin = _Skin.PNClone(),
         _PasswordString = _PasswordString,
         _ParentID = _ParentID,
         _Name = _Name,
         _Id = _Id,
         _FontColor = _FontColor,
         Image = Image.Clone(),
         IsDefaultImage = IsDefaultImage,
         _Font = _Font
     };
     return g;
 }
コード例 #12
0
ファイル: WndCP.xaml.cs プロジェクト: hyrmedia/PNotes.NET
        private void loadGroups(PNGroup group, PNTreeItem local, bool byUser = false)
        {
            try
            {
                int count;
                switch (group.ID)
                {
                    case (int)SpecialGroups.AllGroups:
                        count = PNStatic.Notes.Count(nt => nt.GroupID != (int)SpecialGroups.RecycleBin);
                        break;
                    case (int)SpecialGroups.Favorites:
                        count = PNStatic.Notes.Count(nt => nt.Favorite && nt.GroupID != (int)SpecialGroups.RecycleBin);
                        break;
                    case (int)SpecialGroups.Backup:
                        var di = new DirectoryInfo(PNPaths.Instance.BackupDir);
                        var fis = di.GetFiles("*" + PNStrings.NOTE_BACK_EXTENSION);
                        count =
                            fis.Count(
                                f =>
                                    PNStatic.Notes.Any(
                                        n =>
                                            n.ID ==
                                            Path.GetFileNameWithoutExtension(f.Name)
                                                .Substring(0, Path.GetFileNameWithoutExtension(f.Name).IndexOf('_'))));
                        break;
                    default:
                        count = PNStatic.Notes.Count(nt => nt.GroupID == group.ID);
                        break;
                }

                PNTreeItem pnTreeItem;
                if (group.IsDefaultImage)
                {
                    pnTreeItem = group.PasswordString == ""
                        ? new PNTreeItem(group.ImageName,
                            group.Name + " (" + count + ")", group) { IsExpanded = true }
                        : new PNTreeItem(group.ImageName,
                            group.Name + " (" + count + ") ***", group) { IsExpanded = true };
                }
                else
                {
                    pnTreeItem = group.PasswordString == ""
                       ? new PNTreeItem(group.Image, group.Name + " (" + count + ")", group) { IsExpanded = true }
                       : new PNTreeItem(group.Image, group.Name + " (" + count + ") ***", group) { IsExpanded = true };
                }

                foreach (var chg in group.Subgroups.OrderBy(g => g.Name))
                {
                    loadGroups(chg, pnTreeItem);
                }

                if (local == null)
                {
                    _PGroups.Add(pnTreeItem);
                }
                else
                {
                    if (!byUser)
                    {
                        local.Items.Add(pnTreeItem);
                    }
                    else
                    {
                        insertGroup(group, local, pnTreeItem);
                    }
                }
                if (group.ID == PNStatic.Settings.Config.CPLastGroup)
                    pnTreeItem.IsSelected = true;
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #13
0
ファイル: WndCP.xaml.cs プロジェクト: hyrmedia/PNotes.NET
 private void collectAllBranchIds(PNGroup parentGroup, List<int> ids)
 {
     try
     {
         foreach (var g in parentGroup.Subgroups)
         {
             collectAllBranchIds(g, ids);
         }
         ids.Add(parentGroup.ID);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #14
0
ファイル: WndCP.xaml.cs プロジェクト: hyrmedia/PNotes.NET
        private void deleteGroupOnDrop(PNGroup pnGroup, PNTreeItem itemToDelete = null)
        {
            try
            {
                var message = PNLang.Instance.GetMessageText("delete_group_warning", "Are you sure you want to delete this group - " + PNStrings.PLACEHOLDER1 + " - and all included subgroups and notes?");
                message = message.Replace(PNStrings.PLACEHOLDER1, pnGroup.Name);
                if (PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) !=
                    MessageBoxResult.Yes) return;
                var groupsIds = new List<int>();
                var notesIds = new List<string>();
                deleteGroup(pnGroup, groupsIds, notesIds);
                var parent = PNStatic.Groups.GetGroupByID(pnGroup.ParentID);
                if (parent != null)
                {
                    parent.Subgroups.RemoveAll(g => g.ID == pnGroup.ID);
                }
                PNStatic.Groups.RemoveAll(g => g.ID == pnGroup.ID);

                if (groupsIds.Count > 0)
                {
                    PNData.DeleteGroups(groupsIds);
                }
                foreach (var id in notesIds)
                {
                    var note = PNStatic.Notes.Note(id);
                    deleteNote(note, note.FromDB ? NoteDeleteType.Bin : NoteDeleteType.Complete);
                }

                if (itemToDelete == null) return;
                if (itemToDelete.ItemParent == null)
                {
                    _PGroups.Remove(itemToDelete);
                }
                else
                {
                    itemToDelete.ItemParent.Items.Remove(itemToDelete);
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #15
0
ファイル: WndCP.xaml.cs プロジェクト: hyrmedia/PNotes.NET
 private void deleteGroup(PNGroup group, List<int> groupsIds, List<string> notesIds)
 {
     try
     {
         groupsIds.Add(group.ID);
         //collect all notes belong to png
         notesIds.AddRange(PNStatic.Notes.Where(n => n.GroupID == group.ID).Select(n => n.ID));
         for (var i = group.Subgroups.Count - 1; i >= 0; i--)
         {
             deleteGroup(group.Subgroups[i], groupsIds, notesIds);
             PNStatic.Groups.RemoveAll(g => g.ID == group.Subgroups[i].ID);
             group.Subgroups.RemoveAll(g => g.ID == group.Subgroups[i].ID);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #16
0
ファイル: WndMain.xaml.cs プロジェクト: hyrmedia/PNotes.NET
 private void prepareSingleGroupHotKey(PNGroup group, SQLiteDataObject oData, List<string> names, HotkeyType type, ref int id)
 {
     try
     {
         foreach (var g in group.Subgroups)
         {
             prepareSingleGroupHotKey(g, oData, names, HotkeyType.Group, ref id);
         }
         var prefix = group.ID + "_show";
         if (names.All(n => n != prefix))
         {
             var sqlQuery = "INSERT INTO HOT_KEYS (HK_TYPE, MENU_NAME, ID, SHORTCUT) VALUES(" + ((int)type).ToString(CultureInfo.InvariantCulture) + ",'" + prefix + "'," + id.ToString(CultureInfo.InvariantCulture) + ",'')";
             oData.Execute(sqlQuery);
             id++;
         }
         prefix = group.ID + "_hide";
         if (names.All(n => n != prefix))
         {
             string sqlQuery = "INSERT INTO HOT_KEYS (HK_TYPE, MENU_NAME, ID, SHORTCUT) VALUES(" + ((int)type).ToString(CultureInfo.InvariantCulture) + ",'" + prefix + "'," + id.ToString(CultureInfo.InvariantCulture) + ",'')";
             oData.Execute(sqlQuery);
             id++;
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #17
0
ファイル: WndMain.xaml.cs プロジェクト: hyrmedia/PNotes.NET
        private void loadDatabase()
        {
            try
            {
                if (!File.Exists(PNPaths.Instance.DBPath))
                {
                    PNStatic.SpTextProvider.SplashText = PNLang.Instance.GetMessageText("create_database", "Creating database");
                    _FirstRun = true;
                }
                else
                {
                    PNStatic.SpTextProvider.SplashText = PNLang.Instance.GetMessageText("load_database", "Loading database");
                }
                PNData.ConnectionString = SQLiteDataObject.CheckAndCreateDatabase(PNPaths.Instance.DBPath);
                if (PNData.ConnectionString != "")
                {
                    using (var oData = new SQLiteDataObject(PNData.ConnectionString))
                    {
                        //notes
                        var sqlQuery = "CREATE TABLE IF NOT EXISTS [NOTES] ([ID] TEXT PRIMARY KEY NOT NULL, [NAME] TEXT NOT NULL, [GROUP_ID] INT NOT NULL, [PREV_GROUP_ID] INT, [OPACITY] REAL, [VISIBLE] BOOLEAN, [FAVORITE] BOOLEAN, [PROTECTED] BOOLEAN, [COMPLETED] BOOLEAN, [PRIORITY] BOOLEAN, [PASSWORD_STRING] TEXT, [PINNED] BOOLEAN, [TOPMOST] BOOLEAN, [ROLLED] BOOLEAN, [DOCK_STATUS] INT, [DOCK_ORDER] INT, [SEND_RECEIVE_STATUS] INT, [DATE_CREATED] TEXT, [DATE_SAVED] TEXT, [DATE_SENT] TEXT, [DATE_RECEIVED] TEXT, [DATE_DELETED] TEXT, [SIZE] TEXT, [LOCATION] TEXT, [EDIT_SIZE] TEXT, [REL_X] REAL, [REL_Y] REAL, [UPD_DATE] TEXT DEFAULT(strftime ( '%Y%m%d%H%M%S' , 'now' , 'localtime' )), [SENT_TO] TEXT, [RECEIVED_FROM] TEXT, [PIN_CLASS] TEXT, [PIN_TEXT] TEXT, [SCRAMBLED] BOOLEAN DEFAULT (0), [THUMBNAIL] BOOLEAN DEFAULT (0), [RECEIVED_IP] TEXT)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.GetSchema("Columns"))
                        {
                            var rows = t.Select("COLUMN_NAME = 'SCRAMBLED' AND TABLE_NAME = 'NOTES'");
                            if (rows.Length == 0)
                            {
                                sqlQuery = "ALTER TABLE NOTES ADD COLUMN [SCRAMBLED] BOOLEAN DEFAULT (0)";
                                oData.Execute(sqlQuery);
                                sqlQuery = "UPDATE NOTES SET SCRAMBLED = 0";
                                oData.Execute(sqlQuery);
                            }
                            rows = t.Select("COLUMN_NAME = 'THUMBNAIL' AND TABLE_NAME = 'NOTES'");
                            if (rows.Length == 0)
                            {
                                sqlQuery = "ALTER TABLE NOTES ADD COLUMN [THUMBNAIL] BOOLEAN DEFAULT (0)";
                                oData.Execute(sqlQuery);
                                sqlQuery = "UPDATE NOTES SET THUMBNAIL = 0";
                                oData.Execute(sqlQuery);
                            }
                            rows = t.Select("COLUMN_NAME = 'RECEIVED_IP' AND TABLE_NAME = 'NOTES'");
                            if (rows.Length == 0)
                            {
                                sqlQuery = "ALTER TABLE NOTES ADD COLUMN [RECEIVED_IP] TEXT";
                                oData.Execute(sqlQuery);
                                sqlQuery = "UPDATE NOTES SET THUMBNAIL = 0";
                                oData.Execute(sqlQuery);
                            }
                        }
                        if (!PNSingleton.Instance.PlatformChanged)
                        {
                            //custom notes settings
                            sqlQuery =
                                "CREATE TABLE IF NOT EXISTS [CUSTOM_NOTES_SETTINGS] ([NOTE_ID] TEXT NOT NULL, [BACK_COLOR] TEXT, [CAPTION_FONT_COLOR] TEXT, [CAPTION_FONT] TEXT, [SKIN_NAME] TEXT, [CUSTOM_OPACITY] BOOLEAN, [UPD_DATE] TEXT DEFAULT(strftime ( '%Y%m%d%H%M%S' , 'now' , 'localtime' )))";
                            oData.Execute(sqlQuery);
                        }
                        else
                        {
                            if (oData.TableExists("CUSTOM_NOTES_SETTINGS"))
                            {
                                PNData.NormalizeCustomNotesTable(oData);
                            }
                            else
                            {
                                sqlQuery =
                                    "CREATE TABLE [CUSTOM_NOTES_SETTINGS] ([NOTE_ID] TEXT NOT NULL, [BACK_COLOR] TEXT, [CAPTION_FONT_COLOR] TEXT, [CAPTION_FONT] TEXT, [SKIN_NAME] TEXT, [CUSTOM_OPACITY] BOOLEAN, [UPD_DATE] TEXT DEFAULT(strftime ( '%Y%m%d%H%M%S' , 'now' , 'localtime' )))";
                                oData.Execute(sqlQuery);
                            }
                        }
                        //notes tags
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [NOTES_TAGS] ([NOTE_ID] TEXT NOT NULL, [TAG] TEXT NOT NULL, [UPD_DATE] TEXT DEFAULT(strftime ( '%Y%m%d%H%M%S' , 'now' , 'localtime' )))";
                        oData.Execute(sqlQuery);
                        //notes schedule
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [NOTES_SCHEDULE] ([NOTE_ID] TEXT NOT NULL, [SCHEDULE_TYPE] INT, [ALARM_DATE] TEXT, [START_DATE] TEXT, [LAST_RUN] TEXT, [SOUND] TEXT, [STOP_AFTER] INT, [TRACK] BOOLEAN, [REPEAT_COUNT] INT, [SOUND_IN_LOOP] BOOLEAN, [USE_TTS] BOOLEAN, [START_FROM] INT, [MONTH_DAY] TEXT, [ALARM_AFTER] TEXT, [WEEKDAYS] TEXT, [UPD_DATE] TEXT DEFAULT(strftime ( '%Y%m%d%H%M%S' , 'now' , 'localtime' )), [PROG_TO_RUN] TEXT, [CLOSE_ON_NOTIFICATION] BOOLEAN)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.GetSchema("Columns"))
                        {
                            var rows = t.Select("COLUMN_NAME = 'PROG_TO_RUN' AND TABLE_NAME = 'NOTES_SCHEDULE'");
                            if (rows.Length == 0)
                            {
                                sqlQuery = "ALTER TABLE NOTES_SCHEDULE ADD COLUMN [PROG_TO_RUN] TEXT";
                                oData.Execute(sqlQuery);
                            }
                            rows = t.Select("COLUMN_NAME = 'CLOSE_ON_NOTIFICATION' AND TABLE_NAME = 'NOTES_SCHEDULE'");
                            if (rows.Length == 0)
                            {
                                sqlQuery = "ALTER TABLE NOTES_SCHEDULE ADD COLUMN [CLOSE_ON_NOTIFICATION] BOOLEAN";
                                oData.Execute(sqlQuery);
                            }
                            rows = t.Select("COLUMN_NAME = 'MULTI_ALERTS' AND TABLE_NAME = 'NOTES_SCHEDULE'");
                            if (rows.Length == 0)
                            {
                                sqlQuery = "ALTER TABLE NOTES_SCHEDULE ADD COLUMN [MULTI_ALERTS] TEXT";
                                oData.Execute(sqlQuery);
                            }
                            rows = t.Select("COLUMN_NAME = 'TIME_ZONE' AND TABLE_NAME = 'NOTES_SCHEDULE'");
                            if (rows.Length == 0)
                            {
                                sqlQuery = "ALTER TABLE NOTES_SCHEDULE ADD COLUMN [TIME_ZONE] TEXT";
                                oData.Execute(sqlQuery);
                            }
                        }
                        //linked notes
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [LINKED_NOTES] ([NOTE_ID] TEXT NOT NULL, [LINK_ID] TEXT NOT NULL, [UPD_DATE] TEXT DEFAULT(strftime ( '%Y%m%d%H%M%S' , 'now' , 'localtime' )))";
                        oData.Execute(sqlQuery);
                        //groups
                        if (!oData.TableExists("GROUPS"))
                        {
                            sqlQuery =
                                "CREATE TABLE [GROUPS] ([GROUP_ID] INT PRIMARY KEY NOT NULL UNIQUE, [PARENT_ID] INT, [GROUP_NAME] TEXT NOT NULL, [ICON] TEXT, [BACK_COLOR] TEXT NOT NULL, [CAPTION_FONT_COLOR] TEXT NOT NULL, [CAPTION_FONT] TEXT NOT NULL, [SKIN_NAME] TEXT NOT NULL, [PASSWORD_STRING] TEXT, [FONT] TEXT, [FONT_COLOR] TEXT, [UPD_DATE] TEXT DEFAULT(strftime ( '%Y%m%d%H%M%S' , 'now' , 'localtime' )), [IS_DEFAULT_IMAGE] BOOLEAN)";
                            oData.Execute(sqlQuery);
                            var sb = new StringBuilder();

                            sb.Append(prepareGroupInsert((int)SpecialGroups.AllGroups, (int)SpecialGroups.DummyGroup,
                                "All groups", "gr_all.png"));
                            sb.Append(prepareGroupInsert(0, (int)SpecialGroups.AllGroups, "General", "gr.png"));
                            sb.Append(prepareGroupInsert((int)SpecialGroups.RecycleBin, (int)SpecialGroups.DummyGroup,
                                "Recycle Bin", "gr_bin.png"));
                            sb.Append(prepareGroupInsert((int)SpecialGroups.Diary, (int)SpecialGroups.DummyGroup,
                                "Diary", "gr_diary.png"));
                            sb.Append(prepareGroupInsert((int)SpecialGroups.SearchResults,
                                (int)SpecialGroups.DummyGroup, "Search Results", "gr_search.png"));
                            sb.Append(prepareGroupInsert((int)SpecialGroups.Backup, (int)SpecialGroups.DummyGroup,
                                "Backup", "gr_back.png"));
                            sb.Append(prepareGroupInsert((int)SpecialGroups.Favorites, (int)SpecialGroups.DummyGroup,
                                "Favorites", "gr_fav.png"));
                            sb.Append(prepareGroupInsert((int)SpecialGroups.Incoming, (int)SpecialGroups.DummyGroup,
                                "Incoming", "gr_inc.png"));
                            sb.Append(prepareGroupInsert((int)SpecialGroups.Docking, (int)SpecialGroups.DummyGroup,
                                "Docking", "dockall.png"));

                            sqlQuery = sb.ToString();
                            oData.Execute(sqlQuery);
                        }
                        else
                        {
                            using (var t = oData.GetSchema("Columns"))
                            {
                                var rows = t.Select("COLUMN_NAME = 'IS_DEFAULT_IMAGE' AND TABLE_NAME = 'GROUPS'");
                                if (rows.Length == 0)
                                {
                                    sqlQuery = "ALTER TABLE GROUPS ADD COLUMN [IS_DEFAULT_IMAGE] BOOLEAN";
                                    oData.Execute(sqlQuery);
                                    sqlQuery = "UPDATE GROUPS SET IS_DEFAULT_IMAGE = 1";
                                    oData.Execute(sqlQuery);
                                }
                            }
                            if (PNSingleton.Instance.PlatformChanged)
                            {
                                PNData.NormalizeGroupsTable(oData, false);
                                upgradeGroups(oData);
                            }
                        }
                        var groupsWithoutParent = new List<PNGroup>();

                        sqlQuery = "SELECT GROUP_ID, PARENT_ID, GROUP_NAME, ICON, BACK_COLOR, CAPTION_FONT_COLOR, CAPTION_FONT, SKIN_NAME, PASSWORD_STRING, FONT, FONT_COLOR, IS_DEFAULT_IMAGE FROM GROUPS ORDER BY GROUP_ID ASC";
                        using (var t = oData.FillDataTable(sqlQuery))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                if ((int)r["GROUP_ID"] < 0)
                                {
                                    if ((int)r["GROUP_ID"] != (int)SpecialGroups.Docking)
                                    {
                                        var group = new PNGroup();
                                        fillGroup(group, r);
                                        PNStatic.Groups.Insert(0, group);
                                    }
                                    else
                                    {
                                        fillGroup(PNStatic.Docking, r);
                                    }
                                }
                                else
                                {
                                    var gr = new PNGroup();
                                    fillGroup(gr, r);

                                    var parentExists = PNStatic.Groups.Select(grp => grp.GetGroupById(gr.ParentID)).Any(pg => pg != null);
                                    if (!parentExists)
                                    {
                                        groupsWithoutParent.Add(gr);
                                        continue;
                                    }

                                    foreach (var parent in PNStatic.Groups.Select(g => g.GetGroupById(gr.ParentID)).Where(parent => parent != null))
                                    {
                                        parent.Subgroups.Add(gr);
                                        break;
                                    }
                                }
                            }
                        }
                        while (groupsWithoutParent.Count > 0)
                        {
                            for (var i = groupsWithoutParent.Count - 1; i >= 0; i--)
                            {
                                if (PNStatic.Groups.Select(grp => grp.GetGroupById(groupsWithoutParent[i].ParentID)).All(pg => pg == null))
                                    continue;
                                var i1 = i;
                                foreach (
                                    var parent in
                                        PNStatic.Groups.Select(g => g.GetGroupById(groupsWithoutParent[i1].ParentID))
                                            .Where(parent => parent != null))
                                {
                                    parent.Subgroups.Add(groupsWithoutParent[i]);
                                    groupsWithoutParent.RemoveAt(i);
                                    break;
                                }
                            }
                        }
                        applyStandardGroupsNames();

                        //sync comps
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [SYNC_COMPS] ([COMP_NAME] TEXT NOT NULL, [DATA_DIR] TEXT NOT NULL, [DB_DIR] TEXT NOT NULL, [USE_DATA_DIR] TEXT NOT NULL)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT * FROM SYNC_COMPS"))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.SyncComps.Add(new PNSyncComp
                                {
                                    CompName = (string)r["COMP_NAME"],
                                    DataDir = (string)r["DATA_DIR"],
                                    DBDir = (string)r["DB_DIR"],
                                    UseDataDir = bool.Parse((string)r["USE_DATA_DIR"])
                                });
                            }
                        }
                        //contact groups
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [CONTACT_GROUPS] ([ID] INT PRIMARY KEY ON CONFLICT REPLACE NOT NULL UNIQUE ON CONFLICT REPLACE, [GROUP_NAME] TEXT NOT NULL UNIQUE ON CONFLICT REPLACE)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT * FROM CONTACT_GROUPS"))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.ContactGroups.Add(new PNContactGroup { ID = (int)r["ID"], Name = (string)r["GROUP_NAME"] });
                            }
                        }
                        //contacts
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [CONTACTS] ([ID] INT PRIMARY KEY ON CONFLICT REPLACE NOT NULL UNIQUE ON CONFLICT REPLACE, [GROUP_ID] INT NOT NULL, [CONTACT_NAME] TEXT NOT NULL UNIQUE ON CONFLICT REPLACE, [COMP_NAME] TEXT NOT NULL, [IP_ADDRESS] TEXT NOT NULL, [USE_COMP_NAME] BOOLEAN NOT NULL)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT ID, GROUP_ID, CONTACT_NAME, COMP_NAME, IP_ADDRESS, USE_COMP_NAME FROM CONTACTS"))
                        {
                            foreach (var cont in from DataRow r in t.Rows
                                                 select new PNContact
                                                 {
                                                     Name = (string)r["CONTACT_NAME"],
                                                     ComputerName = (string)r["COMP_NAME"],
                                                     IpAddress = (string)r["IP_ADDRESS"],
                                                     GroupID = (int)r["GROUP_ID"],
                                                     UseComputerName = (bool)r["USE_COMP_NAME"],
                                                     ID = (int)r["ID"]
                                                 })
                            {
                                PNStatic.Contacts.Add(cont);
                            }
                            Task.Factory.StartNew(updateContactsWithoutIp);
                        }
                        //externals
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [EXTERNALS] ([EXT_NAME] TEXT PRIMARY KEY ON CONFLICT REPLACE NOT NULL UNIQUE ON CONFLICT REPLACE, [PROGRAM] TEXT NOT NULL, [COMMAND_LINE] TEXT NOT NULL)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT EXT_NAME, PROGRAM, COMMAND_LINE FROM EXTERNALS "))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.Externals.Add(new PNExternal
                                {
                                    Name = (string)r["EXT_NAME"],
                                    Program = (string)r["PROGRAM"],
                                    CommandLine = (string)r["COMMAND_LINE"]
                                });
                            }
                        }
                        //search providers
                        if (!oData.TableExists("SEARCH_PROVIDERS"))
                        {
                            sqlQuery = "CREATE TABLE [SEARCH_PROVIDERS] ([SP_NAME] TEXT PRIMARY KEY ON CONFLICT REPLACE NOT NULL UNIQUE ON CONFLICT REPLACE, [SP_QUERY] TEXT NOT NULL)";
                            oData.Execute(sqlQuery);
                            //insert two default provider for the first time
                            sqlQuery = "INSERT INTO SEARCH_PROVIDERS VALUES('Google', 'http://www.google.com/search?q=')";
                            oData.Execute(sqlQuery);
                            sqlQuery = "INSERT INTO SEARCH_PROVIDERS VALUES('Yahoo', 'http://search.yahoo.com/search?p=')";
                            oData.Execute(sqlQuery);
                        }
                        using (var t = oData.FillDataTable("SELECT * FROM SEARCH_PROVIDERS"))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.SearchProviders.Add(new PNSearchProvider
                                {
                                    Name = (string)r["SP_NAME"],
                                    QueryString = (string)r["SP_QUERY"]
                                });
                            }
                        }
                        //tags
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [TAGS] ([TAG] TEXT PRIMARY KEY ON CONFLICT REPLACE NOT NULL UNIQUE ON CONFLICT REPLACE)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT * FROM TAGS"))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.Tags.Add((string)r["TAG"]);
                            }
                        }
                        //plugins
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [POST_PLUGINS] ([PLUGIN] TEXT PRIMARY KEY NOT NULL UNIQUE)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT * FROM POST_PLUGINS"))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.PostPlugins.Add((string)r["PLUGIN"]);
                            }
                        }
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [SYNC_PLUGINS] ([PLUGIN] TEXT PRIMARY KEY NOT NULL UNIQUE)";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT * FROM SYNC_PLUGINS"))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.SyncPlugins.Add((string)r["PLUGIN"]);
                            }
                        }
                        //hotkeys
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [HOT_KEYS] ([HK_TYPE] INT NOT NULL, [MENU_NAME] TEXT NOT NULL, [ID] INT NOT NULL DEFAULT(0), [MODIFIERS] INT NOT NULL DEFAULT(0), [VK] INT NOT NULL DEFAULT(0), [SHORTCUT] TEXT NOT NULL DEFAULT(''), PRIMARY KEY ([HK_TYPE], [MENU_NAME]))";
                        oData.Execute(sqlQuery);
                        prepareHotkeysTable(oData);
                        //find/replace
                        if (!oData.TableExists("FIND_REPLACE"))
                        {
                            sqlQuery = "CREATE TABLE [FIND_REPLACE] ([FIND] TEXT, [REPLACE] TEXT); ";
                            sqlQuery += "INSERT INTO FIND_REPLACE VALUES(NULL, NULL)";
                        }
                        oData.Execute(sqlQuery);
                        //remove possible program version table from previous versions
                        if (oData.TableExists("PROGRAM_VERSION"))
                        {
                            sqlQuery = "DROP TABLE [PROGRAM_VERSION]; ";
                            oData.Execute(sqlQuery);
                        }
                        //hidden menus
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [HIDDEN_MENUS] ([MENU_NAME] TEXT NOT NULL, [MENU_TYPE] INT NOT NULL, PRIMARY KEY ([MENU_NAME], [MENU_TYPE]))";
                        oData.Execute(sqlQuery);
                        PNData.LoadHiddenMenus();
                        //menus order
                        if (!oData.TableExists("MENUS_ORDER"))
                        {
                            sqlQuery =
                                "CREATE TABLE [MENUS_ORDER] ([CONTEXT_NAME] TEXT NOT NULL, [MENU_NAME] TEXT NOT NULL, [ORDER_ORIGINAL] INT NOT NULL, [ORDER_NEW] INT NOT NULL, [PARENT_NAME] TEXT, PRIMARY KEY ( [CONTEXT_NAME], [MENU_NAME]));";
                            oData.Execute(sqlQuery);
                            createMenusOrder(oData, true);
                        }
                        else
                        {
                            createMenusOrder(oData, false);
                        }
                        //SMTP profiles
                        sqlQuery =
                            "CREATE TABLE IF NOT EXISTS [SMTP_PROFILES] ([ID] INT UNIQUE ON CONFLICT REPLACE, [ACTIVE] BOOLEAN, [HOST_NAME] TEXT, [DISPLAY_NAME] TEXT, [SENDER_ADDRESS] TEXT PRIMARY KEY UNIQUE, [PASSWORD] TEXT, [PORT] INT )";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT * FROM SMTP_PROFILES"))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.SmtpProfiles.Add(new PNSmtpProfile
                                {
                                    Active = Convert.ToBoolean(r["ACTIVE"]),
                                    Id = Convert.ToInt32(r["ID"]),
                                    HostName = Convert.ToString(r["HOST_NAME"]),
                                    SenderAddress = Convert.ToString(r["SENDER_ADDRESS"]),
                                    Password = Convert.ToString(r["PASSWORD"]),
                                    Port = Convert.ToInt32(r["PORT"]),
                                    DisplayName = Convert.ToString(r["DISPLAY_NAME"])
                                });
                            }
                        }
                        //mail contacts
                        sqlQuery = "CREATE TABLE IF NOT EXISTS [MAIL_CONTACTS] ([ID] INT UNIQUE ON CONFLICT REPLACE, [DISPLAY_NAME] TEXT, [ADDRESS] TEXT )";
                        oData.Execute(sqlQuery);
                        using (var t = oData.FillDataTable("SELECT * FROM MAIL_CONTACTS"))
                        {
                            foreach (DataRow r in t.Rows)
                            {
                                PNStatic.MailContacts.Add(new PNMailContact
                                {
                                    DisplayName = Convert.ToString(r["DISPLAY_NAME"]),
                                    Address = Convert.ToString(r["ADDRESS"]),
                                    Id = Convert.ToInt32(r["ID"]),
                                });
                            }
                        }
                        //services
                        sqlQuery =
                            "CREATE TABLE IF NOT EXISTS SERVICES ( APP_NAME TEXT PRIMARY KEY, CLIENT_ID TEXT, CLIENT_SECRET TEXT, ACCESS_TOKEN TEXT, REFRESH_TOKEN TEXT, TOKEN_EXPIRY TEXT )";
                        oData.Execute(sqlQuery);
                        prepareServices(oData);
                        //triggers
                        sqlQuery = PNStrings.CREATE_TRIGGERS;
                        oData.Execute(sqlQuery);
                    }
                }
                //load plugins
                PNPlugins.Instance.LoadPlugins(this, PNPaths.Instance.PluginsDir);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #18
0
ファイル: PNClasses.cs プロジェクト: hyrmedia/PNotes.NET
 public bool Equals(PNGroup gr)
 {
     if ((object)gr == null)
         return false;
     return (_Skin == gr._Skin
         && _Skinless == gr._Skinless
         && _PasswordString == gr._PasswordString
         && _FontColor == gr._FontColor
         && _Font == gr._Font
         && Image.Equals(gr.Image)
         && IsDefaultImage == gr.IsDefaultImage);
 }
コード例 #19
0
ファイル: WndMain.xaml.cs プロジェクト: hyrmedia/PNotes.NET
        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);
            }
        }
コード例 #20
0
 private void loadGroups(PNGroup gr, PNTreeItem item, string captionShow, string captionHide)
 {
     try
     {
         var ti = new PNTreeItem("submnu", gr.Name, gr.ID.ToString(CultureInfo.InvariantCulture)) { IsExpanded = true };
         ti.Items.Add(new PNTreeItem("mnu", captionShow,
             gr.ID.ToString(CultureInfo.InvariantCulture) + "_show"));
         ti.Items.Add(new PNTreeItem("mnu", captionHide,
             gr.ID.ToString(CultureInfo.InvariantCulture) + "_hide"));
         if (item == null)
         {
             _ItemsGroup.Add(ti);
         }
         else
         {
             item.Items.Add(ti);
         }
         foreach (PNGroup g in gr.Subgroups)
         {
             loadGroups(g, ti, captionShow, captionHide);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #21
0
ファイル: PNData.cs プロジェクト: hyrmedia/PNotes.NET
 internal static void SaveGroupPassword(PNGroup group)
 {
     try
     {
         var sb = new StringBuilder();
         sb.Append("UPDATE GROUPS SET PASSWORD_STRING = '");
         sb.Append(group.PasswordString);
         sb.Append("' WHERE GROUP_ID = ");
         sb.Append(group.ID);
         ExecuteTransactionForStringBuilder(sb, ConnectionString);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #22
0
ファイル: PNEvents.cs プロジェクト: hyrmedia/PNotes.NET
 internal GroupChangedEventArgs(PNGroup group, AddEditMode mode, PNTreeItem treeItem)
 {
     Group = group;
     Mode = mode;
     TreeItem = treeItem;
 }
コード例 #23
0
ファイル: PNData.cs プロジェクト: hyrmedia/PNotes.NET
 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);
     }
 }
コード例 #24
0
        private Dictionary<int, int> importGroups()
        {
            try
            {
                var dict = new Dictionary<int, int>();
                var size = 1024;

                string iniPath = txtIniPath.Text.Trim();
                // get all notes ids
                string buffer = new string(' ', size);
                while (PNInterop.GetPrivateProfileString(null, null, null, buffer, size, iniPath) == size - 2)
                {
                    // loop until sufficient buffer size
                    size *= 2;
                    buffer = new string(' ', size);
                }
                // section names are delimeted by '\0' character with additional '\0' character at the end
                var names = buffer.ToString(CultureInfo.InvariantCulture).Split('\0');
                var groupSection = names.FirstOrDefault(s => s == "groups");
                if (groupSection == null) return null;
                // get ids of all groups under section
                size = 1024;
                buffer = new string(' ', size);
                while (PNInterop.GetPrivateProfileString(groupSection, null, null, buffer, size, iniPath) == size - 2)
                {
                    // loop until sufficient buffer size
                    size *= 2;
                    buffer = new string(' ', size);
                }
                names =
                    buffer.ToString(CultureInfo.InvariantCulture)
                          .Split('\0')
                          .Where(s => s.Trim().Length > 0 && s.Trim() != "0")
                          .ToArray();
                var png = new PNGROUP();
                var crc = new ColorConverter();
                var crd = new System.Drawing.ColorConverter();
                foreach (var id in names)
                {
                    int structSize = Marshal.SizeOf(typeof(PNGROUP));
                    int intSize = Marshal.SizeOf(typeof(int));
                    int boolSize = Marshal.SizeOf(typeof(bool));
                    int hkSize = Marshal.SizeOf(typeof(HK_TYPE));
                    png = PNInterop.ReadINIStructure(iniPath, "groups", id, png, structSize);
                    if (png.Equals(default(PNGROUP)))
                    {
                        structSize -= (intSize * 3 + boolSize * 4 + 2 * 64);
                        png = PNInterop.ReadINIStructure(iniPath, "groups", id, png, structSize);
                        if (png.Equals(default(PNGROUP)))
                        {
                            structSize -= 2 * 256;
                            png = PNInterop.ReadINIStructure(iniPath, "groups", id, png, structSize);
                            if (png.Equals(default(PNGROUP)))
                            {
                                structSize -= hkSize * 2;
                                png = PNInterop.ReadINIStructure(iniPath, "groups", id, png, structSize);
                                if (!png.Equals(default(PNGROUP)))
                                {
                                    png.customCRCaption = png.customCRFont = png.customCRWindow = png.customSkin = false;
                                    png.szSkin = "";
                                    png.szLock = "";
                                    png.hotKeyHide = png.hotKeyShow = default(HK_TYPE);
                                }
                            }
                            else
                            {
                                png.customCRCaption = png.customCRFont = png.customCRWindow = png.customSkin = false;
                                png.szSkin = "";
                                png.szLock = "";
                            }
                        }
                        else
                        {
                            png.customCRCaption = png.customCRFont = png.customCRWindow = png.customSkin = false;
                            png.szSkin = "";
                        }
                    }
                    if (png.Equals(default(PNGROUP))) return null;

                    var pg = new PNGroup();
                    var idNew = PNData.GetNewGroupID();
                    var idOld = png.id;
                    pg.Name = png.szName;
                    pg.ID = idNew;
                    pg.ParentID = -1;
                    if (png.customCRWindow)
                    {
                        var fromString = crc.ConvertFromString(null, PNStatic.CultureInvariant, PNStatic.FromIntToColorString(png.crWindow));
                        if (fromString != null)
                            pg.Skinless.BackColor = (Color)fromString;
                    }
                    if (png.customCRCaption)
                    {
                        var fromString = crc.ConvertFromString(null, PNStatic.CultureInvariant, PNStatic.FromIntToColorString(png.crCaption));
                        if (fromString != null)
                            pg.Skinless.CaptionColor = (Color)fromString;
                    }
                    if (png.customCRFont)
                    {
                        var fromString = crd.ConvertFromString(null, PNStatic.CultureInvariant, PNStatic.FromIntToDrawinfColorString(png.crFont));
                        if (fromString != null)
                            pg.FontColor = (System.Drawing.Color)fromString;
                    }
                    if (png.customSkin)
                    {
                        pg.Skin.SkinName = png.szSkin;
                        var path = Path.Combine(PNPaths.Instance.SkinsDir, pg.Skin.SkinName + PNStrings.SKIN_EXTENSION);
                        if (File.Exists(path))
                        {
                            PNSkinsOperations.LoadSkin(path, pg.Skin);
                        }
                    }
                    pg.Image = TryFindResource("gr") as BitmapImage;
                    pg.IsDefaultImage = true;
                    var parent = PNStatic.Groups.GetGroupByID((int)SpecialGroups.AllGroups);
                    if (parent == null) continue;
                    parent.Subgroups.Add(pg);
                    PNData.InsertNewGroup(pg);
                    dict.Add(idOld, idNew);
                }
                return dict;
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return null;
            }
        }
コード例 #25
0
        private void DlgSettings_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                PNStatic.FormSettings = this;
                prepareLists();
                initializeComboBoxes();

                var f = new PNFont();
                cmdRestoreFontUI.IsEnabled = f != PNSingleton.Instance.FontUser;

                applyFirstTimeLanguage();
                //applyLanguage();

                PNStatic.FormMain.LanguageChanged += FormMain_LanguageChanged;

                _TempSettings = PNStatic.Settings.PNClone();
                _SyncComps = PNStatic.SyncComps.PNClone();
                _Groups = PNStatic.ContactGroups.PNClone();
                _Contacts = PNStatic.Contacts.PNClone();
                _Externals = PNStatic.Externals.PNClone();
                _SProviders = PNStatic.SearchProviders.PNClone();
                _SmtpClients = PNStatic.SmtpProfiles.PNClone();
                _MailContacts = PNStatic.MailContacts.PNClone();
                _Tags = PNStatic.Tags.PNClone();
                _TempDocking = (PNGroup)PNStatic.Docking.Clone();
                _SocialPlugins = PNStatic.PostPlugins.PNClone();
                _SyncPlugins = PNStatic.SyncPlugins.PNClone();

                initPageGeneral(true);
                initPageSchedule(true);
                initPageAppearance(true);
                initPageBehavior(true);
                initPageNetwork(true);
                initPageProtection(true);

                _TimerConnections.Elapsed += _TimerConnections_Elapsed;
                if (_TempSettings.Network.EnableExchange)
                    _TimerConnections.Start();

                _Loaded = true;
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #26
0
ファイル: WndSaveAs.xaml.cs プロジェクト: hyrmedia/PNotes.NET
        private void loadGroup(PNGroup pgroup, PNTreeItem item)
        {
            try
            {
                var ti = new PNTreeItem(pgroup.Image, pgroup.Name, pgroup) { IsExpanded = true };
                foreach (var sg in pgroup.Subgroups)
                {
                    loadGroup(sg, ti);
                }

                if (pgroup.ID == m_GroupID)
                {
                    ti.IsSelected = true;
                }
                else if (pgroup.ID == 0 && m_GroupID == -1)
                {
                    ti.IsSelected = true;
                }

                if (item == null)
                    _Items.Add(ti);
                else
                    item.Items.Add(ti);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #27
0
 internal static bool LoginToGroup(PNGroup group, ref List<int> loggedGroups)
 {
     try
     {
         var result = true;
         if (group.ParentID != -1)
         {
             var parent = PNStatic.Groups.GetGroupByID(group.ParentID);
             if (parent != null)
             {
                 result &= LoginToGroup(parent, ref loggedGroups);
             }
         }
         if (!loggedGroups.Contains(group.ID))
         {
             if (group.PasswordString.Trim().Length > 0)
             {
                 var text = " [" + PNLang.Instance.GetCaptionText("group", "Group") + " \"" + group.Name + "\"]";
                 var pwrdDelete = new WndPasswordDelete(PasswordDlgMode.LoginGroup, text, group.PasswordString)
                 {
                     Topmost = true,
                     Owner = PNStatic.FormMain
                 };
                 var showDialog = pwrdDelete.ShowDialog();
                 if (showDialog == null || !showDialog.Value)
                 {
                     return false;
                 }
                 loggedGroups.Add(@group.ID);
             }
             else
             {
                 loggedGroups.Add(group.ID);
             }
         }
         return result;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return false;
     }
 }
コード例 #28
0
ファイル: WndMain.xaml.cs プロジェクト: hyrmedia/PNotes.NET
        private void addGroupToShowHideMenu(MenuItem mi, PNGroup group, bool show)
        {
            try
            {
                var ti = new MenuItem { Header = group.Name, Tag = @group.ID };
                if (PNStatic.Settings.Behavior.ShowSeparateNotes)
                {
                    var notes = PNStatic.Notes.Where(n => n.GroupID == group.ID);
                    var pNotes = notes as PNote[] ?? notes.ToArray();
                    if (!pNotes.Any())
                    {
                        ti.IsEnabled = false;
                    }
                    else
                    {
                        var tt = new MenuItem();
                        if (show)
                        {
                            tt.Header = PNLang.Instance.GetMenuText("main_menu", "mnuShowAll", "Show All");
                            tt.Tag = group.ID + "_show";
                        }
                        else
                        {
                            tt.Header = PNLang.Instance.GetMenuText("main_menu", "mnuHideAll", "Hide All");
                            tt.Tag = group.ID + "_hide";
                        }
                        tt.Click += menuClick;
                        ti.Items.Add(tt);
                        ti.Items.Add(new Separator());

                        foreach (PNote n in pNotes)
                        {
                            addNoteToShowHideMenu(ti, n);
                        }
                    }
                }
                else
                {
                    ti.Click += menuClick;
                }
                mi.Items.Insert(2, ti);

                foreach (PNGroup g in group.Subgroups)
                {
                    addGroupToShowHideMenu(mi, g, show);
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #29
0
        private void DlgAdjustAppearance_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (PNStatic.Settings.GeneralSettings.UseSkins)
                {
                    GridSkinless.Visibility = Visibility.Hidden;
                    GridSkinnable.Visibility = Visibility.Visible;
                }
                _CustomOpacity = _Note.CustomOpacity;
                applyLanguage();
                if (_CustomOpacity)
                {
                    trkTrans.Value = (int)(100 - (_Note.Opacity * 100));
                    _Opacity = _Note.Opacity;
                }
                else
                {
                    trkTrans.Value = (int)(100 - (PNStatic.Settings.Behavior.Opacity * 100));
                    _Opacity = PNStatic.Settings.Behavior.Opacity;
                }
                _Group = PNStatic.Groups.GetGroupByID(_Note.GroupID);
                if (_Group == null)
                {
                    throw new Exception("Group cannot be null");
                }
                if (_Note.Skinless != null)
                {
                    _CustomSkinless = true;
                    Skinless = (PNSkinlessDetails)_Note.Skinless.Clone();
                }
                else
                {
                    Skinless = (PNSkinlessDetails)_Group.Skinless.Clone();
                }

                blkCaption.DataContext = Skinless.CaptionFont;

                pckBGSknls.SelectedColor = Skinless.BackColor;

                if (GridSkinnable.Visibility == Visibility.Visible)
                {
                    if (_Note.Skin != null)
                    {
                        _CustomSkin = true;
                        Skin = _Note.Skin.PNClone();
                    }
                    else
                    {
                        Skin = _Group.Skin.PNClone();
                    }
                    loadSkinsList();
                    if (Skin.SkinName != PNSkinDetails.NO_SKIN)
                    {
                        lstSkins.SelectedItem =
                            lstSkins.Items.OfType<PNListBoxItem>().FirstOrDefault(it => it.Text == Skin.SkinName);
                    }
                    else
                    {
                        lstSkins.SelectedIndex = -1;
                    }
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #30
0
ファイル: WndCP.xaml.cs プロジェクト: hyrmedia/PNotes.NET
 private VisibleHidden checkBranchVisibility(PNGroup png)
 {
     try
     {
         var vh = VisibleHidden.None;
         var notes = PNStatic.Notes.Where(n => n.GroupID == png.ID).ToArray();
         if (notes.Any(n => !n.Visible))
         {
             vh |= VisibleHidden.Hidden;
         }
         if (notes.Any(n => n.Visible))
         {
             vh |= VisibleHidden.Visible;
         }
         return png.Subgroups.Aggregate(vh, (current, g) => current | checkBranchVisibility(g));
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return VisibleHidden.None;
     }
 }