using DevExpress.Internal.WinApi.Windows.UI.Notifications; using DevExpress.XtraEditors; using DevExpress.XtraLayout.Utils; 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.Forms; namespace XdCxRhDW.App.CorTools { public partial class DetectToolForm : DevExpress.XtraEditors.XtraForm { static readonly string inifile = Path.Combine(Application.StartupPath, "par.ini"); volatile bool beRunning = false; BindingList gridSource = new BindingList(); public DetectToolForm() { InitializeComponent(); } void openfile(object sender) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { if (sender == btnFile1) { btnFile1.Text = openFileDialog1.FileName; } else { btnFile2.Text = openFileDialog1.FileName; } } } /// /// 读取配置 /// void ReadIni() { if (File.Exists(inifile)) { var lines = File.ReadAllLines(inifile); if (lines.Length != 9) { return; } btnFile1.Text = lines[0]; btnFile2.Text = lines[1]; teCount.Text = lines[2]; tefs.Text = lines[3]; teCenter.Text = lines[4]; teRange.Text = lines[5]; teSnr.Text = lines[6]; tePos.Text = lines[7]; teDfRange.Text = lines[8]; } } /// /// 写入配置 /// void WriteIni() { var lines = new List(); lines.Add(btnFile1.Text); lines.Add(btnFile2.Text); lines.Add(teCount.Text); lines.Add(tefs.Text); lines.Add(teCenter.Text); lines.Add(teRange.Text); lines.Add(teSnr.Text); lines.Add(tePos.Text); lines.Add(teDfRange.Text); File.WriteAllLines(inifile, lines); } private void MainForm_Load(object sender, EventArgs e) { this.gridControl1.DataSource = gridSource; ReadIni(); } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { //if (!DxHelper.MsgBoxHelper.ShowConfirm("是否退出当前程序")) //{ // e.Cancel = true; //} } private bool ValidateFile(string filename) { if (string.IsNullOrWhiteSpace(filename)) { DxHelper.MsgBoxHelper.ShowError($"请选择文件!"); return false; } if (!File.Exists(filename)) { DxHelper.MsgBoxHelper.ShowError($"文件【{filename}】不存在"); return false; } return true; } /// /// 网格右键菜单弹出 /// /// /// private void gridView1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right && !beRunning) { popupMenu1.ShowPopup(Cursor.Position); } } /// /// 清除网格 /// /// /// private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { gridSource.Clear(); } /// /// 文件拖拽 /// /// /// private void btnFile_DragOver(object sender, DragEventArgs e) { e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; } private void btnFile_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files != null && files.Length != 0) { if (sender == btnFile1) { btnFile1.Text = files[0]; } else if (sender == btnFile2) { btnFile2.Text = files[0]; } } } private void btnFile_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { openfile(sender); } private void btnFile_DoubleClick(object sender, EventArgs e) { openfile(sender); } private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "csv|*.csv"; if (dialog.ShowDialog() == DialogResult.OK) { gridView1.ExportToCsv(dialog.FileName); } } private async void btnCheck_Click(object sender, EventArgs e) { if (!ValidateFile(btnFile1.Text)) { return; } var dmcResult = await XcorrUtils.DmcCheckAsync(btnFile1.Text, double.Parse(tefs.Text)); gridSource.Clear(); foreach (var dmcItem in dmcResult) { gridSource.Add(new CafResult() { file1 = btnFile1.Text, file2 = btnFile2.Text, smpstart = dmcItem.Start, smplen = dmcItem.Length }); } } private void chkDama_CheckedChanged(object sender, EventArgs e) { //lciBtnCheck.Visibility = chkDama.Checked ? LayoutVisibility.Always : LayoutVisibility.Never; lciStartPos.Visibility = lciSampleLength.Visibility = chkDama.Checked ? LayoutVisibility.Never : LayoutVisibility.Always; //layoutControl1.BestFit(); } } }