private void GroupDataGrid_SelectionChange(object sender, SelectionChangedEventArgs e) { if (GroupDataGrid.SelectedIndex > -1) { GroupOpcConfigEntity bItem = (GroupOpcConfigEntity)GroupDataGrid.SelectedItem; ItemDataGrid.ItemsSource = bItem.dataList; } }
private static void LoadOpcConfig() { try { XmlDocument xmlContent = new XmlDocument(); xmlContent.Load(Properties.Settings.Default.OpcConfig); XmlNodeList Host = xmlContent.DocumentElement.GetElementsByTagName("Hostname"); for (int i = 0; i < Host.Count; i++) { Remote aRemote = new Remote(); aRemote.RemoteHost = Host[i].Attributes["RemoteHost"].InnerText; aRemote.Remotes = int.Parse(Host[i].Attributes["Remote"].InnerText); RemoteList.Add(aRemote); } XmlNodeList Serve = xmlContent.DocumentElement.GetElementsByTagName("Server"); for (int i = 0; i < Serve.Count; i++) { Server aServer = new Server(); aServer.ServerName = Serve[i].Attributes["Name"].InnerText; aServer.Connected = int.Parse(Serve[i].Attributes["Connected"].InnerText); aServer.GroupCount = int.Parse(Serve[i].Attributes["GroupCount"].InnerText); ServerList.Add(aServer); } XmlNodeList groups = xmlContent.DocumentElement.GetElementsByTagName("Group"); for (int i = 0; i < groups.Count; i++) { GroupOpcConfigEntity aGroup = new GroupOpcConfigEntity(); aGroup.GroupName = groups[i].Attributes["Name"].InnerText; aGroup.GroupActive = int.Parse(groups[i].Attributes["Active"].InnerText); aGroup.ReqUpdateRate = int.Parse(groups[i].Attributes["ReqUpdateRate"].InnerText); aGroup.TimeBias = int.Parse(groups[i].Attributes["TimeBias"].InnerText); aGroup.PercentDeadband = groups[i].Attributes["PercentDeadband"].InnerText; aGroup.GroupConnected = int.Parse(groups[i].Attributes["Connected"].InnerText); // aGroup.ItemCount = int.Parse(groups[i].Attributes["ItemCount"].InnerText); XmlNodeList aItem = groups[i].SelectNodes("Item"); for (int j = 0; j < aItem.Count; j++) { OpcConfigEntity aComponent = new OpcConfigEntity(); aComponent.AccessPath = aItem[j].Attributes["AccessPath"].InnerText; aComponent.Active = int.Parse(aItem[j].Attributes["Active"].InnerText); aComponent.ReqDataType = int.Parse(aItem[j].Attributes["ReqDataType"].InnerText); aComponent.Component = aItem[j].InnerText; aGroup.dataList.Add(aComponent); } GroupList.Add(aGroup); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }