PDF-Merge/ConfForm.cs

111 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PDF_Merge
{
public partial class ConfForm : Form
{
public ConfForm()
{
InitializeComponent();
string sourcePath = ConfigurationManager.AppSettings["PDF-Path"];
string outputPath = ConfigurationManager.AppSettings["PDF-Output"];
string outputName = ConfigurationManager.AppSettings["PDF-Name"];
sourceBox.Text = sourcePath;
outputBox.Text = outputPath;
FileNameBox.Text = outputName;
if (ConfigurationManager.AppSettings["overwrite"] == true.ToString())
{
overrideCBox.Checked = true;
}
else
{
overrideCBox.Checked = false;
}
}
private void cancelBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void saveBtn_Click(object sender, EventArgs e)
{
Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection appSettings = appConfig.AppSettings;
if (sourceBox.Text.Length > 0)
{
appSettings.Settings["PDF-Path"].Value = sourceBox.Text;
}
else
{
MessageBox.Show("Source path cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (outputBox.Text.Length > 0)
{
appSettings.Settings["PDF-Output"].Value = outputBox.Text;
}
else
{
MessageBox.Show("Output path cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (FileNameBox.Text.Length > 0)
{
appSettings.Settings["PDF-Name"].Value = FileNameBox.Text;
}
else
{
MessageBox.Show("File must be named.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
appSettings.Settings["overwrite"].Value = overrideCBox.Checked.ToString();
appConfig.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
this.Close();
}
private void sourceDirBtn_Click(object sender, EventArgs e)
{
using (var SourceDirPicker = new FolderBrowserDialog())
{
if (sourceBox.Text == "")
{
SourceDirPicker.RootFolder = Environment.SpecialFolder.MyDocuments;
}
else
{
string startingDir = sourceBox.Text;
SourceDirPicker.SelectedPath = startingDir;
}
if (SourceDirPicker.ShowDialog() == DialogResult.OK)
{
var sourceDir = SourceDirPicker.SelectedPath;
sourceBox.Text = sourceDir;
}
}
}
private void outPathBtn_Click(object sender, EventArgs e)
{
using (var OutPathPicker = new FolderBrowserDialog())
{
OutPathPicker.RootFolder = Environment.SpecialFolder.Desktop;
if (OutPathPicker.ShowDialog() == DialogResult.OK)
{
var OutPath = OutPathPicker.SelectedPath;
outputBox.Text = OutPath;
}
}
}
}
}