using System; using System.Windows.Forms; namespace DataStreamMeter { public partial class MeterSimulationDlg : Form { MeterSimulation meterSimulation; double currentFlow; public string MeterID; public void OnMeterdata(MeterDataEventArgs args) { if (MeterDataHandler == null) return; MeterDataHandler(null, args); } public event EventHandler MeterDataHandler; /// /// Default constructor with no meter /// public MeterSimulationDlg() : this(null, string.Empty) { } public MeterSimulationDlg(MeterSimulation meterSimulation, string meterID) { InitializeComponent(); this.meterSimulation = meterSimulation; meterIDTextBox.Text = meterID; currentFlow = 0; flowm3phTextBox.Text = currentFlow.ToString(); flowTrackBar.Value = Convert.ToInt32(currentFlow); MeterDataHandler += delegate(object sender, MeterDataEventArgs args) { if (InvokeRequired) { Invoke(new EventHandler(DisplayMeterData), sender, args); } else { DisplayMeterData(sender, args); } }; if (meterSimulation != null) { timer1.Enabled = true; timer1.Start(); } } private void flowTrackBar_Scroll(object sender, EventArgs e) { currentFlow = flowTrackBar.Value; flowm3phTextBox.Text = currentFlow.ToString("F2"); } private void setFlowButton_Click(object sender, EventArgs e) { GetDblValueDlg dlg = new GetDblValueDlg("Enter flow in [m3/h] please", 0, 25.0); if (dlg.ShowDialog() == DialogResult.OK) { currentFlow = dlg.DblValue; flowm3phTextBox.Text = currentFlow.ToString(); flowTrackBar.Value = Convert.ToInt32(currentFlow); } } private void timer1_Tick(object sender, EventArgs e) { lastUITickTextBox.Text = DateTime.Now.ToString("HH:mm:ss fff"); meterSimulation.TimerTick(currentFlow); } void DisplayMeterData(object sender, MeterDataEventArgs args) { stateTextBox.Text = args.State.ToString(); timeTextBox.Text = args.Time.ToString(); volumeTextBox.Text = args.Volume.ToString(); flowTextBox.Text = args.Flow.ToString(); } } }