GpuCalcForm.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using DevExpress.Data.Extensions;
  2. using DevExpress.Internal.WinApi.Windows.UI.Notifications;
  3. using DevExpress.Mvvm.Native;
  4. using DevExpress.XtraEditors;
  5. using DevExpress.XtraLayout.Utils;
  6. using DxHelper;
  7. using ExtensionsDev;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.IO.Compression;
  15. using System.Linq;
  16. using System.Net;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using DW5S.KxcApi;
  21. using DW5S.DTO;
  22. using DW5S.Repostory;
  23. using Microsoft.Extensions.Logging;
  24. namespace DW5S.App.CorTools
  25. {
  26. public partial class GpuCalcForm : DevExpress.XtraEditors.XtraForm
  27. {
  28. [Autowired]
  29. private readonly ILogger logger;
  30. [Autowired]
  31. private readonly UnitOfWork unitOfWork;
  32. static readonly string inifile = Path.Combine(Application.StartupPath, "parGpu.ini");
  33. List<GpuCafResult> gridSource = new List<GpuCafResult>();
  34. public GpuCalcForm()
  35. {
  36. InitializeComponent();
  37. }
  38. private void MainForm_Load(object sender, EventArgs e)
  39. {
  40. this.gridGpuCg.UseDefault(gridSource).UseExportXlsx().UseRowNumber()
  41. .UseExportCsv().UseClear<GpuCafResult>();
  42. this.btnFile1.UseChooseWaveFile((file, fsHz) =>
  43. {
  44. if (fsHz > 0)
  45. txtfs.Text = (fsHz / 1e6).ToString();
  46. else
  47. txtfs.Text = "0.096";
  48. }).UseDoubleClickToSelectAll();
  49. this.btnFile2.UseChooseFile().UseDoubleClickToSelectAll();
  50. ReadIni();
  51. }
  52. private async void btnCalc_Click(object sender, EventArgs e)
  53. {
  54. if (!ValidateFiles(btnFile1.Text, btnFile2.Text)) return;
  55. if (!ValidateParams()) return;
  56. layoutControl1.Enabled = false;
  57. string file1, file2;
  58. try
  59. {
  60. file1 = await HttpHelper.UploadFileAsync(btnFile1.Text, SysConfig.GetBaseUrl());
  61. file2 = await HttpHelper.UploadFileAsync(btnFile2.Text, SysConfig.GetBaseUrl());
  62. }
  63. catch (Exception ex)
  64. {
  65. layoutControl1.Enabled = true;
  66. string msg = "GPU参估上传文件异常";
  67. logger.LogError(ex,msg);
  68. DxHelper.MsgBoxHelper.ShowError(msg);
  69. return;
  70. }
  71. var samplingRate = double.Parse(txtfs.Text) * 1e6;
  72. var dtCenter = double.Parse(txtDtoCenter.Text);
  73. var dtRange = double.Parse(txtDtoRange.Text);
  74. var dfRange = double.Parse(txtDfoRange.Text);
  75. var smpCount = double.Parse(txtSmpCount.Text);
  76. var snrThreshold = double.Parse(txtSnr.Text);
  77. GpuCgRequestDto dto = new GpuCgRequestDto()
  78. {
  79. dfRange = dfRange,
  80. smpCount = smpCount,
  81. dtCenter = dtCenter,
  82. dtRange = dtRange,
  83. file1 = file1,
  84. file2 = file2,
  85. samplingRate = samplingRate,
  86. snrThreshold = snrThreshold,
  87. };
  88. WriteIni();
  89. gridSource.Clear();
  90. try
  91. {
  92. var result = await HttpHelper.PostRequestAsync<List<GpuCgResponseDto>>(SysConfig.GetUrl("DetectCg/GpuCgCalc"), dto);
  93. if (result.code == 200)
  94. {
  95. foreach (var item in result.data)
  96. {
  97. gridSource.Add(new GpuCafResult()
  98. {
  99. file1 = btnFile1.Text,
  100. file2 = btnFile2.Text,
  101. dt = item.Dt,
  102. df = item.Df,
  103. snr = item.Snr,
  104. tm = item.TimeMs,
  105. });
  106. }
  107. }
  108. else
  109. {
  110. logger.LogError(result.msg);
  111. DxHelper.MsgBoxHelper.ShowError(result.msg);
  112. }
  113. }
  114. catch (Exception ex)
  115. {
  116. string msg = "GPU文件参估出错";
  117. logger.LogError(ex,msg);
  118. DxHelper.MsgBoxHelper.ShowError(msg);
  119. }
  120. gridView1.RefreshData();
  121. layoutControl1.Enabled = true;
  122. }
  123. private bool ValidateFiles(params string[] files)
  124. {
  125. foreach (var file in files)
  126. {
  127. if (string.IsNullOrWhiteSpace(file))
  128. {
  129. DxHelper.MsgBoxHelper.ShowError($"请选择文件!");
  130. return false;
  131. }
  132. if (!File.Exists(file))
  133. {
  134. DxHelper.MsgBoxHelper.ShowError($"文件【{file}】不存在");
  135. return false;
  136. }
  137. }
  138. return true;
  139. }
  140. private bool ValidateParams()
  141. {
  142. if (!double.TryParse(txtfs.Text, out _))
  143. {
  144. DxHelper.MsgBoxHelper.ShowError($"采样率非有效数字");
  145. return false;
  146. }
  147. if (!double.TryParse(txtDtoCenter.Text, out _))
  148. {
  149. DxHelper.MsgBoxHelper.ShowError($"时差中心非有效数字");
  150. return false;
  151. }
  152. if (!double.TryParse(txtDtoRange.Text, out _))
  153. {
  154. DxHelper.MsgBoxHelper.ShowError($"时差范围非有效数字");
  155. return false;
  156. }
  157. if (!double.TryParse(txtDfoRange.Text, out _))
  158. {
  159. DxHelper.MsgBoxHelper.ShowError($"频差范围非有效数字");
  160. return false;
  161. }
  162. if (!double.TryParse(txtSnr.Text, out _))
  163. {
  164. DxHelper.MsgBoxHelper.ShowError($"信噪比门限非有效数字");
  165. return false;
  166. }
  167. if (!double.TryParse(txtSmpCount.Text, out _))
  168. {
  169. DxHelper.MsgBoxHelper.ShowError($"样点数非有效数字");
  170. return false;
  171. }
  172. return true;
  173. }
  174. //读取配置
  175. void ReadIni()
  176. {
  177. if (File.Exists(inifile))
  178. {
  179. try
  180. {
  181. var lines = File.ReadAllLines(inifile);
  182. btnFile1.Text = lines[0];
  183. btnFile2.Text = lines[1];
  184. txtSmpCount.Text = lines[2];
  185. txtfs.Text = lines[3];
  186. txtDtoCenter.Text = lines[4];
  187. txtDtoRange.Text = lines[5];
  188. txtSnr.Text = lines[6];
  189. txtDfoRange.Text = lines[7];
  190. }
  191. catch
  192. {
  193. }
  194. }
  195. }
  196. // 写入配置
  197. void WriteIni()
  198. {
  199. var lines = new List<string>
  200. {
  201. btnFile1.Text,
  202. btnFile2.Text,
  203. txtSmpCount.Text,
  204. txtfs.Text,
  205. txtDtoCenter.Text,
  206. txtDtoRange.Text,
  207. txtSnr.Text,
  208. txtDfoRange.Text,
  209. };
  210. File.WriteAllLines(inifile, lines);
  211. }
  212. }
  213. }