ResampleForm.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using DevExpress.XtraEditors;
  2. using DxHelper;
  3. using ExtensionsDev;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Documents;
  14. using System.Windows.Forms;
  15. using DW5S.DTO;
  16. using DW5S.Entity;
  17. using DW5S.Repostory;
  18. namespace DW5S.App.CorTools
  19. {
  20. public partial class ResampleForm : DevExpress.XtraEditors.XtraForm
  21. {
  22. public SatInfo info;
  23. public ResampleForm()
  24. {
  25. InitializeComponent();
  26. txtOutFile.Text = "";
  27. txtFile.UseChooseWaveFile((file, fsHz) =>
  28. {
  29. this.txtOutDir.Text = Path.GetDirectoryName(file);
  30. if (fsHz > 0)
  31. txtFs.Text = (fsHz / 1e3).ToString();
  32. else
  33. this.txtFs.Text = "";
  34. }).UseDoubleClickToSelectAll();
  35. txtOutDir.UseChooseDir().UseDoubleClickToSelectAll();
  36. this.txtOutFile.UseDoubleClickToSelectAll();
  37. this.layoutControl1.UseDefault();
  38. }
  39. private void btnCancel_Click(object sender, EventArgs e)
  40. {
  41. this.DialogResult = DialogResult.Cancel;
  42. }
  43. private async void btnOk_ClickAsync(object sender, EventArgs e)
  44. {
  45. double fsHz, outFsHz;
  46. if (!double.TryParse(txtFs.Text, out fsHz))
  47. {
  48. DxHelper.MsgBoxHelper.ShowError($"原始采样率非数字!");
  49. return;
  50. }
  51. if (!double.TryParse(txtOutFs.Text, out outFsHz))
  52. {
  53. DxHelper.MsgBoxHelper.ShowError($"变换后采样率非数字!");
  54. return;
  55. }
  56. if (!File.Exists(txtFile.Text))
  57. {
  58. DxHelper.MsgBoxHelper.ShowError($"文件[{txtFile.Text}]不存在");
  59. return;
  60. }
  61. if (!Directory.Exists(txtOutDir.Text))
  62. {
  63. DxHelper.MsgBoxHelper.ShowError($"输出目录[{txtOutDir.Text}]不存在");
  64. return;
  65. }
  66. txtOutFile.Text = "";
  67. fsHz *= 1e3;
  68. outFsHz *= 1e3;
  69. try
  70. {
  71. layoutControl1.Enabled = false;
  72. if (SysConfig.Config== null)
  73. {
  74. layoutControl1.Enabled = true;
  75. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置基础信息");
  76. return;
  77. }
  78. string file = null;
  79. try
  80. {
  81. file = await HttpHelper.UploadFileAsync(txtFile.Text, SysConfig.GetBaseUrl());
  82. }
  83. catch (Exception ex)
  84. {
  85. layoutControl1.Enabled = true;
  86. DW5S.Framework.LogHelper.Error(ex.Message, ex);
  87. DxHelper.MsgBoxHelper.ShowError(ex.Message);
  88. return;
  89. }
  90. ResampleRequestDto dto = new ResampleRequestDto()
  91. {
  92. File = file,
  93. FsHz = (int)fsHz,
  94. OutFsHz = (int)outFsHz,
  95. };
  96. var response = await HttpHelper.PostRequestAsync<ResampleResponseDto>(SysConfig.GetUrl("DetectCg/Resample"), dto);
  97. if (response.code == 200)
  98. {
  99. string outFile = Path.Combine(txtOutDir.Text, Path.GetFileNameWithoutExtension(txtFile.Text) + $"_Resample{txtOutFs.Text}K.dat");
  100. if (await HttpHelper.DownloadFileAsync(SysConfig.GetBaseUrl(), response.data.File, outFile))
  101. this.txtOutFile.Text = outFile;
  102. else
  103. {
  104. DW5S.Framework.LogHelper.Error($"下载文件[{response.data.File}]失败");
  105. MsgBoxHelper.ShowError($"下载文件[{response.data.File}]失败");
  106. }
  107. }
  108. else
  109. {
  110. MsgBoxHelper.ShowError(response.msg);
  111. }
  112. }
  113. catch (TaskCanceledException)
  114. {
  115. DW5S.Framework.LogHelper.Warning("变采样Http接口调用超时");
  116. DxHelper.MsgBoxHelper.ShowInfo("变采样Http接口调用超时");
  117. }
  118. catch (Exception ex)
  119. {
  120. DW5S.Framework.LogHelper.Error("变采样出错", ex);
  121. DxHelper.MsgBoxHelper.ShowError("变采样出错");
  122. }
  123. finally
  124. {
  125. layoutControl1.Enabled = true;
  126. }
  127. }
  128. }
  129. }