Appending a date to the output file is now working.

This commit should resolve issue #1. Appending a date to the output file
is now a selectable option in the app configuration.
This commit is contained in:
efrick 2024-08-06 09:53:40 -04:00
parent 8c5d3f9e06
commit 1e75972ae9
5 changed files with 54 additions and 2 deletions

View File

@ -3,7 +3,9 @@
<appSettings>
<add key="PDF-Path" value=""/>
<add key="PDF-Output" value=""/>
<add key="PDF-Name" value="merged.pdf"/>
<add key="PDF-Name" value="merged"/>
<add key ="PDF-Extension" value=".pdf"/>
<add key="overwrite" value="true"/>
<add key="appendDate" value="false"/>
</appSettings>
</configuration>

25
ConfForm.Designer.cs generated
View File

@ -42,6 +42,8 @@ namespace PDF_Merge
outPathBtn = new Button();
FileLable = new Label();
FileNameBox = new TextBox();
fileExtlabel = new Label();
appendDatecheckBox = new CheckBox();
SuspendLayout();
//
// saveBtn
@ -144,11 +146,32 @@ namespace PDF_Merge
FileNameBox.Size = new Size(150, 31);
FileNameBox.TabIndex = 10;
//
// fileExtlabel
//
fileExtlabel.AutoSize = true;
fileExtlabel.Location = new Point(327, 114);
fileExtlabel.Name = "fileExtlabel";
fileExtlabel.Size = new Size(44, 25);
fileExtlabel.TabIndex = 11;
fileExtlabel.Text = ".pdf";
//
// appendDatecheckBox
//
appendDatecheckBox.AutoSize = true;
appendDatecheckBox.Location = new Point(171, 187);
appendDatecheckBox.Name = "appendDatecheckBox";
appendDatecheckBox.Size = new Size(144, 29);
appendDatecheckBox.TabIndex = 12;
appendDatecheckBox.Text = "Append Date";
appendDatecheckBox.UseVisualStyleBackColor = true;
//
// ConfForm
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(500, 282);
Controls.Add(appendDatecheckBox);
Controls.Add(fileExtlabel);
Controls.Add(FileNameBox);
Controls.Add(FileLable);
Controls.Add(outPathBtn);
@ -180,5 +203,7 @@ namespace PDF_Merge
private Button outPathBtn;
private Label FileLable;
private TextBox FileNameBox;
private Label fileExtlabel;
private CheckBox appendDatecheckBox;
}
}

View File

@ -20,10 +20,13 @@ namespace PDF_Merge
string sourcePath = ConfigurationManager.AppSettings["PDF-Path"];
string outputPath = ConfigurationManager.AppSettings["PDF-Output"];
string outputName = ConfigurationManager.AppSettings["PDF-Name"];
string outputExt = ConfigurationManager.AppSettings["PDF-Extension"];
sourceBox.Text = sourcePath;
outputBox.Text = outputPath;
FileNameBox.Text = outputName;
fileExtlabel.Text = outputExt;
if (ConfigurationManager.AppSettings["overwrite"] == true.ToString())
{
overrideCBox.Checked = true;
@ -32,6 +35,13 @@ namespace PDF_Merge
{
overrideCBox.Checked = false;
}
if (ConfigurationManager.AppSettings["appendDate"] == true.ToString() )
{
appendDatecheckBox.Checked = true;
} else
{
appendDatecheckBox.Checked = false;
}
}
private void cancelBtn_Click(object sender, EventArgs e)
@ -68,6 +78,7 @@ namespace PDF_Merge
MessageBox.Show("File must be named.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
appSettings.Settings["overwrite"].Value = overrideCBox.Checked.ToString();
appSettings.Settings["appendDate"].Value = appendDatecheckBox.Checked.ToString();
appConfig.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
this.Close();

View File

@ -12,7 +12,15 @@ namespace PDF_Merge
}
private static string getOutputPath()
{
string pdfPath = ConfigurationManager.AppSettings["PDF-Output"] + Path.DirectorySeparatorChar + ConfigurationManager.AppSettings["PDF-Name"];
string pdfPath;
if (ConfigurationManager.AppSettings["appendDate"] == true.ToString())
{
pdfPath = ConfigurationManager.AppSettings["PDF-Output"] + Path.DirectorySeparatorChar + ConfigurationManager.AppSettings["PDF-Name"] + "_" + MergePDFs.GetDate() + ConfigurationManager.AppSettings["PDF-Extension"];
}
else
{
pdfPath = ConfigurationManager.AppSettings["PDF-Output"] + Path.DirectorySeparatorChar + ConfigurationManager.AppSettings["PDF-Name"] + ConfigurationManager.AppSettings["PDF-Extension"];
}
return pdfPath;
}
public void SetPathLable()

View File

@ -77,6 +77,12 @@
}
return pdfFiles;
}
public static string GetDate()
{
DateTime date = DateTime.Now;
return date.ToString("yyyy-MM-dd");
}
}
}