From 27aa247c36cb1fa6db70c7abd87570623508e57c Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 7 Dec 2020 19:11:05 -0600 Subject: [PATCH] Updated the ProfileManager so that users can change the FolderGroup's name (a very hacky job but it'll do). Hooked up the FileViewers 'Update Databse' button so new files can be commited to the database. --- .vs/DataOrganizer/v16/.suo | Bin 139776 -> 139776 bytes DataOrganizer/DB.cs | 91 ++++- DataOrganizer/FileViewer.cs | 11 +- .../NamingConventionManager.Designer.cs | 2 +- DataOrganizer/ProfileManager.Designer.cs | 370 +++++++++--------- DataOrganizer/ProfileManager.cs | 102 +++-- DataOrganizer/Snapshot.cs | 10 +- 7 files changed, 347 insertions(+), 239 deletions(-) diff --git a/.vs/DataOrganizer/v16/.suo b/.vs/DataOrganizer/v16/.suo index 48995581fe3dc2dc2a4fe259f8a5adcc776eba5c..363590f6eb335476121e1406a547bb7d6e1f27a1 100644 GIT binary patch delta 3353 zcmZoT!qISqV}cE%_(ofOCe8)7jxYFk<{G2L3XPjKcT*Yh6z`!tv zg8>XgCNr{#vzjn4FqlnN5r0~-Sa13Lo) zgXQFh9O5$J3=9ko3=9m83=9lT3=9m;3=9k|3=9me3=9mDML1PB{TUb-0vH$={!L7j zW{qHAV2GQn$SH0a&%nTtz`(#D$iTpm47Ejofq@~Ffq@|#%HIN|K`sR090mr4^vRB# z?h^|*CNbr3E{GKC1%;mMR*+Z)M46^qQ>7s;>xg zT_lpJQ49G0;F$1;?cdhlnWNVB!jq1epZGGZ`2dW-%}@%mz7YVxsZp1zcMg z38>&vVVdm1XR!H;NCOk&w8^F7-J8Tp7$K}ld>$N(P*+YC01qhX z*`rAEU*OS!hB7FmKsp$$CYK7-Gg?mmDo_u~2ZHsipj5}S`KLHL(;^9`NgjuJ!RgKt z*`zNX{*#@V4JVg)`tve^QmPe_EN2@71H&#*fKUD_UCyYzxm2c`c{0Z(iOCN0rKT6C zFtSZvGg)SHh|(I?MG8!l1WItb!TdK9n?3^rL#V{$Usk_3br~2K%9ub&J5fq_vVhbK z0Z_n#yab{_*>3Ulb`I&XSlh2e}W zN|OcViLirW5EO}wN}?cBRRnfR8ra3D?9F?Yaq|D}$$RZ5A5=1!lxD{mFxfs$R6Cs^ zm7$11k0F_%n1O-e90LObs4xZ5pqva!XE4k-xjxO9w+gC0fT4&Xe|o(eV+oTwuhJtM#j0cz|S$$yxWiCj{6o;owaAJj&Gn@x7_%qY9Y&6Z%_WWjjGK@6*f36ZEcKZjH=}F%g(ya2##0~zChuA1 z#JCs4nl9kSXu5e$g&*Ve0!AjeNp8-Ncnj!ZBqQfe{^A+Jfje)+(KT;uu1M}+S`@=H z{eUxL$mWooSBx}C4@*gmca~l{TSTuKlZ<2WMD9( zj^CFuPPb2ByekN*6v6&v&^zG4z`#(mc|lt`^W>sa37fa}aWhVu;IMg9<7`Ia18RHY zU&aNDILzHXMS>}Zahe2^{qzG~j0ZOLIxvD6jQrafGa2g{H#_t-fb5(cpyB{#Z*RzA zbYR>xF^*C3-R@FR&C0nQ%4HJKCS43?oEHRo9#}o?Lg2KE+>h+t-a(4@S%7VPU}JphU09A1296SIcIcMNNY@9dcltTy!LC zx)v)_78y0s=2-`q!3|hNW^Kf{WOAc&;p7hsO%%63_|*RP`17>*ruMmq(`Jiqb?Hgf zH@MbS?;o_{;Kj#VA>nmUNe$-cRf{e#fhxesa+icA2X(8!>c8pItW1^|b>HR-XABq@ XU16cb#%t3=m<))ts_D+MJB)4s)C8g? delta 3136 zcmZoT!qISqV}cDM&qiB)Ce8z4y2~D)xyGn5xs<7%amM7YOwCMcOp~jat9We~7#QYo zFn|I3WJVToM;fq_AYfq@~8 zfq?;{5<)6WR%8`7;6)PUXJBAZ1KGgHz@W^)z#z}Sz`zET=YrCc7jTF$>QCOvkn0PA)JAMAp+`@C*R+l;xhIO z3=9qo3=ED83=B>T3=GZ;3=A&Nz?>|?s=^5h!2nPQPTt7su9(cgz>o$t6cl!#FvJKu zt`Od7P$NJA@o!?H{pJN+TNts3@~ANJfE)yJAP7$u&c~J z^^8`Nzlzl}T23w%ujd50oe7jqCjYf}<7KphIv%Eba*2cgWM^hW)=LZw3|A%#^65`j z;FFnr#L;H50-pjH8!)ke_>=gKV6(e{iE;YmQo-&?@(P<3BpxtMPB9ReEMPE002Eyy z|L8*fHhG7E0;BolL<3esW+P_GLi7Y3WfSs^O=L-{?7btUzP5!0#iw%^5 z%9tkq(*4C|$-uzC4i@Exh=Kx@Ve)_1BcSk`{KX9%j+0B=H%wM>n~yBExgrRt z7$;eH;PFxk%ccUbmlXYsCp-9wYPPvX`)XL)!_-tCQnxB}wzs=F;MBrb$6| zj4qSygG8Ab7)mA=dJ9j^@)n!i5M(5m%aF;C$B@q8%#hEJ$6(6HzyK=0ZqSuM(h(R#9Ap!8(+U>&A843kZR>lwi+r~h|j44ZyQlTmVdgF9n5 za~?zPWJe`oVQU5#hD3%EhC~K`h9ZV^hD3(E$qvyCo67812A8WgJ4BZ;i54&fFcdN5 zGh{Kai!m^OiggZ#Qb$%su_$KTp5fQ3>h35j5qIJ$H>UYIGHiVo=okIjGG-cH85^>$YOM0+{Oz^ zR!+NoCZE~yW%GgPZ;VL6&j$~F)bN0ZJuryTXY!AZ=ZwLy;Ahl=27WAQ z@fQO#034ezLr9Fl$wkpdWQILWqHgn<9b1?PgrXzkX2xUojFTID93~&w=`gwBc*A6e zfCG~*&zWAJz$7refrUwg9bBt3FifA#!eqJWm;(u_1$Ijs*u|;r&3l${^8fD1d+jGX zE;iWga8rhH@+2P>xWN}$m@K8yl_oP3gDOG>P-ZaPp$b?5qU6+=qSS)?;ux32l0l`(Evm5T-+tCT8Zj d5CFF|8$SR5 diff --git a/DataOrganizer/DB.cs b/DataOrganizer/DB.cs index 9339ea3..e9e9a8a 100644 --- a/DataOrganizer/DB.cs +++ b/DataOrganizer/DB.cs @@ -147,6 +147,34 @@ namespace DataOrganizer return true; } + public FolderGroup GetFolderGroupByName(string name, int profileId) + { + var query = @"SELECT root_id, name, path, pattern_id, profile_id FROM main.folder_root WHERE profile_id = @ProfileId AND name = @Name"; + + using (var connection = new SqliteConnection(ConnectionString)) + { + using (var command = new SqliteCommand(query, connection)) + { + command.Parameters.AddWithValue("ProfileId", profileId); + command.Parameters.AddWithValue("Name", name); + + connection.Open(); + + var reader = command.ExecuteReader(); + + reader.Read(); + + return new FolderGroup + { + Id = Convert.ToInt32(reader["root_id"]), + Name = reader["name"].ToString(), + Path = reader["path"].ToString(), + PatternId = Convert.ToInt32(reader["pattern_id"]) + }; + } + } + } + public int InsertNewProfile(Profile profile) { var query = @"INSERT INTO main.profile (machine_name, default_new_content_folder_name, profile_name) VALUES (@MachineName, @DefaultPath, @Name)"; @@ -440,6 +468,24 @@ namespace DataOrganizer } } + public int GetPatternIdByName(string name) + { + if (string.IsNullOrEmpty(name)) return 0; + + var query = @"SELECT pattern_id FROM main.naming_pattern WHERE name = @Name"; + + using (var connection = new SqliteConnection(ConnectionString)) + { + connection.Open(); + using (var command = new SqliteCommand(query, connection)) + { + command.Parameters.AddWithValue("Name", name); + + return Convert.ToInt32(command.ExecuteScalar()); + } + } + } + public string GetRootPathById(int id) { var query = @"SELECT path FROM folder_root WHERE root_id = @ID"; @@ -479,9 +525,9 @@ namespace DataOrganizer return true; } - public List GetFilesForProfileByFolderGroup(int profileId, int folderGroupId) + public List GetFilesForProfileByFolderGroup(int profileId, int folderGroupId) { - var files = new List(); + var files = new List(); var query = @"SELECT * FROM main.file INNER JOIN main.folder_root ON main.file.folder_root_id = main.folder_root.root_id WHERE main.file.profile_id = @ProfileId AND folder_root_id = @GroupId ORDER BY main.file.full_path ASC"; @@ -497,7 +543,7 @@ namespace DataOrganizer while(reader.Read()) { - files.Add(new FileSnapshot + files.Add(new DBFileSnapshot { Id = Convert.ToInt32(reader["file_id"]), PathNoRoot = reader["full_path"].ToString(), @@ -517,7 +563,7 @@ namespace DataOrganizer return files; } - public void InsertNewFileRecord(List files, int profileId, int folderGroupId, string root) + public void InsertNewFileRecord(List files, int profileId, int folderGroupId, string root) { var query = @"INSERT INTO main.file (full_path, name, size, date_created, date_modified, folder_root_id, profile_id, pattern_override_id) VALUES (@FullPath, @Name, @Size, @DateCreated, @DateModified, @FolderId, @ProfileId, @PatternId)"; var rootLength = root.Length; @@ -552,6 +598,41 @@ namespace DataOrganizer } } + public void InsertNewFileRecord(List files, int profileId, int folderGroupId, string root) + { + var query = @"INSERT INTO main.file (full_path, name, size, date_created, date_modified, folder_root_id, profile_id, pattern_override_id) VALUES (@FullPath, @Name, @Size, @DateCreated, @DateModified, @FolderId, @ProfileId, @PatternId)"; + var rootLength = root.Length; + + using (var connection = new SqliteConnection(ConnectionString)) + { + connection.Open(); + using (var transaction = connection.BeginTransaction()) + { + + using (var command = new SqliteCommand(query, connection, transaction)) + { + foreach (var file in files) + { + command.Parameters.AddWithValue("FullPath", file.PathNoRoot); + command.Parameters.AddWithValue("Name", file.Name); + command.Parameters.AddWithValue("Size", file.Size); + command.Parameters.AddWithValue("DateCreated", file.CreatedDate); + command.Parameters.AddWithValue("DateModified", file.ModifiedDate); + command.Parameters.AddWithValue("FolderId", folderGroupId); + command.Parameters.AddWithValue("ProfileId", profileId); + command.Parameters.AddWithValue("PatternId", GetPatternIdByName(file.NamingPattern)); + + command.ExecuteNonQuery(); + + command.Parameters.Clear(); + } + } + + transaction.Commit(); + } + } + } + public struct Profile { public string Name; @@ -578,7 +659,7 @@ namespace DataOrganizer public string Regex; } - public struct FileSnapshot + public struct DBFileSnapshot { public int Id; public string PathNoRoot; diff --git a/DataOrganizer/FileViewer.cs b/DataOrganizer/FileViewer.cs index d285047..c95f01b 100644 --- a/DataOrganizer/FileViewer.cs +++ b/DataOrganizer/FileViewer.cs @@ -67,7 +67,10 @@ namespace DataOrganizer private void CommitScanResultsButton_Click(object sender, EventArgs e) { - throw new NotImplementedException(); + var newFiles = ActiveSnapshotForPrimaryTree.Files.Values.Where(x => x.Status == FileSnapshot.FileStatus.PendingInsert).ToList(); + var db = new DB(); + + db.InsertNewFileRecord(newFiles, GetActiveProfile().Id, GetActiveFolderGroup().Id, GetActiveFolderGroup().Path); } private void FolderSelectButton_Click1(object sender, EventArgs e) @@ -319,17 +322,17 @@ namespace DataOrganizer } } - private List GetFileSnapshots(string path) + private List GetFileSnapshots(string path) { var dir = new DirectoryInfo(path); var profile = GetActiveProfile(); var folderGroup = GetActiveFolderGroup(); - var snapshots = new List(); + var snapshots = new List(); foreach(var file in dir.EnumerateFiles()) { - snapshots.Add(new DB.FileSnapshot + snapshots.Add(new DB.DBFileSnapshot { PathNoRoot = file.FullName, Name = file.Name, diff --git a/DataOrganizer/NamingConventionManager.Designer.cs b/DataOrganizer/NamingConventionManager.Designer.cs index 13326cc..c155074 100644 --- a/DataOrganizer/NamingConventionManager.Designer.cs +++ b/DataOrganizer/NamingConventionManager.Designer.cs @@ -179,7 +179,7 @@ this.DeleteButton.Enabled = false; this.DeleteButton.Location = new System.Drawing.Point(13, 388); this.DeleteButton.Name = "DeleteButton"; - this.DeleteButton.Size = new System.Drawing.Size(107, 47); + this.DeleteButton.Size = new System.Drawing.Size(111, 47); this.DeleteButton.TabIndex = 8; this.DeleteButton.Text = "Delete"; this.DeleteButton.UseVisualStyleBackColor = true; diff --git a/DataOrganizer/ProfileManager.Designer.cs b/DataOrganizer/ProfileManager.Designer.cs index e2ff952..7d7d61a 100644 --- a/DataOrganizer/ProfileManager.Designer.cs +++ b/DataOrganizer/ProfileManager.Designer.cs @@ -33,34 +33,34 @@ this.ProfilesComboBox = new System.Windows.Forms.ComboBox(); this.label3 = new System.Windows.Forms.Label(); this.ProfileInfoPanel = new System.Windows.Forms.Panel(); - this.InsertGroupName = new System.Windows.Forms.Button(); - this.DeleteProfileButton = new System.Windows.Forms.Button(); - this.MachineNameTextBox = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); - this.ProfileNameTextBox = new System.Windows.Forms.TextBox(); - this.MachineNameLabel = new System.Windows.Forms.Label(); - this.AddOrUpdateProfileButton = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.SelectNewContentLocationButton = new System.Windows.Forms.Button(); - this.label2 = new System.Windows.Forms.Label(); - this.NewContentLocationTextBox = new System.Windows.Forms.TextBox(); - this.label6 = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.FolderNameTextBox = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.NamingConventionComboBox = new System.Windows.Forms.ComboBox(); + this.label5 = new System.Windows.Forms.Label(); this.FolderGroupPathTextBox = new System.Windows.Forms.TextBox(); - this.FolderGroupPathButton = new System.Windows.Forms.Button(); + this.InsertGroupName = new System.Windows.Forms.Button(); this.FolderGroupListView = new System.Windows.Forms.ListView(); this.NameColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.label5 = new System.Windows.Forms.Label(); - this.NamingConventionComboBox = new System.Windows.Forms.ComboBox(); + this.FolderGroupPathButton = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.groupBox2 = new System.Windows.Forms.GroupBox(); - this.label7 = new System.Windows.Forms.Label(); - this.FolderNameTextBox = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); + this.NewContentLocationTextBox = new System.Windows.Forms.TextBox(); + this.MachineNameTextBox = new System.Windows.Forms.TextBox(); + this.AddOrUpdateProfileButton = new System.Windows.Forms.Button(); + this.DeleteProfileButton = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.ProfileNameTextBox = new System.Windows.Forms.TextBox(); + this.SelectNewContentLocationButton = new System.Windows.Forms.Button(); + this.label4 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.MachineNameLabel = new System.Windows.Forms.Label(); this.MainLayoutPanel.SuspendLayout(); this.MainPanel.SuspendLayout(); this.ProfileInfoPanel.SuspendLayout(); - this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); + this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // MainLayoutPanel @@ -116,6 +116,65 @@ this.ProfileInfoPanel.Size = new System.Drawing.Size(1283, 440); this.ProfileInfoPanel.TabIndex = 1; // + // groupBox2 + // + this.groupBox2.Controls.Add(this.FolderNameTextBox); + this.groupBox2.Controls.Add(this.label7); + this.groupBox2.Controls.Add(this.NamingConventionComboBox); + this.groupBox2.Controls.Add(this.label5); + this.groupBox2.Controls.Add(this.FolderGroupPathTextBox); + this.groupBox2.Controls.Add(this.InsertGroupName); + this.groupBox2.Controls.Add(this.FolderGroupListView); + this.groupBox2.Controls.Add(this.FolderGroupPathButton); + this.groupBox2.Controls.Add(this.label6); + this.groupBox2.Location = new System.Drawing.Point(620, 3); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(658, 430); + this.groupBox2.TabIndex = 18; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Folder Group Details"; + // + // FolderNameTextBox + // + this.FolderNameTextBox.Location = new System.Drawing.Point(163, 273); + this.FolderNameTextBox.Name = "FolderNameTextBox"; + this.FolderNameTextBox.Size = new System.Drawing.Size(311, 26); + this.FolderNameTextBox.TabIndex = 5; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(6, 276); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(104, 20); + this.label7.TabIndex = 15; + this.label7.Text = "Group Name:"; + // + // NamingConventionComboBox + // + this.NamingConventionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.NamingConventionComboBox.FormattingEnabled = true; + this.NamingConventionComboBox.Location = new System.Drawing.Point(163, 377); + this.NamingConventionComboBox.Name = "NamingConventionComboBox"; + this.NamingConventionComboBox.Size = new System.Drawing.Size(311, 28); + this.NamingConventionComboBox.TabIndex = 8; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(6, 380); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(151, 20); + this.label5.TabIndex = 15; + this.label5.Text = "Naming Convention:"; + // + // FolderGroupPathTextBox + // + this.FolderGroupPathTextBox.Location = new System.Drawing.Point(163, 325); + this.FolderGroupPathTextBox.Name = "FolderGroupPathTextBox"; + this.FolderGroupPathTextBox.Size = new System.Drawing.Size(311, 26); + this.FolderGroupPathTextBox.TabIndex = 6; + // // InsertGroupName // this.InsertGroupName.Enabled = false; @@ -127,122 +186,6 @@ this.InsertGroupName.UseVisualStyleBackColor = true; this.InsertGroupName.Click += new System.EventHandler(this.InsertGroupName_Click); // - // DeleteProfileButton - // - this.DeleteProfileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.DeleteProfileButton.Location = new System.Drawing.Point(17, 320); - this.DeleteProfileButton.Name = "DeleteProfileButton"; - this.DeleteProfileButton.Size = new System.Drawing.Size(75, 40); - this.DeleteProfileButton.TabIndex = 8; - this.DeleteProfileButton.TabStop = false; - this.DeleteProfileButton.Text = "Delete"; - this.DeleteProfileButton.UseVisualStyleBackColor = true; - this.DeleteProfileButton.Click += new System.EventHandler(this.DeleteProfileButton_Click); - // - // MachineNameTextBox - // - this.MachineNameTextBox.Location = new System.Drawing.Point(195, 253); - this.MachineNameTextBox.Name = "MachineNameTextBox"; - this.MachineNameTextBox.Size = new System.Drawing.Size(311, 26); - this.MachineNameTextBox.TabIndex = 4; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(10, 256); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(119, 20); - this.label4.TabIndex = 7; - this.label4.Text = "Machine Name:"; - // - // ProfileNameTextBox - // - this.ProfileNameTextBox.Location = new System.Drawing.Point(198, 39); - this.ProfileNameTextBox.Name = "ProfileNameTextBox"; - this.ProfileNameTextBox.Size = new System.Drawing.Size(311, 26); - this.ProfileNameTextBox.TabIndex = 1; - // - // MachineNameLabel - // - this.MachineNameLabel.AutoSize = true; - this.MachineNameLabel.Location = new System.Drawing.Point(13, 186); - this.MachineNameLabel.Name = "MachineNameLabel"; - this.MachineNameLabel.Size = new System.Drawing.Size(88, 20); - this.MachineNameLabel.TabIndex = 5; - this.MachineNameLabel.Text = "profile stuff"; - // - // AddOrUpdateProfileButton - // - this.AddOrUpdateProfileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.AddOrUpdateProfileButton.Location = new System.Drawing.Point(479, 320); - this.AddOrUpdateProfileButton.Name = "AddOrUpdateProfileButton"; - this.AddOrUpdateProfileButton.Size = new System.Drawing.Size(86, 40); - this.AddOrUpdateProfileButton.TabIndex = 10; - this.AddOrUpdateProfileButton.Text = "button1"; - this.AddOrUpdateProfileButton.UseVisualStyleBackColor = true; - this.AddOrUpdateProfileButton.Click += new System.EventHandler(this.AddOrUpdateProfileButton_Click); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 42); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(103, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Profile Name:"; - // - // SelectNewContentLocationButton - // - this.SelectNewContentLocationButton.Location = new System.Drawing.Point(512, 119); - this.SelectNewContentLocationButton.Name = "SelectNewContentLocationButton"; - this.SelectNewContentLocationButton.Size = new System.Drawing.Size(50, 30); - this.SelectNewContentLocationButton.TabIndex = 3; - this.SelectNewContentLocationButton.Text = "..."; - this.SelectNewContentLocationButton.UseVisualStyleBackColor = true; - this.SelectNewContentLocationButton.Click += new System.EventHandler(this.SelectNewContentLocationButton_Click); - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(13, 124); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(170, 20); - this.label2.TabIndex = 2; - this.label2.Text = "New Content Location:"; - // - // NewContentLocationTextBox - // - this.NewContentLocationTextBox.Location = new System.Drawing.Point(195, 121); - this.NewContentLocationTextBox.Name = "NewContentLocationTextBox"; - this.NewContentLocationTextBox.Size = new System.Drawing.Size(311, 26); - this.NewContentLocationTextBox.TabIndex = 2; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(6, 328); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(144, 20); - this.label6.TabIndex = 11; - this.label6.Text = "Folder Group Path:"; - // - // FolderGroupPathTextBox - // - this.FolderGroupPathTextBox.Location = new System.Drawing.Point(163, 325); - this.FolderGroupPathTextBox.Name = "FolderGroupPathTextBox"; - this.FolderGroupPathTextBox.Size = new System.Drawing.Size(311, 26); - this.FolderGroupPathTextBox.TabIndex = 6; - // - // FolderGroupPathButton - // - this.FolderGroupPathButton.Location = new System.Drawing.Point(480, 323); - this.FolderGroupPathButton.Name = "FolderGroupPathButton"; - this.FolderGroupPathButton.Size = new System.Drawing.Size(50, 30); - this.FolderGroupPathButton.TabIndex = 7; - this.FolderGroupPathButton.Text = "..."; - this.FolderGroupPathButton.UseVisualStyleBackColor = true; - this.FolderGroupPathButton.Click += new System.EventHandler(this.FolderGroupPathButton_Click); - // // FolderGroupListView // this.FolderGroupListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { @@ -265,23 +208,24 @@ this.NameColumn.Text = "Name"; this.NameColumn.Width = 623; // - // label5 + // FolderGroupPathButton // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(6, 380); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(151, 20); - this.label5.TabIndex = 15; - this.label5.Text = "Naming Convention:"; + this.FolderGroupPathButton.Location = new System.Drawing.Point(480, 323); + this.FolderGroupPathButton.Name = "FolderGroupPathButton"; + this.FolderGroupPathButton.Size = new System.Drawing.Size(50, 30); + this.FolderGroupPathButton.TabIndex = 7; + this.FolderGroupPathButton.Text = "..."; + this.FolderGroupPathButton.UseVisualStyleBackColor = true; + this.FolderGroupPathButton.Click += new System.EventHandler(this.FolderGroupPathButton_Click); // - // NamingConventionComboBox + // label6 // - this.NamingConventionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.NamingConventionComboBox.FormattingEnabled = true; - this.NamingConventionComboBox.Location = new System.Drawing.Point(163, 377); - this.NamingConventionComboBox.Name = "NamingConventionComboBox"; - this.NamingConventionComboBox.Size = new System.Drawing.Size(311, 28); - this.NamingConventionComboBox.TabIndex = 8; + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(6, 328); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(144, 20); + this.label6.TabIndex = 11; + this.label6.Text = "Folder Group Path:"; // // groupBox1 // @@ -303,41 +247,6 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Profile Details"; // - // groupBox2 - // - this.groupBox2.Controls.Add(this.FolderNameTextBox); - this.groupBox2.Controls.Add(this.label7); - this.groupBox2.Controls.Add(this.NamingConventionComboBox); - this.groupBox2.Controls.Add(this.label5); - this.groupBox2.Controls.Add(this.FolderGroupPathTextBox); - this.groupBox2.Controls.Add(this.InsertGroupName); - this.groupBox2.Controls.Add(this.FolderGroupListView); - this.groupBox2.Controls.Add(this.FolderGroupPathButton); - this.groupBox2.Controls.Add(this.label6); - this.groupBox2.Location = new System.Drawing.Point(620, 3); - this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(658, 430); - this.groupBox2.TabIndex = 18; - this.groupBox2.TabStop = false; - this.groupBox2.Text = "Folder Group Details"; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(6, 276); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(104, 20); - this.label7.TabIndex = 15; - this.label7.Text = "Group Name:"; - // - // FolderNameTextBox - // - this.FolderNameTextBox.Enabled = false; - this.FolderNameTextBox.Location = new System.Drawing.Point(163, 273); - this.FolderNameTextBox.Name = "FolderNameTextBox"; - this.FolderNameTextBox.Size = new System.Drawing.Size(311, 26); - this.FolderNameTextBox.TabIndex = 5; - // // label8 // this.label8.AutoSize = true; @@ -347,6 +256,95 @@ this.label8.TabIndex = 10; this.label8.Text = "New content location is the default location where you will add new files to."; // + // NewContentLocationTextBox + // + this.NewContentLocationTextBox.Location = new System.Drawing.Point(195, 121); + this.NewContentLocationTextBox.Name = "NewContentLocationTextBox"; + this.NewContentLocationTextBox.Size = new System.Drawing.Size(311, 26); + this.NewContentLocationTextBox.TabIndex = 2; + // + // MachineNameTextBox + // + this.MachineNameTextBox.Location = new System.Drawing.Point(195, 253); + this.MachineNameTextBox.Name = "MachineNameTextBox"; + this.MachineNameTextBox.Size = new System.Drawing.Size(311, 26); + this.MachineNameTextBox.TabIndex = 4; + // + // AddOrUpdateProfileButton + // + this.AddOrUpdateProfileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.AddOrUpdateProfileButton.Location = new System.Drawing.Point(519, 380); + this.AddOrUpdateProfileButton.Name = "AddOrUpdateProfileButton"; + this.AddOrUpdateProfileButton.Size = new System.Drawing.Size(86, 40); + this.AddOrUpdateProfileButton.TabIndex = 10; + this.AddOrUpdateProfileButton.Text = "button1"; + this.AddOrUpdateProfileButton.UseVisualStyleBackColor = true; + this.AddOrUpdateProfileButton.Click += new System.EventHandler(this.AddOrUpdateProfileButton_Click); + // + // DeleteProfileButton + // + this.DeleteProfileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.DeleteProfileButton.Location = new System.Drawing.Point(14, 380); + this.DeleteProfileButton.Name = "DeleteProfileButton"; + this.DeleteProfileButton.Size = new System.Drawing.Size(75, 40); + this.DeleteProfileButton.TabIndex = 8; + this.DeleteProfileButton.TabStop = false; + this.DeleteProfileButton.Text = "Delete"; + this.DeleteProfileButton.UseVisualStyleBackColor = true; + this.DeleteProfileButton.Click += new System.EventHandler(this.DeleteProfileButton_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(13, 124); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(170, 20); + this.label2.TabIndex = 2; + this.label2.Text = "New Content Location:"; + // + // ProfileNameTextBox + // + this.ProfileNameTextBox.Location = new System.Drawing.Point(198, 39); + this.ProfileNameTextBox.Name = "ProfileNameTextBox"; + this.ProfileNameTextBox.Size = new System.Drawing.Size(311, 26); + this.ProfileNameTextBox.TabIndex = 1; + // + // SelectNewContentLocationButton + // + this.SelectNewContentLocationButton.Location = new System.Drawing.Point(512, 119); + this.SelectNewContentLocationButton.Name = "SelectNewContentLocationButton"; + this.SelectNewContentLocationButton.Size = new System.Drawing.Size(50, 30); + this.SelectNewContentLocationButton.TabIndex = 3; + this.SelectNewContentLocationButton.Text = "..."; + this.SelectNewContentLocationButton.UseVisualStyleBackColor = true; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(10, 256); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(119, 20); + this.label4.TabIndex = 7; + this.label4.Text = "Machine Name:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 42); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(103, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Profile Name:"; + // + // MachineNameLabel + // + this.MachineNameLabel.AutoSize = true; + this.MachineNameLabel.Location = new System.Drawing.Point(13, 186); + this.MachineNameLabel.Name = "MachineNameLabel"; + this.MachineNameLabel.Size = new System.Drawing.Size(88, 20); + this.MachineNameLabel.TabIndex = 5; + this.MachineNameLabel.Text = "profile stuff"; + // // ProfileManager // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); @@ -364,10 +362,10 @@ this.MainPanel.ResumeLayout(false); this.MainPanel.PerformLayout(); this.ProfileInfoPanel.ResumeLayout(false); - this.groupBox1.ResumeLayout(false); - this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); this.ResumeLayout(false); } diff --git a/DataOrganizer/ProfileManager.cs b/DataOrganizer/ProfileManager.cs index 053fc73..08024eb 100644 --- a/DataOrganizer/ProfileManager.cs +++ b/DataOrganizer/ProfileManager.cs @@ -21,6 +21,7 @@ namespace DataOrganizer private List NamingConventions { get; } private Dictionary Profiles { get; } = new Dictionary(); private Dictionary FolderGroups { get; } = new Dictionary(); + private DB.FolderGroup ActiveFolderGroup { get; set; } public ProfileManager() { @@ -43,6 +44,8 @@ namespace DataOrganizer NewContentLocationTextBox.TextChanged += ToggleAddOrUpdateButton; MachineNameTextBox.TextChanged += MachineNameTextBox_TextChanged; FolderGroupPathTextBox.TextChanged += ToggleGroupInsertButton; + FolderNameTextBox.TextChanged += ToggleGroupInsertButton; + FolderGroupListView.SelectedIndexChanged += FolderGroupListView_SelectedIndexChanged; FolderGroupListView.MouseClick += FolderGroupListView_MouseClick; SelectNewContentLocationButton.Click += SelectNewContentLocationButton_Click1; deleteMenuItem.Click += DeleteMenuItem_Click; @@ -51,6 +54,23 @@ namespace DataOrganizer SetupForNewProfile(); } + private void FolderGroupListView_SelectedIndexChanged(object sender, EventArgs e) + { + var db = new DB(); + GetSelectedFolderGroup(out DB.FolderGroup folderGroup); + + FolderGroupPathTextBox.Text = folderGroup.Path; + FolderNameTextBox.Text = folderGroup.Name; + var index = NamingConventions.FindIndex(x => x.Id == folderGroup.PatternId); + + if (index != -1) + NamingConventionComboBox.SelectedIndex = index + 1; + else + NamingConventionComboBox.SelectedIndex = 0; + + InsertGroupName.Text = "Update Folder Group"; + } + private void SelectNewContentLocationButton_Click1(object sender, EventArgs e) { var dialog = new FolderBrowserDialog() { Description = "Select the folder where new content will be placed." }; @@ -124,7 +144,7 @@ namespace DataOrganizer private void ToggleGroupInsertButton(object sender, EventArgs e) { - if (!string.IsNullOrEmpty(FolderGroupPathTextBox.Text)) + if (!string.IsNullOrEmpty(FolderGroupPathTextBox.Text) && !string.IsNullOrEmpty(FolderNameTextBox.Text)) InsertGroupName.Enabled = true; else InsertGroupName.Enabled = false; @@ -181,16 +201,45 @@ namespace DataOrganizer private void InsertGroupName_Click(object sender, EventArgs e) { + if (FolderGroups.ContainsKey(FolderNameTextBox.Text)) + { + MessageBox.Show($"'{FolderNameTextBox.Text}' already exists as a Folder Group. Duplicate names are not allowed.", "Duplication Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + FolderNameTextBox.Focus(); + return; + } + FolderGroupPathTextBox.Text = FolderGroupPathTextBox.Text.TrimEnd(new char[] { '\\' }); - var dir = new DirectoryInfo(FolderGroupPathTextBox.Text); - var groupName = dir.Name; - - if (!FolderGroups.ContainsKey(groupName)) + if(GetSelectedFolderGroup(out DB.FolderGroup folderGroup)) { + FolderGroups.Remove(folderGroup.Name); + + folderGroup.Path = FolderGroupPathTextBox.Text; + folderGroup.Name = FolderNameTextBox.Text; + GetCurrentNamingConvention(out DB.Namingconvention convention); + folderGroup.PatternId = convention.Id; + InsertGroupName.Text = "Insert Folder Group"; + + if (IsUpdating) + { + var db = new DB(); + db.UpdateFolderGroup(folderGroup); + FolderGroupListView.SelectedItems[0].Text = folderGroup.Name; + } + + FolderGroups.Add(folderGroup.Name, folderGroup); + + NamingConventionComboBox.SelectedIndex = 0; + FolderNameTextBox.Text = string.Empty; + FolderGroupPathTextBox.Text = string.Empty; + InsertGroupName.Enabled = false; + } + else + { + var groupName = FolderNameTextBox.Text; GetCurrentNamingConvention(out DB.Namingconvention convention); GetCurrentProfile(out DB.Profile profile); - var newFolder = new DB.FolderGroup { Name = groupName, Path = FolderGroupPathTextBox.Text, PatternId = convention.Id}; + var newFolder = new DB.FolderGroup { Name = groupName, Path = FolderGroupPathTextBox.Text, PatternId = convention.Id }; FolderGroupListView.Items.Add(groupName); @@ -212,28 +261,6 @@ namespace DataOrganizer FolderGroupPathTextBox.Text = string.Empty; InsertGroupName.Enabled = false; } - else - { - var folderGroup = FolderGroups[groupName];//(DB.FolderGroup) FolderGroupListView.Items.Find(groupName, true)[0].Tag; - folderGroup.Path = FolderGroupPathTextBox.Text; - folderGroup.Name = groupName; - GetCurrentNamingConvention(out DB.Namingconvention convention); - folderGroup.PatternId = convention.Id; - InsertGroupName.Text = "Insert Folder Group"; - - if (IsUpdating) - { - var db = new DB(); - db.UpdateFolderGroup(folderGroup); - } - - FolderGroups[groupName] = folderGroup; - - NamingConventionComboBox.SelectedIndex = 0; - FolderNameTextBox.Text = string.Empty; - FolderGroupPathTextBox.Text = string.Empty; - InsertGroupName.Enabled = false; - } FolderGroupPathButton.Focus(); } @@ -297,6 +324,8 @@ namespace DataOrganizer { FolderGroupPathTextBox.Text = dialog.SelectedPath; InsertGroupName.Text = "Insert Folder Group"; + var dir = new DirectoryInfo(dialog.SelectedPath); + FolderNameTextBox.Text = dir.Name; } } @@ -413,6 +442,13 @@ namespace DataOrganizer { ClearForm(); IsUpdating = true; + Profiles.Clear(); + var db = new DB(); + + foreach(var p in db.GetProfiles()) + { + Profiles.Add(p.Name, p); + } GetCurrentProfile(out DB.Profile profile); @@ -435,15 +471,5 @@ namespace DataOrganizer AddOrUpdateProfileButton.Enabled = true; DeleteProfileButton.Enabled = true; } - - private void SelectNewContentLocationButton_Click(object sender, EventArgs e) - { - var dialog = new FolderBrowserDialog() { Description = "Select the default location to look for new content." }; - - if (dialog.ShowDialog() == DialogResult.OK) - { - NewContentLocationTextBox.Text = dialog.SelectedPath; - } - } } } diff --git a/DataOrganizer/Snapshot.cs b/DataOrganizer/Snapshot.cs index 799da53..8718ae8 100644 --- a/DataOrganizer/Snapshot.cs +++ b/DataOrganizer/Snapshot.cs @@ -19,7 +19,7 @@ namespace DataOrganizer //with the text "Death Note" would return all files in that folder. public Dictionary> OrganizationFolders { get; private set; } = new Dictionary>(); - public Snapshot(List fileRecords, DB.FolderGroup folderGroup) + public Snapshot(List fileRecords, DB.FolderGroup folderGroup) { Root = new Folder(folderGroup.Name, folderGroup.Path, null); Directories.Add(Root.FullPath, Root); @@ -39,7 +39,7 @@ namespace DataOrganizer ProcessFilesAsOneLevel(files, folderGroup); } - private void ProcessFilesAsOneLevel(List files, DB.FolderGroup folderGroup) + private void ProcessFilesAsOneLevel(List files, DB.FolderGroup folderGroup) { Folder firstLevelFolder = null; @@ -137,7 +137,7 @@ namespace DataOrganizer } } - private void ProcessFilesAsFlat(List files, DB.FolderGroup folderGroup) + private void ProcessFilesAsFlat(List files, DB.FolderGroup folderGroup) { } @@ -213,7 +213,7 @@ namespace DataOrganizer public struct Duplicate { - public DB.FileSnapshot File; + public DB.DBFileSnapshot File; public List Duplicates; } } @@ -324,7 +324,7 @@ namespace DataOrganizer get { return _Name; } } - public FileSnapshot(DB.FileSnapshot file, Folder organizationalFolder, Folder parentFolder, string rootPath) + public FileSnapshot(DB.DBFileSnapshot file, Folder organizationalFolder, Folder parentFolder, string rootPath) { OrganizationalFolder = organizationalFolder; ParentFolder = parentFolder;