private void ReadPriceFromRealDeviceList() { // Получаем realDeviceList (SortedList) CurrentComPortObject.GetRealDeviceList(progressInfoMainForm); if (CurrentComPortObject.realDeviceList.Count > 0) { labelPasswordDU.Text = "Текущий пароль пульта ДУ: " + CurrentComPortObject.GetPasswordPultDU(); int i = 0; foreach (KeyValuePair <int, string> infoFromOneDevice in CurrentComPortObject.realDeviceList) { if (infoFromOneDevice.Value != "часы") { Label NameOfFuel = new Label(); TextBox PriceOfFuel = new TextBox(); panelForPriceDisplay.Controls.Add(NameOfFuel); panelForPriceDisplay.Controls.Add(PriceOfFuel); NameOfFuel.Text = infoFromOneDevice.Key.ToString(); NameOfFuel.Enabled = true; NameOfFuel.Width = 100; NameOfFuel.Font = new Font(new FontFamily("Arial"), 10); PriceOfFuel.Text = CurrentComPortObject.GetPriceFromCurrentDevice((byte)infoFromOneDevice.Key); PriceOfFuel.Enabled = true; PriceOfFuel.Width = 100; PriceOfFuel.MaxLength = 5; PriceOfFuel.Tag = infoFromOneDevice.Key; PriceOfFuel.Font = new Font(new FontFamily("Arial"), 10); NameOfFuel.Location = new Point(20, i * PriceOfFuel.Height + 40); PriceOfFuel.Location = new Point(150, i * PriceOfFuel.Height + 40); PriceOfFuel.Enter += PriceOfFuel_Enter; PriceOfFuel.KeyPress += new KeyPressEventHandler(EditPrice_KeyPress); PriceOfFuel.TextChanged += new EventHandler(EditPrice_TextChanged); PriceOfFuel.MouseEnter += PriceOfFuel_MouseEnter; i++; } } } else { Label NonIformation = new Label(); panelForPriceDisplay.Controls.Add(NonIformation); NonIformation.AutoSize = true; NonIformation.Text = "Устройств в сети не обнаружено"; NonIformation.Location = new Point(40, 40); } }
private void buttonScanning_Click(object sender, EventArgs e) { progressInfo.Visible = true; buttonApplyChanges.Enabled = true; comport.GetRealDeviceList(progressInfo); //Образовался comport.realDeviceList (SortedList) RealDeviceTable.Items.Clear(); //Очистили первую таблицу UserTableView.Rows.Clear(); //Очистили вторую таблицу XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("settings.xml"); //Удаляем секцию/секции в конфиг файле, если она/они там есть XmlNodeList nodelist = xmlDoc.SelectNodes("allsettings/FromRealdeviceList"); if (nodelist.Count > 0) { foreach (XmlNode item in nodelist) { xmlDoc.DocumentElement.RemoveChild(item); } xmlDoc.Save("settings.xml"); } int index = 0; if (comport.realDeviceList.Count > 0) { XmlElement realDeviceListSection = xmlDoc.CreateElement("FromRealdeviceList"); xmlDoc.DocumentElement.AppendChild(realDeviceListSection); foreach (KeyValuePair <int, string> infoForDevice in comport.realDeviceList) { index = comport.realDeviceList.IndexOfKey(infoForDevice.Key); //Первая строка сразу создается со значением первого столбца - порядоквым индексом ListViewItem item = new ListViewItem((index + 1).ToString()); //Значение второго столбца - имя реального устройства в сети item.SubItems.Add(infoForDevice.Value); //Значение 3-го столбца - адрес реального устройства в сети item.SubItems.Add(infoForDevice.Key.ToString()); RealDeviceTable.Items.Add(item); //В список комбобокса колонки адресов добавляется очередной адрес из списка ColumnAdress.Items.Add(item.SubItems[2].Text); if (infoForDevice.Value != "часы") { //Собственно само заполнение UserTableView UserTableView.Rows.Add( (index + 1).ToString(), // 1 столбец - порядковый номер строки true, // 2 столбец - видимость в главном окне "", // 3 столбец - метка/псевдоним адреса/имя топлива item.SubItems[1].Text, // 4 столбец - тип устройства comport.GetPriceFromCurrentDevice((byte)infoForDevice.Key), // 5 столбец - значение цены ColumnAdress.Items[index].ToString()); // 6 столбец - значение адреса } XmlElement CurrentDeviceElement = null; if (infoForDevice.Value == "панель с ценой") { CurrentDeviceElement = xmlDoc.CreateElement("pricedevice"); } else { CurrentDeviceElement = xmlDoc.CreateElement("clockdevice"); } CurrentDeviceElement.InnerText = infoForDevice.Key.ToString(); realDeviceListSection.AppendChild(CurrentDeviceElement); //realDeviceListSection.SetAttribute("Адрес" + infoForDevice.Key.ToString(), infoForDevice.Value); } XmlTextWriter tr = new XmlTextWriter("settings.xml", null); tr.Formatting = Formatting.Indented; xmlDoc.WriteContentTo(tr); tr.Close(); } /* * int totalHeight = 0; // высота всех столбцов в таблице * for (int i = 0; i < UserTableView.Rows.Count; i++) // перебираем все строки и колонки * { * totalHeight += UserTableView.Rows[i].Height; // суммируем высоту каждой строки * } * UserTableView.Height = totalHeight + UserTableView.ColumnHeadersHeight; // меняем высоту dataGridView */ System.Threading.Thread.Sleep(300); Application.DoEvents(); System.Threading.Thread.Sleep(600); progressInfo.Visible = false; }