private void ckbDefault_CheckedChanged(object sender, EventArgs e) { string dir = txtDirectory.Text; bool isChecked = ckbDefault.Checked; if (isChecked) { if (dir != string.Empty && System.IO.Directory.Exists(dir)) { XMLSettings.SetSettingsValue(XMLSettings.ApplicationSettings.DefaultDirectory, dir); ckbDefault.Enabled = false; } } }
private void btnSave_Click(object sender, EventArgs e) { string dir = txtDirectory.Text; bool alwaysOverwrite = ckbAlwaysOverwrite.Checked; if (alwaysOverwrite) { XMLSettings.SetSettingsValue(XMLSettings.ApplicationSettings.AlwaysOverwrite, "true"); } else { XMLSettings.SetSettingsValue(XMLSettings.ApplicationSettings.AlwaysOverwrite, "false"); } XMLSettings.SetSettingsValue(XMLSettings.ApplicationSettings.DefaultDirectory, dir); }
private void btnCombine_Click(object sender, EventArgs e) { if (lstFiles.Items.Count > 1) { TaskDialog tdConfirm = new TaskDialog(); tdConfirm.Caption = "Combine PDF"; tdConfirm.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; tdConfirm.InstructionText = "Are you sure you want to combine the files?"; if (tdConfirm.Show() == TaskDialogResult.Yes) { PdfDocument outputDocument = new PdfDocument(); string dir = txtDirectory.Text; foreach (string file in lstFiles.Items) { PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import); int count = inputDocument.PageCount; for (int idx = 0; idx < count; idx++) { PdfPage page = inputDocument.Pages[idx]; outputDocument.AddPage(page); } } frmInput input = new frmInput(); input.lblPrompt.Text = "Enter the name of the combined file"; input.Text = "Combine PDF"; if (input.ShowDialog() == DialogResult.OK) { string name = input.txtInput.Text + ".pdf"; string filename = Path.Combine(dir, name); TaskDialog tdOpen = new TaskDialog(); tdOpen.Caption = "Combine PDF"; tdOpen.Icon = TaskDialogStandardIcon.Information; tdOpen.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; tdOpen.InstructionText = "Files have been combined successfully"; tdOpen.Text = "Would you like the open the combined file now?"; tdOpen.FooterText = filename; if (!File.Exists(filename)) { outputDocument.Save(filename); if (tdOpen.Show() == TaskDialogResult.Yes) { Process.Start(filename); } } else { bool alwaysOverwrite = bool.Parse(XMLSettings.GetSettingsValue(XMLSettings.ApplicationSettings.AlwaysOverwrite)); if (alwaysOverwrite) { File.Delete(filename); outputDocument.Save(filename); if (tdOpen.Show() == TaskDialogResult.Yes) { Process.Start(filename); } } else { TaskDialog tdFileExists = new TaskDialog(); tdFileExists.Caption = "Combine PDF"; tdFileExists.Icon = TaskDialogStandardIcon.Warning; tdFileExists.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No; tdFileExists.InstructionText = "File already exists in this location"; tdFileExists.Text = "Overwrite file?"; tdFileExists.FooterText = filename; tdFileExists.FooterCheckBoxText = "Always Overwrite?"; tdFileExists.FooterCheckBoxChecked = false; if (tdFileExists.Show() == TaskDialogResult.Yes) { if (tdFileExists.FooterCheckBoxChecked.Value) { XMLSettings.SetSettingsValue(XMLSettings.ApplicationSettings.AlwaysOverwrite, "true"); } else { XMLSettings.SetSettingsValue(XMLSettings.ApplicationSettings.AlwaysOverwrite, "false"); } File.Delete(filename); outputDocument.Save(filename); if (tdOpen.Show() == TaskDialogResult.Yes) { Process.Start(filename); } } } } } } } else { TaskDialog tdAddFiles = new TaskDialog(); tdAddFiles.Caption = "Combine PDF"; tdAddFiles.Icon = TaskDialogStandardIcon.Warning; tdAddFiles.StandardButtons = TaskDialogStandardButtons.Ok; tdAddFiles.InstructionText = "At least two files must be provided before combining"; tdAddFiles.Text = "Click Add File to add more files"; tdAddFiles.Show(); } }