Update code to reflect change in config file.
The configuration now seperates the output path and filename into seperate componentants.
This commit is contained in:
parent
f85361ed27
commit
1d332927d6
@ -2,7 +2,8 @@
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="PDF-Path" value="C:\Users\ltdvw\Documents\PDF-Test"/>
|
||||
<add key="PDF-Output" value="C:\Users\ltdvw\Documents\PDF-Test\merged.pdf"/>
|
||||
<add key="PDF-Output" value="C:\Users\ltdvw\Documents\PDF-Test\"/>
|
||||
<add key="PDF-Name" value="merged.pdf"/>
|
||||
<add key="overwrite" value="true"/>
|
||||
</appSettings>
|
||||
</configuration>
|
29
ConfForm.Designer.cs
generated
29
ConfForm.Designer.cs
generated
@ -40,11 +40,13 @@ namespace PDF_Merge
|
||||
overrideCBox = new CheckBox();
|
||||
sourceDirBtn = new Button();
|
||||
outPathBtn = new Button();
|
||||
FileLable = new Label();
|
||||
FileNameBox = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// saveBtn
|
||||
//
|
||||
saveBtn.Location = new Point(327, 175);
|
||||
saveBtn.Location = new Point(327, 227);
|
||||
saveBtn.Name = "saveBtn";
|
||||
saveBtn.Size = new Size(112, 34);
|
||||
saveBtn.TabIndex = 0;
|
||||
@ -54,7 +56,7 @@ namespace PDF_Merge
|
||||
//
|
||||
// cancelBtn
|
||||
//
|
||||
cancelBtn.Location = new Point(193, 175);
|
||||
cancelBtn.Location = new Point(193, 227);
|
||||
cancelBtn.Name = "cancelBtn";
|
||||
cancelBtn.Size = new Size(112, 34);
|
||||
cancelBtn.TabIndex = 1;
|
||||
@ -99,7 +101,7 @@ namespace PDF_Merge
|
||||
overrideCBox.AutoSize = true;
|
||||
overrideCBox.Checked = true;
|
||||
overrideCBox.CheckState = CheckState.Checked;
|
||||
overrideCBox.Location = new Point(171, 105);
|
||||
overrideCBox.Location = new Point(171, 152);
|
||||
overrideCBox.Name = "overrideCBox";
|
||||
overrideCBox.Size = new Size(179, 29);
|
||||
overrideCBox.TabIndex = 6;
|
||||
@ -124,12 +126,31 @@ namespace PDF_Merge
|
||||
outPathBtn.TabIndex = 8;
|
||||
outPathBtn.Text = "...";
|
||||
outPathBtn.UseVisualStyleBackColor = true;
|
||||
outPathBtn.Click += outPathBtn_Click;
|
||||
//
|
||||
// FileLable
|
||||
//
|
||||
FileLable.AutoSize = true;
|
||||
FileLable.Location = new Point(25, 108);
|
||||
FileLable.Name = "FileLable";
|
||||
FileLable.Size = new Size(82, 25);
|
||||
FileLable.TabIndex = 9;
|
||||
FileLable.Text = "Filename";
|
||||
//
|
||||
// FileNameBox
|
||||
//
|
||||
FileNameBox.Location = new Point(171, 108);
|
||||
FileNameBox.Name = "FileNameBox";
|
||||
FileNameBox.Size = new Size(150, 31);
|
||||
FileNameBox.TabIndex = 10;
|
||||
//
|
||||
// ConfForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(500, 282);
|
||||
Controls.Add(FileNameBox);
|
||||
Controls.Add(FileLable);
|
||||
Controls.Add(outPathBtn);
|
||||
Controls.Add(sourceDirBtn);
|
||||
Controls.Add(overrideCBox);
|
||||
@ -157,5 +178,7 @@ namespace PDF_Merge
|
||||
private CheckBox overrideCBox;
|
||||
private Button sourceDirBtn;
|
||||
private Button outPathBtn;
|
||||
private Label FileLable;
|
||||
private TextBox FileNameBox;
|
||||
}
|
||||
}
|
26
ConfForm.cs
26
ConfForm.cs
@ -19,9 +19,11 @@ namespace PDF_Merge
|
||||
|
||||
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;
|
||||
@ -57,6 +59,14 @@ namespace PDF_Merge
|
||||
{
|
||||
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");
|
||||
@ -67,12 +77,26 @@ namespace PDF_Merge
|
||||
{
|
||||
using (var SourceDirPicker = new FolderBrowserDialog())
|
||||
{
|
||||
if(SourceDirPicker.ShowDialog() == DialogResult.OK)
|
||||
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 OpenFileDialog()) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,8 @@ namespace PDF_Merge
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
string[] pdf_files = MergePDFs.CollectPdfFiles();
|
||||
MergePDFs.MergePdfFiles(pdf_files, ConfigurationManager.AppSettings["PDF-Output"]);
|
||||
string pdfPath = ConfigurationManager.AppSettings["PDF-Output"] + "/" + ConfigurationManager.AppSettings["PDF-Name"];
|
||||
MergePDFs.MergePdfFiles(pdf_files, pdfPath);
|
||||
}
|
||||
|
||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
using (var output = new PdfDocument())
|
||||
{
|
||||
if (ConfigurationManager.AppSettings["overwrite"] == "true")
|
||||
if (ConfigurationManager.AppSettings["overwrite"] == true.ToString())
|
||||
{
|
||||
if (File.Exists(outputPath))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user