From d7789612e4edde4e8d2164851c758c154980170c Mon Sep 17 00:00:00 2001 From: Miguel Nieto Date: Fri, 18 Jun 2021 18:23:06 +0200 Subject: [PATCH 01/11] Menu and recent profiles list --- AccessScrCtrl/AccessScrCtl.json | 48 ++++++++ AccessScrCtrl/AccessScrCtrl.csproj | 9 ++ AccessScrCtrl/Configuration.cs | 35 ++++++ AccessScrCtrl/MainFrm.Designer.cs | 103 +++++++++++++++--- AccessScrCtrl/MainFrm.cs | 71 ++++++++++++ AccessScrCtrl/MainFrm.resx | 5 +- .../Properties/Resources.Designer.cs | 28 +++++ AccessScrCtrl/Properties/Resources.resx | 10 ++ 8 files changed, 293 insertions(+), 16 deletions(-) create mode 100644 AccessScrCtrl/AccessScrCtl.json create mode 100644 AccessScrCtrl/Configuration.cs diff --git a/AccessScrCtrl/AccessScrCtl.json b/AccessScrCtrl/AccessScrCtl.json new file mode 100644 index 0000000..527143f --- /dev/null +++ b/AccessScrCtrl/AccessScrCtl.json @@ -0,0 +1,48 @@ +{ + "LogLevel": "NFO", + "Profiles": [ + { + "Name": "my name2", + "FileName": "path/to/file.accvcs", + "LastUsedOrder": 2 + }, + { + "Name": "my name1", + "FileName": "path/to/file.accvcs", + "LastUsedOrder": 1 + } + ], + "MRUNumber": 4, + "Default": { + "Name": "DefaultProfile", + "Version": 1, + "AccessFile": "path/to/file.mdb", + "WorkingCopy": "folderName", + "LastSaveDateTime": "", + "LogLevel": "NFO", + "LogFileName": "", + "ImportOptions": { + "OverwriteDatabase": false, + "ConfirmImportedObjects": false, + "RemoveNotLoaded": false, + "AllowDataLostTables": [ + "TableName1", + "Pattern*" + ], + "Excludes": [ + "Pattern*" + ] + }, + "ExportOptions": { + "ExtensionNaming": "type.vb|type.txt|type", + "ExportTableData": [ + "Pattern*" + ], + "ExportTableFormat": "sql|csv", + "ExportQueryDefAs": "Definition|sql|both", + "Excludes": [ + "Pattern*" + ] + } + } +} \ No newline at end of file diff --git a/AccessScrCtrl/AccessScrCtrl.csproj b/AccessScrCtrl/AccessScrCtrl.csproj index d60a98c..26ae1ff 100644 --- a/AccessScrCtrl/AccessScrCtrl.csproj +++ b/AccessScrCtrl/AccessScrCtrl.csproj @@ -95,6 +95,7 @@ + Form @@ -134,6 +135,9 @@ ResXFileCodeGenerator Names.Designer.cs + + PreserveNewest + SettingsSingleFileGenerator @@ -164,6 +168,11 @@ + + + 13.0.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 153, 17 + + + Microsoft Access (*.accdb;*.mdb;*.adp;*.mda;*.accda)|*.accdb;*.mdb;*.adp;*.mda;*.accda|Microsoft Access database (*.mdb;*.accdb)|*.mdb;*.accdb|Microsoft Access 2007 onwards database (*.accdb;*.accda)|*.accdb;*.accda|Microsoft Access up to 2007 database (*.mdb;*.mda)|*.mdb;*.mda + + + 270, 17 + + \ No newline at end of file diff --git a/AccessScrCtrl/Properties/Resources.Designer.cs b/AccessScrCtrl/Properties/Resources.Designer.cs index a58d4a0..080888b 100644 --- a/AccessScrCtrl/Properties/Resources.Designer.cs +++ b/AccessScrCtrl/Properties/Resources.Designer.cs @@ -99,6 +99,24 @@ internal static System.Drawing.Icon Export { } } + /// + /// Looks up a localized string similar to File not found.. + /// + internal static string FileNotFound { + get { + return ResourceManager.GetString("FileNotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Folder doesn't exist.. + /// + internal static string FolderNotFound { + get { + return ResourceManager.GetString("FolderNotFound", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// @@ -155,6 +173,15 @@ internal static string Saving { } } + /// + /// Looks up a localized string similar to Specify a file name. + /// + internal static string SpecifyFileName { + get { + return ResourceManager.GetString("SpecifyFileName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Unexpected error: ///{0}. diff --git a/AccessScrCtrl/Properties/Resources.resx b/AccessScrCtrl/Properties/Resources.resx index 64c81b2..c9cf099 100644 --- a/AccessScrCtrl/Properties/Resources.resx +++ b/AccessScrCtrl/Properties/Resources.resx @@ -131,6 +131,12 @@ ..\Resources\1137.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + File not found. + + + Folder doesn't exist. + ..\Resources\1145.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -150,6 +156,9 @@ Do you want to remove it from the Recent list? Saving {0} + + Specify a file name + Unexpected error: {0} diff --git a/AccessScrCtrl/TestDatabase2.accvcs b/AccessScrCtrl/TestDatabase2.accvcs new file mode 100644 index 0000000..10c81cf --- /dev/null +++ b/AccessScrCtrl/TestDatabase2.accvcs @@ -0,0 +1,17 @@ +{ + "Name": "TestDatabase2", + "Version": 0, + "AccessFile": "..\\TestDatabase - copia.accdb", + "WorkingCopy": "..\\TestDatabase", + "LastSaveDateTime": null, + "LogLevel": null, + "LogFileName": null, + "ImportOptions": { + "OverwriteDatabase": false, + "ConfirmImportedObjects": false, + "RemoveNotLoaded": false, + "AllowDataLostTables": null, + "Excludes": null + }, + "ExportOptions": null +} \ No newline at end of file diff --git a/AccessScrCtrlUI/AccessScrCtrlUI.csproj b/AccessScrCtrlUI/AccessScrCtrlUI.csproj index 07840ae..febc3df 100644 --- a/AccessScrCtrlUI/AccessScrCtrlUI.csproj +++ b/AccessScrCtrlUI/AccessScrCtrlUI.csproj @@ -51,6 +51,12 @@ + + UserControl + + + ExpressionGrid.cs + UserControl @@ -79,6 +85,9 @@ + + ExpressionGrid.cs + FilesTree.cs diff --git a/AccessScrCtrlUI/ExpressionGrid.Designer.cs b/AccessScrCtrlUI/ExpressionGrid.Designer.cs new file mode 100644 index 0000000..f259b09 --- /dev/null +++ b/AccessScrCtrlUI/ExpressionGrid.Designer.cs @@ -0,0 +1,79 @@ + +namespace AccessScrCtrlUI { + partial class ExpressionGrid { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.gridView = new System.Windows.Forms.DataGridView(); + this.ExpressionColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.captionLabel = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.gridView)).BeginInit(); + this.SuspendLayout(); + // + // gridView + // + this.gridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.gridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ExpressionColumn}); + this.gridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.gridView.Location = new System.Drawing.Point(0, 13); + this.gridView.Name = "gridView"; + this.gridView.Size = new System.Drawing.Size(334, 179); + this.gridView.TabIndex = 0; + // + // ExpressionColumn + // + this.ExpressionColumn.HeaderText = "Expression"; + this.ExpressionColumn.Name = "ExpressionColumn"; + this.ExpressionColumn.Width = 180; + // + // captionLabel + // + this.captionLabel.AutoSize = true; + this.captionLabel.Dock = System.Windows.Forms.DockStyle.Top; + this.captionLabel.Location = new System.Drawing.Point(0, 0); + this.captionLabel.Name = "captionLabel"; + this.captionLabel.Size = new System.Drawing.Size(0, 13); + this.captionLabel.TabIndex = 1; + // + // ExpressionGrid + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.gridView); + this.Controls.Add(this.captionLabel); + this.Name = "ExpressionGrid"; + this.Size = new System.Drawing.Size(334, 192); + ((System.ComponentModel.ISupportInitialize)(this.gridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataGridView gridView; + private System.Windows.Forms.DataGridViewTextBoxColumn ExpressionColumn; + private System.Windows.Forms.Label captionLabel; + } +} diff --git a/AccessScrCtrlUI/ExpressionGrid.cs b/AccessScrCtrlUI/ExpressionGrid.cs new file mode 100644 index 0000000..60789f7 --- /dev/null +++ b/AccessScrCtrlUI/ExpressionGrid.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace AccessScrCtrlUI { + public partial class ExpressionGrid : UserControl { + public ExpressionGrid() { + InitializeComponent(); + } + + [Browsable(true)] + public string Caption { + get => captionLabel.Text; + set => captionLabel.Text = value; + } + + public void AddValues(IEnumerable expressions) { + foreach(string expression in expressions) { + var row = (DataGridViewRow)gridView.RowTemplate.Clone(); + row.CreateCells(gridView, expression); + gridView.Rows.Add(row); + } + } + + public IEnumerableGetValues() { + return gridView.Rows. + Cast(). + Select(x => x.Cells[0].ToString()); + } + } +} diff --git a/AccessScrCtrlUI/ExpressionGrid.resx b/AccessScrCtrlUI/ExpressionGrid.resx new file mode 100644 index 0000000..4708b74 --- /dev/null +++ b/AccessScrCtrlUI/ExpressionGrid.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file From 328cb1a238d49035ac5d923d1dd4b914399138b6 Mon Sep 17 00:00:00 2001 From: Miguel Nieto Date: Fri, 25 Jun 2021 20:50:28 +0200 Subject: [PATCH 07/11] Use existing info to create new profile --- AccessScrCtrl/MainFrm.cs | 2 +- AccessScrCtrl/Profiles/ProfileFrm.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/AccessScrCtrl/MainFrm.cs b/AccessScrCtrl/MainFrm.cs index 502b6fe..efde86c 100644 --- a/AccessScrCtrl/MainFrm.cs +++ b/AccessScrCtrl/MainFrm.cs @@ -255,7 +255,7 @@ private void MainFrm_FormClosed(object sender, FormClosedEventArgs e) { } private void newMenu_Click(object sender, EventArgs e) { - var profileFrm = new ProfileFrm(null); + var profileFrm = new ProfileFrm(fileNameTextBox.Text, workingCopyTextBox.Text); if (profileFrm.ShowDialog() == DialogResult.OK) { Config.SaveProfile(profileFrm.Profile, profileFrm.ProfileFileName); Config.AddProfile(profileFrm.Profile, profileFrm.ProfileFileName); diff --git a/AccessScrCtrl/Profiles/ProfileFrm.cs b/AccessScrCtrl/Profiles/ProfileFrm.cs index fe9993a..60f620e 100644 --- a/AccessScrCtrl/Profiles/ProfileFrm.cs +++ b/AccessScrCtrl/Profiles/ProfileFrm.cs @@ -23,10 +23,17 @@ public ProfileFrm() { Validator = new Helpers.ValidationHelper(errorProvider1); } - public ProfileFrm(Profile profile): this() { - Profile = profile; + + public ProfileFrm(string accessFileName, string workinCopy) : this() { + Profile = new Profile { + AccessFile = accessFileName, + WorkingCopy = workinCopy + }; + accessNameTextBox.Text = accessFileName; + workingCopyTextBox.Text = workinCopy; + absoluteRadioButton.Checked = true; } - + private void ProfileFrm_Load(object sender, EventArgs e) { ImportFrm = EmbedForm(new ImportOptionsFrm(), importTab); } From 49866faad712f75ce1dc4720489c7fbe8e6a8da5 Mon Sep 17 00:00:00 2001 From: Miguel Nieto Date: Sun, 27 Jun 2021 19:56:39 +0200 Subject: [PATCH 08/11] Profile editor: Edit profile --- AccessScrCtrl/AccessScrCtrl.csproj | 2 + AccessScrCtrl/Helpers/CommonDialogs.cs | 27 ++++++++ AccessScrCtrl/Helpers/PathUtil.cs | 4 +- AccessScrCtrl/ImportOptionsFrm.Designer.cs | 1 - AccessScrCtrl/ImportOptionsFrm.cs | 49 ++++++++------- AccessScrCtrl/MainFrm.Designer.cs | 42 ++++++++----- AccessScrCtrl/MainFrm.cs | 61 +++++++++++++------ AccessScrCtrl/MainFrm.resx | 5 +- AccessScrCtrl/Profiles/Configuration.cs | 13 ++-- AccessScrCtrl/Profiles/Profile.cs | 16 ++++- AccessScrCtrl/Profiles/ProfileFrm.cs | 23 ++++--- .../Properties/Resources.Designer.cs | 36 +++++++++++ AccessScrCtrl/Properties/Resources.resx | 12 ++++ AccessScrCtrl/TestDatabase2.accvcs | 17 ------ 14 files changed, 211 insertions(+), 97 deletions(-) create mode 100644 AccessScrCtrl/Helpers/CommonDialogs.cs delete mode 100644 AccessScrCtrl/TestDatabase2.accvcs diff --git a/AccessScrCtrl/AccessScrCtrl.csproj b/AccessScrCtrl/AccessScrCtrl.csproj index b23bacd..10fb714 100644 --- a/AccessScrCtrl/AccessScrCtrl.csproj +++ b/AccessScrCtrl/AccessScrCtrl.csproj @@ -85,6 +85,7 @@ + @@ -95,6 +96,7 @@ + diff --git a/AccessScrCtrl/Helpers/CommonDialogs.cs b/AccessScrCtrl/Helpers/CommonDialogs.cs new file mode 100644 index 0000000..6ec6d6b --- /dev/null +++ b/AccessScrCtrl/Helpers/CommonDialogs.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace AccessScrCtrl.Helpers { + class CommonDialogs { + public static OpenFileDialog OpenAccess(string selectedFile) { + var result = new OpenFileDialog { + Title = Properties.Resources.OpenAccessFile, + Filter = Properties.Resources.OpenAccessFilter, + FileName = selectedFile + }; + return result; + } + + public static OpenFileDialog OpenProfile(string selectedFile) { + var result = new OpenFileDialog { + Title = Properties.Resources.OpenProfileFile, + Filter = Properties.Resources.OpenProfileFilter, + FileName = selectedFile + }; + return result; + } + } +} diff --git a/AccessScrCtrl/Helpers/PathUtil.cs b/AccessScrCtrl/Helpers/PathUtil.cs index 88edfaf..d5c3d11 100644 --- a/AccessScrCtrl/Helpers/PathUtil.cs +++ b/AccessScrCtrl/Helpers/PathUtil.cs @@ -22,10 +22,10 @@ public static string GetFullPath(string path, string basePath) { //on net standard 2.1 and net core 2.1 is available Path.GetFullPath(string, string) if (path == null) throw new ArgumentNullException(nameof(path)); - if (basePath == null) - throw new ArgumentNullException(nameof(basePath)); if (Path.IsPathRooted(path)) return path; + if (basePath == null) + throw new ArgumentNullException(nameof(basePath)); if (!Path.IsPathRooted(basePath)) throw new ArgumentException($"{nameof(basePath)} must be an absolute path"); diff --git a/AccessScrCtrl/ImportOptionsFrm.Designer.cs b/AccessScrCtrl/ImportOptionsFrm.Designer.cs index 19b4fbe..0df54ff 100644 --- a/AccessScrCtrl/ImportOptionsFrm.Designer.cs +++ b/AccessScrCtrl/ImportOptionsFrm.Designer.cs @@ -88,7 +88,6 @@ private void InitializeComponent() { this.okButton.Text = "Ok"; this.okButton.UseVisualStyleBackColor = true; this.okButton.Visible = false; - this.okButton.Click += new System.EventHandler(this.okButton_Click); // // cancelButton // diff --git a/AccessScrCtrl/ImportOptionsFrm.cs b/AccessScrCtrl/ImportOptionsFrm.cs index 0e47ce1..5916999 100644 --- a/AccessScrCtrl/ImportOptionsFrm.cs +++ b/AccessScrCtrl/ImportOptionsFrm.cs @@ -23,40 +23,39 @@ public ImportOptionsFrm() { options = new ImportOptions(); } - /// - /// Constructor. Initializes the form and fill the list of tables that will be available to configure their AllowDataLost property - /// - /// - /// - public ImportOptionsFrm(ImportOptions options) : this() { - this.options = options; - overwriteCheckBox.Checked = options.OverwriteDatabase; - overwritePromptCheckBox.Checked = options.ConfirmImportedObjects; - deleteNotLoadedCheckBox.Checked = options.RemoveNotLoaded; - tablesGrid.AddValues(options.AllowDataLostTables); - excludesGrid.AddValues(options.Excludes); - okButton.Visible = true; - cancelButton.Visible = true; - } - /// /// Gets configured in this dialog /// public ImportOptions Options { - get { return options; } - } + get { + return new ImportOptions { + OverwriteDatabase = overwriteCheckBox.Checked, + ConfirmImportedObjects = overwritePromptCheckBox.Checked, + RemoveNotLoaded = deleteNotLoadedCheckBox.Checked, + AllowDataLostTables = tablesGrid.GetValues().ToList(), + Excludes = excludesGrid.GetValues().ToList(), + }; + } set { + if (value == null) { + overwriteCheckBox.Checked = false; + overwritePromptCheckBox.Checked = false; + deleteNotLoadedCheckBox.Checked = false; + tablesGrid.Clear(); + excludesGrid.Clear(); + } else { + overwriteCheckBox.Checked = value.OverwriteDatabase; + overwritePromptCheckBox.Checked = value.ConfirmImportedObjects; + deleteNotLoadedCheckBox.Checked = value.RemoveNotLoaded; + tablesGrid.AddValues(value.AllowDataLostTables); + excludesGrid.AddValues(value.Excludes); + } + } + } private void overwriteCheckBox_CheckedChanged(object sender, EventArgs e) { bool value = !overwriteCheckBox.Checked; deleteNotLoadedCheckBox.Enabled = value; } - private void okButton_Click(object sender, EventArgs e) { - options.OverwriteDatabase = overwriteCheckBox.Checked; - options.ConfirmImportedObjects = overwritePromptCheckBox.Checked; - options.RemoveNotLoaded = deleteNotLoadedCheckBox.Checked; - options.AllowDataLostTables = tablesGrid.GetValues().ToList(); - options.Excludes = excludesGrid.GetValues().ToList(); - } } } diff --git a/AccessScrCtrl/MainFrm.Designer.cs b/AccessScrCtrl/MainFrm.Designer.cs index c9c9cb8..62ba3f5 100644 --- a/AccessScrCtrl/MainFrm.Designer.cs +++ b/AccessScrCtrl/MainFrm.Designer.cs @@ -28,7 +28,6 @@ private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.fileNameTextBox = new System.Windows.Forms.TextBox(); this.selectFileButton = new System.Windows.Forms.Button(); - this.openDlg = new System.Windows.Forms.OpenFileDialog(); this.label2 = new System.Windows.Forms.Label(); this.workingCopyTextBox = new System.Windows.Forms.TextBox(); this.selectFolderButton = new System.Windows.Forms.Button(); @@ -50,6 +49,8 @@ private void InitializeComponent() { this.UpperSeparatorMenu = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator(); this.ExitMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.editMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.profileMenu = new System.Windows.Forms.ToolStripMenuItem(); this.backgroundAttach = new System.ComponentModel.BackgroundWorker(); this.tabControl1.SuspendLayout(); this.saveTab.SuspendLayout(); @@ -87,12 +88,6 @@ private void InitializeComponent() { this.selectFileButton.UseVisualStyleBackColor = true; this.selectFileButton.Click += new System.EventHandler(this.selectFileButton_Click); // - // openDlg - // - this.openDlg.Filter = "Access database (*.mdb; *.adp;*.accdb)|*.mdb;*.adp;*.accdb"; - this.openDlg.SupportMultiDottedExtensions = true; - this.openDlg.Title = "Select Access file"; - // // label2 // this.label2.AutoSize = true; @@ -242,7 +237,8 @@ private void InitializeComponent() { // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.FileMenu}); + this.FileMenu, + this.editMenu}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(383, 24); @@ -264,34 +260,51 @@ private void InitializeComponent() { // newMenu // this.newMenu.Name = "newMenu"; - this.newMenu.Size = new System.Drawing.Size(135, 22); + this.newMenu.Size = new System.Drawing.Size(180, 22); this.newMenu.Text = "&New"; this.newMenu.Click += new System.EventHandler(this.newMenu_Click); // // OpenMenu // this.OpenMenu.Name = "OpenMenu"; - this.OpenMenu.Size = new System.Drawing.Size(135, 22); + this.OpenMenu.Size = new System.Drawing.Size(180, 22); this.OpenMenu.Text = "&Open..."; + this.OpenMenu.Click += new System.EventHandler(this.OpenMenu_Click); // // UpperSeparatorMenu // this.UpperSeparatorMenu.Name = "UpperSeparatorMenu"; - this.UpperSeparatorMenu.Size = new System.Drawing.Size(132, 6); + this.UpperSeparatorMenu.Size = new System.Drawing.Size(177, 6); // // toolStripMenuItem2 // this.toolStripMenuItem2.Name = "toolStripMenuItem2"; - this.toolStripMenuItem2.Size = new System.Drawing.Size(132, 6); + this.toolStripMenuItem2.Size = new System.Drawing.Size(177, 6); // // ExitMenu // this.ExitMenu.Name = "ExitMenu"; this.ExitMenu.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4))); - this.ExitMenu.Size = new System.Drawing.Size(135, 22); + this.ExitMenu.Size = new System.Drawing.Size(180, 22); this.ExitMenu.Text = "E&xit"; this.ExitMenu.Click += new System.EventHandler(this.ExitMenu_Click); // + // editMenu + // + this.editMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.profileMenu}); + this.editMenu.Enabled = false; + this.editMenu.Name = "editMenu"; + this.editMenu.Size = new System.Drawing.Size(39, 20); + this.editMenu.Text = "&Edit"; + // + // profileMenu + // + this.profileMenu.Name = "profileMenu"; + this.profileMenu.Size = new System.Drawing.Size(180, 22); + this.profileMenu.Text = "&Profile..."; + this.profileMenu.Click += new System.EventHandler(this.profileMenu_Click); + // // backgroundAttach // this.backgroundAttach.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundAttach_DoWork); @@ -333,7 +346,6 @@ private void InitializeComponent() { private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox fileNameTextBox; private System.Windows.Forms.Button selectFileButton; - private System.Windows.Forms.OpenFileDialog openDlg; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox workingCopyTextBox; private System.Windows.Forms.Button selectFolderButton; @@ -356,6 +368,8 @@ private void InitializeComponent() { private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2; private System.Windows.Forms.ToolStripMenuItem ExitMenu; private System.ComponentModel.BackgroundWorker backgroundAttach; + private System.Windows.Forms.ToolStripMenuItem editMenu; + private System.Windows.Forms.ToolStripMenuItem profileMenu; } } diff --git a/AccessScrCtrl/MainFrm.cs b/AccessScrCtrl/MainFrm.cs index efde86c..6fce5c0 100644 --- a/AccessScrCtrl/MainFrm.cs +++ b/AccessScrCtrl/MainFrm.cs @@ -9,6 +9,7 @@ using System.Windows.Forms; using AccessIO; using AccessIO.Properties; +using AccessScrCtrl.Helpers; using AccessScrCtrl.Profiles; namespace AccessScrCtrl { @@ -45,14 +46,16 @@ public MainFrm() { } private void selectFileButton_Click(object sender, EventArgs e) { - if (openDlg.ShowDialog() == DialogResult.OK) { - fileNameTextBox.Text = openDlg.FileName; - if (!string.IsNullOrWhiteSpace(workingCopyTextBox.Text)) { - Attach(fileNameTextBox.Text, workingCopyTextBox.Text); + using (var openDlg = CommonDialogs.OpenAccess(fileNameTextBox.Text)) { + if (openDlg.ShowDialog() == DialogResult.OK) { + fileNameTextBox.Text = openDlg.FileName; + if (!string.IsNullOrWhiteSpace(workingCopyTextBox.Text)) { + Attach(fileNameTextBox.Text, workingCopyTextBox.Text); + } + } else { + fileNameTextBox.Text = String.Empty; + saveButton.Enabled = false; } - } else { - fileNameTextBox.Text = String.Empty; - saveButton.Enabled = false; } } @@ -72,11 +75,16 @@ private void selectFolderButton_Click(object sender, EventArgs e) { private void Attach(string accessFileName, string workingFolderName) { var tempProfile = new Profile { AccessFile = accessFileName, - WorkingCopy = workingFolderName + WorkingCopy = workingFolderName, + FileName = Profile?.FileName }; + Attach(tempProfile); + } + + private void Attach(Profile profile) { Cursor = Cursors.WaitCursor; StatusInfo = Properties.Resources.LoadingObjectsTree; - backgroundAttach.RunWorkerAsync(tempProfile); + backgroundAttach.RunWorkerAsync(profile); } private void DisplayMRU() { @@ -123,15 +131,15 @@ private void LoadProfile(string profilePath) { } } else { Profile = Config.LoadProfile(profilePath); - workingCopyTextBox.Text = Profile.WorkingCopy; + workingCopyTextBox.Text = Profile.WorkingCopyFullPath; folderDlg.SelectedPath = workingCopyTextBox.Text; - fileNameTextBox.Text = Profile.AccessFile; - openDlg.FileName = Profile.AccessFile; - Attach(Profile.AccessFile, Profile.WorkingCopy); + fileNameTextBox.Text = Profile.AccessFileFullPath; + Attach(Profile); - Config.AddProfile(Profile, profilePath); + Config.AddProfile(Profile); RefreshMRU(); + editMenu.Enabled = true; } } @@ -257,9 +265,17 @@ private void MainFrm_FormClosed(object sender, FormClosedEventArgs e) { private void newMenu_Click(object sender, EventArgs e) { var profileFrm = new ProfileFrm(fileNameTextBox.Text, workingCopyTextBox.Text); if (profileFrm.ShowDialog() == DialogResult.OK) { - Config.SaveProfile(profileFrm.Profile, profileFrm.ProfileFileName); - Config.AddProfile(profileFrm.Profile, profileFrm.ProfileFileName); - LoadProfile(profileFrm.ProfileFileName); + Config.SaveProfile(profileFrm.Profile); + Config.AddProfile(profileFrm.Profile); + LoadProfile(profileFrm.Profile.FileName); + } + } + + private void OpenMenu_Click(object sender, EventArgs e) { + using (var openDlg = CommonDialogs.OpenProfile(Profile?.FileName)) { + if (openDlg.ShowDialog() == DialogResult.OK) { + LoadProfile(openDlg.FileName); + } } } @@ -267,6 +283,15 @@ private void ExitMenu_Click(object sender, EventArgs e) { Close(); } + private void profileMenu_Click(object sender, EventArgs e) { + var profileFrm = new ProfileFrm(Profile); + if (profileFrm.ShowDialog() == DialogResult.OK) { + Config.SaveProfile(profileFrm.Profile); + LoadProfile(profileFrm.Profile.FileName); + } + } + + private void MRU_Profile_Click(object sender, EventArgs e) { if (sender is ToolStripMenuItem) { var profileMenu = (ToolStripMenuItem)sender; @@ -294,7 +319,7 @@ private void backgroundAttach_RunWorkerCompleted(object sender, RunWorkerComplet private void backgroundAttach_DoWork(object sender, DoWorkEventArgs e) { var profile = (Profile)e.Argument; - objectTree.Attach(profile.AccessFile, profile.WorkingCopy); + objectTree.Attach(profile.AccessFileFullPath, profile.WorkingCopyFullPath); filesTree.WorkingCopyPath = folderDlg.SelectedPath; } } diff --git a/AccessScrCtrl/MainFrm.resx b/AccessScrCtrl/MainFrm.resx index cba00ee..90ad4ce 100644 --- a/AccessScrCtrl/MainFrm.resx +++ b/AccessScrCtrl/MainFrm.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - 115, 17 @@ -131,7 +128,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABU - CAAAAk1TRnQBSQFMAgEBAgEAAXQBAAF0AQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CAAAAk1TRnQBSQFMAgEBAgEAAZwBAAGcAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/AccessScrCtrl/Profiles/Configuration.cs b/AccessScrCtrl/Profiles/Configuration.cs index 4fafce1..795fd7b 100644 --- a/AccessScrCtrl/Profiles/Configuration.cs +++ b/AccessScrCtrl/Profiles/Configuration.cs @@ -31,15 +31,15 @@ public IEnumerable LastProfiles() { /// /// Adds or updates the profile in the MRU list /// - public void AddProfile(Profile profile, string profilePath) { + public void AddProfile(Profile profile) { var profileName = Profiles - .FirstOrDefault(x => string.Compare(x.FileName, profilePath, true) == 0); + .FirstOrDefault(x => string.Compare(x.FileName, profile.FileName, true) == 0); if (profileName != null) { profileName.LastUsedOrder = 1; } else { profileName = new ProfileName { Name = profile.Name, - FileName = profilePath, + FileName = profile.FileName, LastUsedOrder = 1 }; Profiles.Add(profileName); @@ -53,8 +53,7 @@ public void AddProfile(Profile profile, string profilePath) { public Profile LoadProfile(string profilePath) { var profile = JsonConvert.DeserializeObject(File.ReadAllText(profilePath)); - profile.AccessFile = Helpers.PathUtil.GetFullPath(profile.AccessFile, profilePath); - profile.WorkingCopy = Helpers.PathUtil.GetFullPath(profile.WorkingCopy, profilePath); + profile.FileName = profilePath; return profile; } @@ -64,8 +63,8 @@ public void RemoveProfile(string profilePath) { SaveConfiguration(); } - public void SaveProfile(Profile profile, string profilePath) { - File.WriteAllText(profilePath, JsonConvert.SerializeObject(profile, Formatting.Indented)); + public void SaveProfile(Profile profile) { + File.WriteAllText(profile.FileName, JsonConvert.SerializeObject(profile, Formatting.Indented)); } public List Profiles { get; set; } = new List(); diff --git a/AccessScrCtrl/Profiles/Profile.cs b/AccessScrCtrl/Profiles/Profile.cs index 4957bfc..d3b0dfb 100644 --- a/AccessScrCtrl/Profiles/Profile.cs +++ b/AccessScrCtrl/Profiles/Profile.cs @@ -1,4 +1,6 @@ -namespace AccessScrCtrl.Profiles { +using System.Runtime.Serialization; + +namespace AccessScrCtrl.Profiles { public class Profile { public string Name { get; set; } public int Version { get; set; } = 1; @@ -9,5 +11,17 @@ public class Profile { public string LogFileName { get; set; } public ImportOptions ImportOptions { get; set; } public ExportOptions ExportOptions { get; set; } + + /// + /// Holds the profile file name. Used in memory for convenience, but not serialized in the configuration file + /// + [IgnoreDataMember] + internal string FileName { get; set; } + + [IgnoreDataMember] + public string AccessFileFullPath => Helpers.PathUtil.GetFullPath(AccessFile, FileName); + [IgnoreDataMember] + public string WorkingCopyFullPath => Helpers.PathUtil.GetFullPath(WorkingCopy, FileName); + } } diff --git a/AccessScrCtrl/Profiles/ProfileFrm.cs b/AccessScrCtrl/Profiles/ProfileFrm.cs index 60f620e..50438a3 100644 --- a/AccessScrCtrl/Profiles/ProfileFrm.cs +++ b/AccessScrCtrl/Profiles/ProfileFrm.cs @@ -14,7 +14,6 @@ public partial class ProfileFrm : Form { private ImportOptionsFrm ImportFrm { get; set; } private Helpers.ValidationHelper Validator; internal Profile Profile { get; private set; } - internal string ProfileFileName => profileFileNameTextBox.Text; internal bool IsNewProfile => Profile == null; public ProfileFrm() { @@ -23,7 +22,6 @@ public ProfileFrm() { Validator = new Helpers.ValidationHelper(errorProvider1); } - public ProfileFrm(string accessFileName, string workinCopy) : this() { Profile = new Profile { AccessFile = accessFileName, @@ -33,9 +31,15 @@ public ProfileFrm(string accessFileName, string workinCopy) : this() { workingCopyTextBox.Text = workinCopy; absoluteRadioButton.Checked = true; } + + public ProfileFrm(Profile profile): this() { + Profile = profile; + DataBind(); + } private void ProfileFrm_Load(object sender, EventArgs e) { ImportFrm = EmbedForm(new ImportOptionsFrm(), importTab); + ImportFrm.Options = Profile?.ImportOptions; } private void nameTextBox_TextChanged(object sender, EventArgs e) { @@ -53,11 +57,6 @@ private void profileFileNameTextBox_TextChanged(object sender, EventArgs e) { selectFileButton.Enabled = enabled; workingCopyTextBox.Enabled = enabled; selectWorkingCopyButton.Enabled = enabled; - - if (enabled && relativeRadioButton.Checked) { - accessNameTextBox.Text = null; - workingCopyTextBox.Text = null; - } } private void profileFileNameTextBox_Validating(object sender, CancelEventArgs e) { @@ -183,9 +182,17 @@ private Profile BuildProfile() { Name = nameTextBox.Text, AccessFile = accessNameTextBox.Text, WorkingCopy = workingCopyTextBox.Text, - ImportOptions = ImportFrm.Options + ImportOptions = ImportFrm.Options, + FileName = profileFileNameTextBox.Text }; } + private void DataBind() { + nameTextBox.Text = Profile.Name; + accessNameTextBox.Text = Profile.AccessFile; + workingCopyTextBox.Text = Profile.WorkingCopy; + profileFileNameTextBox.Text = Profile.FileName; + } + } } diff --git a/AccessScrCtrl/Properties/Resources.Designer.cs b/AccessScrCtrl/Properties/Resources.Designer.cs index 080888b..95f1176 100644 --- a/AccessScrCtrl/Properties/Resources.Designer.cs +++ b/AccessScrCtrl/Properties/Resources.Designer.cs @@ -154,6 +154,42 @@ internal static string ObjectsSaved { } } + /// + /// Looks up a localized string similar to Select Access file. + /// + internal static string OpenAccessFile { + get { + return ResourceManager.GetString("OpenAccessFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Microsoft Access (*.accdb;*.mdb;*.adp;*.mda;*.accda)|*.accdb;*.mdb;*.adp;*.mda;*.accda|Microsoft Access database (*.mdb;*.accdb)|*.mdb;*.accdb|Microsoft Access 2007 onwards database (*.accdb;*.accda)|*.accdb;*.accda|Microsoft Access up to 2007 database (*.mdb;*.mda)|*.mdb;*.mda. + /// + internal static string OpenAccessFilter { + get { + return ResourceManager.GetString("OpenAccessFilter", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Select profile file. + /// + internal static string OpenProfileFile { + get { + return ResourceManager.GetString("OpenProfileFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to MS Access Source control version (*.accvcs)|*.accvcs|Json files (*.json)|*.json|All files (*.*)|*.*. + /// + internal static string OpenProfileFilter { + get { + return ResourceManager.GetString("OpenProfileFilter", resourceCulture); + } + } + /// /// Looks up a localized string similar to File '{0}' not found. ///Do you want to remove it from the Recent list?. diff --git a/AccessScrCtrl/Properties/Resources.resx b/AccessScrCtrl/Properties/Resources.resx index c9cf099..3791f2a 100644 --- a/AccessScrCtrl/Properties/Resources.resx +++ b/AccessScrCtrl/Properties/Resources.resx @@ -149,6 +149,18 @@ {0} objects saved + + Select Access file + + + Microsoft Access (*.accdb;*.mdb;*.adp;*.mda;*.accda)|*.accdb;*.mdb;*.adp;*.mda;*.accda|Microsoft Access database (*.mdb;*.accdb)|*.mdb;*.accdb|Microsoft Access 2007 onwards database (*.accdb;*.accda)|*.accdb;*.accda|Microsoft Access up to 2007 database (*.mdb;*.mda)|*.mdb;*.mda + + + Select profile file + + + MS Access Source control version (*.accvcs)|*.accvcs|Json files (*.json)|*.json|All files (*.*)|*.* + File '{0}' not found. Do you want to remove it from the Recent list? diff --git a/AccessScrCtrl/TestDatabase2.accvcs b/AccessScrCtrl/TestDatabase2.accvcs deleted file mode 100644 index 10c81cf..0000000 --- a/AccessScrCtrl/TestDatabase2.accvcs +++ /dev/null @@ -1,17 +0,0 @@ -{ - "Name": "TestDatabase2", - "Version": 0, - "AccessFile": "..\\TestDatabase - copia.accdb", - "WorkingCopy": "..\\TestDatabase", - "LastSaveDateTime": null, - "LogLevel": null, - "LogFileName": null, - "ImportOptions": { - "OverwriteDatabase": false, - "ConfirmImportedObjects": false, - "RemoveNotLoaded": false, - "AllowDataLostTables": null, - "Excludes": null - }, - "ExportOptions": null -} \ No newline at end of file From 01e3c8df0f21db73fa8e8724f53c78989834bfa6 Mon Sep 17 00:00:00 2001 From: Miguel Nieto Date: Mon, 28 Jun 2021 12:59:15 +0200 Subject: [PATCH 09/11] Profile editor: Edit profile (add missing changes) --- AccessScrCtrlUI/ExpressionGrid.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/AccessScrCtrlUI/ExpressionGrid.cs b/AccessScrCtrlUI/ExpressionGrid.cs index 60789f7..949c3ff 100644 --- a/AccessScrCtrlUI/ExpressionGrid.cs +++ b/AccessScrCtrlUI/ExpressionGrid.cs @@ -20,17 +20,24 @@ public string Caption { } public void AddValues(IEnumerable expressions) { - foreach(string expression in expressions) { - var row = (DataGridViewRow)gridView.RowTemplate.Clone(); - row.CreateCells(gridView, expression); - gridView.Rows.Add(row); + if (expressions != null) { + foreach (string expression in expressions) { + var row = (DataGridViewRow)gridView.RowTemplate.Clone(); + row.CreateCells(gridView, expression); + gridView.Rows.Add(row); + } } } + public void Clear() { + gridView.Rows.Clear(); + } + public IEnumerableGetValues() { return gridView.Rows. Cast(). - Select(x => x.Cells[0].ToString()); + Where(x => x.IsNewRow == false). + Select(x => x.Cells[0].Value?.ToString()); } } } From bd93c09d9b4fe8bc4d51a30f2112fc6a760476cb Mon Sep 17 00:00:00 2001 From: miguel nieto Date: Mon, 28 Jun 2021 15:11:15 +0200 Subject: [PATCH 10/11] Use Open or Save Dialog to Edit or Create profile --- AccessScrCtrl/Helpers/CommonDialogs.cs | 10 ++++++++++ AccessScrCtrl/Profiles/ProfileFrm.cs | 15 +++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/AccessScrCtrl/Helpers/CommonDialogs.cs b/AccessScrCtrl/Helpers/CommonDialogs.cs index 6ec6d6b..e8725e6 100644 --- a/AccessScrCtrl/Helpers/CommonDialogs.cs +++ b/AccessScrCtrl/Helpers/CommonDialogs.cs @@ -23,5 +23,15 @@ public static OpenFileDialog OpenProfile(string selectedFile) { }; return result; } + + public static SaveFileDialog SaveProfile(string selectedFile) { + var result = new SaveFileDialog { + Title = Properties.Resources.OpenProfileFile, + Filter = Properties.Resources.OpenProfileFilter, + FileName = selectedFile + }; + return result; + + } } } diff --git a/AccessScrCtrl/Profiles/ProfileFrm.cs b/AccessScrCtrl/Profiles/ProfileFrm.cs index 50438a3..390091b 100644 --- a/AccessScrCtrl/Profiles/ProfileFrm.cs +++ b/AccessScrCtrl/Profiles/ProfileFrm.cs @@ -1,4 +1,5 @@ -using System; +using AccessScrCtrl.Helpers; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -94,11 +95,13 @@ private void workingCopyTextBox_Validating(object sender, CancelEventArgs e) { } private void selectProfileButton_Click(object sender, EventArgs e) { - saveFileDlg.CheckFileExists = !IsNewProfile; - if (saveFileDlg.ShowDialog() == DialogResult.OK) { - profileFileNameTextBox.Text = saveFileDlg.FileName; - if (string.IsNullOrEmpty(nameTextBox.Text)) { - nameTextBox.Text = Path.GetFileNameWithoutExtension(profileFileNameTextBox.Text); + string profileName = profileFileNameTextBox.Text; + using (FileDialog dialog = IsNewProfile ? (FileDialog)CommonDialogs.OpenProfile(profileName) : CommonDialogs.SaveProfile(profileName)) { + if (dialog.ShowDialog() == DialogResult.OK) { + profileFileNameTextBox.Text = dialog.FileName; + if (string.IsNullOrEmpty(nameTextBox.Text)) { + nameTextBox.Text = Path.GetFileNameWithoutExtension(profileFileNameTextBox.Text); + } } } } From 30268bfe659095374cc71319efc13189fc41fa1f Mon Sep 17 00:00:00 2001 From: miguel nieto Date: Mon, 5 Jul 2021 09:29:10 +0200 Subject: [PATCH 11/11] Remove redundant assignment --- AccessScrCtrl/MainFrm.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/AccessScrCtrl/MainFrm.cs b/AccessScrCtrl/MainFrm.cs index 6fce5c0..b9e9f0a 100644 --- a/AccessScrCtrl/MainFrm.cs +++ b/AccessScrCtrl/MainFrm.cs @@ -184,7 +184,6 @@ private void saveButton_Click(object sender, EventArgs e) { if (objectTree.App != null) objectTree.App.WorkingCopyPath = workingCopyTextBox.Text; - filesTree.WorkingCopyPath = folderDlg.SelectedPath; if (objectTree.App == null || String.IsNullOrEmpty(objectTree.App.WorkingCopyPath)) { MessageBox.Show(Properties.Resources.WorkingCopyMissing, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);