Пример #1
0
        private void DlgSearchReplace_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                PNLang.Instance.ApplyControlLanguage(this);

                if (_Mode == SearchReplace.Search)
                {
                    Title = PNLang.Instance.GetCaptionText("dlg_search_find", "Find");
                    lblReplace.Visibility         =
                        cboReplace.Visibility     =
                            cmdReplace.Visibility = cmdReplaceAll.Visibility = Visibility.Collapsed;
                }
                else
                {
                    Title = PNLang.Instance.GetCaptionText("dlg_search_replace", "Replace");
                }
                using (var oData = new SQLiteDataObject(PNData.ConnectionString))
                {
                    using (var t = oData.FillDataTable("SELECT FIND, REPLACE FROM FIND_REPLACE"))
                    {
                        if (t.Rows.Count > 0)
                        {
                            if (!PNData.IsDBNull(t.Rows[0]["FIND"]))
                            {
                                var values = (Convert.ToString(t.Rows[0]["FIND"])).Split(',');
                                foreach (var s in values)
                                {
                                    cboFind.Items.Add(s);
                                }
                            }
                            if (!PNData.IsDBNull(t.Rows[0]["REPLACE"]))
                            {
                                var values = (Convert.ToString(t.Rows[0]["REPLACE"])).Split(',');
                                foreach (var s in values)
                                {
                                    cboReplace.Items.Add(s);
                                }
                            }
                        }
                    }
                }
                cboFind.Text        = _Edit.SelectionLength > 0 ? _Edit.SelectedText : PNStatic.FindString;
                cboReplace.Text     = PNStatic.ReplaceString;
                chkRegExp.IsChecked = PNStatic.SearchMode == SearchMode.RegularExp;
                cboFind.Focus();
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
Пример #2
0
 private void DlgSearchInNotes_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         applyLanguage();
         PNStatic.FormMain.LanguageChanged     += FormMain_LanguageChanged;
         PNStatic.FormMain.NoteBooleanChanged  += FormMain_NoteBooleanChanged;
         PNStatic.FormMain.NoteNameChanged     += FormMain_NoteNameChanged;
         PNStatic.FormMain.NoteScheduleChanged += FormMain_NoteScheduleChanged;
         using (var oData = new SQLiteDataObject(PNData.ConnectionString))
         {
             using (var t = oData.FillDataTable("SELECT FIND, REPLACE FROM FIND_REPLACE"))
             {
                 if (t.Rows.Count <= 0)
                 {
                     return;
                 }
                 if (!PNData.IsDBNull(t.Rows[0]["FIND"]))
                 {
                     var values = Convert.ToString(t.Rows[0]["FIND"]).Split(',');
                     foreach (var s in values)
                     {
                         cboFind.Items.Add(s);
                     }
                 }
                 if (!PNData.IsDBNull(t.Rows[0]["REPLACE"]))
                 {
                     var values = Convert.ToString(t.Rows[0]["REPLACE"]).Split(',');
                     foreach (var s in values)
                     {
                         cboReplace.Items.Add(s);
                     }
                 }
             }
         }
         tvwResults.ItemsSource = _FoundItems;
         setSettings();
         cboFind.Focus();
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Пример #3
0
 internal static void CheckAndApplyNewMenusOrder(ContextMenu ctm)
 {
     try
     {
         var sb = new StringBuilder("SELECT COUNT(MENU_NAME) FROM MENUS_ORDER WHERE CONTEXT_NAME = '");
         sb.Append(ctm.Name);
         sb.Append("' AND ORDER_ORIGINAL <> ORDER_NEW");
         using (var oData = new SQLiteDataObject(PNData.ConnectionString))
         {
             var obj = oData.GetScalar(sb.ToString());
             if (obj != null && !PNData.IsDBNull(obj) && Convert.ToInt32(obj) > 0)
             {
                 RearrangeMenus(ctm);
             }
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Пример #4
0
        internal static List <Tuple <string, string> > GetGoogleContacts()
        {
            var list = new List <Tuple <string, string> >();

            try
            {
                using (var oData = new SQLiteDataObject(PNData.ConnectionString))
                {
                    var update = false;
                    using (var t = oData.FillDataTable("SELECT * FROM SERVICES WHERE APP_NAME = 'PNContactsLoader'"))
                    {
                        if (t.Rows.Count == 0)
                        {
                            return(list);
                        }
                        var row = t.Rows[0];
                        using (var enc = new PNEncryptor(PNKeys.ENC_KEY))
                        {
                            var gc = new GContacts(Convert.ToString(row["CLIENT_ID"]),
                                                   enc.DecryptString(Convert.ToString(row["CLIENT_SECRET"])),
                                                   Convert.ToString(row["APP_NAME"]));
                            if (!PNData.IsDBNull(row["ACCESS_TOKEN"]))
                            {
                                gc.AccessToken = enc.DecryptString(Convert.ToString(row["ACCESS_TOKEN"]));
                            }
                            if (!PNData.IsDBNull(row["REFRESH_TOKEN"]))
                            {
                                gc.RefreshToken = enc.DecryptString(Convert.ToString(row["REFRESH_TOKEN"]));
                            }
                            if (!PNData.IsDBNull(row["TOKEN_EXPIRY"]))
                            {
                                var expDate = Convert.ToDateTime(Convert.ToString(row["TOKEN_EXPIRY"]));
                                if (expDate <= DateTime.Now && !string.IsNullOrWhiteSpace(gc.RefreshToken) &&
                                    !string.IsNullOrWhiteSpace(gc.AccessToken))
                                {
                                    if (!string.IsNullOrWhiteSpace(gc.RefreshToken))
                                    {
                                        update = gc.RefreshAccessToken();
                                    }
                                    if (!update)
                                    {
                                        update = gc.Authenticate();
                                    }
                                    if (!update)
                                    {
                                        return(list);
                                    }
                                }
                            }
                            if (string.IsNullOrWhiteSpace(gc.AccessToken))
                            {
                                update = gc.Authenticate();
                            }

                            while (true)
                            {
                                try
                                {
                                    list = gc.GetContacts();
                                    if (update)
                                    {
                                        var sb = new StringBuilder("UPDATE SERVICES SET ACCESS_TOKEN = '");
                                        sb.Append(enc.EncryptString(gc.AccessToken));
                                        sb.Append("', REFRESH_TOKEN = '");
                                        sb.Append(enc.EncryptString(gc.RefreshToken));
                                        sb.Append("', TOKEN_EXPIRY = '");
                                        sb.Append(gc.TokenExpiry.ToString("dd MMM yyyy HH:mm:ss"));
                                        sb.Append("' WHERE APP_NAME = 'PNContactsLoader'");
                                        oData.Execute(sb.ToString());
                                    }
                                    break;
                                }
                                catch (PNContactsException pnex)
                                {
                                    if (pnex.AdditionalInfo.ToUpper().Contains("UNAUTHORIZED"))
                                    {
                                        if (!string.IsNullOrWhiteSpace(gc.RefreshToken))
                                        {
                                            update = gc.RefreshAccessToken();
                                        }
                                        if (update)
                                        {
                                            continue;
                                        }
                                        update = gc.Authenticate();
                                        if (update)
                                        {
                                            continue;
                                        }
                                        PNStatic.LogException(pnex);
                                        break;
                                    }
                                    PNStatic.LogException(pnex);
                                    break;
                                }
                                catch (Exception ex)
                                {
                                    PNStatic.LogException(ex);
                                    break;
                                }
                            }
                        }
                    }
                }
                return(list);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return(list);
            }
        }