public void ModulesToListView() { if (lvSignalList.InvokeRequired == false) { lvSignalList.Items.Clear(); foreach (NewModuleAbstract module in Program.Net.Modules) { foreach (NewChannelAbstract channel in module.Channels) { string itemKey = "M" + channel.Module.Address + "C" + channel.Channel; string itemText = (lvSignalList.Items.Count + 1).ToString(); if (!lvSignalList.Items.ContainsKey(itemKey)) { ListViewItem curListItem = lvSignalList.Items.Add(itemKey, itemText, null); curListItem.Checked = channel.Selected; curListItem.SubItems.Add(channel.Code); curListItem.SubItems.Add(channel.Name); curListItem.SubItems.Add(channel.Signal); curListItem.SubItems.Add(channel.Value.ToString()); curListItem.SubItems.Add(channel.Time.ToString()); //curListItem.SubItems.Add(((int)channel.Status).ToString()); curListItem.SubItems.Add((channel.Status != null) ? ((int)channel.Status).ToString() : null); curListItem.SubItems.Add(channel.Module.Address10.ToString()); curListItem.SubItems.Add((!channel.IsCjc) ? channel.Channel.ToString() : "CJC"); curListItem.SubItems.Add(channel.Aperture.ToString()); curListItem.SubItems.Add(channel.Min.ToString()); curListItem.SubItems.Add(channel.Max.ToString()); switch (channel.ChannelType) { case "Adam4019+": curListItem.SubItems.Add(((NewChannelAdamAbstract)channel).DataFormat); curListItem.SubItems.Add(((NewChannelAdamAbstract)channel).ChannelRange); break; default: curListItem.SubItems.Add(""); curListItem.SubItems.Add(""); break; } curListItem.SubItems.Add(channel.InLevel); curListItem.SubItems.Add(channel.Conversion); curListItem.SubItems.Add(channel.Units); curListItem.UseItemStyleForSubItems = false; } else { ClassLog.AddLog(ELogType.Event, "ClassViews.AddModuleToListView", "Элемент " + itemKey + " уже существует в списке каналов", DateTime.Now); break; } } } } else { var dlg = new Action(ModulesToListView); lvSignalList.BeginInvoke(dlg); } }
private void butScanNet_Click(object sender, EventArgs e) { if (_flagBlockForm == EFlagState.No) { if (MessageBox.Show(@"Начать сканирование сети?", @"Сканирование сети", MessageBoxButtons.YesNo) == DialogResult.Yes) { ClassLog.AddLog(ELogType.Event, null, "Сканирование сети"); byte firstAddress; byte lastAddress; if (!byte.TryParse(tbFirstModuleAddress.Text, NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out firstAddress)) { firstAddress = 0; } tbFirstModuleAddress.Text = firstAddress.ToString(); if (!byte.TryParse(tbLastModuleAddress.Text, NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out lastAddress)) { lastAddress = 255; } tbLastModuleAddress.Text = lastAddress.ToString(); if (firstAddress > lastAddress) { tbLastModuleAddress.Focus(); MessageBox.Show(@"Кон. адрес должен быть меньше чем нач. адрес"); return; } _flagBlockForm = EFlagState.Yes; UpdateFormView(); Program.FmMonitor.ClearModulesTreeView(); Program.FmMonitor.ClearSignalListView(); //ClassAdamNet.DelegateScanNet dlScanNet = Program.Net.ScanNet; //IAsyncResult asyncResult = dlScanNet.BeginInvoke(firstAddress, lastAddress, UpdateView, null, null); NewNet.DelegateScanNet dlScanNet = Program.Net.ScanStart; IAsyncResult asyncResult = dlScanNet.BeginInvoke(firstAddress, lastAddress, UpdateView, null, null); while (!asyncResult.IsCompleted) { Application.DoEvents(); } tbCurModuleAddress.Text = null; Program.FmMonitor.NetChange(); //ADAMScaner.TagListChange //ADAMScaner.UpdateFormView _flagBlockForm = EFlagState.No; UpdateFormView(); ClassLog.AddLog(ELogType.Event, null, "Сканирование сети закончено"); MessageBox.Show(@"Сканирование сети закончено"); } } else { Program.Net.ScanStop(); } }