| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 | using DevExpress.Data.Extensions;using DevExpress.Internal.WinApi.Windows.UI.Notifications;using DevExpress.Mvvm.Native;using DevExpress.XtraEditors;using DevExpress.XtraLayout.Utils;using DxHelper;using ExtensionsDev;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.Entity;using System.Drawing;using System.IO;using System.IO.Compression;using System.Linq;using System.Net;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using XdCxRhDW.Api;using XdCxRhDW.Dto;using XdCxRhDW.Repostory;namespace XdCxRhDW.App.CorTools{    public partial class GpuCalcForm : DevExpress.XtraEditors.XtraForm    {        static readonly string inifile = Path.Combine(Application.StartupPath, "parGpu.ini");        List<GpuCafResult> gridSource = new List<GpuCafResult>();        public GpuCalcForm()        {            InitializeComponent();        }        private void MainForm_Load(object sender, EventArgs e)        {            this.gridGpuCg.UseDefault(gridSource).UseExportXlsx().UseRowNumber()                .UseExportCsv().UseClear<GpuCafResult>();            this.btnFile1.UseChooseWaveFile((file, fsHz) =>            {                if (fsHz > 0)                    txtfs.Text = (fsHz / 1e6).ToString();                else                    txtfs.Text = "0.096";            }).UseDoubleClickToSelectAll();            this.btnFile2.UseChooseFile().UseDoubleClickToSelectAll();            ReadIni();        }        private async void btnCalc_Click(object sender, EventArgs e)        {            if (!ValidateFiles(btnFile1.Text, btnFile2.Text)) return;            if (!ValidateParams()) return;            layoutControl1.Enabled = false;            string file1, file2;            try            {                file1 = await HttpHelper.UploadFileAsync(btnFile1.Text, SysConfig.GetBaseUrl());                file2 = await HttpHelper.UploadFileAsync(btnFile2.Text, SysConfig.GetBaseUrl());            }            catch (Exception ex)            {                layoutControl1.Enabled = true;                Serilog.Log.Error(ex, ex.Message);                DxHelper.MsgBoxHelper.ShowError(ex.Message);                return;            }            var samplingRate = double.Parse(txtfs.Text) * 1e6;            var dtCenter = double.Parse(txtDtoCenter.Text);            var dtRange = double.Parse(txtDtoRange.Text);            var dfRange = double.Parse(txtDfoRange.Text);            var smpCount = double.Parse(txtSmpCount.Text);            var snrThreshold = double.Parse(txtSnr.Text);            var timeout = int.Parse(txtTimeout.Text);            GpuCgRequestDto dto = new GpuCgRequestDto()            {                dfRange = dfRange,                smpCount = smpCount,                dtCenter = dtCenter,                dtRange = dtRange,                file1 = file1,                file2 = file2,                samplingRate = samplingRate,                snrThreshold = snrThreshold,                TimeoutSeconds = timeout,            };            WriteIni();            gridSource.Clear();            try            {                var result = await HttpHelper.PostRequestAsync<List<GpuCgResponseDto>>(SysConfig.GetUrl("DetectCg/GpuCgCalc"), dto, dto.TimeoutSeconds);                if (result.code == 200)                {                    foreach (var item in result.data)                    {                        gridSource.Add(new GpuCafResult()                        {                            file1 = btnFile1.Text,                            file2 = btnFile2.Text,                            dt = item.Dt,                            df = item.Df,                            snr = item.Snr,                            tm = item.TimeMs,                        });                    }                }                else                {                    Serilog.Log.Error(result.msg);                    DxHelper.MsgBoxHelper.ShowError(result.msg);                }            }            catch (TaskCanceledException)            {                Serilog.Log.Warning("GPU文件参估Http接口调用超时");                DxHelper.MsgBoxHelper.ShowInfo("GPU文件参估Http接口调用超时");            }            catch (Exception ex)            {                Serilog.Log.Error(ex, "GPU文件参估出错");                DxHelper.MsgBoxHelper.ShowError("GPU文件参估出错");            }            gridView1.RefreshData();            layoutControl1.Enabled = true;        }        private bool ValidateFiles(params string[] files)        {            foreach (var file in files)            {                if (string.IsNullOrWhiteSpace(file))                {                    DxHelper.MsgBoxHelper.ShowError($"请选择文件!");                    return false;                }                if (!File.Exists(file))                {                    DxHelper.MsgBoxHelper.ShowError($"文件【{file}】不存在");                    return false;                }            }            return true;        }        private bool ValidateParams()        {            if (!double.TryParse(txtfs.Text, out _))            {                DxHelper.MsgBoxHelper.ShowError($"采样率非有效数字");                return false;            }            if (!double.TryParse(txtDtoCenter.Text, out _))            {                DxHelper.MsgBoxHelper.ShowError($"时差中心非有效数字");                return false;            }            if (!double.TryParse(txtDtoRange.Text, out _))            {                DxHelper.MsgBoxHelper.ShowError($"时差范围非有效数字");                return false;            }            if (!double.TryParse(txtDfoRange.Text, out _))            {                DxHelper.MsgBoxHelper.ShowError($"频差范围非有效数字");                return false;            }            if (!double.TryParse(txtSnr.Text, out _))            {                DxHelper.MsgBoxHelper.ShowError($"信噪比门限非有效数字");                return false;            }            if (!double.TryParse(txtSmpCount.Text, out _))            {                DxHelper.MsgBoxHelper.ShowError($"样点数非有效数字");                return false;            }            if (!int.TryParse(txtTimeout.Text, out _))            {                DxHelper.MsgBoxHelper.ShowError($"超时时间非有效数字");                return false;            }            return true;        }        //读取配置        void ReadIni()        {            if (File.Exists(inifile))            {                try                {                    var lines = File.ReadAllLines(inifile);                    btnFile1.Text = lines[0];                    btnFile2.Text = lines[1];                    txtSmpCount.Text = lines[2];                    txtfs.Text = lines[3];                    txtDtoCenter.Text = lines[4];                    txtDtoRange.Text = lines[5];                    txtSnr.Text = lines[6];                    txtDfoRange.Text = lines[7];                    txtTimeout.Text = lines[8];                }                catch                {                }            }        }        // 写入配置        void WriteIni()        {            var lines = new List<string>            {                btnFile1.Text,                btnFile2.Text,                txtSmpCount.Text,                txtfs.Text,                txtDtoCenter.Text,                txtDtoRange.Text,                txtSnr.Text,                txtDfoRange.Text,                txtTimeout.Text            };            File.WriteAllLines(inifile, lines);        }    }}
 |