CtrlUserCheck.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using DevExpress.Utils;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraExport.Helpers;
  4. using DevExpress.XtraGrid.Views.Grid;
  5. using DxHelper;
  6. using ExtensionsDev;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.ComponentModel.DataAnnotations;
  11. using System.Data;
  12. using System.Data.Entity;
  13. using System.Diagnostics;
  14. using System.Drawing;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows.Controls;
  20. using System.Windows.Documents;
  21. using System.Windows.Forms;
  22. using CG.App.EFContext;
  23. using XzXdDw.App.Model;
  24. namespace CG.App.UserControl
  25. {
  26. public partial class CtrlUserCheck : DevExpress.XtraEditors.XtraUserControl
  27. {
  28. public List<CheckCalcRes> list = new List<CheckCalcRes>();
  29. public CtrlUserCheck()
  30. {
  31. InitializeComponent();
  32. }
  33. private void CtrlUserCheck_Load(object sender, EventArgs e)
  34. {
  35. if (File.Exists("UserCheckTmp.txt"))
  36. {
  37. var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<CheckCalcUIParam>(File.ReadAllText("UserCheckTmp.txt"));
  38. txtValue.Text = "5";
  39. txtF1.Text = obj.F1;
  40. txtFs.Text = obj.fs;
  41. txtSampleCount.Text = obj.sampleCount;
  42. }
  43. txtF1.UseChooseFile();
  44. gridUserCheckRes.Init().UseFilter().UseMultiSelect().UseRowNumber()
  45. .UseExportCsv().UseExportXlsx()
  46. .AddMenu("清除", SvgHelper.CreateClear(), () =>
  47. {
  48. list.Clear();
  49. this.gridView1.RefreshData();
  50. });
  51. gridUserCheckRes.DataSource = list;
  52. //CellMerge
  53. gridView1.OptionsView.AllowCellMerge = true;
  54. gridView1.CellMerge += GridView1_CellMerge;
  55. }
  56. private void GridView1_CellMerge(object sender, CellMergeEventArgs e)
  57. {
  58. if (e.Column.FieldName == nameof(CheckCalcRes.DoTime))
  59. {
  60. var val1 = gridView1.GetRowCellValue(e.RowHandle1, e.Column).ToString();
  61. var val2 = gridView1.GetRowCellValue(e.RowHandle2, e.Column).ToString();
  62. e.Merge = val1 == val2;
  63. }
  64. else if (e.Column.FieldName == nameof(CheckCalcRes.File1)
  65. || e.Column.FieldName == nameof(CheckCalcRes.CostTime))
  66. {
  67. var doTimeV1 = gridView1.GetRowCellValue(e.RowHandle1, nameof(CheckCalcRes.DoTime)).ToString();
  68. var doTimeV2 = gridView1.GetRowCellValue(e.RowHandle2, nameof(CheckCalcRes.DoTime)).ToString();
  69. if (doTimeV1 != doTimeV2)
  70. {
  71. e.Merge = false;
  72. }
  73. else
  74. {
  75. var val1 = gridView1.GetRowCellValue(e.RowHandle1, e.Column).ToString();
  76. var val2 = gridView1.GetRowCellValue(e.RowHandle2, e.Column).ToString();
  77. e.Merge = val1 == val2;
  78. }
  79. }
  80. else
  81. {
  82. e.Merge = false;
  83. }
  84. e.Handled = true;
  85. }
  86. private async void btnDo_Click(object sender, EventArgs e)
  87. {
  88. this.layoutControl1.Enabled = false;
  89. await Task.Run(() =>
  90. {
  91. try
  92. {
  93. CheckCalcUIParam cp = new CheckCalcUIParam()
  94. {
  95. F1 = txtF1.Text,
  96. fs = txtFs.Text,
  97. sampleCount = txtSampleCount.Text,
  98. Value = txtValue.Text,
  99. };
  100. var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(cp);
  101. File.WriteAllText("UserCheckTmp.txt", jsonStr);
  102. Stopwatch sw = new Stopwatch();
  103. sw.Start();
  104. string sampleCount = txtSampleCount.Text;
  105. if (string.IsNullOrWhiteSpace(txtSampleCount.Text) || Convert.ToInt32(txtSampleCount.Text) <= 0)
  106. {
  107. FileInfo info = new FileInfo(txtF1.Text);
  108. sampleCount = (new FileInfo(info.FullName).Length / 4).ToString();
  109. }
  110. var doTime = DateTime.Now;
  111. Process p = new Process();
  112. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "API\\信号识别\\enc.exe");
  113. //enc.exe enc-test.dat 0.096 5 0
  114. p.StartInfo.Arguments = $"{txtF1.Text} {txtFs.Text} {5} {sampleCount}";
  115. p.StartInfo.CreateNoWindow = true;
  116. p.StartInfo.RedirectStandardError = true;
  117. p.StartInfo.RedirectStandardOutput = true;
  118. p.StartInfo.UseShellExecute = false;
  119. p.Start();
  120. p.WaitForExit();
  121. var str = p.StandardOutput.ReadToEnd();
  122. sw.Stop();
  123. var arr = str.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  124. foreach (var item in arr)
  125. {
  126. var startAndLen = item.Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  127. CheckCalcRes calcResOne = new CheckCalcRes()
  128. {
  129. DoTime = doTime,
  130. File1 = txtF1.Text,
  131. Start = Convert.ToInt32(startAndLen[0]),
  132. Len = Convert.ToInt32(startAndLen[1]),
  133. CostTime = sw.ElapsedMilliseconds,
  134. };
  135. list.Add(calcResOne);
  136. }
  137. }
  138. catch (Exception ex)
  139. {
  140. Serilog.Log.Error("用户识别出错", ex);
  141. this.Invoke(new Action(() => XtraMessageBox.Show("用户识别出错")));
  142. }
  143. });
  144. this.gridView1.RefreshData();
  145. this.layoutControl1.Enabled = true;
  146. }
  147. }
  148. public class CheckCalcUIParam
  149. {
  150. public string F1 { get; set; }
  151. public string fs { get; set; }
  152. public string sampleCount { get; set; }
  153. public string Value { get; set; }
  154. }
  155. public class CheckCalcRes
  156. {
  157. [Display(Name = "执行时刻",AutoGenerateField =false)]
  158. public DateTime DoTime { get; set; }
  159. [Display(Name = "文件")]
  160. public string File1 { get; set; }
  161. [Display(Name = "起始样点")]
  162. public int Start { get; set; }
  163. [Display(Name = "样点长度")]
  164. public int Len { get; set; }
  165. [Display(Name = "耗时(ms)")]
  166. public double CostTime { get; set; }
  167. }
  168. }