AutoPassDataCollect.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Collections.Generic;
  4. using UAS_AutoPass.ToolClass;
  5. namespace UAS_AutoPass
  6. {
  7. public partial class AutoPassDataCollect : Form
  8. {
  9. List<string> Data = new List<string>();
  10. //Queue<string> que = new Queue<string>();
  11. /// <summary>
  12. /// 一次采集运行的时间
  13. /// </summary>
  14. int SecondCount = 0;
  15. /// <summary>
  16. /// 设置是否开始采集
  17. /// </summary>
  18. bool StartCount = false;
  19. public AutoPassDataCollect()
  20. {
  21. InitializeComponent();
  22. }
  23. private void Form1_Load(object sender, EventArgs e)
  24. {
  25. //dh = new DataHelper();
  26. AutoPastTimer.Interval = 1000;
  27. AutoPastTimer.Tick += AutoPastTimer_Tick;
  28. }
  29. private void AutoPastTimer_Tick(object sender, EventArgs e)
  30. {
  31. //从采集到第一个数据开始计算秒数
  32. if (StartCount)
  33. {
  34. SecondCount = SecondCount + 1;
  35. if (SecondCount == CollectTime.Value)
  36. {
  37. //停止计数
  38. StartCount = false;
  39. //重置采集时长
  40. SecondCount = 0;
  41. CreateLocalFile();
  42. }
  43. }
  44. }
  45. private void CollectData_KeyDown(object sender, KeyEventArgs e)
  46. {
  47. if (e.KeyCode == Keys.Enter)
  48. {
  49. //设置开始计时本次采集
  50. if (Data.Count == 0)
  51. {
  52. StartCount = true;
  53. }
  54. if (Data.Count < CollectNum.Value)
  55. {
  56. if (CollectData.Text != "")
  57. Data.Add(CollectData.Text);
  58. }
  59. }
  60. }
  61. private void Start_Click(object sender, EventArgs e)
  62. {
  63. AutoPastTimer.Start();
  64. Status_label.Text = "运行中";
  65. }
  66. private void Stop_Click(object sender, EventArgs e)
  67. {
  68. AutoPastTimer.Stop();
  69. Status_label.Text = "未开始";
  70. }
  71. private void CreateLocalFile()
  72. {
  73. for (int i = 0; i < Data.Count; i++)
  74. {
  75. BaseUtil.CreateXml(Data[i], "OK");
  76. }
  77. }
  78. }
  79. }