using DevExpress.XtraEditors; using DxHelper; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using System.Windows.Forms; using DW5S.DTO; using DW5S.Entity; using DW5S.Repostory; using Serilog; using DW5S.Service; namespace DW5S.App.CorTools { public partial class ResampleForm : DevExpress.XtraEditors.XtraForm { public SatInfo info; public ResampleForm() { InitializeComponent(); txtOutFile.Text = ""; txtFile.UseChooseWaveFile((file, fsHz) => { this.txtOutDir.Text = Path.GetDirectoryName(file); if (fsHz > 0) txtFs.Text = (fsHz / 1e3).ToString(); else this.txtFs.Text = ""; }).UseDoubleClickToSelectAll(); txtOutDir.UseChooseDir().UseDoubleClickToSelectAll(); this.txtOutFile.UseDoubleClickToSelectAll(); this.layoutControl1.UseDefault(); } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private async void btnOk_ClickAsync(object sender, EventArgs e) { double fsHz, outFsHz; if (!double.TryParse(txtFs.Text, out fsHz)) { DxHelper.MsgBoxHelper.ShowError($"原始采样率非数字!"); return; } if (!double.TryParse(txtOutFs.Text, out outFsHz)) { DxHelper.MsgBoxHelper.ShowError($"变换后采样率非数字!"); return; } if (!File.Exists(txtFile.Text)) { DxHelper.MsgBoxHelper.ShowError($"文件[{txtFile.Text}]不存在"); return; } if (!Directory.Exists(txtOutDir.Text)) { DxHelper.MsgBoxHelper.ShowError($"输出目录[{txtOutDir.Text}]不存在"); return; } txtOutFile.Text = ""; fsHz *= 1e3; outFsHz *= 1e3; try { layoutControl1.Enabled = false; var unitOfWork = IocContainer.UnitOfWork; var repsSys = unitOfWork.Of(); var settings = await repsSys.FirstOrDefaultAsync(); if (settings == null) { layoutControl1.Enabled = true; DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置基础信息"); return; } string file = null; try { file = await HttpHelper.UploadFileAsync(txtFile.Text); } catch (Exception ex) { layoutControl1.Enabled = true; IocContainer.Logger.Error(ex,ex.Message); DxHelper.MsgBoxHelper.ShowError(ex.Message); return; } ResampleRequestDto dto = new ResampleRequestDto() { File = file, FsHz = (int)fsHz, OutFsHz = (int)outFsHz, }; var response = await HttpHelper.PostRequestAsync(SysConfig.GetUrl("DetectCg/Resample"), dto); if (response.code == 200) { string outFile = Path.Combine(txtOutDir.Text, Path.GetFileNameWithoutExtension(txtFile.Text) + $"_Resample{txtOutFs.Text}K.dat"); if (await HttpHelper.DownloadWithNameAsync(response.data.File, outFile)) this.txtOutFile.Text = outFile; else { IocContainer.Logger.Error($"下载文件[{response.data.File}]失败"); MsgBoxHelper.ShowError($"下载文件[{response.data.File}]失败"); } } else { MsgBoxHelper.ShowError(response.msg); } } catch (TaskCanceledException) { IocContainer.Logger.Information("变采样Http接口调用超时"); DxHelper.MsgBoxHelper.ShowInfo("变采样Http接口调用超时"); } catch (Exception ex) { IocContainer.Logger.Error(ex,"变采样出错"); DxHelper.MsgBoxHelper.ShowError("变采样出错"); } finally { layoutControl1.Enabled = true; } } } }