FileRestoreForm.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Oreo.FileMan.DatabaseEngine;
  2. using Oreo.FileMan.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using Y.Skin.YoForm.NoTitle;
  14. using Y.Utils.DataUtils.Collections;
  15. using Y.Utils.DataUtils.UnitConvertUtils;
  16. using Y.Utils.IOUtils.PathUtils;
  17. namespace Oreo.FileMan.Views
  18. {
  19. public partial class FileRestoreForm : NoTitleForm
  20. {
  21. public string FilePath { get; set; }
  22. public List<BackupFiles> Files { get; set; }
  23. public FileRestoreForm(string path)
  24. {
  25. InitializeComponent();
  26. FilePath = path;
  27. }
  28. private void FileRestoreForm_Load(object sender, EventArgs e)
  29. {
  30. //读取该文件的备份记录
  31. using (var db = new Muse())
  32. {
  33. Files = db.Gets<BackupFiles>(x => x.FullPath == FilePath, null).OrderBy(x => x.Id).ToList();
  34. }
  35. if (ListTool.HasElements(Files))
  36. {
  37. //获取文件名及路径信息
  38. var first = Files.FirstOrDefault();
  39. LbFileName.Text = Path.GetFileName(first.FullPath);
  40. LbPath.Text = first.FullPath;
  41. LbVersion.Text = "共 " + Files.Count + " 版";
  42. TtLabel.SetToolTip(LbFileName, Path.GetFileName(first.FullPath));
  43. TtLabel.SetToolTip(LbPath, first.FullPath);
  44. //显示所有备份记录
  45. int index = 1;
  46. foreach (var file in Files)
  47. {
  48. DgvFiles.Rows.Add(string.Format("第 {0} 版", index++), file.LastWriteTime, ByteConvertTool.Fmt(file.Size));
  49. }
  50. }
  51. }
  52. private void BtClose_Click(object sender, EventArgs e)
  53. {
  54. Close();
  55. }
  56. private void BtRestoreToNew_Click(object sender, EventArgs e)
  57. {
  58. if (DgvFiles.CurrentRow != null && DgvFiles.CurrentRow.Index >= 0)
  59. {
  60. var file = Files[DgvFiles.CurrentRow.Index];
  61. }
  62. }
  63. private void BtRestoreToOld_Click(object sender, EventArgs e)
  64. {
  65. if (DgvFiles.CurrentRow != null && DgvFiles.CurrentRow.Index >= 0)
  66. {
  67. BackupFiles file = Files[DgvFiles.CurrentRow.Index];
  68. string title = string.Format("文件还原", file.LastWriteTime);
  69. string text = string.Format("您确定将文件:{0} [ {1} ]{2}还原到:{2}{3} 吗?", Path.GetFileName(file.FullPath), file.LastWriteTime, Environment.NewLine, file.FullPath);
  70. if (MessageBox.Show(text, title, MessageBoxButtons.OKCancel) == DialogResult.OK)
  71. {
  72. string from = file.BackupFullPath;
  73. string to = file.FullPath;
  74. File.Copy(from, to, true);
  75. }
  76. }
  77. }
  78. }
  79. }