From 1e75972ae91b618576ea1fce5dafe197d8ba1be1 Mon Sep 17 00:00:00 2001 From: efrick Date: Tue, 6 Aug 2024 09:53:40 -0400 Subject: [PATCH 1/3] 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"); + } } } -- 2.39.5 From 3b57fb0edfe6add10c7ea1e3bcde43091e92cc43 Mon Sep 17 00:00:00 2001 From: efrick Date: Tue, 6 Aug 2024 10:37:42 -0400 Subject: [PATCH 2/3] The date format is now selectable. Added the form controls and AppSettings keys to allow the user to select the format of the date appended to the output file. Further update to issue #1. --- AboutBox1.cs | 2 +- App.config | 2 ++ ConfForm.Designer.cs | 63 ++++++++++++++++++++++++++------------------ ConfForm.cs | 46 +++++++++++++++++++++++++++----- MergePDFs.cs | 3 ++- PDF-Merge.csproj | 1 - 6 files changed, 82 insertions(+), 35 deletions(-) diff --git a/AboutBox1.cs b/AboutBox1.cs index 6b64af7..ae5d3a3 100644 --- a/AboutBox1.cs +++ b/AboutBox1.cs @@ -37,7 +37,7 @@ namespace PDF_Merge return titleAttribute.Title; } } - return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); + return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); } } diff --git a/App.config b/App.config index 6b3d49e..2c777dd 100644 --- a/App.config +++ b/App.config @@ -7,5 +7,7 @@ + + \ No newline at end of file diff --git a/ConfForm.Designer.cs b/ConfForm.Designer.cs index b83868f..ee98ebe 100644 --- a/ConfForm.Designer.cs +++ b/ConfForm.Designer.cs @@ -30,8 +30,8 @@ namespace PDF_Merge /// private void InitializeComponent() { - saveBtn = new Button(); - cancelBtn = new Button(); + SaveBtn = new Button(); + CancelBtn = new Button(); sourceBox = new TextBox(); outputBox = new TextBox(); folderBrowserDialog1 = new FolderBrowserDialog(); @@ -44,27 +44,28 @@ namespace PDF_Merge FileNameBox = new TextBox(); fileExtlabel = new Label(); appendDatecheckBox = new CheckBox(); + dateFormatOpts = new ComboBox(); SuspendLayout(); // - // saveBtn + // SaveBtn // - saveBtn.Location = new Point(327, 227); - saveBtn.Name = "saveBtn"; - saveBtn.Size = new Size(112, 34); - saveBtn.TabIndex = 0; - saveBtn.Text = "Save"; - saveBtn.UseVisualStyleBackColor = true; - saveBtn.Click += saveBtn_Click; + SaveBtn.Location = new Point(327, 227); + SaveBtn.Name = "SaveBtn"; + SaveBtn.Size = new Size(112, 34); + SaveBtn.TabIndex = 0; + SaveBtn.Text = "Save"; + SaveBtn.UseVisualStyleBackColor = true; + SaveBtn.Click += SaveBtn_Click; // - // cancelBtn + // CancelBtn // - cancelBtn.Location = new Point(193, 227); - cancelBtn.Name = "cancelBtn"; - cancelBtn.Size = new Size(112, 34); - cancelBtn.TabIndex = 1; - cancelBtn.Text = "Cancel"; - cancelBtn.UseVisualStyleBackColor = true; - cancelBtn.Click += cancelBtn_Click; + CancelBtn.Location = new Point(193, 227); + CancelBtn.Name = "CancelBtn"; + CancelBtn.Size = new Size(112, 34); + CancelBtn.TabIndex = 1; + CancelBtn.Text = "Cancel"; + CancelBtn.UseVisualStyleBackColor = true; + CancelBtn.Click += CancelBtn_Click; // // sourceBox // @@ -118,7 +119,7 @@ namespace PDF_Merge sourceDirBtn.TabIndex = 7; sourceDirBtn.Text = "..."; sourceDirBtn.UseVisualStyleBackColor = true; - sourceDirBtn.Click += sourceDirBtn_Click; + sourceDirBtn.Click += SourceDirBtn_Click; // // outPathBtn // @@ -128,7 +129,7 @@ namespace PDF_Merge outPathBtn.TabIndex = 8; outPathBtn.Text = "..."; outPathBtn.UseVisualStyleBackColor = true; - outPathBtn.Click += outPathBtn_Click; + outPathBtn.Click += OutPathBtn_Click; // // FileLable // @@ -164,12 +165,23 @@ namespace PDF_Merge appendDatecheckBox.TabIndex = 12; appendDatecheckBox.Text = "Append Date"; appendDatecheckBox.UseVisualStyleBackColor = true; + appendDatecheckBox.CheckedChanged += AppendDatecheckBox_CheckedChanged; + // + // dateFormatOpts + // + dateFormatOpts.FormattingEnabled = true; + dateFormatOpts.Items.AddRange(new object[] { "yyyy-MM-dd", "MM-dd-yyyy" }); + dateFormatOpts.Location = new Point(321, 188); + dateFormatOpts.Name = "dateFormatOpts"; + dateFormatOpts.Size = new Size(182, 33); + dateFormatOpts.TabIndex = 13; // // ConfForm // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(500, 282); + ClientSize = new Size(546, 282); + Controls.Add(dateFormatOpts); Controls.Add(appendDatecheckBox); Controls.Add(fileExtlabel); Controls.Add(FileNameBox); @@ -181,8 +193,8 @@ namespace PDF_Merge Controls.Add(sourceLabel); Controls.Add(outputBox); Controls.Add(sourceBox); - Controls.Add(cancelBtn); - Controls.Add(saveBtn); + Controls.Add(CancelBtn); + Controls.Add(SaveBtn); Name = "ConfForm"; Text = "Configure"; ResumeLayout(false); @@ -191,8 +203,8 @@ namespace PDF_Merge #endregion - private Button saveBtn; - private Button cancelBtn; + private Button SaveBtn; + private Button CancelBtn; private TextBox sourceBox; private TextBox outputBox; private FolderBrowserDialog folderBrowserDialog1; @@ -205,5 +217,6 @@ namespace PDF_Merge private TextBox FileNameBox; private Label fileExtlabel; private CheckBox appendDatecheckBox; + private ComboBox dateFormatOpts; } } \ No newline at end of file diff --git a/ConfForm.cs b/ConfForm.cs index c4316ab..6e93b70 100644 --- a/ConfForm.cs +++ b/ConfForm.cs @@ -21,12 +21,24 @@ namespace PDF_Merge string outputPath = ConfigurationManager.AppSettings["PDF-Output"]; string outputName = ConfigurationManager.AppSettings["PDF-Name"]; string outputExt = ConfigurationManager.AppSettings["PDF-Extension"]; + string dateIndex = ConfigurationManager.AppSettings["dateIndex"]; + + int dateIndexValue; + + bool indexSet = int.TryParse(dateIndex, out dateIndexValue); + if (indexSet) + { + dateFormatOpts.SelectedIndex = dateIndexValue; + } else + { + dateFormatOpts.SelectedIndex = 0; + } sourceBox.Text = sourcePath; outputBox.Text = outputPath; FileNameBox.Text = outputName; fileExtlabel.Text = outputExt; - + if (ConfigurationManager.AppSettings["overwrite"] == true.ToString()) { overrideCBox.Checked = true; @@ -35,21 +47,23 @@ namespace PDF_Merge { overrideCBox.Checked = false; } - if (ConfigurationManager.AppSettings["appendDate"] == true.ToString() ) + if (ConfigurationManager.AppSettings["appendDate"] == true.ToString()) { appendDatecheckBox.Checked = true; - } else + } + else { appendDatecheckBox.Checked = false; } + CheckAppend(); } - private void cancelBtn_Click(object sender, EventArgs e) + private void CancelBtn_Click(object sender, EventArgs e) { this.Close(); } - private void saveBtn_Click(object sender, EventArgs e) + private void SaveBtn_Click(object sender, EventArgs e) { Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); AppSettingsSection appSettings = appConfig.AppSettings; @@ -79,12 +93,14 @@ namespace PDF_Merge } appSettings.Settings["overwrite"].Value = overrideCBox.Checked.ToString(); appSettings.Settings["appendDate"].Value = appendDatecheckBox.Checked.ToString(); + appSettings.Settings["dateFormat"].Value = dateFormatOpts.SelectedItem.ToString(); + appSettings.Settings["dateIndex"].Value = dateFormatOpts.SelectedIndex.ToString(); appConfig.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); this.Close(); } - private void sourceDirBtn_Click(object sender, EventArgs e) + private void SourceDirBtn_Click(object sender, EventArgs e) { using (var SourceDirPicker = new FolderBrowserDialog()) { @@ -105,7 +121,7 @@ namespace PDF_Merge } } - private void outPathBtn_Click(object sender, EventArgs e) + private void OutPathBtn_Click(object sender, EventArgs e) { using (var OutPathPicker = new FolderBrowserDialog()) { @@ -117,5 +133,21 @@ namespace PDF_Merge } } } + + private void AppendDatecheckBox_CheckedChanged(object sender, EventArgs e) + { + CheckAppend(); + } + private void CheckAppend() + { + if (appendDatecheckBox.Checked) + { + dateFormatOpts.Visible = true; + } + else + { + dateFormatOpts.Visible = false; + } + } } } diff --git a/MergePDFs.cs b/MergePDFs.cs index 6f02570..03ff9e2 100644 --- a/MergePDFs.cs +++ b/MergePDFs.cs @@ -81,7 +81,8 @@ public static string GetDate() { DateTime date = DateTime.Now; - return date.ToString("yyyy-MM-dd"); + string dateFormat = ConfigurationManager.AppSettings["dateFormat"]; + return date.ToString(dateFormat); } } diff --git a/PDF-Merge.csproj b/PDF-Merge.csproj index 28f9cf7..0691204 100644 --- a/PDF-Merge.csproj +++ b/PDF-Merge.csproj @@ -26,7 +26,6 @@ - -- 2.39.5 From ba059015cf7143960d0d5c804850404ed3f42f23 Mon Sep 17 00:00:00 2001 From: efrick Date: Tue, 6 Aug 2024 10:41:00 -0400 Subject: [PATCH 3/3] Bump version number. --- PDF-Merge.csproj | 2 +- PDF-Merge.nsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PDF-Merge.csproj b/PDF-Merge.csproj index 0691204..3584672 100644 --- a/PDF-Merge.csproj +++ b/PDF-Merge.csproj @@ -9,7 +9,7 @@ enable LICENSE README.md - 2024.08.05 + 2024.08.06.01 ABSC Inc. This tool merges PDF files from a configured directory into a single PDF. GNU GPL v3 2024 diff --git a/PDF-Merge.nsi b/PDF-Merge.nsi index a999ca9..3fa1a17 100644 --- a/PDF-Merge.nsi +++ b/PDF-Merge.nsi @@ -23,7 +23,7 @@ Var Current_Version Function SetWelcomeMsg StrCpy $Company_Name "Applied Business Solutions Consulting, Inc. (ABSC)" - StrCpy $Current_Version "2024.08.05.1" + StrCpy $Current_Version "2024.08.06.1" SendMessage $mui.WelcomePage.Text= ${WM_SETTEXT} 0 "STR: Merge several PDFs into a single file.$\n Requiers .NET version 6 $\n Version: $Current_Version $\n Developed by: $Company_Name" FunctionEnd -- 2.39.5