using DevExpress.Utils; using DevExpress.XtraEditors; using DevExpress.XtraExport.Helpers; using DevExpress.XtraGrid.Views.Grid; using DxHelper; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Data; using System.Data.Entity; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Forms; using CG.App.EFContext; using XzXdDw.App.Model; namespace CG.App.UserControl { public partial class CtrlUserCheck : DevExpress.XtraEditors.XtraUserControl { public List list = new List(); public CtrlUserCheck() { InitializeComponent(); } private void CtrlUserCheck_Load(object sender, EventArgs e) { if (File.Exists("UserCheckTmp.txt")) { var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText("UserCheckTmp.txt")); txtValue.Text = "5"; txtF1.Text = obj.F1; txtFs.Text = obj.fs; txtSampleCount.Text = obj.sampleCount; } txtF1.UseChooseFile(); gridUserCheckRes.Init().UseFilter().UseMultiSelect().UseRowNumber() .UseExportCsv().UseExportXlsx() .AddMenu("清除", SvgHelper.CreateClear(), () => { list.Clear(); this.gridView1.RefreshData(); }); gridUserCheckRes.DataSource = list; //CellMerge gridView1.OptionsView.AllowCellMerge = true; gridView1.CellMerge += GridView1_CellMerge; } private void GridView1_CellMerge(object sender, CellMergeEventArgs e) { if (e.Column.FieldName == nameof(CheckCalcRes.DoTime)) { var val1 = gridView1.GetRowCellValue(e.RowHandle1, e.Column).ToString(); var val2 = gridView1.GetRowCellValue(e.RowHandle2, e.Column).ToString(); e.Merge = val1 == val2; } else if (e.Column.FieldName == nameof(CheckCalcRes.File1) || e.Column.FieldName == nameof(CheckCalcRes.CostTime)) { var doTimeV1 = gridView1.GetRowCellValue(e.RowHandle1, nameof(CheckCalcRes.DoTime)).ToString(); var doTimeV2 = gridView1.GetRowCellValue(e.RowHandle2, nameof(CheckCalcRes.DoTime)).ToString(); if (doTimeV1 != doTimeV2) { e.Merge = false; } else { var val1 = gridView1.GetRowCellValue(e.RowHandle1, e.Column).ToString(); var val2 = gridView1.GetRowCellValue(e.RowHandle2, e.Column).ToString(); e.Merge = val1 == val2; } } else { e.Merge = false; } e.Handled = true; } private async void btnDo_Click(object sender, EventArgs e) { this.layoutControl1.Enabled = false; await Task.Run(() => { try { CheckCalcUIParam cp = new CheckCalcUIParam() { F1 = txtF1.Text, fs = txtFs.Text, sampleCount = txtSampleCount.Text, Value = txtValue.Text, }; var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(cp); File.WriteAllText("UserCheckTmp.txt", jsonStr); Stopwatch sw = new Stopwatch(); sw.Start(); string sampleCount = txtSampleCount.Text; if (string.IsNullOrWhiteSpace(txtSampleCount.Text) || Convert.ToInt32(txtSampleCount.Text) <= 0) { FileInfo info = new FileInfo(txtF1.Text); sampleCount = (new FileInfo(info.FullName).Length / 4).ToString(); } var doTime = DateTime.Now; Process p = new Process(); p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "API\\信号识别\\enc.exe"); //enc.exe enc-test.dat 0.096 5 0 p.StartInfo.Arguments = $"{txtF1.Text} {txtFs.Text} {5} {sampleCount}"; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.Start(); p.WaitForExit(); var str = p.StandardOutput.ReadToEnd(); sw.Stop(); var arr = str.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var item in arr) { var startAndLen = item.Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); CheckCalcRes calcResOne = new CheckCalcRes() { DoTime = doTime, File1 = txtF1.Text, Start = Convert.ToInt32(startAndLen[0]), Len = Convert.ToInt32(startAndLen[1]), CostTime = sw.ElapsedMilliseconds, }; list.Add(calcResOne); } } catch (Exception ex) { Serilog.Log.Error("用户识别出错", ex); this.Invoke(new Action(() => XtraMessageBox.Show("用户识别出错"))); } }); this.gridView1.RefreshData(); this.layoutControl1.Enabled = true; } } public class CheckCalcUIParam { public string F1 { get; set; } public string fs { get; set; } public string sampleCount { get; set; } public string Value { get; set; } } public class CheckCalcRes { [Display(Name = "执行时刻",AutoGenerateField =false)] public DateTime DoTime { get; set; } [Display(Name = "文件")] public string File1 { get; set; } [Display(Name = "起始样点")] public int Start { get; set; } [Display(Name = "样点长度")] public int Len { get; set; } [Display(Name = "耗时(ms)")] public double CostTime { get; set; } } }