ManageForm.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.Text;
  9. using System.Windows.Forms;
  10. namespace MOTINOVA_Motor_Factory_Set
  11. {
  12. public partial class ManageForm : Form
  13. {
  14. public string FilePath = "";//文件路径
  15. public ManageForm()
  16. {
  17. InitializeComponent();
  18. }
  19. private void ManageForm_Load(object sender, EventArgs e)
  20. {
  21. groupBox_File.Visible = true;
  22. button_Delete.Visible = true;
  23. button_OpenFile.Visible = true;
  24. richTextBox1.Visible = false;
  25. if (System.IO.Directory.Exists(FilePath) == false)
  26. System.IO.Directory.CreateDirectory(FilePath);
  27. ListDate(FilePath);
  28. }
  29. private void ListDate(string path)
  30. {
  31. if (System.IO.Directory.Exists(path) == false)
  32. {
  33. System.IO.Directory.CreateDirectory(path);
  34. }
  35. //装载配置文件日期列表
  36. string[] DateList = { "" };
  37. DateList = System.IO.Directory.GetDirectories(path);
  38. comboBox_Date.Items.Clear();
  39. foreach (var file in DateList)
  40. {
  41. comboBox_Date.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  42. }
  43. }
  44. private void ListFileRefresh(string path)
  45. {
  46. var files = Directory.GetFiles(path, "*.ttcfg");
  47. listBox_File.Items.Clear();
  48. foreach (var file in files)
  49. {
  50. listBox_File.Items.Add(Path.GetFileName(file));
  51. }
  52. if (listBox_File.Items.Count != 0)
  53. listBox_File.SelectedIndex = 0;
  54. }
  55. private void button_Delete_Click(object sender, EventArgs e)
  56. {
  57. try
  58. {
  59. string SelectFile;
  60. SelectFile = listBox_File.SelectedItem.ToString();
  61. //删除选中文件
  62. if (MessageBox.Show("确认删除?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  63. {
  64. File.Delete(FilePath + "\\" + comboBox_Date.Text + "\\" + SelectFile);
  65. if (System.IO.Directory.Exists(FilePath) == false)
  66. System.IO.Directory.CreateDirectory(FilePath);
  67. ListFileRefresh(FilePath + "\\" + comboBox_Date.Text);
  68. }
  69. }
  70. catch
  71. {
  72. MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  73. }
  74. finally
  75. {
  76. }
  77. }
  78. private void button_OpenFile_Click(object sender, EventArgs e)
  79. {
  80. if (button_OpenFile.Text == "查看")
  81. {
  82. button_OpenFile.Text = "隐藏";
  83. button_Delete.Visible = false;
  84. richTextBox1.Visible = true;
  85. richTextBox1.Text = "";
  86. //读取选择文件
  87. try
  88. {
  89. string SelectFile;
  90. if (listBox_File.Items.Count == 0)
  91. {
  92. MessageBox.Show("无可用文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  93. button_OpenFile.Text = "查看";
  94. button_Delete.Visible = true;
  95. richTextBox1.Visible = false;
  96. richTextBox1.Text = "";
  97. return;
  98. }
  99. if (listBox_File.SelectedItems.Count == 0)
  100. {
  101. MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  102. button_OpenFile.Text = "查看";
  103. button_Delete.Visible = true;
  104. richTextBox1.Visible = false;
  105. richTextBox1.Text = "";
  106. return;
  107. }
  108. SelectFile = listBox_File.SelectedItem.ToString();
  109. richTextBox1.Text += "文件名称:" + SelectFile + "\r\n";
  110. //打开选中文件
  111. StreamReader objReader = new StreamReader(FilePath + "\\" + comboBox_Date.Text + "\\" + SelectFile);
  112. string sLine = "";
  113. ArrayList arrText = new ArrayList();//创建一个动态数组
  114. while (sLine != null)
  115. {
  116. sLine = objReader.ReadLine();
  117. arrText.Add(sLine);
  118. }
  119. objReader.Close();
  120. richTextBox1.Text = "";
  121. foreach (string sOutput in arrText)
  122. {
  123. richTextBox1.Text += sOutput + "\r\n";
  124. }
  125. }
  126. catch
  127. {
  128. MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  129. button_OpenFile.Text = "查看";
  130. button_Delete.Visible = true;
  131. richTextBox1.Visible = false;
  132. richTextBox1.Text = "";
  133. }
  134. finally
  135. {
  136. }
  137. }
  138. else if (button_OpenFile.Text == "隐藏")
  139. {
  140. button_OpenFile.Text = "查看";
  141. button_Delete.Visible = true;
  142. richTextBox1.Visible = false;
  143. richTextBox1.Text = "";
  144. }
  145. }
  146. private void comboBox_Date_SelectionChangeCommitted(object sender, EventArgs e)
  147. {
  148. ListFileRefresh(FilePath + "\\" + comboBox_Date.SelectedItem.ToString());
  149. }
  150. }
  151. }