From 1e75972ae91b618576ea1fce5dafe197d8ba1be1 Mon Sep 17 00:00:00 2001 From: efrick Date: Tue, 6 Aug 2024 09:53:40 -0400 Subject: [PATCH] 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. --- App.config | 4 +++- ConfForm.Designer.cs | 25 +++++++++++++++++++++++++ ConfForm.cs | 11 +++++++++++ MainForm.cs | 10 +++++++++- MergePDFs.cs | 6 ++++++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/App.config b/App.config index 953f313..6b3d49e 100644 --- a/App.config +++ b/App.config @@ -3,7 +3,9 @@ - + + + \ No newline at end of file diff --git a/ConfForm.Designer.cs b/ConfForm.Designer.cs index 545b413..b83868f 100644 --- a/ConfForm.Designer.cs +++ b/ConfForm.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/ConfForm.cs b/ConfForm.cs index b1dc462..c4316ab 100644 --- a/ConfForm.cs +++ b/ConfForm.cs @@ -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(); diff --git a/MainForm.cs b/MainForm.cs index 22879b2..6da352e 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -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() diff --git a/MergePDFs.cs b/MergePDFs.cs index ec87d90..6f02570 100644 --- a/MergePDFs.cs +++ b/MergePDFs.cs @@ -77,6 +77,12 @@ } return pdfFiles; } + + public static string GetDate() + { + DateTime date = DateTime.Now; + return date.ToString("yyyy-MM-dd"); + } } }