From 306e06045cf7d1c485d769f5692700f7562fccd6 Mon Sep 17 00:00:00 2001 From: Falcon <12919280+falconfly@user.noreply.gitee.com> Date: Tue, 8 Oct 2024 11:04:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=99=84=E4=BB=B6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=A1=86=E6=94=AF=E6=8C=81=E6=8B=96=E6=94=BE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CalendarNotepad/Extends/ListViewFileModel.cs | 40 ++++++ CalendarNotepad/Extends/PlusFile.cs | 20 ++- CalendarNotepad/WorkMain.Designer.cs | 42 ++++--- CalendarNotepad/WorkMain.cs | 49 +++++--- CalendarNotepad/WorkMain.resx | 122 ++++++++++++++++--- 5 files changed, 219 insertions(+), 54 deletions(-) create mode 100644 CalendarNotepad/Extends/ListViewFileModel.cs diff --git a/CalendarNotepad/Extends/ListViewFileModel.cs b/CalendarNotepad/Extends/ListViewFileModel.cs new file mode 100644 index 0000000..5691e2e --- /dev/null +++ b/CalendarNotepad/Extends/ListViewFileModel.cs @@ -0,0 +1,40 @@ +namespace CalendarNotepad.Extends +{ + /// + /// 文件列表视图模型 + /// + public class ListViewFileModel + { + public ListViewItem Item { get; set; } + + public ListViewFileModel() : this("","","初始化") { } + + public ListViewFileModel(string? fileName,string? fileKey,string? status) { + var item = new ListViewItem(Path.GetFileName(fileName)); + item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = status }); + item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = fileKey }); + this.Item = item; + } + + public ListViewFileModel(ListViewItem item) { + this.Item = item; + } + + public ListViewItem ToListViewItem() { + return this.Item; + } + + /// + /// 文件名 + /// + public string? FileName { get => this.Item.Name; set => this.Item.Name = Path.GetFileName(value); } + /// + /// 文件指纹 + /// + public string? FileKey { get => this.Item.SubItems[2].Text; set => this.Item.SubItems[2].Text = value; } + /// + /// 文件说明 + /// + public string? Status { get => this.Item.SubItems[1].Text; set => this.Item.SubItems[1].Text = value; } + } +} diff --git a/CalendarNotepad/Extends/PlusFile.cs b/CalendarNotepad/Extends/PlusFile.cs index 205bbcc..2a321a8 100644 --- a/CalendarNotepad/Extends/PlusFile.cs +++ b/CalendarNotepad/Extends/PlusFile.cs @@ -1,4 +1,5 @@ -using System.Security.Cryptography; +using CalendarNotepad.Models; +using System.Security.Cryptography; using System.Text; namespace CalendarNotepad.Extends @@ -62,5 +63,22 @@ namespace CalendarNotepad.Extends bw.Flush(); bw.Close(); } + /// + /// 存储文件到数据库 + /// + /// 数据库上下文 + /// 完整文件名 + /// 文件指纹 + public static string SaveFileToDb(DbContext db,string fullFilePath) { + var fc = PlusFile.LoadFile(fullFilePath); + var fk = PlusFile.GetMd5(fc); + var pfu = new PlusFileUnit { FileContent = fc,FileId = fk }; + var qu = db.Queryable().Where(a => a.FileId == fk); + if(qu.Any()) { + return qu.First().FileId; + } + db.Insertable(pfu).ExecuteCommand(); + return fk; + } } } diff --git a/CalendarNotepad/WorkMain.Designer.cs b/CalendarNotepad/WorkMain.Designer.cs index fcfaa2a..1ea7cfc 100644 --- a/CalendarNotepad/WorkMain.Designer.cs +++ b/CalendarNotepad/WorkMain.Designer.cs @@ -56,11 +56,12 @@ tsb_loadin = new ToolStripButton(); FileListView = new ListView(); cms_FileList = new ContextMenuStrip(components); + 打开ToolStripMenuItem = new ToolStripMenuItem(); + toolStripSeparator2 = new ToolStripSeparator(); 删除ToolStripMenuItem = new ToolStripMenuItem(); 导入ToolStripMenuItem = new ToolStripMenuItem(); 下载ToolStripMenuItem = new ToolStripMenuItem(); 更名ToolStripMenuItem = new ToolStripMenuItem(); - 打开ToolStripMenuItem = new ToolStripMenuItem(); tabPage1 = new TabPage(); flowLayoutPanel5 = new FlowLayoutPanel(); bt_m_dbshc = new Button(); @@ -78,7 +79,6 @@ panel2 = new Panel(); panel3 = new Panel(); OpenFileDlg = new OpenFileDialog(); - toolStripSeparator2 = new ToolStripSeparator(); tabControl1.SuspendLayout(); tpWorkManage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); @@ -418,50 +418,57 @@ FileListView.TabIndex = 9; FileListView.UseCompatibleStateImageBehavior = false; FileListView.View = View.Details; + FileListView.DragDrop += FileListView_DragDrop; + FileListView.DragEnter += FileListView_DragEnter; FileListView.DoubleClick += FileListView_DoubleClick; // // cms_FileList // cms_FileList.Items.AddRange(new ToolStripItem[] { 打开ToolStripMenuItem,toolStripSeparator2,删除ToolStripMenuItem,导入ToolStripMenuItem,下载ToolStripMenuItem,更名ToolStripMenuItem }); cms_FileList.Name = "contextMenuStrip1"; - cms_FileList.Size = new Size(181,142); + cms_FileList.Size = new Size(101,120); + // + // 打开ToolStripMenuItem + // + 打开ToolStripMenuItem.Font = new Font("微软雅黑",9F,FontStyle.Bold,GraphicsUnit.Point); + 打开ToolStripMenuItem.Name = "打开ToolStripMenuItem"; + 打开ToolStripMenuItem.Size = new Size(100,22); + 打开ToolStripMenuItem.Text = "打开"; + 打开ToolStripMenuItem.Click += 打开ToolStripMenuItem_Click; + // + // toolStripSeparator2 + // + toolStripSeparator2.Name = "toolStripSeparator2"; + toolStripSeparator2.Size = new Size(97,6); // // 删除ToolStripMenuItem // 删除ToolStripMenuItem.Name = "删除ToolStripMenuItem"; - 删除ToolStripMenuItem.Size = new Size(180,22); + 删除ToolStripMenuItem.Size = new Size(100,22); 删除ToolStripMenuItem.Text = "删除"; 删除ToolStripMenuItem.Click += 删除ToolStripMenuItem_Click; // // 导入ToolStripMenuItem // 导入ToolStripMenuItem.Name = "导入ToolStripMenuItem"; - 导入ToolStripMenuItem.Size = new Size(180,22); + 导入ToolStripMenuItem.Size = new Size(100,22); 导入ToolStripMenuItem.Text = "导入"; 导入ToolStripMenuItem.Click += 导入ToolStripMenuItem_Click; // // 下载ToolStripMenuItem // 下载ToolStripMenuItem.Name = "下载ToolStripMenuItem"; - 下载ToolStripMenuItem.Size = new Size(180,22); + 下载ToolStripMenuItem.Size = new Size(100,22); 下载ToolStripMenuItem.Text = "下载"; 下载ToolStripMenuItem.Click += 下载ToolStripMenuItem_Click; // // 更名ToolStripMenuItem // 更名ToolStripMenuItem.Name = "更名ToolStripMenuItem"; - 更名ToolStripMenuItem.Size = new Size(180,22); + 更名ToolStripMenuItem.Size = new Size(100,22); 更名ToolStripMenuItem.Text = "更名"; 更名ToolStripMenuItem.Click += 更名ToolStripMenuItem_Click; // - // 打开ToolStripMenuItem - // - 打开ToolStripMenuItem.Font = new Font("微软雅黑",9F,FontStyle.Bold,GraphicsUnit.Point); - 打开ToolStripMenuItem.Name = "打开ToolStripMenuItem"; - 打开ToolStripMenuItem.Size = new Size(180,22); - 打开ToolStripMenuItem.Text = "打开"; - 打开ToolStripMenuItem.Click += 打开ToolStripMenuItem_Click; - // // tabPage1 // tabPage1.Controls.Add(flowLayoutPanel5); @@ -640,11 +647,6 @@ // OpenFileDlg.Multiselect = true; // - // toolStripSeparator2 - // - toolStripSeparator2.Name = "toolStripSeparator2"; - toolStripSeparator2.Size = new Size(177,6); - // // WorkMain // AutoScaleDimensions = new SizeF(7F,17F); diff --git a/CalendarNotepad/WorkMain.cs b/CalendarNotepad/WorkMain.cs index 8a2aa6e..c73d615 100644 --- a/CalendarNotepad/WorkMain.cs +++ b/CalendarNotepad/WorkMain.cs @@ -37,6 +37,8 @@ namespace CalendarNotepad this.FileListView.Columns.Add(new ColumnHeader { Text = "文件指纹",Width = 100,TextAlign = HorizontalAlignment.Left, }); + + this.FileListView.AllowDrop = true; } private void Rab_CheckedChanged(object? sender,EventArgs e) { @@ -281,25 +283,13 @@ namespace CalendarNotepad } var wd = this.mcWorkDay.SelectionStart.ToString("yyyyMMdd"); foreach(var f in OpenFileDlg.FileNames) { - var lit1 = new ListViewItem(Path.GetFileName(f)); - lit1.SubItems.Add(new ListViewItem.ListViewSubItem { Text = "导入中" }); - lit1.SubItems.Add(new ListViewItem.ListViewSubItem { Text = "" }); - this.FileListView.Items.Add(lit1); - - var fc = PlusFile.LoadFile(f); - var fk = PlusFile.GetMd5(fc); - lit1.SubItems[2].Text = fk; - var pfu = new PlusFileUnit { FileContent = fc,FileId = fk }; - var qu = this.Db.Queryable().Where(a => a.FileId == fk); - if(!qu.Any()) { - this.Db.Insertable(pfu).ExecuteCommand(); - } + var fk = PlusFile.SaveFileToDb(this.Db,f); this.Db.Insertable(new WorkUnitPlusFile { FileKey = fk, WorkDay = wd, FileName = Path.GetFileName(f), }).ExecuteCommand(); - lit1.SubItems[1].Text = "已导入"; + this.FileListView.Items.Add(new ListViewFileModel(f,fk,"已导入").ToListViewItem()); } } @@ -444,6 +434,37 @@ namespace CalendarNotepad 打开ToolStripMenuItem_Click(sender,e); } + private void FileListView_DragEnter(object sender,DragEventArgs e) { + if(e.Data == null) { + e.Effect = DragDropEffects.None; + return; + } + var isfd = e.Data.GetDataPresent(DataFormats.FileDrop); + if(isfd) { + e.Effect = DragDropEffects.Copy; + return; + } + e.Effect = DragDropEffects.None; + } + + private void FileListView_DragDrop(object sender,DragEventArgs e) { + if(e.Data == null) { + return; + } + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + var wd = this.mcWorkDay.SelectionStart.ToString("yyyyMMdd"); + foreach(string file in files) { + MessageBox.Show(file); + var fk = PlusFile.SaveFileToDb(this.Db,file); + this.Db.Insertable(new WorkUnitPlusFile { + FileKey = fk, + WorkDay = wd, + FileName = Path.GetFileName(file), + }).ExecuteCommand(); + this.FileListView.Items.Add(new ListViewFileModel(file,fk,"已导入").ToListViewItem()); + } + } + /// /// 当前记录日志的键 /// diff --git a/CalendarNotepad/WorkMain.resx b/CalendarNotepad/WorkMain.resx index 3940893..fd7c6f8 100644 --- a/CalendarNotepad/WorkMain.resx +++ b/CalendarNotepad/WorkMain.resx @@ -132,6 +132,66 @@ True + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + 17, 17 + + + True + + + True + + + 127, 17 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + True @@ -144,7 +204,16 @@ True - + + True + + + True + + + True + + True @@ -153,9 +222,6 @@ True - - True - True @@ -174,19 +240,19 @@ True - + True - + True - + True - - 17, 17 + + True - + True @@ -208,15 +274,6 @@ AAAAAElFTkSuQmCC - - True - - - 127, 17 - - - True - True @@ -226,6 +283,12 @@ True + + True + + + True + True @@ -235,6 +298,12 @@ True + + True + + + True + True @@ -247,6 +316,15 @@ True + + True + + + True + + + True + True @@ -256,6 +334,12 @@ True + + True + + + True + True