namespace XylemCommonUiLegacyGenCtl { using System; using System.Collections.Concurrent; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; [ComVisible(true)] [Guid("D4615BA6-BB83-4C87-BBBB-E5A080BB28EE")] public class MeterTable : TableLayoutPanel, IDisposable { private readonly ConcurrentDictionary meters; public MeterTable() { this.InitializeComponent(); this.meters = new ConcurrentDictionary(); } public void AddMeter(int slotNr, uint address, string serialNr) { var eregister = new Meter(slotNr, address, serialNr); this.meters.AddOrUpdate(slotNr, eregister, (slot, meter) => eregister); this.UpdateComponent(); } public void ClearComponent() { this.BeginInvoke(new Action(() => { for (int row = this.RowCount - 1; row > 0; row--) { this.Controls.RemoveAt(row); } })); } private void AddCell(string text, int col, int row) { var cell = new Label { Text = text, Dock = DockStyle.Fill, FlatStyle = FlatStyle.Flat, TextAlign = ContentAlignment.MiddleLeft }; this.Controls.Add(cell, col, row); } private void AddColumnHeader(string text, int col, int row) { var header = new Label { Text = text, Dock = DockStyle.Fill, FlatStyle = FlatStyle.Flat, TextAlign = ContentAlignment.MiddleLeft }; header.Font = new Font(header.Font, FontStyle.Bold); this.Controls.Add(header, col, row); } private void InitializeComponent() { this.Dock = DockStyle.Top; this.BackColor = Color.White; this.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single; this.AutoSize = true; this.AutoSizeMode = AutoSizeMode.GrowAndShrink; this.ColumnCount = 4; this.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 80F)); this.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100F)); this.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100F)); this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); this.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); this.AddColumnHeader("Einbauplatz", 0, 0); this.AddColumnHeader("Radio Address", 1, 0); this.AddColumnHeader("Serial Nr.", 2, 0); this.AddColumnHeader("Ablauf", 3, 0); } private void UpdateComponent() { this.BeginInvoke(new Action(() => { foreach (var meterKVP in this.meters) { var meter = meterKVP.Value; meter.Row = this.RowStyles.Add(new RowStyle(SizeType.AutoSize)); this.AddCell($"{meter.SlotNr}", meter.Col++, meter.Row); this.AddCell($"{meter.AddressI}", meter.Col++, meter.Row); this.AddCell(meter.SerialNr, meter.Col++, meter.Row); } })); } } public class Meter { public Meter(int slotNr, uint address, string serialNr) { this.SlotNr = slotNr; this.AddressI = address; this.SerialNr = serialNr; } public int SlotNr { get; set; } public uint AddressI { get; set; } public uint AddressII { get; set; } public string SerialNr { get; set; } public bool Connected { get; set; } public bool Parameterized { get; set; } public bool Closed { get; set; } public int Row { get; set; } public int Col { get; set; } } }