GpuCalcForm.cs 7.2 KB

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