FileNameSelect.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace OTSIncAReportApp._1_UI.OTSTemplateDesigner
  13. {
  14. public partial class FileNameSelect : Form
  15. {
  16. string folderPath = "";
  17. string PathName = "";
  18. public string ChangePathName = "";
  19. public bool yes = false;
  20. Hashtable table;
  21. public FileNameSelect(string a_Route, string a_PathName)
  22. {
  23. folderPath = a_Route;
  24. PathName = a_PathName;
  25. ChangePathName = a_PathName;
  26. InitializeComponent();
  27. #region 国际化语言
  28. OTSCommon.Language lan = new OTSCommon.Language(this);
  29. table = lan.GetNameTable(this.Name);
  30. #endregion
  31. }
  32. private void FileNameSelect_Load(object sender, EventArgs e)
  33. {
  34. listView1.View = View.Details; // 设置视图为Details以显示列标题和子项
  35. listView1.FullRowSelect = true; // 允许整行选择
  36. listView1.CheckBoxes = true; // 允许在项旁边显示勾选框
  37. listView1.Columns.Add(table["file_name"].ToString(), 229); // 添加列标题
  38. // 获取文件夹中的所有文件信息
  39. FileInfo[] files = new DirectoryInfo(folderPath).GetFiles("*.xml", SearchOption.AllDirectories);
  40. // 遍历文件信息数组并打印出文件名
  41. foreach (FileInfo file in files)
  42. {
  43. listView1.Items.Add(file.Name);
  44. }
  45. for(int i=0;i<listView1.Items.Count;i++)
  46. {
  47. if(ChangePathName== listView1.Items[i].Text)
  48. {
  49. listView1.Items[i].Checked = true;
  50. }
  51. }
  52. listView1.ItemCheck += new ItemCheckEventHandler(listView_ItemCheck);
  53. //label1.Text = PathName;
  54. }
  55. private void button1_Click(object sender, EventArgs e)
  56. {
  57. for (int i = 0; i < listView1.Items.Count; i++)
  58. {
  59. if (listView1.Items[i].Checked)
  60. ChangePathName = listView1.Items[i].Text;
  61. }
  62. yes = true;
  63. this.Close();
  64. }
  65. // 当ListView中的项的检查状态改变时触发的事件处理器
  66. private void listView_ItemCheck(object sender, ItemCheckEventArgs e)
  67. {
  68. for (int i = 0; i < listView1.Items.Count; i++)
  69. {
  70. listView1.Items[i].Checked = false;
  71. }
  72. listView1.Items[e.Index].Checked = true;
  73. }
  74. private void button2_Click(object sender, EventArgs e)
  75. {
  76. this.Close();
  77. }
  78. }
  79. }