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