文件打开功能。未实现文件类型保存

This commit is contained in:
Falcon 2024-08-01 11:18:49 +08:00
parent 19d498cdd5
commit c0f2a1ab6e
3 changed files with 65 additions and 6 deletions

View File

@ -13,5 +13,9 @@
/// 文件内容
/// </summary>
public byte[]? FileContent { get; set; }
/// <summary>
/// 文件类型 .jpj .txt等
/// </summary>
public string? FileType { get; set; }
}
}

View File

@ -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;
}
}

View File

@ -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<PlusFileUnit>()
.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();
}
/// <summary>
/// 当前记录日志的键
/// </summary>