|
@@ -9,7 +9,9 @@ using System.ComponentModel;
|
|
|
using System.Data;
|
|
|
using System.Drawing;
|
|
|
using System.IO;
|
|
|
+using System.IO.Compression;
|
|
|
using System.Linq;
|
|
|
+using System.Net.Http;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
@@ -208,6 +210,7 @@ namespace XdCxRhDW.App.CorTools
|
|
|
private void chkDama_CheckedChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
lciStartPos.Visibility = lciSampleLength.Visibility = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? LayoutVisibility.Never : LayoutVisibility.Always;
|
|
|
+ btnCalc.Enabled = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? false : true;
|
|
|
if (chkDama.Checked)
|
|
|
{
|
|
|
ckIBS.Checked = false;
|
|
@@ -217,8 +220,10 @@ namespace XdCxRhDW.App.CorTools
|
|
|
private void ckIBS_CheckedChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
lciStartPos.Visibility = lciSampleLength.Visibility = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? LayoutVisibility.Never : LayoutVisibility.Always;
|
|
|
+ btnCalc.Enabled = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? false : true;
|
|
|
if (ckIBS.Checked)
|
|
|
{
|
|
|
+
|
|
|
chkDama.Checked = false;
|
|
|
ckKY.Checked = false;
|
|
|
}
|
|
@@ -227,6 +232,7 @@ namespace XdCxRhDW.App.CorTools
|
|
|
private void ckKY_CheckedChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
lciStartPos.Visibility = lciSampleLength.Visibility = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? LayoutVisibility.Never : LayoutVisibility.Always;
|
|
|
+ btnCalc.Enabled = ckKY.Checked | ckIBS.Checked | chkDama.Checked ? false : true;
|
|
|
if (ckKY.Checked)
|
|
|
{
|
|
|
ckIBS.Checked = false;
|
|
@@ -251,11 +257,49 @@ namespace XdCxRhDW.App.CorTools
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- if (lciStartPos.Visibility == LayoutVisibility.Never && gridSource.Count == 0)
|
|
|
+
|
|
|
+
|
|
|
+ // 压缩文件
|
|
|
+ string compressedFilePath = CompressFile(btnFile1.Text);
|
|
|
+
|
|
|
+ // 创建 HttpClient 对象
|
|
|
+ using (HttpClient client = new HttpClient())
|
|
|
{
|
|
|
- DxHelper.MsgBoxHelper.ShowError($"请输入计算参数起始样点及计算样点(勿勾选DAMA|IBS|Ky5758)!");
|
|
|
- return;
|
|
|
+ // 构建上传请求的 Uri
|
|
|
+ string uploadUri = "http://localhost:8091/api/DetectCg/UploadFile";
|
|
|
+
|
|
|
+ // 创建 MultipartFormDataContent 用于封装文件内容
|
|
|
+ MultipartFormDataContent content = new MultipartFormDataContent();
|
|
|
+
|
|
|
+ // 添加压缩后的文件内容到 MultipartFormDataContent
|
|
|
+ byte[] fileBytes = File.ReadAllBytes(compressedFilePath);
|
|
|
+ ByteArrayContent fileContent = new ByteArrayContent(fileBytes);
|
|
|
+ content.Add(fileContent, "file", Path.GetFileName(compressedFilePath));
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 发送上传请求
|
|
|
+ HttpResponseMessage response = await client.PostAsync(uploadUri, content);
|
|
|
+
|
|
|
+ // 检查响应状态码
|
|
|
+ if (response.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ MessageBox.Show("文件上传成功!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("文件上传失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show("文件上传失败:" + ex.Message);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 删除压缩后的临时文件
|
|
|
+ File.Delete(compressedFilePath);
|
|
|
+
|
|
|
List<XcorrStruct> xcorrs = new List<XcorrStruct>();
|
|
|
XcorrStruct xItem = new XcorrStruct();
|
|
|
xItem.file1 = btnFile1.Text;
|
|
@@ -281,8 +325,8 @@ namespace XdCxRhDW.App.CorTools
|
|
|
{
|
|
|
foreach (var item in gridSource)
|
|
|
{
|
|
|
- var corritem= xItem.Copy();
|
|
|
- corritem.smpCount =(int)item.smplen;
|
|
|
+ var corritem = xItem.Copy();
|
|
|
+ corritem.smpCount = (int)item.smplen;
|
|
|
corritem.smpStart = (int)item.smpstart;
|
|
|
xcorrs.Add(corritem);
|
|
|
}
|
|
@@ -296,35 +340,53 @@ namespace XdCxRhDW.App.CorTools
|
|
|
WriteIni();
|
|
|
btnCalc.Text = "停止";
|
|
|
beRunning = true;
|
|
|
+ gridSource.Clear();
|
|
|
foreach (var xcitem in xcorrs)
|
|
|
{
|
|
|
var result = await ExecuteCorAsync(xcitem);
|
|
|
if (result != null)
|
|
|
{
|
|
|
- var smitemindex = gridSource.FindIndex(m => m.smpstart == xcitem.smpStart && m.smplen == xcitem.smpCount);
|
|
|
- if (smitemindex == -1)
|
|
|
- {
|
|
|
- gridSource.Add(result);
|
|
|
- gridView1.FocusedRowHandle = gridSource.Count - 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var smitem = gridSource[smitemindex];
|
|
|
- smitem.dt = result.dt;
|
|
|
- smitem.df = result.df;
|
|
|
- smitem.snr = result.snr;
|
|
|
- smitem.tm = result.tm;
|
|
|
- gridView1.RefreshData();
|
|
|
- gridView1.FocusedRowHandle = smitemindex;
|
|
|
- }
|
|
|
+ //var smitemindex = gridSource.FindIndex(m => m.smpstart == xcitem.smpStart && m.smplen == xcitem.smpCount);
|
|
|
+ //if (smitemindex == -1)
|
|
|
+ //{
|
|
|
+ gridSource.Add(result);
|
|
|
+ gridView1.FocusedRowHandle = gridSource.Count - 1;
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // var smitem = gridSource[smitemindex];
|
|
|
+ // smitem.dt = result.dt;
|
|
|
+ // smitem.df = result.df;
|
|
|
+ // smitem.snr = result.snr;
|
|
|
+ // smitem.tm = result.tm;
|
|
|
+ // gridView1.RefreshData();
|
|
|
+ // gridView1.FocusedRowHandle = smitemindex;
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
btnCalc.Text = "计算";
|
|
|
beRunning = false;
|
|
|
|
|
|
}
|
|
|
+ private string CompressFile(string filePath)
|
|
|
+ {
|
|
|
+ string compressedFilePath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".zip");
|
|
|
+
|
|
|
+ using (FileStream originalFileStream = File.OpenRead(filePath))
|
|
|
+ {
|
|
|
+ using (FileStream compressedFileStream = File.Create(compressedFilePath))
|
|
|
+ {
|
|
|
+ using (GZipStream compressionStream = new GZipStream(compressedFileStream, CompressionMode.Compress))
|
|
|
+ {
|
|
|
+ originalFileStream.CopyTo(compressionStream);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return compressedFilePath;
|
|
|
+ }
|
|
|
private async Task<CafResult> ExecuteCorAsync(XcorrStruct xItem)
|
|
|
{
|
|
|
|