WFA_psychometric_chart.Form1_main.loadXMLDoc C# (CSharp) Method

loadXMLDoc() public method

public loadXMLDoc ( ) : void
return void
        public void loadXMLDoc()
        {
            nodeInfoFromXMLfile.Clear();
            lineInfoFromXMLfile.Clear();
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "xml file|*.xml";  //|Bitmap Image|*.bmp|Gif Image|*.gif";
            openFileDialog.Title = "Save an Image File";
            string path = null;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                path= openFileDialog.FileName;
                //xmlDoc.Save(name);
            }

            if(path == "")
            {
                return;
            }
            //now lets read the data from the file
            XmlDocument xmlDoc = new XmlDocument();
            try { 
            xmlDoc.Load(path);
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            XmlNodeList identifierList = xmlDoc.SelectNodes("RootNode/identifier");
            //because if the node is empty it returns null
            if (identifierList == null)
            {
                MessageBox.Show("This file can not be loaded.");
                return;


            }
            else
            {
                if (identifierList.Count > 0)
                {
                    string identifierSignature = identifierList[0].InnerText;

                    if (identifierSignature == "")
                    {
                        MessageBox.Show("File contains are edited outside,can not load");
                        return;

                    }
                    else if (identifierSignature == "BuildingSetting")
                    {
                        MessageBox.Show("This file belongs to online mode Load in Building Setting");
                        return;
                    }
                    else if (identifierSignature == "AirHandler")
                    {
                        MessageBox.Show("This file belongs to air handler. Please load in air handler section");
                        return;
                    }

                }
            }



            XmlNodeList xnList = xmlDoc.SelectNodes("RootNode/nodes/node");
            foreach (XmlNode xn in xnList)
            {
                string idVal = xn["nodeID"].InnerText;
                string name = xn["name"].InnerText;
                string label = xn["label"].InnerText;                
                string source = xn["source"].InnerText;
                string color = xn["color"].InnerText;
                string xvalue = xn["xvalue"].InnerText;
                string yvalue = xn["yvalue"].InnerText;
                string showTextItem = xn["showTextItem"].InnerText;

                //now lets add these values to list
                nodeInfoFromXMLfile.Add(new Tempdt
                {
                    id = idVal ,
                    name = name,
                    label = label,
                    source = source,
                    colorValue = ColorTranslator.FromHtml(color),
                    xVal = double.Parse(xvalue),
                    yVal = double.Parse(yvalue),
                    showItemText = showTextItem
                });            
            }//close of foreach

            //--loading the line info from the doc
            XmlNodeList xlList = xmlDoc.SelectNodes("RootNode/lines/line");

            foreach (XmlNode xn in xlList)
            {
                string idVal = xn["ID"].InnerText;
                string prevNodeIDVal = xn["prevNodeID"].InnerText;
                string nextNodeIDVal = xn["nextNodeID"].InnerText;
               // string lineThicknessVal = xn["linethickness"].InnerText;
                string serieNameIDval = xn["seriesname"].InnerText;
                string linecolor = xn["linecolor"].InnerText;
                //now lets add these values to list
                lineInfoFromXMLfile.Add(new lineNodeDataType
                {
                    ID = idVal,
                    prevNodeId = prevNodeIDVal,
                    nextNodeId =nextNodeIDVal,                   
                    lineSeriesID = new Series(serieNameIDval),
                    lineColorValue = ColorTranslator.FromHtml(linecolor)
                });
            }//close of foreach



            //Now lets load the values  first copy in two list and the load

            menuStripNodeInfoValues.Clear();//First clear the node info
            menuStripNodeLineInfoValues.Clear();//Line info value

            //now clone the newly create list
            // menuStripNodeInfoValues = Clone(lineInfoFromXMLfile);

            //var mi = typeof(Form1_main).GetMethod("Clone");
            //var fooRef = mi.MakeGenericMethod(bar);
            //fooRef.Invoke(new Test(), null);

           //=====================loading the data ============================// 
            foreach(var node in nodeInfoFromXMLfile)
            {
                menuStripNodeInfoValues.Add(new TempDataType
                {
                    //==This need to be uncommented later=============//
                     //Some task letf 
                    id = node.id,
                   // label = node.label,
                    name = node.name,
                   // source = node.source,
                   //temperature_source =  node.
                    xVal = node.xVal,
                    yVal = node.yVal,
                    colorValue = node.colorValue,
                   // showItemText = node.showItemText

                 //==============end uncomment=====================//
                });

            }

            foreach(var line in lineInfoFromXMLfile)
            {
                menuStripNodeLineInfoValues.Add(new lineNodeDataType
                {
                       ID = line.ID,
                       nextNodeId = line.nextNodeId,
                       prevNodeId = line.prevNodeId,
                       lineColorValue = line.lineColorValue,
                       lineSeriesID = line.lineSeriesID

                });
            }

          //  MessageBox.Show("Count  node = " + menuStripNodeInfoValues.Count + " , line count = " + menuStripNodeLineInfoValues.Count);
            //=======================end of loading data : now lets plot the data values=======================//


            //ClearChart();   //this will clear the chart first
            // ResettingLines();
            // ReDrawingLineAndNode();
           // ReDrawingLineAndNodeForLoadXML();

        }
Form1_main