106 lines
3.9 KiB
C#
106 lines
3.9 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
|
|
namespace DTS.Serialization.TDM
|
|
{
|
|
public partial class TDMParameterDlg : Form
|
|
{
|
|
private readonly double _min;
|
|
private readonly double _max;
|
|
protected TDMParameterDlg()
|
|
{
|
|
}
|
|
public TDMParameterDlg(string testName, double testStart, double testEnd)
|
|
{
|
|
InitializeComponent();
|
|
DialogResult = DialogResult.Cancel;
|
|
var di = new System.IO.DirectoryInfo(Properties.Settings1.Default.TDMFolder);
|
|
if (!di.Exists)
|
|
{
|
|
di.Create();
|
|
}
|
|
var path = System.IO.Path.Combine(di.FullName, string.Format("{0}.csv", testName));
|
|
tbLocation.Text = path;
|
|
//tbStart.Text = (testStart*1000D).ToString();
|
|
//tbStop.Text = (testEnd*1000D).ToString();
|
|
var start = testStart * 1000D;
|
|
var stop = testEnd * 1000D;
|
|
_min = start;
|
|
_max = stop;
|
|
if (Properties.Settings1.Default.DefaultStart < start) { tbStart.Text = start.ToString(); }
|
|
else { tbStart.Text = Properties.Settings1.Default.DefaultStart.ToString(); }
|
|
|
|
if (Properties.Settings1.Default.DefaultStop > stop) { tbStop.Text = stop.ToString(); }
|
|
else { tbStop.Text = Properties.Settings1.Default.DefaultStop.ToString(); }
|
|
}
|
|
|
|
private void btnBrowse_Click(object sender, EventArgs e)
|
|
{
|
|
using (var dlg = new SaveFileDialog())
|
|
{
|
|
dlg.Filter = "TDM CSV (*.csv)|*.csv";
|
|
dlg.FilterIndex = 0;
|
|
dlg.RestoreDirectory = true;
|
|
dlg.OverwritePrompt = true;
|
|
|
|
var fi = new System.IO.FileInfo(tbLocation.Text);
|
|
dlg.InitialDirectory = fi.Directory.FullName;
|
|
dlg.FileName = tbLocation.Text;
|
|
|
|
if (DialogResult.OK == dlg.ShowDialog(this))
|
|
{
|
|
tbLocation.Text = dlg.FileName;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
errorProvider1.SetError(tbStart, null);
|
|
errorProvider1.SetError(tbStop, null);
|
|
var fi = new System.IO.FileInfo(tbLocation.Text);
|
|
Properties.Settings1.Default.TDMFolder = fi.Directory.FullName;
|
|
|
|
var dstart = double.MinValue;
|
|
if (double.TryParse(tbStart.Text, out dstart))
|
|
{
|
|
Properties.Settings1.Default.DefaultStart = dstart;
|
|
}
|
|
else
|
|
{
|
|
errorProvider1.SetError(tbStart, "Could not parse");
|
|
return;
|
|
}
|
|
var dend = double.MinValue;
|
|
if (double.TryParse(tbStop.Text, out dend))
|
|
{
|
|
Properties.Settings1.Default.DefaultStop = dend;
|
|
}
|
|
else
|
|
{
|
|
errorProvider1.SetError(tbStop, "Could not parse");
|
|
return;
|
|
}
|
|
|
|
if (dend < dstart) { errorProvider1.SetError(tbStart, "Start must be before end"); return; }
|
|
if (dend > _max) { errorProvider1.SetError(tbStop, string.Format("exceeds max data in test ({0} ms)", _max)); return; }
|
|
if (dstart < _min) { errorProvider1.SetError(tbStart, string.Format("test does not contain requested region, min start is ({0} ms)", _min)); return; }
|
|
|
|
Properties.Settings1.Default.Save();
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
|
|
public string FileName => tbLocation.Text;
|
|
|
|
public double Start => double.Parse(tbStart.Text) / 1000D;
|
|
public double Stop => double.Parse(tbStop.Text) / 1000D;
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
}
|