GpuCalcForm.cs 7.3 KB

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