private void createOrderSql(PNTreeItem node) { try { foreach (var pti in node.Items.OfType <PNTreeItem>()) { createOrderSql(pti); } var pnm = node.Tag as PNMenu; if (pnm == null) { return; } var sb = new StringBuilder("UPDATE MENUS_ORDER SET ORDER_NEW = "); sb.Append(node.Index); sb.Append(" WHERE CONTEXT_NAME = '"); sb.Append(pnm.ContextName); sb.Append("' AND MENU_NAME = '"); sb.Append(pnm.Name); sb.Append("'"); _OrderSql.Add(sb.ToString()); } catch (Exception ex) { PNStatic.LogException(ex); } }
private void DlgSmtp_Loaded(object sender, RoutedEventArgs e) { try { PNLang.Instance.ApplyControlLanguage(this); if (_Mode == AddEditMode.Edit) { Title = PNLang.Instance.GetCaptionText("smtp_edit", "Edit SMTP client"); txtSmtpHost.Text = _Client.HostName; txtSmtpAddress.Text = _Client.SenderAddress; txtSmtpDisplayName.Text = _Client.DisplayName; txtSmtpPort.Text = _Client.Port.ToString(CultureInfo.InvariantCulture); using (var encryptor = new PNEncryptor(PNKeys.ENC_KEY)) { txtSmtpPassword.Password = encryptor.DecryptString(_Client.Password); } cmdOK.IsEnabled = true; } else { Title = PNLang.Instance.GetCaptionText("smtp_new", "New SMTP client"); } txtSmtpHost.SelectAll(); txtSmtpHost.Focus(); } catch (Exception ex) { PNStatic.LogException(ex); } }
private void downloadFile(string url) { try { disableControls(); m_Progress = lblDownloadInProgress.Text; var wr = WebRequest.Create(url); try { wr.Method = "HEAD"; wr.GetResponse(); } catch (Exception ex) { PNStatic.LogException(ex); DialogResult = false; } using (var wc = new WebClient()) { wc.DownloadFileCompleted += wc_DownloadFileCompleted; wc.DownloadProgressChanged += wc_DownloadProgressChanged; var uri = new Uri(url); wc.DownloadFileAsync(uri, m_FileToOpen); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void cmdOK_Click(object sender, RoutedEventArgs e) { try { ContactGroupChangedEventArgs ce; if (m_Mode == AddEditMode.Add) { var cg = new PNContactGroup { Name = txtGroupName.Text.Trim(), ID = m_NewId }; ce = new ContactGroupChangedEventArgs(cg, m_Mode); } else { m_Group.Name = txtGroupName.Text.Trim(); ce = new ContactGroupChangedEventArgs(m_Group, m_Mode); } if (ContactGroupChanged != null) { ContactGroupChanged(this, ce); } if (!ce.Accepted) { txtGroupName.SelectAll(); txtGroupName.Focus(); return; } DialogResult = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void DlgCanvas_Loaded(object sender, RoutedEventArgs e) { try { var loc = _Parent.GetLocation(); var scr = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point((int)loc.X, (int)loc.Y)); if (scr.WorkingArea.Left < _Parent.Left - ActualWidth) { Left = _Parent.Left - ActualWidth; } else { Left = _Parent.Left + _Parent.ActualWidth; } var anim = new DoubleAnimation(-100, _Parent.Top, new Duration(TimeSpan.FromMilliseconds(300))) { AccelerationRatio = 0.1 }; BeginAnimation(TopProperty, anim); inkCanvas.Background = new SolidColorBrush(_Color); inkCanvas.DefaultDrawingAttributes = new DrawingAttributes { Color = Colors.Black, Height = _PenSize, Width = _PenSize }; _Loaded = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
internal static T ReadINIStructure <T>(string fileName, string sectionName, string keyName, T type) { IntPtr ptr = IntPtr.Zero; try { ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(T))); if (ptr != IntPtr.Zero) { if (GetPrivateProfileStruct(sectionName, keyName, ptr, Marshal.SizeOf(typeof(T)), fileName)) { return((T)Marshal.PtrToStructure(ptr, typeof(T))); } } return(default(T)); } catch (Exception ex) { PNStatic.LogException(ex); return(default(T)); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeCoTaskMem(ptr); } } }
private void DlgExternals_Loaded(object sender, RoutedEventArgs e) { try { PNLang.Instance.ApplyControlLanguage(this); if (m_Mode == AddEditMode.Add) { Title = PNLang.Instance.GetCaptionText("ext_new", "New external program"); } else { Title = PNLang.Instance.GetCaptionText("ext_edit", "Edit external program"); txtExtName.IsReadOnly = true; txtExtName.Text = m_Ext.Name; txtExtProg.Text = m_Ext.Program; txtCommandLine.Text = m_Ext.CommandLine; } txtExtName.Focus(); txtExtName.SelectAll(); } catch (Exception ex) { PNStatic.LogException(ex); } }
internal string GetMenuText(string menuSection, string name, string defText) { try { if (Instance.XLang == null) { return(defText); } if (Instance.XLang.Root == null) { return(defText); } var xp = Instance.XLang.Root.Element(menuSection); if (xp == null) { return(defText); } var xe = xp.Element(name); return(xe != null ? xe.Value : defText); } catch (Exception ex) { PNStatic.LogException(ex); return(defText); } }
internal void ApplyMenuItemLanguage(MenuItem ti, string section) { try { if (Instance.XLang == null) { return; } if (ti.Name == "") { return; } if (Instance.XLang.Root != null) { var xElement = Instance.XLang.Root.Element(section); if (xElement != null) { var xe = xElement.Element(ti.Name); if (xe != null) { ti.Header = xe.Value; } } } foreach (var di in ti.Items.OfType <MenuItem>()) { ApplyMenuItemLanguage(di, section); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void cmdOK_Click(object sender, RoutedEventArgs e) { try { if (txtEnterPwrd.Password != txtConfirmPwrd.Password) { var message = PNLang.Instance.GetMessageText("pwrd_not_identical", "Both password strings should be identical. Please, check the spelling."); PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation); txtEnterPwrd.Focus(); txtEnterPwrd.SelectAll(); return; } string hash = PNEncryptor.GetHashString(txtEnterPwrd.Password.Trim()); if (hash != null) { if (PasswordChanged != null) { PasswordChanged(this, new PasswordChangedEventArgs(hash)); } } DialogResult = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void applyComboItems(ComboBox cbo) { try { if (Instance.XLang == null || Instance.XLang.Root == null) { return; } var index = cbo.SelectedIndex; var xp = Instance.XLang.Root.Element("list_" + cbo.Name); if (xp != null) { var arr = (from e in xp.Elements() select e.Value).ToArray(); cbo.Items.Clear(); foreach (var s in arr) { cbo.Items.Add(s); } } if (cbo.Items.Count > index) { cbo.SelectedIndex = index; } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void enableOk() { try { if (txtContactName.Text.Trim().Length == 0) { cmdOK.IsEnabled = false; return; } if (optUseCompName.IsChecked != null && optUseCompName.IsChecked.Value && txtCompName.Text.Trim().Length == 0) { cmdOK.IsEnabled = false; return; } if (optUseAddress.IsChecked != null && optUseAddress.IsChecked.Value && ipaAddress.IsAnyBlank) { cmdOK.IsEnabled = false; return; } cmdOK.IsEnabled = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private bool prepareDownloadList() { try { _FilesList = new List <Tuple <string, string, string, string> >(); var tempDir = Path.GetTempPath(); foreach (var item in lstThemes.Items.OfType <PNListBoxItem>().Where(it => it.IsChecked != null && it.IsChecked.Value)) { var sb = new StringBuilder(); var tu = item.Tag as ThemesUpdate; if (tu == null) { continue; } sb.Append(PNStrings.URL_DOWNLOAD_DIR); sb.Append(tu.Name); sb.Append(ZIP_SUFFIX); var tuple = Tuple.Create(sb.ToString(), Path.Combine(tempDir, tu.Name + ZIP_SUFFIX), Path.Combine(PNPaths.Instance.ThemesDir, tu.FileName), tu.FileName); _FilesList.Add(tuple); } return(true); } catch (Exception ex) { PNStatic.LogException(ex); return(false); } }
private void _WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { try { if (_Index >= _FilesList.Count) { return; } using (var zipFile = new ZipFile(_FilesList[_Index].Item2)) { zipFile.ExtractAll(Path.Combine(Path.GetTempPath(), PNStrings.TEMP_THEMES_DIR), ExtractExistingFileAction.OverwriteSilently); } File.Delete(_FilesList[_Index].Item2); _Index++; if (_Index < _FilesList.Count) { if (File.Exists(_FilesList[_Index].Item2)) { File.Delete(_FilesList[_Index].Item2); } _WebClient.DownloadFileAsync(new Uri(_FilesList[_Index].Item1), _FilesList[_Index].Item2, Path.GetFileName(_FilesList[_Index].Item2)); } else { cmdCancel.IsEnabled = false; preparePreRunXml(); DialogResult = true; } } catch (Exception ex) { PNStatic.LogException(ex); } }
private bool areFilesDifferent(string path1, string path2) { try { using (var fs1 = new FileStream(path1, FileMode.Open, FileAccess.Read)) { using (var fs2 = new FileStream(path2, FileMode.Open, FileAccess.Read)) { var l1 = fs1.Length; var l2 = fs2.Length; if (l1 != l2) { return(true); } while (fs1.Position < l1 && fs2.Position < l2) { if (fs1.ReadByte() != fs2.ReadByte()) { return(true); } } } } return(false); } catch (Exception ex) { PNStatic.LogException(ex); return(false); } }
internal string GetGridColumnCaption(string columnName, string defaultText) { try { string result = defaultText; if (Instance.XLang != null && Instance.XLang.Root != null) { XElement xp = Instance.XLang.Root.Element("grid_columns"); if (xp != null) { xp = xp.Element(columnName); if (xp != null) { result = xp.Value; } } } return(result); } catch (Exception ex) { PNStatic.LogException(ex); return(defaultText); } }
private bool EnumWindowsProc(IntPtr hwnd, int lParam) { try { if (!PNInterop.IsWindowVisible(hwnd)) { return(true); } var count = PNInterop.GetWindowTextLength(hwnd); if (count <= 0) { return(true); } var sb = new StringBuilder(count + 1); PNInterop.GetWindowText(hwnd, sb, count + 1); var sbClass = new StringBuilder(1024); PNInterop.GetClassName(hwnd, sbClass, sbClass.Capacity); m_Windows.Add(new PinWindow { ClassWnd = sbClass.ToString(), TextWnd = sb.ToString() }); return(true); } catch (Exception ex) { PNStatic.LogException(ex); return(false); } }
//internal void ApplyColumnsMenuLanguage(ContextMenu ctm) //{ // try // { // if (Instance.XLang == null || Instance.XLang.Root == null) return; // XElement xp = Instance.XLang.Root.Element("columns"); // if (xp != null) // { // var elements = xp.Elements().Where(e => e.Name.ToString().StartsWith("lvwNotes")).ToList(); // foreach (MenuItem ti in ctm.Items.OfType<MenuItem>()) // { // XElement xe = elements.FirstOrDefault(e => e.Name.ToString().EndsWith('_' + ti.Tag.ToString())); // if (xe != null) // { // ti.Header = xe.Value; // } // } // } // } // catch (Exception ex) // { // PNStatic.LogException(ex); // } //} internal void ApplyColumnsVisibilityMenuLanguage(ContextMenu ctm, string gridName) { try { if (Instance.XLang == null || Instance.XLang.Root == null) { return; } var xp = Instance.XLang.Root.Element("grid_columns"); if (xp == null) { return; } var elements = xp.Elements().Where(e => e.Name.ToString().StartsWith(gridName)).ToList(); var items = ctm.Items.OfType <MenuItem>(); foreach (var item in items) { var xe = elements.FirstOrDefault(e => e.Name.ToString().EndsWith((string)item.Tag)); if (xe != null) { item.Header = xe.Value; } } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void cmdOK_Click(object sender, RoutedEventArgs e) { try { var name = txtExtName.Text.Trim(); if (m_Mode == AddEditMode.Add && m_Prefs.ExternalExists(name)) { var message = PNLang.Instance.GetMessageText("ext_exists", "External program with this name already exists"); PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Information); } else { if (m_Mode == AddEditMode.Add) { m_Ext = new PNExternal { Name = name, Program = txtExtProg.Text.Trim(), CommandLine = txtCommandLine.Text.Trim() }; m_Prefs.ExternalAdd(m_Ext); } else { m_Ext.Program = txtExtProg.Text.Trim(); m_Ext.CommandLine = txtCommandLine.Text.Trim(); m_Prefs.ExternalReplace(m_Ext); } DialogResult = true; } } catch (Exception ex) { PNStatic.LogException(ex); } }
internal string GetControlText(string key, string defString) { try { string result = defString; if (Instance.XLang != null) { if (Instance.XLang.Root != null) { XElement xp = Instance.XLang.Root.Element("controls"); if (xp != null) { xp = xp.Element(key); if (xp != null) { result = xp.Value; } } } } return(result); } catch (Exception ex) { PNStatic.LogException(ex); return(defString); } }
internal static void CleanRegMUICache() { try { var fileName = Path.GetFileName(Application.ExecutablePath); var progName = fileName.ToUpper(); using (var key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\ShellNoRoam\\MUICache", true)) { if (key == null) { return; } var values = key.GetValueNames(); try { foreach (var s in values.Where(s => s.ToUpper().Contains(progName))) { key.DeleteValue(s, false); } } catch (SecurityException) { } } } catch (SecurityException) { } catch (Exception ex) { PNStatic.LogException(ex); } }
internal string GetOrdinalName(DayOrdinal ordinal) { try { string result = ordinal.ToString(); if (Instance.XLang != null) { if (Instance.XLang.Root != null) { XElement xp = Instance.XLang.Root.Element("lists"); if (xp != null) { xp = xp.Element("cboOrdinal"); if (xp != null) { string[] arr = xp.Value.Split('|'); result = arr[(int)ordinal - 1]; } } } } return(result); } catch (Exception ex) { PNStatic.LogException(ex); return(ordinal.ToString()); } }
private void FormMain_NoteTagsChanged(object sender, EventArgs e) { try { var note = sender as PNote; if (note == null || _Notes.Count == 0) { return; } var item = _Notes.FirstOrDefault(n => n.Id == note.ID); var tags = _Tags.Where(t => t.Selected).Select(t => t.Tag); if (item == null) //note was not in list { if (!note.Tags.Any(nt => tags.Any(t => t == nt))) { return; } var key = PNNotesOperations.GetNoteImage(note); _Notes.Add(new FoundNote(key, note.Name, note.Tags.ToCommaSeparatedString(), note.ID)); } else //note was in list { if (!note.Tags.Any(nt => tags.Any(t => t == nt))) { _Notes.Remove(item); } } } catch (Exception ex) { PNStatic.LogException(ex); } }
private bool importSounds(string iniPath) { try { var result = false; if (iniPath != null) { var dirName = Path.GetDirectoryName(iniPath); if (string.IsNullOrEmpty(dirName)) { return(false); } var soundsDir = Path.Combine(dirName, "sound"); if (Directory.Exists(soundsDir)) { var files = new DirectoryInfo(soundsDir).GetFiles("*.wav"); foreach (var fi in files) { var filePath = Path.Combine(PNPaths.Instance.SoundsDir, fi.Name); File.Copy(fi.FullName, filePath, true); result = true; } } } return(result); } catch (Exception ex) { PNStatic.LogException(ex); return(false); } }
internal static PNSkinDetails GetSkin(WndNote dlg, PNote note) { try { PNSkinDetails skn; if (note.Skin != null) { skn = note.Skin; } else { PNGroup gr = PNStatic.Groups.GetGroupByID(note.GroupID); if (gr.Skin == null || gr.Skin.SkinName == PNSkinDetails.NO_SKIN) //if (gr.ID != (int)SpecialGroups.Docking && gr.ID != (int)SpecialGroups.Diary) { // get General png skin gr = PNStatic.Groups.GetGroupByID(0); } skn = gr.Skin; } return(skn); } catch (Exception ex) { PNStatic.LogException(ex); return(null); } }
private bool executeTransaction(SQLiteDataObject oData, string sqlQuery) { var inTrans = false; try { inTrans = oData.BeginTransaction(); if (!inTrans) { return(false); } oData.ExecuteInTransaction(sqlQuery); oData.CommitTransaction(); inTrans = false; return(true); } catch (Exception ex) { if (inTrans) { oData.RollbackTransaction(); } PNStatic.LogException(ex); return(false); } }
internal static bool IsAppInstalled(OfficeApp app) { try { var keyName = ""; switch (app) { case OfficeApp.Outlook: keyName = OUTLOOK_APP; break; case OfficeApp.Excel: keyName = EXCEL_APP; break; case OfficeApp.Word: keyName = WORD_APP; break; } var key = Registry.ClassesRoot; var subKey = key.OpenSubKey(keyName); return(subKey != null); } catch (Exception ex) { PNStatic.LogException(ex); return(false); } }
//todo private bool exchangeData(SQLiteDataObject dataSrc, SQLiteDataObject dataDest, string id, Dictionary <string, List <_FieldData> > tablesData) { try { //todo if (!exchangeNotes(dataSrc, dataDest, id, tablesData.FirstOrDefault(td => td.Key == "NOTES"))) { return(false); } if (!exchangeCustomNotesSettings(dataSrc, dataDest, id, tablesData.FirstOrDefault(td => td.Key == "CUSTOM_NOTES_SETTINGS"))) { return(false); } if (!exchangeLinkedNotes(dataSrc, dataDest, id, tablesData.FirstOrDefault(td => td.Key == "LINKED_NOTES"))) { return(false); } if (!exchangeNotesSchedule(dataSrc, dataDest, id, tablesData.FirstOrDefault(td => td.Key == "NOTES_SCHEDULE"))) { return(false); } if (!exchangeNotesTags(dataSrc, dataDest, id, tablesData.FirstOrDefault(td => td.Key == "NOTES_TAGS"))) { return(false); } return(true); } catch (Exception ex) { PNStatic.LogException(ex); return(false); } }
private void cmdOK_Click(object sender, RoutedEventArgs e) { try { if (optGoOnlineHelp.IsChecked != null && optGoOnlineHelp.IsChecked.Value) { PNStatic.LoadPage(PNStrings.URL_HELP); DialogResult = true; } else if (optGetCHM.IsChecked != null && optGetCHM.IsChecked.Value) { m_FileToOpen = Path.Combine(System.Windows.Forms.Application.StartupPath, PNStrings.CHM_FILE); downloadFile(PNStrings.URL_DOWNLOAD_ROOT + PNStrings.CHM_FILE); } else { m_FileToOpen = Path.Combine(System.Windows.Forms.Application.StartupPath, PNStrings.PDF_FILE); downloadFile(PNStrings.URL_DOWNLOAD_ROOT + PNStrings.PDF_FILE); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private TreeView getActiveTreeView() { try { switch (tabMenus.SelectedIndex) { case 0: return(tvwMain); case 1: return(tvwNote); case 2: return(tvwEdit); case 3: return(tvwCP); } return(null); } catch (Exception ex) { PNStatic.LogException(ex); return(null); } }