public void LoadControls(String panelName) { //Cargamos la configuracion var configuracion = ProyectoCraft.Base.Configuracion.Configuracion.Instance(); var opcion = configuracion.GetValue("Semaforos_Brasil_Enabled"); //puede retornar un true, false o null var pathxml = ""; Path = opcion.HasValue && opcion.Value.Equals(true) ? @"panel de control/Brasil" : @"panel de control/Chile"; pathxml = System.IO.Path.Combine(Application.StartupPath, string.Format( @Path + "/panel de control/{0}", panelName)); var xmldoc = new XmlDocument(); xmldoc.Load(pathxml); var panelNodes = xmldoc.SelectNodes("/panel/panel"); foreach (XmlNode panelNode in panelNodes) { var size = new Size(Convert.ToInt16(panelNode.Attributes["width"].Value), Convert.ToInt16(panelNode.Attributes["heigth"].Value)); var location = new Point(Convert.ToInt16(panelNode.Attributes["x"].Value), Convert.ToInt16(panelNode.Attributes["y"].Value)); var panelContainer = new PanelContainer(panelNode.Attributes["title"].Value, location, size); var xmlnodes = panelNode.SelectNodes("control"); foreach (XmlNode xmlnode in xmlnodes) { if (!String.IsNullOrEmpty(xmlnode.InnerText.Trim())) { MyControl myControl = null; var xmldocControles = new XmlDocument(); xmldocControles.Load(System.IO.Path.Combine(Application.StartupPath, string.Format( @Path + "/controles/{0}", xmlnode.InnerText.Trim()))); var TypeOfControl = xmldocControles.SelectSingleNode("/control").Attributes["type"].Value; size = new Size(Convert.ToInt16(xmlnode.Attributes["width"].Value), Convert.ToInt16(xmlnode.Attributes["heigth"].Value)); location = new Point(Convert.ToInt16(xmlnode.Attributes["x"].Value), Convert.ToInt16(xmlnode.Attributes["y"].Value)); switch (TypeOfControl.ToUpper()) { case "DIGITALGAUGE": myControl = new DigitalGauge(xmldocControles, location, size); break; case "LINEARGAUGE": myControl = new LinearGauge(xmldocControles, location, size); break; case "SEMAFORO": myControl = new Semaforo(xmldocControles, location, size); break; case "GRAFICOBARRA3D": myControl = new GraficoBarra3D(xmldocControles, location, size); break; case "SEMAFORO_V2": myControl = new SemaforoV2(xmldocControles, location, size); break; } if (myControl != null) panelContainer.Controles.Add(myControl); } } PanelContainers.Add(panelContainer); } }
public void LoadControls(String panelName) { //Cargamos la configuracion var configuracion = ProyectoCraft.Base.Configuracion.Configuracion.Instance(); var opcion = configuracion.GetValue("Semaforos_Brasil_Enabled"); //puede retornar un true, false o null var pathxml = ""; Path = opcion.HasValue && opcion.Value.Equals(true) ? @"panel de control/Brasil" : @"panel de control/Chile"; pathxml = System.IO.Path.Combine(Application.StartupPath, string.Format( @Path + "/panel de control/{0}", panelName)); var xmldoc = new XmlDocument(); xmldoc.Load(pathxml); var panelNodes = xmldoc.SelectNodes("/panel/panel"); foreach (XmlNode panelNode in panelNodes) { var size = new Size(Convert.ToInt16(panelNode.Attributes["width"].Value), Convert.ToInt16(panelNode.Attributes["heigth"].Value)); var location = new Point(Convert.ToInt16(panelNode.Attributes["x"].Value), Convert.ToInt16(panelNode.Attributes["y"].Value)); var panelContainer = new PanelContainer(panelNode.Attributes["title"].Value, location, size); var xmlnodes = panelNode.SelectNodes("control"); foreach (XmlNode xmlnode in xmlnodes) { if (!String.IsNullOrEmpty(xmlnode.InnerText.Trim())) { MyControl myControl = null; var xmldocControles = new XmlDocument(); xmldocControles.Load(System.IO.Path.Combine(Application.StartupPath, string.Format( @Path + "/controles/{0}", xmlnode.InnerText.Trim()))); var TypeOfControl = xmldocControles.SelectSingleNode("/control").Attributes["type"].Value; size = new Size(Convert.ToInt16(xmlnode.Attributes["width"].Value), Convert.ToInt16(xmlnode.Attributes["heigth"].Value)); location = new Point(Convert.ToInt16(xmlnode.Attributes["x"].Value), Convert.ToInt16(xmlnode.Attributes["y"].Value)); switch (TypeOfControl.ToUpper()) { case "DIGITALGAUGE": myControl = new DigitalGauge(xmldocControles, location, size); break; case "LINEARGAUGE": myControl = new LinearGauge(xmldocControles, location, size); break; case "SEMAFORO": myControl = new Semaforo(xmldocControles, location, size); break; case "GRAFICOBARRA3D": myControl = new GraficoBarra3D(xmldocControles, location, size); break; case "SEMAFORO_V2": myControl = new SemaforoV2(xmldocControles, location, size); break; } if (myControl != null) { panelContainer.Controles.Add(myControl); } } } PanelContainers.Add(panelContainer); } }