using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace ProgramLib.GUI.Model { internal partial class PassthroughData { private int _datagridColumnCount = 0; // this dictionary stores variable and the info needed to locate it in the passthroughdatamodel dictionary which contains a 2-d array private Dictionary _variableEnumToVariableInfoDict = new Dictionary(); // this dictionary stores variable and its corresponding data model private Dictionary> _rowNumberToPassthroughDataDict = new Dictionary>(); public PassthroughData(int datagridColumnCount) { _datagridColumnCount = datagridColumnCount; VariableInfo variableInfo = new VariableInfo(); int dictIndex = 0; int colIndex = 0; // contruct a 2-d array of strings based on the list of Variables foreach (Variables enumVar in Enum.GetValues(typeof(Variables))) { if (_rowNumberToPassthroughDataDict.Count == 0 || colIndex == _datagridColumnCount) { dictIndex++; _rowNumberToPassthroughDataDict[dictIndex] = new ObservableCollection(new string[_datagridColumnCount]); colIndex = 0; } // name of the variable _rowNumberToPassthroughDataDict[dictIndex][colIndex] = String.Empty; variableInfo.passthroughDataModelItemIndex = colIndex++; // value of the variable _rowNumberToPassthroughDataDict[dictIndex][colIndex++] = String.Empty; // save the row index so we can refer to this item variableInfo.passthroughDataModelDictIndex = dictIndex; // save the column index of this item so we can refer to this item _variableEnumToVariableInfoDict[enumVar] = variableInfo; } } public Dictionary> GetPassthroughDataModelDict() { return _rowNumberToPassthroughDataDict; } public void SetValue(Variables variableName, string val) { _rowNumberToPassthroughDataDict[_variableEnumToVariableInfoDict[variableName].passthroughDataModelDictIndex][_variableEnumToVariableInfoDict[variableName].passthroughDataModelItemIndex] = _variableEnumToDescriptionDict[variableName]; _rowNumberToPassthroughDataDict[_variableEnumToVariableInfoDict[variableName].passthroughDataModelDictIndex][_variableEnumToVariableInfoDict[variableName].passthroughDataModelItemIndex + 1] = val; } } }