public int updateDevice(string oldname, string name, string ip, string port) { foreach (DeviceInf dev in bindingSource) { if (dev.name.Equals(name) && !dev.name.Equals(oldname)) { return 1; } if (dev.ip.Equals(ip) && !dev.name.Equals(oldname)) { return 2; } } DeviceInf d = getCurrentDeviceInf(); if (d.Difference(name, ip, port)) { bindingSource.Remove(d); d = new DeviceInf(name, ip,port); bindingSource.Add(d); listBox1.SelectedItem = d; if (discover.Equals("0")) { XmlNode device = root.SelectSingleNode("/Devices/Device[@name=\"" + oldname + "\"]"); device.Attributes.GetNamedItem("name").InnerText = name; device.Attributes.GetNamedItem("ip").InnerText = ip; device.Attributes.GetNamedItem("port").InnerText = port; doc.Save(configPath); } } return 0; }
public void AddDevice(string name, string ip, string port) { DeviceInf dev = new DeviceInf(name,ip,port); bindingSource.Add(dev); if (discover.Equals("0")) { XmlElement device = doc.CreateElement("Device"); device.SetAttribute("name", name); device.SetAttribute("ip", ip); device.SetAttribute("port", port); root.AppendChild(device); doc.Save(configPath); } }