diff --git a/CalendarNotepad/Models/PlusFileUnit.cs b/CalendarNotepad/Models/PlusFileUnit.cs index 6d4ca50..6432684 100644 --- a/CalendarNotepad/Models/PlusFileUnit.cs +++ b/CalendarNotepad/Models/PlusFileUnit.cs @@ -13,5 +13,9 @@ /// 文件内容 /// public byte[]? FileContent { get; set; } + /// + /// 文件类型 .jpj .txt等 + /// + public string? FileType { get; set; } } } diff --git a/CalendarNotepad/WorkMain.Designer.cs b/CalendarNotepad/WorkMain.Designer.cs index bf26bc5..1a84095 100644 --- a/CalendarNotepad/WorkMain.Designer.cs +++ b/CalendarNotepad/WorkMain.Designer.cs @@ -77,6 +77,7 @@ panel2 = new Panel(); panel3 = new Panel(); OpenFileDlg = new OpenFileDialog(); + 打开ToolStripMenuItem = new ToolStripMenuItem(); tabControl1.SuspendLayout(); tpWorkManage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); @@ -419,35 +420,35 @@ // // cms_FileList // - cms_FileList.Items.AddRange(new ToolStripItem[] { 删除ToolStripMenuItem,导入ToolStripMenuItem,下载ToolStripMenuItem,更名ToolStripMenuItem }); + cms_FileList.Items.AddRange(new ToolStripItem[] { 删除ToolStripMenuItem,导入ToolStripMenuItem,下载ToolStripMenuItem,更名ToolStripMenuItem,打开ToolStripMenuItem }); cms_FileList.Name = "contextMenuStrip1"; - cms_FileList.Size = new Size(101,92); + cms_FileList.Size = new Size(181,136); // // 删除ToolStripMenuItem // 删除ToolStripMenuItem.Name = "删除ToolStripMenuItem"; - 删除ToolStripMenuItem.Size = new Size(100,22); + 删除ToolStripMenuItem.Size = new Size(180,22); 删除ToolStripMenuItem.Text = "删除"; 删除ToolStripMenuItem.Click += 删除ToolStripMenuItem_Click; // // 导入ToolStripMenuItem // 导入ToolStripMenuItem.Name = "导入ToolStripMenuItem"; - 导入ToolStripMenuItem.Size = new Size(100,22); + 导入ToolStripMenuItem.Size = new Size(180,22); 导入ToolStripMenuItem.Text = "导入"; 导入ToolStripMenuItem.Click += 导入ToolStripMenuItem_Click; // // 下载ToolStripMenuItem // 下载ToolStripMenuItem.Name = "下载ToolStripMenuItem"; - 下载ToolStripMenuItem.Size = new Size(100,22); + 下载ToolStripMenuItem.Size = new Size(180,22); 下载ToolStripMenuItem.Text = "下载"; 下载ToolStripMenuItem.Click += 下载ToolStripMenuItem_Click; // // 更名ToolStripMenuItem // 更名ToolStripMenuItem.Name = "更名ToolStripMenuItem"; - 更名ToolStripMenuItem.Size = new Size(100,22); + 更名ToolStripMenuItem.Size = new Size(180,22); 更名ToolStripMenuItem.Text = "更名"; 更名ToolStripMenuItem.Click += 更名ToolStripMenuItem_Click; // @@ -629,6 +630,13 @@ // OpenFileDlg.Multiselect = true; // + // 打开ToolStripMenuItem + // + 打开ToolStripMenuItem.Name = "打开ToolStripMenuItem"; + 打开ToolStripMenuItem.Size = new Size(180,22); + 打开ToolStripMenuItem.Text = "打开"; + 打开ToolStripMenuItem.Click += 打开ToolStripMenuItem_Click; + // // WorkMain // AutoScaleDimensions = new SizeF(7F,17F); @@ -727,5 +735,6 @@ private Button bt_m_dbshc; private Label label5; private ToolStripMenuItem 更名ToolStripMenuItem; + private ToolStripMenuItem 打开ToolStripMenuItem; } } \ No newline at end of file diff --git a/CalendarNotepad/WorkMain.cs b/CalendarNotepad/WorkMain.cs index 14f9cce..0910663 100644 --- a/CalendarNotepad/WorkMain.cs +++ b/CalendarNotepad/WorkMain.cs @@ -390,6 +390,52 @@ namespace CalendarNotepad MessageBox.Show("文件名修改完成"); } + private void 打开ToolStripMenuItem_Click(object sender,EventArgs e) { + var items = this.FileListView.SelectedItems; + if(items.Count == 0) { + MessageBox.Show("必须要选择打开的文件"); + return; + } + if(items.Count > 1) { + MessageBox.Show("不能同时打开对多个文件,只能选择一个"); + return; + } + var item = items[0]; + var fk = item.SubItems[2].Text; + var fileNam = item.Text; + var qu = this.Db.Queryable() + .Where(a => a.FileId == fk) + .Select(a => a.FileContent) + .ToList(); + if(!qu.Any() || qu.First() == null) { + MessageBox.Show("打开文件错误,没有找到文件,需要重新导入文件!"); + return; + } + var fc = qu.First(); + var tempPath = Path.GetTempPath(); + var ran = new Random(); + var fn = ran.NextInt64(10000,99999).ToString(); + var path = Path.Combine(tempPath,"CalendarNotepadFile"); + if(!Directory.Exists(path)) { + Directory.CreateDirectory(path); + } + var fullPath = Path.Combine(path,fn + ".txt"); + using(var fs = File.Create(fullPath,fc.Length)) { + fs.Write(fc,0,fc.Length); + fs.Close(); + } + Process process = new Process(); + process.StartInfo.FileName = fullPath; + process.StartInfo.UseShellExecute = true; + process.EnableRaisingEvents = true; + process.Exited += new EventHandler((s,e) => { + File.Delete(fullPath); + }); + + // 启动进程 + process.Start(); + } + /// /// 当前记录日志的键 ///