ManageForm.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. //删除其它相关文件
  66. string extFileName = "";
  67. extFileName = SelectFile.Split('_')[0] + "_" + SelectFile.Split('_')[1] + "_" + SelectFile.Split('_')[6] + "_" + (SelectFile.Split('_')[7].Substring(0, SelectFile.Split('_')[7].LastIndexOf(".")) + ".pdf");
  68. File.Delete(FilePath + "\\" + comboBox_Date.Text + "\\" + extFileName);
  69. extFileName = SelectFile.Split('_')[0] + "_" + SelectFile.Split('_')[1] + "_" + SelectFile.Split('_')[6] + "_" + (SelectFile.Split('_')[7].Substring(0, SelectFile.Split('_')[7].LastIndexOf(".")) + ".xls");
  70. File.Delete(FilePath + "\\" + comboBox_Date.Text + "\\" + extFileName);
  71. if (System.IO.Directory.Exists(FilePath) == false)
  72. System.IO.Directory.CreateDirectory(FilePath);
  73. ListFileRefresh(FilePath + "\\" + comboBox_Date.Text);
  74. }
  75. }
  76. catch
  77. {
  78. MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  79. }
  80. finally
  81. {
  82. }
  83. }
  84. private void button_OpenFile_Click(object sender, EventArgs e)
  85. {
  86. if (button_OpenFile.Text == "查看")
  87. {
  88. button_OpenFile.Text = "隐藏";
  89. button_Delete.Visible = false;
  90. richTextBox1.Visible = true;
  91. richTextBox1.Text = "";
  92. //读取选择文件
  93. try
  94. {
  95. string SelectFile;
  96. if (listBox_File.Items.Count == 0)
  97. {
  98. MessageBox.Show("无可用文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  99. button_OpenFile.Text = "查看";
  100. button_Delete.Visible = true;
  101. richTextBox1.Visible = false;
  102. richTextBox1.Text = "";
  103. return;
  104. }
  105. if (listBox_File.SelectedItems.Count == 0)
  106. {
  107. MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  108. button_OpenFile.Text = "查看";
  109. button_Delete.Visible = true;
  110. richTextBox1.Visible = false;
  111. richTextBox1.Text = "";
  112. return;
  113. }
  114. SelectFile = listBox_File.SelectedItem.ToString();
  115. richTextBox1.Text += "文件名称:" + SelectFile + "\r\n";
  116. //打开选中文件
  117. StreamReader objReader = new StreamReader(FilePath + "\\" + comboBox_Date.Text + "\\" + SelectFile);
  118. string sLine = "";
  119. ArrayList arrText = new ArrayList();//创建一个动态数组
  120. while (sLine != null)
  121. {
  122. sLine = objReader.ReadLine();
  123. arrText.Add(sLine);
  124. }
  125. objReader.Close();
  126. richTextBox1.Text = "";
  127. foreach (string sOutput in arrText)
  128. {
  129. richTextBox1.Text += sOutput + "\r\n";
  130. }
  131. }
  132. catch
  133. {
  134. MessageBox.Show("请选择文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  135. button_OpenFile.Text = "查看";
  136. button_Delete.Visible = true;
  137. richTextBox1.Visible = false;
  138. richTextBox1.Text = "";
  139. }
  140. finally
  141. {
  142. }
  143. }
  144. else if (button_OpenFile.Text == "隐藏")
  145. {
  146. button_OpenFile.Text = "查看";
  147. button_Delete.Visible = true;
  148. richTextBox1.Visible = false;
  149. richTextBox1.Text = "";
  150. }
  151. }
  152. private void comboBox_Date_SelectionChangeCommitted(object sender, EventArgs e)
  153. {
  154. ListFileRefresh(FilePath + "\\" + comboBox_Date.SelectedItem.ToString());
  155. }
  156. private void button_SetPath_Click(object sender, EventArgs e)
  157. {
  158. string path = textBox_LocalPath.Text;
  159. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\UserPath";
  160. StreamReader objReader = new StreamReader(cfg_file);
  161. ArrayList arrText = new ArrayList();//创建一个动态数组
  162. objReader.Close();
  163. arrText.Add("logPath =" + path);
  164. using (StreamWriter file = new StreamWriter(cfg_file))
  165. {
  166. foreach (var entry in arrText)
  167. {
  168. file.WriteLine(entry);
  169. }
  170. }
  171. MessageBox.Show("路径已设置,软件重启后生效!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  172. }
  173. private void textBox_LocalPath_Click(object sender, EventArgs e)
  174. {
  175. textBox_LocalPath.SelectAll();
  176. }
  177. }
  178. }