private void setupChart(ref Chart cChart, ref byte[] arrBytes, ref SADBin cBin, ref SADS6x cS6x) { cChart.Series[0].Points.DataBindY(arrBytes); string legendText = cBin.BinaryFileName; if (cBin.Calibration.Info.VidStrategy != string.Empty) { legendText += " - " + cBin.Calibration.Info.VidStrategy + "(" + cBin.Calibration.Info.VidStrategyVersion + ")"; } cChart.Series[0].LegendText = legendText; string legentToolTip = string.Empty; if (cBin.Calibration.Info.is8061) { legentToolTip += "8061"; } else { legentToolTip += "8065"; } legentToolTip += " binary.\r\nBanks :"; foreach (string[] bankInfos in cBin.Calibration.Info.slBanksInfos.Values) { legentToolTip += string.Format("\r\n{0,4}{1,8}{2,3}{3,6}", bankInfos[0], bankInfos[1], "=>", bankInfos[2]); } legentToolTip += "\r\n\r\n"; if (cS6x.isValid) { legentToolTip += cS6x.FileName; } else { legentToolTip += "No SAD 806x File"; } cChart.Series[0].LegendToolTip = legentToolTip; if (cChart == calibComparedChart) { cChart.Series[0].Color = Color.Green; } cChart.ChartAreas[0].AxisY.Minimum = 0.0; cChart.ChartAreas[0].AxisY.Maximum = 255.0; cChart.ChartAreas[0].AxisY.LabelStyle.Enabled = false; cChart.ChartAreas[0].AxisY.MajorGrid.Enabled = false; cChart.ChartAreas[0].AxisY.MajorTickMark.Enabled = false; cChart.ChartAreas[0].AxisX.MajorGrid.Enabled = false; cChart.ChartAreas[0].AxisX.MajorTickMark.Enabled = false; cChart.ChartAreas[0].AxisX.CustomLabels.Clear(); cChart.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll; // To remove non interesting buttons cChart.ChartAreas[0].AxisX.ScaleView.Size = (double)(sadBin.Calibration.Size / 10); // For both Charts to be aligned setupChartLabels(ref cChart, ref arrBytes, ref cBin, ref cS6x); }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { sadBin = null; sadS6x = null; arrCurBytes = null; cmpSadBin = null; cmpSadS6x = null; arrCmpBytes = null; Dispose(); GC.Collect(); }
public SearchSignatureForm(ref SADBin mainSadBin) { sadBin = mainSadBin; InitializeComponent(); try { Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch { } //searchTreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(searchTreeView_NodeMouseClick); //searchTreeView.AfterSelect += new TreeViewEventHandler(searchTreeView_AfterSelect); mainTipPictureBox.Tag = SharedUI.ElementSignatureTip(); mainTipPictureBox.MouseHover += new EventHandler(TipPictureBox_MouseHover); mainTipPictureBox.Click += new EventHandler(TipPictureBox_Click); }
public static int binAddressCorrected(int bankNum, int address, ref SADBin sadBin, int addressBin) { if (sadBin == null) { return(addressBin); } if (!sadBin.isLoaded || !sadBin.isValid) { return(addressBin); } SADBank sadBank = null; int newAddressBin = 0; switch (bankNum) { case 8: sadBank = sadBin.Bank8; break; case 1: sadBank = sadBin.Bank1; break; case 9: sadBank = sadBin.Bank9; break; case 0: sadBank = sadBin.Bank0; break; } if (sadBank == null) { return(newAddressBin); } if (address < sadBank.Size) { newAddressBin = sadBank.AddressBinInt + address; } sadBank = null; return(newAddressBin); }
public void Create(string xlsFilePath, ref SADBin sadBin) { filePath = xlsFilePath; fileName = Path.GetFileName(xlsFilePath); valid = true; ConfigParameters = new List <XlsConfigParameter>(); Revisions = new List <XlsRevision>(); Levels = new SortedList <string, XlsLevel>(); QHorses = new List <XlsQHorse>(); TwEECers = new List <XlsTwEECer>(); PayLoads = new SortedList <int, XlsPayLoad>(); Scalars = new SortedList <string, XlsScalar>(); Functions = new SortedList <string, XlsFunction>(); Tables = new SortedList <string, XlsTable>(); // To be checked // Some Minimum records on Config or Revisions could be required }
private void setupChartLabels(ref Chart cChart, ref byte[] arrBytes, ref SADBin cBin, ref SADS6x cS6x) { foreach (S6xTable s6xTable in cS6x.slTables.Values) { if (s6xTable.Skip) { continue; } if (!s6xTable.isCalibrationElement) { continue; } if (s6xTable.ColsNumber <= 0 || s6xTable.RowsNumber <= 0) { continue; } int arrBytesAddressInt = s6xTable.AddressInt - cBin.Calibration.AddressBankInt; int size = (s6xTable.ColsNumber * s6xTable.RowsNumber) * ((s6xTable.WordOutput) ? 2 : 1); if (arrBytesAddressInt >= arrBytes.Length) { continue; } if (arrBytesAddressInt + size >= arrBytes.Length) { continue; } CustomLabel cLabel = new CustomLabel(); cLabel.FromPosition = arrBytesAddressInt; cLabel.ToPosition = arrBytesAddressInt + size; cLabel.Text = s6xTable.ShortLabel; cLabel.ToolTip = s6xTable.Label; cLabel.Tag = s6xTable; cChart.ChartAreas[0].AxisX.CustomLabels.Add(cLabel); } foreach (S6xFunction s6xFunction in cS6x.slFunctions.Values) { if (s6xFunction.Skip) { continue; } if (!s6xFunction.isCalibrationElement) { continue; } if (s6xFunction.RowsNumber <= 0) { continue; } int arrBytesAddressInt = s6xFunction.AddressInt - cBin.Calibration.AddressBankInt; int size = s6xFunction.RowsNumber * (((s6xFunction.ByteInput) ? 1 : 2) + ((s6xFunction.ByteOutput) ? 1 : 2)); if (arrBytesAddressInt >= arrBytes.Length) { continue; } if (arrBytesAddressInt + size >= arrBytes.Length) { continue; } CustomLabel cLabel = new CustomLabel(); cLabel.FromPosition = arrBytesAddressInt; cLabel.ToPosition = arrBytesAddressInt + size; cLabel.Text = s6xFunction.ShortLabel; cLabel.ToolTip = s6xFunction.Label; cLabel.Tag = s6xFunction; cChart.ChartAreas[0].AxisX.CustomLabels.Add(cLabel); } }
private void openBinaryToolStripMenuItem_Click(object sender, EventArgs e) { string cmpBinaryFilePath = string.Empty; string cmpS6xFilePath = string.Empty; string sError = string.Empty; bool bError = false; if (openFileDialogBin.ShowDialog() != DialogResult.OK) { return; } if (!File.Exists(openFileDialogBin.FileName)) { sError += openFileDialogBin.FileName + "\r\n"; sError += "Not existing Binary."; MessageBox.Show(sError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } cmpBinaryFilePath = openFileDialogBin.FileName; FileInfo fiFI = new FileInfo(cmpBinaryFilePath); cmpS6xFilePath = fiFI.Directory.FullName + "\\" + fiFI.Name.Substring(0, fiFI.Name.Length - fiFI.Extension.Length) + ".s6x"; fiFI = null; if (!File.Exists(cmpS6xFilePath)) { cmpS6xFilePath = string.Empty; } cmpSadBin = null; cmpSadS6x = null; System.Windows.Forms.Cursor processPreviousCursor = Cursor; Cursor = System.Windows.Forms.Cursors.WaitCursor; cmpSadBin = new SADBin(cmpBinaryFilePath, cmpS6xFilePath); cmpSadS6x = cmpSadBin.S6x; bError = (cmpSadBin == null); if (bError) { sError += cmpBinaryFilePath + "\r\n"; sError += "Unrecognized Binary."; Cursor = processPreviousCursor; MessageBox.Show(sError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Text = getTitle(); return; } bError = (!cmpSadBin.isLoaded || !cmpSadBin.isValid); if (bError) { sError += cmpBinaryFilePath + "\r\n"; sError += "Unrecognized Binary."; Cursor = processPreviousCursor; MessageBox.Show(sError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Text = getTitle(); return; } cmpSadBin.processBin(); bError = (!cmpSadBin.isDisassembled); if (bError) { sError += cmpBinaryFilePath + "\r\n"; sError += "Binary can not be disassembled."; Cursor = processPreviousCursor; MessageBox.Show(sError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Text = getTitle(); return; } string[] arrSBytes = cmpSadBin.Calibration.getBytesArray(cmpSadBin.Calibration.AddressBankInt, cmpSadBin.Calibration.Size); arrCmpBytes = new byte[arrSBytes.Length]; for (int iPos = 0; iPos < arrCmpBytes.Length; iPos++) { arrCmpBytes[iPos] = Convert.ToByte(arrSBytes[iPos], 16); } arrSBytes = null; setupChart(ref calibComparedChart, ref arrCmpBytes, ref cmpSadBin, ref cmpSadS6x); Cursor = processPreviousCursor; calibComparedChart.Visible = true; this.Text = getTitle(); }
public CompareGraphForm(ref SADBin mainSadBin, ref SADS6x mainSadS6x, ref TreeView mainElemsTreeView) { sadBin = mainSadBin; sadS6x = mainSadS6x; elemsTreeView = mainElemsTreeView; InitializeComponent(); try { Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch { } string[] chartTypes = Enum.GetNames(typeof(SeriesChartType)); foreach (string chartType in chartTypes) { switch ((SeriesChartType)Enum.Parse(typeof(SeriesChartType), chartType, true)) { case SeriesChartType.Bubble: case SeriesChartType.StackedArea100: case SeriesChartType.StackedBar100: case SeriesChartType.StackedColumn100: case SeriesChartType.SplineArea: case SeriesChartType.Pie: case SeriesChartType.Doughnut: case SeriesChartType.SplineRange: case SeriesChartType.Radar: case SeriesChartType.Polar: case SeriesChartType.ErrorBar: case SeriesChartType.Renko: case SeriesChartType.Funnel: case SeriesChartType.Pyramid: // Not working continue; } chartStyleToolStripMenuItem.DropDownItems.Add(chartType, null, chartStyle_Click); } chartStyleToolStripMenuItem.DropDownOpening += new EventHandler(chartStyleToolStripMenuItem_DropDownOpening); List <Color> allColors = new List <Color>(); foreach (PropertyInfo property in typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public)) { if (property.PropertyType == typeof(Color)) { allColors.Add((Color)property.GetValue(null, null)); } } List <Color> lColors = new List <Color>(); foreach (Color cColor in allColors) { switch (cColor.Name) { case "Black": case "Blue": case "Cyan": case "Gray": case "Green": case "Lime": case "Magenta": case "Maroon": case "Navy": case "Olive": case "Orange": case "Pink": case "Purple": case "Red": case "Silver": case "Teal": case "Transparent": case "White": case "Yellow": lColors.Add(cColor); break; } } foreach (Color chartColor in lColors) { chartColorToolStripMenuItem.DropDownItems.Add(chartColor.Name, null, chartColor_Click); } chartColorToolStripMenuItem.DropDownOpening += new EventHandler(chartColorToolStripMenuItem_DropDownOpening); foreach (Color chartColor in lColors) { chartBackColorToolStripMenuItem.DropDownItems.Add(chartColor.Name, null, chartBackColor_Click); } chartBackColorToolStripMenuItem.DropDownOpening += new EventHandler(chartBackColorToolStripMenuItem_DropDownOpening); calibCurrentChart.Visible = false; calibComparedChart.Visible = false; calibCurrentChart.Series[0].Color = Color.Blue; calibComparedChart.Series[0].Color = Color.Green; calibCurrentChart.ChartAreas[0].BackColor = Color.White; calibComparedChart.ChartAreas[0].BackColor = Color.White; calibCurrentChart.MouseWheel += new MouseEventHandler(calibChart_MouseWheel); calibCurrentChart.MouseClick += new MouseEventHandler(calibChart_MouseClick); calibComparedChart.MouseWheel += new MouseEventHandler(calibChart_MouseWheel); calibComparedChart.MouseClick += new MouseEventHandler(calibChart_MouseClick); chartContextMenuStrip.Opening += new CancelEventHandler(chartContextMenuStrip_Opening); }
public XdfFile(ref SADBin sadBin) { int lastXdfUniqueId = 0; ArrayList alXdfTables = null; ArrayList alXdfFunctions = null; ArrayList alXdfScalars = null; int xdfBaseOffset = 0; version = "1.60"; xdfHeader = new XdfHeader(); xdfHeader.xdfBaseOffset = new XdfHeaderBaseOffset(); xdfHeader.deftitle = sadBin.S6x.Properties.Label; xdfHeader.description = sadBin.S6x.Properties.Comments; xdfHeader.xdfBaseOffset.offset = "0"; xdfHeader.xdfBaseOffset.subtract = "0"; try { xdfHeader.xdfBaseOffset.offset = Convert.ToInt32(sadBin.S6x.Properties.XdfBaseOffset, 16).ToString(); if (sadBin.S6x.Properties.XdfBaseOffsetSubtract) { xdfHeader.xdfBaseOffset.subtract = "1"; } } catch { } xdfBaseOffset = Convert.ToInt32(xdfHeader.xdfBaseOffset.offset); if (xdfHeader.xdfBaseOffset.subtract == "1") { xdfBaseOffset *= -1; } xdfHeader.xdfRegion = new XdfHeaderRegion(); xdfHeader.xdfRegion.type = "0xFFFFFFFF"; xdfHeader.xdfRegion.startaddress = "0x0"; xdfHeader.xdfRegion.size = string.Format("0x{0:X4}", sadBin.BinaryFileSize); xdfHeader.xdfRegion.regionflags = "0x0"; xdfHeader.xdfRegion.name = "Binary File"; xdfHeader.xdfRegion.desc = "This region describes the bin file edited by this XDF"; alXdfTables = new ArrayList(); alXdfFunctions = new ArrayList(); alXdfScalars = new ArrayList(); // Functions first for Scalers foreach (S6xFunction s6xObject in sadBin.S6x.slFunctions.Values) { if (!s6xObject.Skip && s6xObject.Store && s6xObject.AddressBinInt >= xdfBaseOffset) { XdfFunction xdfObject = new XdfFunction(s6xObject, xdfBaseOffset); xdfObject.uniqueid = "0x" + string.Format("{0:x4}", lastXdfUniqueId); s6xObject.XdfUniqueId = xdfObject.uniqueid; lastXdfUniqueId++; alXdfFunctions.Add(xdfObject); xdfObject = null; } } foreach (S6xFunction s6xObject in sadBin.S6x.slDupFunctions.Values) { if (!s6xObject.Skip && s6xObject.Store && s6xObject.AddressBinInt >= xdfBaseOffset) { XdfFunction xdfObject = new XdfFunction(s6xObject, xdfBaseOffset); xdfObject.uniqueid = "0x" + string.Format("{0:x4}", lastXdfUniqueId); s6xObject.XdfUniqueId = xdfObject.uniqueid; lastXdfUniqueId++; alXdfFunctions.Add(xdfObject); xdfObject = null; } } foreach (S6xTable s6xObject in sadBin.S6x.slTables.Values) { if (!s6xObject.Skip && s6xObject.Store && s6xObject.AddressBinInt >= xdfBaseOffset) { // Trying to find Scalers Unique Xdf Ids if (s6xObject.ColsScalerAddress != null && s6xObject.ColsScalerAddress != string.Empty) { if (sadBin.S6x.slFunctions.ContainsKey(s6xObject.ColsScalerAddress)) { s6xObject.ColsScalerXdfUniqueId = ((S6xFunction)sadBin.S6x.slFunctions[s6xObject.ColsScalerAddress]).XdfUniqueId; } else if (sadBin.S6x.slDupFunctions.ContainsKey(s6xObject.ColsScalerAddress)) { s6xObject.ColsScalerXdfUniqueId = ((S6xFunction)sadBin.S6x.slDupFunctions[s6xObject.ColsScalerAddress]).XdfUniqueId; } else { s6xObject.ColsScalerXdfUniqueId = string.Empty; } } if (s6xObject.RowsScalerAddress != null && s6xObject.RowsScalerAddress != string.Empty) { if (sadBin.S6x.slFunctions.ContainsKey(s6xObject.RowsScalerAddress)) { s6xObject.RowsScalerXdfUniqueId = ((S6xFunction)sadBin.S6x.slFunctions[s6xObject.RowsScalerAddress]).XdfUniqueId; } else if (sadBin.S6x.slDupFunctions.ContainsKey(s6xObject.RowsScalerAddress)) { s6xObject.RowsScalerXdfUniqueId = ((S6xFunction)sadBin.S6x.slDupFunctions[s6xObject.RowsScalerAddress]).XdfUniqueId; } else { s6xObject.RowsScalerXdfUniqueId = string.Empty; } } XdfTable xdfObject = new XdfTable(s6xObject, xdfBaseOffset); xdfObject.uniqueid = "0x" + string.Format("{0:x4}", lastXdfUniqueId); s6xObject.XdfUniqueId = xdfObject.uniqueid; lastXdfUniqueId++; alXdfTables.Add(xdfObject); xdfObject = null; } } foreach (S6xTable s6xObject in sadBin.S6x.slDupTables.Values) { if (!s6xObject.Skip && s6xObject.Store && s6xObject.AddressBinInt >= xdfBaseOffset) { // Trying to find Scalers Unique Xdf Ids if (s6xObject.ColsScalerAddress != null && s6xObject.ColsScalerAddress != string.Empty) { if (sadBin.S6x.slFunctions.ContainsKey(s6xObject.ColsScalerAddress)) { s6xObject.ColsScalerXdfUniqueId = ((S6xFunction)sadBin.S6x.slFunctions[s6xObject.ColsScalerAddress]).XdfUniqueId; } else if (sadBin.S6x.slDupFunctions.ContainsKey(s6xObject.ColsScalerAddress)) { s6xObject.ColsScalerXdfUniqueId = ((S6xFunction)sadBin.S6x.slDupFunctions[s6xObject.ColsScalerAddress]).XdfUniqueId; } else { s6xObject.ColsScalerXdfUniqueId = string.Empty; } } if (s6xObject.RowsScalerAddress != null && s6xObject.RowsScalerAddress != string.Empty) { if (sadBin.S6x.slFunctions.ContainsKey(s6xObject.RowsScalerAddress)) { s6xObject.RowsScalerXdfUniqueId = ((S6xFunction)sadBin.S6x.slFunctions[s6xObject.RowsScalerAddress]).XdfUniqueId; } else if (sadBin.S6x.slDupFunctions.ContainsKey(s6xObject.RowsScalerAddress)) { s6xObject.RowsScalerXdfUniqueId = ((S6xFunction)sadBin.S6x.slDupFunctions[s6xObject.RowsScalerAddress]).XdfUniqueId; } else { s6xObject.RowsScalerXdfUniqueId = string.Empty; } } XdfTable xdfObject = new XdfTable(s6xObject, xdfBaseOffset); xdfObject.uniqueid = "0x" + string.Format("{0:x4}", lastXdfUniqueId); s6xObject.XdfUniqueId = xdfObject.uniqueid; lastXdfUniqueId++; alXdfTables.Add(xdfObject); xdfObject = null; } } foreach (S6xScalar s6xObject in sadBin.S6x.slScalars.Values) { if (!s6xObject.Skip && s6xObject.Store && s6xObject.AddressBinInt >= xdfBaseOffset) { XdfScalar xdfObject = new XdfScalar(s6xObject, xdfBaseOffset); xdfObject.uniqueid = "0x" + string.Format("{0:x4}", lastXdfUniqueId); s6xObject.XdfUniqueId = xdfObject.uniqueid; lastXdfUniqueId++; alXdfScalars.Add(xdfObject); xdfObject = null; } } foreach (S6xScalar s6xObject in sadBin.S6x.slDupScalars.Values) { if (!s6xObject.Skip && s6xObject.Store && s6xObject.AddressBinInt >= xdfBaseOffset) { XdfScalar xdfObject = new XdfScalar(s6xObject, xdfBaseOffset); xdfObject.uniqueid = "0x" + string.Format("{0:x4}", lastXdfUniqueId); s6xObject.XdfUniqueId = xdfObject.uniqueid; lastXdfUniqueId++; alXdfScalars.Add(xdfObject); xdfObject = null; } } xdfTables = (XdfTable[])alXdfTables.ToArray(typeof(XdfTable)); xdfFunctions = (XdfFunction[])alXdfFunctions.ToArray(typeof(XdfFunction)); xdfScalars = (XdfScalar[])alXdfScalars.ToArray(typeof(XdfScalar)); alXdfTables = null; alXdfFunctions = null; alXdfScalars = null; GC.Collect(); }
public static void s6xNavCategoriesReset(S6xNavHeaderCategory headerCateg, ref S6xNavCategories s6xNavCategories, ref SADBin sadBin, ref SADS6x sadS6x) { if (s6xNavCategories == null) { s6xNavCategories = new S6xNavCategories(); } if (headerCateg == S6xNavHeaderCategory.RESERVED && sadBin != null) { if (sadBin.Bank8 != null) { s6xNavCategories.addCategory(headerCateg, S6xNavCategoryLevel.ONE, "Bank 8"); } if (sadBin.Bank1 != null) { s6xNavCategories.addCategory(headerCateg, S6xNavCategoryLevel.ONE, "Bank 1"); } if (sadBin.Bank9 != null) { s6xNavCategories.addCategory(headerCateg, S6xNavCategoryLevel.ONE, "Bank 9"); } if (sadBin.Bank0 != null) { s6xNavCategories.addCategory(headerCateg, S6xNavCategoryLevel.ONE, "Bank 0"); } return; } if (sadS6x != null) { s6xNavCategories.resetCategory(headerCateg, S6xNavCategoryLevel.ONE); s6xNavCategories.resetCategory(headerCateg, S6xNavCategoryLevel.TWO); s6xNavCategories.resetCategory(headerCateg, S6xNavCategoryLevel.THREE); string nameOfCategory = "Category"; string nameOfCategory2 = "Category2"; string nameOfCategory3 = "Category3"; S6xNavHeaderCategory replacedHeaderCateg = S6xNavHeaderCategory.UNDEFINED; SortedList slS6xList = null; switch (headerCateg) { case S6xNavHeaderCategory.TABLES: slS6xList = sadS6x.slTables; break; case S6xNavHeaderCategory.FUNCTIONS: slS6xList = sadS6x.slFunctions; break; case S6xNavHeaderCategory.SCALARS: slS6xList = sadS6x.slScalars; break; case S6xNavHeaderCategory.STRUCTURES: slS6xList = sadS6x.slStructures; break; case S6xNavHeaderCategory.ROUTINES: slS6xList = sadS6x.slRoutines; break; case S6xNavHeaderCategory.OPERATIONS: slS6xList = sadS6x.slOperations; break; case S6xNavHeaderCategory.REGISTERS: slS6xList = sadS6x.slRegisters; break; case S6xNavHeaderCategory.OTHER: slS6xList = sadS6x.slOtherAddresses; break; case S6xNavHeaderCategory.SIGNATURES: slS6xList = sadS6x.slSignatures; replacedHeaderCateg = headerCateg; nameOfCategory = "SignatureCategory"; nameOfCategory2 = "SignatureCategory2"; nameOfCategory3 = "SignatureCategory3"; break; case S6xNavHeaderCategory.ELEMSSIGNATURES: slS6xList = sadS6x.slElementsSignatures; replacedHeaderCateg = headerCateg; nameOfCategory = "SignatureCategory"; nameOfCategory2 = "SignatureCategory2"; nameOfCategory3 = "SignatureCategory3"; break; } if (slS6xList != null) { foreach (object s6xObject in slS6xList.Values) { if (s6xObject == null) { continue; } Type s6xType = s6xObject.GetType(); PropertyInfo piPI = null; object oValue = null; piPI = s6xType.GetProperty(nameOfCategory); if (piPI != null) { oValue = piPI.GetValue(s6xObject, null); if (oValue != null) { s6xNavCategories.addCategory(replacedHeaderCateg, S6xNavCategoryLevel.ONE, (string)oValue); } } piPI = null; piPI = s6xType.GetProperty(nameOfCategory2); if (piPI != null) { oValue = piPI.GetValue(s6xObject, null); if (oValue != null) { s6xNavCategories.addCategory(replacedHeaderCateg, S6xNavCategoryLevel.TWO, (string)oValue); } } piPI = null; piPI = s6xType.GetProperty(nameOfCategory3); if (piPI != null) { oValue = piPI.GetValue(s6xObject, null); if (oValue != null) { s6xNavCategories.addCategory(replacedHeaderCateg, S6xNavCategoryLevel.THREE, (string)oValue); } } piPI = null; } } } }
// To be able to show scaled data for tables public static string[] getTableElemDataScale(ref SADBin sadBin, string scalerUniqueAddress, int stepNumber) { string[] scaleResult = null; S6xFunction s6xScaler = null; if (sadBin == null) { return new string[] { } } ; if (stepNumber <= 0) { return new string[] { } } ; scaleResult = new string[stepNumber]; for (int iStep = 0; iStep < stepNumber; iStep++) { scaleResult[iStep] = (iStep + 1).ToString(); } if (scalerUniqueAddress != null && scalerUniqueAddress != string.Empty) { s6xScaler = (S6xFunction)sadBin.S6x.slFunctions[scalerUniqueAddress]; } if (s6xScaler == null && scalerUniqueAddress != null && scalerUniqueAddress != string.Empty) { s6xScaler = (S6xFunction)sadBin.S6x.slDupFunctions[scalerUniqueAddress]; } if (s6xScaler != null) { if (s6xScaler.RowsNumber <= 0) { s6xScaler = null; } } if (s6xScaler == null) { return(scaleResult); } s6xScaler.AddressBinInt = Tools.binAddressCorrected(s6xScaler.BankNum, s6xScaler.AddressInt, ref sadBin, s6xScaler.AddressBinInt); int iRowSize = 4; if (s6xScaler.ByteInput) { iRowSize--; } if (s6xScaler.ByteOutput) { iRowSize--; } object[] arrRows = new object[s6xScaler.RowsNumber]; string[] arrBytes = sadBin.getBytesArray(s6xScaler.AddressBinInt, iRowSize * s6xScaler.RowsNumber); bool failedInputScale = false; bool failedOutputScale = false; int iAddress = 0; for (int iRow = 0; iRow < arrRows.Length; iRow++) { object[] arrRow = new object[2]; int iValue = 0; if (s6xScaler.ByteInput) { try { iValue = Tools.getByteInt(arrBytes[iAddress], s6xScaler.SignedInput); } catch { iValue = 0; } iAddress++; } else { try { iValue = Tools.getWordInt(arrBytes[iAddress + 1] + arrBytes[iAddress], s6xScaler.SignedInput); } catch { iValue = 0; } iAddress += 2; } if (failedInputScale) { arrRow[0] = iValue; } else { try { arrRow[0] = Tools.ScaleValue(iValue, s6xScaler.InputScaleExpression, true); } catch { failedInputScale = true; arrRow[0] = iValue; } } if (s6xScaler.ByteOutput) { try { iValue = Tools.getByteInt(arrBytes[iAddress], s6xScaler.SignedOutput); } catch { iValue = 0; } iAddress++; } else { try { iValue = Tools.getWordInt(arrBytes[iAddress + 1] + arrBytes[iAddress], s6xScaler.SignedOutput); } catch { iValue = 0; } iAddress += 2; } if (failedOutputScale) { arrRow[1] = iValue; } else { try { arrRow[1] = Tools.ScaleValue(iValue, s6xScaler.OutputScaleExpression, true); } catch { failedOutputScale = true; arrRow[1] = iValue; } } arrRows[iRow] = arrRow; } if (failedOutputScale) { return(scaleResult); } double[] scaleValues = new double[stepNumber]; for (int iStep = 0; iStep < stepNumber; iStep++) { scaleResult[iStep] = string.Empty; scaleValues[iStep] = 0.0; } double dMaxIndex = 0.0; double dMinIndex = double.MaxValue; double dMaxValue = 0.0; double dMinValue = 0.0; for (int iRow = 0; iRow < arrRows.Length; iRow++) { double dSc = (double)((object[])arrRows[iRow])[1]; if (dSc >= dMaxIndex) { dMaxIndex = dSc; dMaxValue = (double)((object[])arrRows[iRow])[0]; } if (dSc <= dMinIndex) { dMinIndex = dSc; dMinValue = (double)((object[])arrRows[iRow])[0]; } if (dSc == (int)dSc && dSc >= 0 && dSc < stepNumber) { scaleValues[(int)dSc] = (double)((object[])arrRows[iRow])[0]; scaleResult[(int)dSc] = string.Format("{0:G}", scaleValues[(int)dSc]); } if (dSc <= 0.0) { break; } } if (scaleResult[0] == string.Empty) { if (dMinIndex > (double)(0) && dMinIndex < (double)(0 + 1)) { scaleValues[0] = dMinValue; scaleResult[0] = string.Format("{0:G}", scaleValues[0]); } } if (scaleResult[scaleResult.Length - 1] == string.Empty) { if (dMaxIndex > (double)(scaleResult.Length - 1 - 1) && dMinIndex < (double)(scaleResult.Length - 1 + 1)) { scaleValues[scaleResult.Length - 1] = dMaxValue; scaleResult[scaleResult.Length - 1] = string.Format("{0:G}", scaleValues[scaleResult.Length - 1]); } else if (dMaxIndex > 0.0 && dMaxIndex > dMinIndex) { for (int iStep = (int)dMaxIndex; iStep < stepNumber; iStep++) { scaleValues[scaleResult.Length - 1] = dMaxValue; scaleResult[iStep] = string.Format("{0:G}", scaleValues[scaleResult.Length - 1]); } } } if (scaleResult[0] == string.Empty || scaleResult[scaleResult.Length - 1] == string.Empty) { for (int iStep = 0; iStep < stepNumber; iStep++) { scaleResult[iStep] = (iStep + 1).ToString(); } return(scaleResult); } int lastStepWithValue = -1; for (int iStep = 0; iStep < stepNumber; iStep++) { if (scaleResult[iStep] == string.Empty) { continue; } if (lastStepWithValue >= 0 && iStep - lastStepWithValue > 1) { double stepGap = (scaleValues[iStep] - scaleValues[lastStepWithValue]) / (iStep - lastStepWithValue); for (int iStepUpdate = lastStepWithValue + 1; iStepUpdate < iStep; iStepUpdate++) { scaleValues[iStepUpdate] = scaleValues[iStepUpdate - 1] + stepGap; } } lastStepWithValue = iStep; } // Final Format bool pureIntFormat = true; bool lowNumberFormat = true; for (int iStep = 0; iStep < stepNumber; iStep++) { if (scaleValues[iStep] != (int)iStep) { pureIntFormat = false; } // Thinking about Transfer function on 5v12 if (scaleValues[iStep] > 6.0) { lowNumberFormat = false; } } string sFormat = "{0:0}"; if (pureIntFormat || !lowNumberFormat) { sFormat = "{0:0}"; } // New Scale Precision field if (s6xScaler.InputScalePrecision >= 0 && s6xScaler.InputScalePrecision <= 8) { sFormat = "{0:0." + new string('0', s6xScaler.InputScalePrecision) + "}"; } for (int iStep = 0; iStep < stepNumber; iStep++) { scaleResult[iStep] = string.Format(sFormat, scaleValues[iStep]); } return(scaleResult); } } }
public static bool showElemData(ref DataGridView elemDataGridView, ref SADBin sadBin, object s6xObject, bool dataDecimal, bool ignoreDefinedConversion, bool dataReversed, RepositoryConversionItem rcOutput, RepositoryConversionItem rcInput) { S6xScalar s6xScalar = null; S6xFunction s6xFunction = null; S6xTable s6xTable = null; S6xStructure s6xStruct = null; DataTable dtTable = null; Type dataType = null; string sValue = string.Empty; int iValue = 0; int iAddress = 0; string[] arrBytes = null; string[] arrCols = null; object[] arrRows = null; object[] arrRowsHeaders = null; object[] arrRow = null; bool failedScale = false; int iBfTop = -1; if (elemDataGridView == null) { return(false); } if (sadBin == null) { return(false); } if (s6xObject == null) { return(false); } if (dataDecimal) { dataType = typeof(double); } else { dataType = typeof(string); } elemDataGridView.DataSource = null; S6xNavHeaderCategory headerCategory = S6xNavHeaderCategory.UNDEFINED; if (s6xObject.GetType() == typeof(S6xScalar)) { headerCategory = S6xNavHeaderCategory.SCALARS; } else if (s6xObject.GetType() == typeof(S6xFunction)) { headerCategory = S6xNavHeaderCategory.FUNCTIONS; } else if (s6xObject.GetType() == typeof(S6xTable)) { headerCategory = S6xNavHeaderCategory.TABLES; } else if (s6xObject.GetType() == typeof(S6xStructure)) { headerCategory = S6xNavHeaderCategory.STRUCTURES; } switch (headerCategory) { case S6xNavHeaderCategory.SCALARS: s6xScalar = (S6xScalar)s6xObject; elemDataGridView.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; s6xScalar.AddressBinInt = Tools.binAddressCorrected(s6xScalar.BankNum, s6xScalar.AddressInt, ref sadBin, s6xScalar.AddressBinInt); if (s6xScalar.isBitFlags) { dataType = typeof(string); arrCols = null; if (s6xScalar.BitFlags != null) { if (s6xScalar.BitFlags.Length > 0) { arrCols = new string[s6xScalar.BitFlags.Length + 1]; for (int iCol = 1; iCol < arrCols.Length; iCol++) { arrCols[iCol] = s6xScalar.BitFlags[arrCols.Length - iCol - 1].ShortLabel; } } } // Default BitFlags if (arrCols == null) { iBfTop = 15; if (s6xScalar.Byte) { iBfTop = 7; } for (int iBf = iBfTop; iBf >= 0; iBf--) { arrCols = new string[iBfTop + 2]; for (int iCol = 1; iCol < arrCols.Length; iCol++) { arrCols[iCol] = "B" + iBf.ToString(); } } } // For better output if (arrCols != null) { for (int iCol = 1; iCol < arrCols.Length; iCol++) { arrCols[iCol] = OutputTools.GetSpacesCenteredString(arrCols[iCol], 20); } } } else { arrCols = new string[1]; } if (s6xScalar.Byte) { arrCols[0] = "Byte"; arrBytes = sadBin.getBytesArray(s6xScalar.AddressBinInt, 1); try { sValue = arrBytes[0]; iValue = Tools.getByteInt(sValue, s6xScalar.Signed); } catch { sValue = string.Empty; iValue = 0; } } else { arrCols[0] = "Word"; arrBytes = sadBin.getBytesArray(s6xScalar.AddressBinInt, 2); try { sValue = Tools.LsbFirst(arrBytes); iValue = Tools.getWordInt(sValue, s6xScalar.Signed); } catch { sValue = string.Empty; iValue = 0; } } // For better output if (arrCols.Length == 1) { arrCols[0] = OutputTools.GetSpacesCenteredString(arrCols[0], 100); } else { arrCols[0] = OutputTools.GetSpacesCenteredString(arrCols[0], 50); } arrRow = new object[arrCols.Length]; if (s6xScalar.isBitFlags) { BitArray arrBit = new BitArray(new int[] { iValue }); for (int iCol = 1; iCol < arrRow.Length; iCol++) { if (arrBit[s6xScalar.BitFlags[arrRow.Length - iCol - 1].Position]) { arrRow[iCol] = s6xScalar.BitFlags[arrRow.Length - iCol - 1].SetValue; } else { arrRow[iCol] = s6xScalar.BitFlags[arrRow.Length - iCol - 1].NotSetValue; } } } if (dataDecimal) { if (failedScale) { arrRow[0] = iValue; } else { try { if (ignoreDefinedConversion) { if (rcOutput == null) { arrRow[0] = iValue; } else { arrRow[0] = Tools.ScaleValue(iValue, rcOutput.InternalFormula, 0, true); } } else { if (rcOutput == null) { arrRow[0] = Tools.ScaleValue(iValue, s6xScalar.ScaleExpression, s6xScalar.ScalePrecision, true); } else { arrRow[0] = Tools.ScaleValue(iValue, rcOutput.InternalFormula.ToUpper().Replace("X", "(" + s6xScalar.ScaleExpression + ")"), s6xScalar.ScalePrecision, true); } } } catch { failedScale = true; arrRow[0] = iValue; } } } else { arrRow[0] = sValue.ToUpper(); } arrRows = new object[] { arrRow }; s6xScalar = null; break; case S6xNavHeaderCategory.FUNCTIONS: s6xFunction = (S6xFunction)s6xObject; elemDataGridView.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; s6xFunction.AddressBinInt = Tools.binAddressCorrected(s6xFunction.BankNum, s6xFunction.AddressInt, ref sadBin, s6xFunction.AddressBinInt); arrCols = new string[2]; arrCols[0] = "Word Input"; iValue = 2; if (s6xFunction.ByteInput) { arrCols[0] = "Byte Input"; iValue--; } arrCols[1] = "Word Output"; iValue += 2; if (s6xFunction.ByteOutput) { arrCols[1] = "Byte Output"; iValue--; } arrCols[0] = OutputTools.GetSpacesCenteredString(arrCols[0], 50); // For better output arrCols[1] = OutputTools.GetSpacesCenteredString(arrCols[1], 50); // For better output if (s6xFunction.RowsNumber <= 0) { arrRows = new object[] { }; } else { arrRows = new object[s6xFunction.RowsNumber]; arrBytes = sadBin.getBytesArray(s6xFunction.AddressBinInt, iValue * arrRows.Length); iAddress = 0; for (int iRow = 0; iRow < arrRows.Length; iRow++) { arrRow = new object[arrCols.Length]; for (int iCol = 0; iCol < arrRow.Length; iCol++) { if (iCol % 2 == 0) { if (s6xFunction.ByteInput) { try { sValue = arrBytes[iAddress]; iValue = Tools.getByteInt(sValue, s6xFunction.SignedInput); } catch { sValue = string.Empty; iValue = 0; } iAddress++; } else { try { sValue = arrBytes[iAddress + 1] + arrBytes[iAddress]; iValue = Tools.getWordInt(sValue, s6xFunction.SignedInput); } catch { sValue = string.Empty; iValue = 0; } iAddress += 2; } if (dataDecimal) { if (failedScale) { arrRow[iCol] = iValue; } else { try { if (ignoreDefinedConversion) { if (rcInput == null) { arrRow[iCol] = iValue; } else { arrRow[iCol] = Tools.ScaleValue(iValue, rcInput.InternalFormula, 0, true); } } else { if (rcInput == null) { arrRow[iCol] = Tools.ScaleValue(iValue, s6xFunction.InputScaleExpression, s6xFunction.InputScalePrecision, true); } else { arrRow[iCol] = Tools.ScaleValue(iValue, rcInput.InternalFormula.ToUpper().Replace("X", "(" + s6xFunction.InputScaleExpression + ")"), s6xFunction.InputScalePrecision, true); } } } catch { failedScale = true; arrRow[iCol] = iValue; } } } else { arrRow[iCol] = sValue.ToUpper(); } } else { if (s6xFunction.ByteOutput) { try { sValue = arrBytes[iAddress]; iValue = Tools.getByteInt(sValue, s6xFunction.SignedOutput); } catch { sValue = string.Empty; iValue = 0; } iAddress++; } else { try { sValue = arrBytes[iAddress + 1] + arrBytes[iAddress]; iValue = Tools.getWordInt(sValue, s6xFunction.SignedOutput); } catch { sValue = string.Empty; iValue = 0; } iAddress += 2; } if (dataDecimal) { if (failedScale) { arrRow[iCol] = iValue; } else { try { if (ignoreDefinedConversion) { if (rcOutput == null) { arrRow[iCol] = iValue; } else { arrRow[iCol] = Tools.ScaleValue(iValue, rcOutput.InternalFormula, 0, true); } } else { if (rcOutput == null) { arrRow[iCol] = Tools.ScaleValue(iValue, s6xFunction.OutputScaleExpression, s6xFunction.OutputScalePrecision, true); } else { arrRow[iCol] = Tools.ScaleValue(iValue, rcOutput.InternalFormula.ToUpper().Replace("X", "(" + s6xFunction.OutputScaleExpression + ")"), s6xFunction.OutputScalePrecision, true); } } } catch { failedScale = true; arrRow[iCol] = iValue; } } } else { arrRow[iCol] = sValue.ToUpper(); } } } arrRows[iRow] = arrRow; } } s6xFunction = null; break; case S6xNavHeaderCategory.TABLES: s6xTable = (S6xTable)s6xObject; if (s6xTable.ColsNumber <= 0) { return(false); } elemDataGridView.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; s6xTable.AddressBinInt = Tools.binAddressCorrected(s6xTable.BankNum, s6xTable.AddressInt, ref sadBin, s6xTable.AddressBinInt); //arrCols = new string[s6xTable.ColsNumber]; //for (int iCol = 0; iCol < arrCols.Length; iCol++) arrCols[iCol] = (iCol + 1).ToString(); arrCols = getTableElemDataScale(ref sadBin, s6xTable.ColsScalerAddress, s6xTable.ColsNumber); // For better output if (arrCols != null) { for (int iCol = 0; iCol < arrCols.Length; iCol++) { arrCols[iCol] = OutputTools.GetSpacesCenteredString(arrCols[iCol], 10); } } if (s6xTable.RowsNumber <= 0) { arrRows = new object[] { }; } else { arrRows = new object[s6xTable.RowsNumber]; arrRowsHeaders = getTableElemDataScale(ref sadBin, s6xTable.RowsScalerAddress, s6xTable.RowsNumber); if (s6xTable.WordOutput) { arrBytes = sadBin.getBytesArray(s6xTable.AddressBinInt, arrCols.Length * arrRows.Length * 2); } else { arrBytes = sadBin.getBytesArray(s6xTable.AddressBinInt, arrCols.Length * arrRows.Length); } iAddress = 0; for (int iRow = 0; iRow < arrRows.Length; iRow++) { arrRow = new object[arrCols.Length]; for (int iCol = 0; iCol < arrRow.Length; iCol++) { try { if (s6xTable.WordOutput) { sValue = arrBytes[iAddress + 1] + arrBytes[iAddress]; iValue = Tools.getWordInt(sValue, s6xTable.SignedOutput); } else { sValue = arrBytes[iAddress]; iValue = Tools.getByteInt(sValue, s6xTable.SignedOutput); } } catch { sValue = string.Empty; iValue = 0; } iAddress++; if (s6xTable.WordOutput) { iAddress++; } if (dataDecimal) { if (failedScale) { arrRow[iCol] = iValue; } else { try { if (ignoreDefinedConversion) { if (rcOutput == null) { arrRow[iCol] = iValue; } else { arrRow[iCol] = Tools.ScaleValue(iValue, rcOutput.InternalFormula, 0, true); } } else { if (rcOutput == null) { arrRow[iCol] = Tools.ScaleValue(iValue, s6xTable.CellsScaleExpression, s6xTable.CellsScalePrecision, true); } else { arrRow[iCol] = Tools.ScaleValue(iValue, rcOutput.InternalFormula.ToUpper().Replace("X", "(" + s6xTable.CellsScaleExpression + ")"), s6xTable.CellsScalePrecision, true); } } } catch { failedScale = true; arrRow[iCol] = iValue; } } } else { arrRow[iCol] = sValue.ToUpper(); } } arrRows[iRow] = arrRow; } } s6xTable = null; break; case S6xNavHeaderCategory.STRUCTURES: s6xStruct = (S6xStructure)s6xObject; if (s6xStruct.Number <= 0) { return(false); } s6xStruct.Structure = new Structure(s6xStruct); if (!s6xStruct.Structure.isValid) { return(false); } if (s6xStruct.Structure.isEmpty) { return(false); } elemDataGridView.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; s6xStruct.Structure.AddressBinInt = Tools.binAddressCorrected(s6xStruct.Structure.BankNum, s6xStruct.Structure.AddressInt, ref sadBin, s6xStruct.Structure.AddressBinInt); arrBytes = sadBin.getBytesArray(s6xStruct.Structure.AddressBinInt, s6xStruct.Structure.MaxSizeSingle * s6xStruct.Number); s6xStruct.Structure.Read(ref arrBytes, s6xStruct.Number); arrBytes = null; arrCols = new string[s6xStruct.Structure.MaxLineItemsNum]; for (int iCol = 0; iCol < arrCols.Length; iCol++) { arrCols[iCol] = (iCol + 1).ToString(); } // For better output for (int iCol = 0; iCol < arrCols.Length; iCol++) { arrCols[iCol] = OutputTools.GetSpacesCenteredString(arrCols[iCol], 10); } dataType = typeof(string); if (s6xStruct.Structure.Lines.Count <= 0) { arrRows = new object[] { }; } else { arrRows = new object[s6xStruct.Structure.Lines.Count]; arrRowsHeaders = new object[s6xStruct.Structure.Lines.Count]; int iRow = 0; foreach (StructureLine structLine in s6xStruct.Structure.Lines) { arrRowsHeaders[iRow] = structLine.NumberInStructure.ToString(); arrRow = new object[arrCols.Length]; for (int iCol = 0; iCol < structLine.Items.Count; iCol++) { arrRow[iCol] = ((StructureItem)structLine.Items[iCol]).Value(structLine.NumberInStructure); } arrRows[iRow] = arrRow; iRow++; } } s6xStruct = null; break; default: return(false); } if (arrCols == null) { return(false); } if (dataReversed) { object[] arrReversedRows = new object[arrRows.Length]; for (int iRow = 0; iRow < arrReversedRows.Length; iRow++) { arrReversedRows[arrReversedRows.Length - 1 - iRow] = arrRows[iRow]; } arrRows = arrReversedRows; arrReversedRows = null; if (arrRowsHeaders != null) { arrReversedRows = new object[arrRowsHeaders.Length]; for (int iRow = 0; iRow < arrReversedRows.Length; iRow++) { arrReversedRows[arrReversedRows.Length - 1 - iRow] = arrRowsHeaders[iRow]; } arrRowsHeaders = arrReversedRows; arrReversedRows = null; } } dtTable = new DataTable(); //foreach (string colLabel in arrCols) dtTable.Columns.Add(new DataColumn(colLabel, dataType)); for (int iCol = 0; iCol < arrCols.Length; iCol++) { DataColumn dcDC = new DataColumn(iCol.ToString(), dataType); dcDC.Caption = arrCols[iCol]; dtTable.Columns.Add(dcDC); } foreach (object[] oRow in arrRows) { dtTable.Rows.Add(oRow); } arrRows = null; elemDataGridView.Tag = new object[] { arrCols, arrRowsHeaders }; // For Speed purpose elemDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; elemDataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; elemDataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; try { elemDataGridView.DataSource = dtTable; } catch { return(false); } // For Speed purpose switch (headerCategory) { case S6xNavHeaderCategory.SCALARS: case S6xNavHeaderCategory.FUNCTIONS: elemDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; break; case S6xNavHeaderCategory.TABLES: case S6xNavHeaderCategory.STRUCTURES: //elemDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; elemDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; break; } elemDataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; elemDataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; dtTable = null; arrCols = null; arrRowsHeaders = null; elemDataGridView.Visible = true; return(true); }
public ElemDataForm(ref SADBin elemDataSADBin, object elemS6xObject, ref ContextMenuStrip mfElemContextMenuStrip) { sadBin = elemDataSADBin; s6xObject = elemS6xObject; MFElemContextMenuStrip = mfElemContextMenuStrip; InitializeComponent(); try { Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch { } this.Load += new EventHandler(Form_Load); this.FormClosing += new FormClosingEventHandler(Form_FormClosing); elemDataGridView.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(elemDataGridView_DataBindingComplete); elemContextMenuStrip.Opening += new CancelEventHandler(elemContextMenuStrip_Opening); decimalToolStripMenuItem.Click += new EventHandler(decimalToolStripMenuItem_Click); decimalNotConvertedToolStripMenuItem.Click += new EventHandler(decimalNotConvertedToolStripMenuItem_Click); reverseOrderToolStripMenuItem.Click += new EventHandler(reverseOrderToolStripMenuItem_Click); convertToolStripMenuItem.DropDownItemClicked += new ToolStripItemClickedEventHandler(convertToolStripMenuItem_DropDownItemClicked); convertInputToolStripMenuItem.DropDownItemClicked += new ToolStripItemClickedEventHandler(convertInputToolStripMenuItem_DropDownItemClicked); if (MFElemContextMenuStrip != null) { foreach (ToolStripItem tsMI in MFElemContextMenuStrip.Items) { if (tsMI.Name == decimalToolStripMenuItem.Name) { decimalToolStripMenuItem.Checked = ((ToolStripMenuItem)tsMI).Checked; } else if (tsMI.Name == decimalNotConvertedToolStripMenuItem.Name) { decimalNotConvertedToolStripMenuItem.Checked = ((ToolStripMenuItem)tsMI).Checked; } else if (tsMI.Name == reverseOrderToolStripMenuItem.Name) { reverseOrderToolStripMenuItem.Checked = ((ToolStripMenuItem)tsMI).Checked; } else if (tsMI.Name == convertToolStripMenuItem.Name) { foreach (ToolStripMenuItem subMFMI in ((ToolStripMenuItem)tsMI).DropDownItems) { ToolStripMenuItem subMI = new ToolStripMenuItem(); subMI.Tag = subMFMI.Tag; subMI.Text = subMFMI.Text; subMI.ToolTipText = subMFMI.ToolTipText; convertToolStripMenuItem.DropDownItems.Add(subMI); } } else if (tsMI.Name == convertInputToolStripMenuItem.Name) { foreach (ToolStripMenuItem subMFMI in ((ToolStripMenuItem)tsMI).DropDownItems) { ToolStripMenuItem subMI = new ToolStripMenuItem(); subMI.Tag = subMFMI.Tag; subMI.Text = subMFMI.Text; subMI.ToolTipText = subMFMI.ToolTipText; convertInputToolStripMenuItem.DropDownItems.Add(subMI); } } } } }