Files
DP44/Common/DTS.Common.Serialization/DDAS (Chrysler)/TSVSettingsWindow.cs
2026-04-17 14:55:32 -04:00

167 lines
6.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DTS.Serialization.TSV
{
public partial class TSVSettingsWindow : Form
{
protected TSVSettingsWindow() { InitializeComponent(); }
private volatile bool _bPopulating = false;
private TSVTest _test;
public TSVSettingsWindow(TSVTest test)
{
InitializeComponent();
_test = test;
_bPopulating = true;
try
{
c1GridGlobal.AutoGenerateColumns = false;
c1GridGlobal.Styles.Alternate.BackColor = Properties.Settings1.Default.AlternatingRow;
c1GridGlobal.Styles.Fixed.BackColor = Properties.Settings1.Default.TableHeader;
TSVTest.Fields[] fields = Enum.GetValues(typeof(TSVTest.Fields)).Cast<TSVTest.Fields>().ToArray();
foreach (var field in fields)
{
switch (field)
{
case TSVTest.Fields.AAFilterCutoffDescription:
case TSVTest.Fields.BitResolution:
case TSVTest.Fields.ChannelErrors:
case TSVTest.Fields.DataType:
case TSVTest.Fields.DigitalFilterType:
case TSVTest.Fields.EngineeringUnits:
case TSVTest.Fields.SensorAxis:
case TSVTest.Fields.SensorLocation:
case TSVTest.Fields.SensorMakeModelSerial:
case TSVTest.Fields.SensorMountType:
//do not display
break;
default:
var row = c1GridGlobal.Rows.Add();
row["colField"] = TSVStrings.ResourceManager.GetString(string.Format("{0}_Title", field.ToString()));
row["colDescription"] = TSVStrings.ResourceManager.GetString(string.Format("{0}_Description", field.ToString()));
row["colValue"] = test.GetValue(field);
row.UserData = field;
break;
}
}
c1GridChannels.Styles.Fixed.BackColor = Properties.Settings1.Default.TableHeader;
c1GridChannels.Styles.Alternate.BackColor = Properties.Settings1.Default.AlternatingRow;
var c = c1GridChannels.Cols.Add();
c.Caption = "Channel Number";
c.AllowEditing = false;
c.DataType = typeof(int);
c.Name = "colNumber";
c.UserData = null;
c = c1GridChannels.Cols.Add();
c.Caption = "File Name";
c.AllowEditing = true;
c.DataType = typeof(string);
c.Name = "colFileName";
c.UserData = null;
foreach (var field in fields)
{
c = c1GridChannels.Cols.Add();
c.Caption = TSVStrings.ResourceManager.GetString(string.Format("{0}_Title", field.ToString()));
c.DataType = typeof(string);
c.AllowEditing = true;
c.Name = "col" + field.ToString();
c.UserData = field;
}
foreach (var channel in test.Channels)
{
var r = c1GridChannels.Rows.Add();
r["colNumber"] = channel.ChannelNumber;
r["colFileName"] = channel.FileName;
foreach (var field in fields) { r["col" + field.ToString()] = channel.GetValue(field); }
r.UserData = channel;
}
}
finally
{
_bPopulating = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void c1GridGlobal_CellChanged(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
}
private void gridChannels_CellChanged(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
}
private void c1GridChannels_AfterEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
if (_bPopulating) { return; }
try
{
_bPopulating = true;
if (null != c1GridChannels.Rows[e.Row].UserData)
{
TSVChannel channel = c1GridChannels.Rows[e.Row].UserData as TSVChannel;
if (null == channel) { return; }
if (null != c1GridChannels.Cols[e.Col].UserData)
{
TSVTest.Fields field = (TSVTest.Fields)c1GridChannels.Cols[e.Col].UserData;
channel.SetValue(field, c1GridChannels.Rows[e.Row][e.Col] as string);
}
}
}
finally
{
_bPopulating = false;
}
}
private void c1GridGlobal_AfterEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
if (_bPopulating) { return; }
try
{
if (null != c1GridGlobal.Rows[e.Row].UserData)
{
TSVTest.Fields field = (TSVTest.Fields)c1GridGlobal.Rows[e.Row].UserData;
_test.SetValue(field, c1GridGlobal.Rows[e.Row]["colValue"] as string);
for (int i = 0; i < c1GridChannels.Rows.Count; i++)
{
if (null != c1GridChannels.Rows[i].UserData)
{
TSVChannel channel = c1GridChannels.Rows[i].UserData as TSVChannel;
if (null != channel)
{
c1GridChannels.Rows[i]["col" + field.ToString()] = channel.GetValue(field);
}
}
}
}
}
finally { _bPopulating = false; }
}
}
}