public void loadXMLDoc()
{
// nodeInfoFromXMLfile.Clear();
// lineInfoFromXMLfile.Clear();
nodeInformationFromXML.Clear();
lineInformationFromXML.Clear();
OpenFileDialog saveFileDialog1 = new OpenFileDialog();
saveFileDialog1.Filter = "xml file|*.xml"; //|Bitmap Image|*.bmp|Gif Image|*.gif";
saveFileDialog1.Title = "Load an Image File";
string path = null;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
path = saveFileDialog1.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("File could not be loaded : " + 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 is edited outside,can not load");
return;
}
else if (identifierSignature == "MainForm")
{
MessageBox.Show("This file belongs to offline mode Load in main section");
return;
}
else if (identifierSignature == "BuildingSetting")
{
MessageBox.Show("This file belongs to buidding setting . Please load in online mode building setting section");
return;
}
}
}
XmlNodeList xnList = xmlDoc.SelectNodes("RootNode/nodes/node");
foreach (XmlNode xn in xnList)
{
string nodeID = 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;
//=============================comment now,not required===================//
//string nodeSize = xn["nodesize"].InnerText;
//string deviceInstanceVal = xn["deviceInstance"].InnerText;
//string ipVal = xn["ip"].InnerText;
//string param1idVal = xn["param1id"].InnerText;
//string param2idVal = xn["param2id"].InnerText;
//string param1infoVal = xn["param1info"].InnerText;
//string param2infoVal = xn["param2info"].InnerText;
//string param1typeVal = xn["param1id_type"].InnerText;
//string param2typeVal = xn["param2id_type"].InnerText;
//=================no required============================================//
//now lets add these values to list
nodeInformationFromXML.Add(new TempDataType
{
id = int.Parse( nodeID),
name = name,
label = label,
source = source,
colorValue = ColorTranslator.FromHtml(color),
xVal = double.Parse(xvalue),
yVal = double.Parse(yvalue),
showItemText = showTextItem,
//nodeSize = nodeSize,
//device_instance_id = deviceInstanceVal,
//ip = ipVal,
//param1id = param1idVal,
//param2id = param2idVal,
//param1info = param1infoVal,
//param2info = param2infoVal,
//param1_id_type = param1typeVal,
//param2_id_type = param2typeVal
});
}//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
lineInformationFromXML.Add(new lineNodeDataType
{
ID = int.Parse(idVal),
prevNodeId =int.Parse( prevNodeIDVal),
nextNodeId =int.Parse( nextNodeIDVal),
// lineThickness = int.Parse(lineThicknessVal),
lineSeriesID = new Series(serieNameIDval),
lineColorValue = ColorTranslator.FromHtml(linecolor)
});
}//close of foreach
// MessageBox.Show("count node values " + nodeInfoFromXMLfile.Count + ",line count" + lineInfoFromXMLfile.Count);
//--now since both value is added we need to insert these values to db now
//-- and reload them
/*
Task :
1. delete the existing value first
2. insert the existing file value form file
*/
//First lets check if the chart is selected or not.
if(currentNodeTableFromDB == "" || currentLineTableFromDB == "")
{
MessageBox.Show("Please select a chart properly first");
return;
}
//===============================Delete the line and node value================//
if(currentNodeTableFromDB != null && currentLineTableFromDB != null)
{
//First delete the node values
DeleteAllTableData(currentNodeTableFromDB);
//Delete all data form line table
DeleteAllTableData(currentLineTableFromDB);
}
//===============================end of the delete===========================//
//===================================inserting data form xml into db=====================================//
foreach (var node in nodeInformationFromXML)
{
//we need to inset it to db but if the node id is already present then dont inset just load....
InsertNodeInfoToDB(node.id, node.xVal, node.yVal, node.source, node.name, node.label, node.colorValue, node.showItemText);
}
foreach (var line in lineInformationFromXML)
{
InsertLineInfoToDB(line.ID, line.prevNodeId, line.nextNodeId, line.lineColorValue, line.lineSeriesID);
}
//=====================================end of inserting in db=============================//
//now lets load the data back again..
//--helps in loading in redrawing the parts.
RefreshGraph();
LoadNodeAndLineFromDB(idSelectedOfChart); //Lets make it passing the stirngs
ReDrawingLineAndNode();
MessageBox.Show("Load success");
}