LogDetail.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. namespace Archives_Center
  5. {
  6. public partial class LogDetail : Form
  7. {
  8. string folderPath = Path.GetTempPath() + @"ArchivesCenter\Data\" + Properties.Settings.Default.current_user + @"\" + Properties.Settings.Default.selectedYText + @"\" + Properties.Settings.Default.selectedMText + @"\" + Properties.Settings.Default.selectedDText + @"\";
  9. public LogDetail()
  10. {
  11. InitializeComponent();
  12. string[] imageFiles = Directory.GetFiles(folderPath, "*.jpg");
  13. listView1.Columns.Add("文件名", 300);
  14. listView1.Columns.Add("大小 (KB)", 125);
  15. listView1.Columns.Add("创建时间", 150);
  16. PopulateListView(folderPath);
  17. using (StreamReader sr = new StreamReader(Path.GetTempPath() + @"ArchivesCenter\Data\" + Properties.Settings.Default.current_user + @"\" + Properties.Settings.Default.selectedYText + @"\" + Properties.Settings.Default.selectedMText + @"\" + Properties.Settings.Default.selectedDText + @"\" + "text.txt"))
  18. {
  19. string firstLine = sr.ReadLine();
  20. label1.Text = firstLine;
  21. string secondLine = sr.ReadLine();
  22. label2.Text = secondLine;
  23. string thirdLine = sr.ReadLine();
  24. label3.Text = thirdLine;
  25. }
  26. using (StreamReader sr = new StreamReader(Path.GetTempPath() + @"ArchivesCenter\Data\" + Properties.Settings.Default.current_user + @"\" + Properties.Settings.Default.selectedYText + @"\" + Properties.Settings.Default.selectedMText + @"\" + Properties.Settings.Default.selectedDText + @"\" + "text.txt"))
  27. {
  28. int lineNumber = 0;
  29. while (!sr.EndOfStream)
  30. {
  31. string line = sr.ReadLine();
  32. if (lineNumber >= 3)
  33. richTextBox1.AppendText(line + Environment.NewLine);
  34. lineNumber++;
  35. }
  36. }
  37. }
  38. private void PopulateListView(string folderPath)
  39. {
  40. listView1.Items.Clear();
  41. string[] files = Directory.GetFiles(folderPath, "*.jpg");
  42. foreach (string file in files)
  43. {
  44. FileInfo fileInfo = new FileInfo(file);
  45. ListViewItem item = new ListViewItem(fileInfo.Name);
  46. item.SubItems.Add((fileInfo.Length / 1024).ToString());
  47. item.SubItems.Add(fileInfo.CreationTime.ToString());
  48. listView1.Items.Add(item);
  49. }
  50. }
  51. private void button2_Click(object sender, EventArgs e)
  52. {
  53. DeleteFolderWithAdminRights.DeleteFolder(Path.GetTempPath() + @"ArchivesCenter\Data\" + Properties.Settings.Default.current_user + @"\" + Properties.Settings.Default.selectedYText + @"\" + Properties.Settings.Default.selectedMText + @"\" + Properties.Settings.Default.selectedDText + @"\");
  54. this.Close();
  55. }
  56. private void listView1_DoubleClick(object sender, EventArgs e)
  57. {
  58. if (listView1.SelectedItems.Count > 0)
  59. {
  60. string selectedFile = listView1.SelectedItems[0].Text;
  61. string filePath = Path.Combine(folderPath, selectedFile);
  62. System.Diagnostics.Process.Start(filePath);
  63. }
  64. }
  65. private void 属性ToolStripMenuItem_Click(object sender, EventArgs e)
  66. {
  67. long totalSize = 0;
  68. foreach (string file in Directory.GetFiles(folderPath))
  69. {
  70. FileInfo fileInfo = new FileInfo(file);
  71. totalSize += fileInfo.Length;
  72. }
  73. MessageBox.Show("日志标题:" + label1.Text + "\n日期:" + label2.Text + "\n作者:" + label3.Text + "\n占地大小:" + totalSize/1024 + "KB", label1.Text + "属性", MessageBoxButtons.OK, MessageBoxIcon.Information);
  74. }
  75. }
  76. }