public void AddMixNodeBetweenTwoNodes()
{
//Steps:
/*
1.Identify node1 and node2,
2. CALCULATE THE mid point using section formula
(x1,y1)-------------------------------(x2,y2)
<------m-->P(x,y)<------n----->
P(x,y) = [(m*x2+n*x1)/(m+n),(m*y2+n*y1)/(m+n)]
*/
//============Lets check first=======
if(indexOfPrevPointForLineMovement == ""|| indexOfNextNodeForLineMovement == "")
{
return;//If index seleted is empty return
}
mixCorrespondingNodeValuesList.Clear();
//--ADDING NODE1 info
foreach(var node in menuStripNodeInfoValues)
{
//--Now lets find which node is being found
if(node.id == indexOfPrevPointForLineMovement)
{
//Previous node is found ie node1
mixCorrespondingNodeValuesList.Add(new TempDataType
{
id = node.id,
name= node.name,
xVal = node.xVal,
yVal = node.yVal,
temperature_source = node.temperature_source ,
humidity_source = node.humidity_source,
colorValue = node.colorValue ,
airFlow = node.airFlow,
marker_Size = node.marker_Size,
lastUpdatedDate = node.lastUpdatedDate
});//This is the node of previous node found
break;
}
}
//Adding node2 info
foreach (var node in menuStripNodeInfoValues)
{
//--Now lets find which node is being found
if (node.id == indexOfNextNodeForLineMovement)
{
//Previous node is found ie node1
mixCorrespondingNodeValuesList.Add(new TempDataType
{
id = node.id,
name = node.name,
xVal = node.xVal,
yVal = node.yVal,
temperature_source = node.temperature_source,
humidity_source = node.humidity_source,
colorValue = node.colorValue,
airFlow = node.airFlow,
marker_Size = node.marker_Size,
lastUpdatedDate = node.lastUpdatedDate
});//This is the node of previous node found
break;
}
}//Close of for each..
//Now let x_mix,y_mix contain the mix value of node
double m = mixCorrespondingNodeValuesList[0].airFlow;
double n = mixCorrespondingNodeValuesList[1].airFlow;
double x1 = mixCorrespondingNodeValuesList[0].xVal;
double y1 = mixCorrespondingNodeValuesList[0].yVal;
//x2,y2;
double x2 = mixCorrespondingNodeValuesList[1].xVal;
double y2 = mixCorrespondingNodeValuesList[1].yVal;
double x_mix = ((n * x2) + (m * x1)) / (m + n);
double y_mix = ((n * y2) + (m * y1)) / (m + n);
//Now we know the coordinates we need to plot now..
string idForNode = GetGUID();//This get the id
int mixAirFlowContent = (int)(m + n);
//Finding appropriate name
string mixNodeName = UniqueMixName();
//--Now insert into db first then only plot the values
//--Now lets update the values
DatabaseOperations ObjDbOperation = new DatabaseOperations();
// MessageBox.Show("Building Name= " + selectedBuildingList[0].BuildingName);
// MessageBox.Show(unique_id_for_node+"xval = "+ xval+" yval"+ yval+"temp "+ temperature_sourceGlobal+"hum="+ humidity_sourceGlobal+",name="+ tbName+",col="+ colorValue+",size=" +markerSize +",air="+airFlowValueGlobal.ToString());
ObjDbOperation.InsertNodeInfoToDBWithoutDeviceInfo(CurrentSelectedBuilding, chartDetailList[indexForWhichChartIsSelected].chart_respective_nodeID, idForNode, x_mix, y_mix, "Mix","Mix", mixNodeName, Color.Blue, 20, mixAirFlowContent.ToString());
//--Now inserting the node info
ObjDbOperation.InsertMixNodeInfo(CurrentSelectedBuilding,chartDetailList[indexForWhichChartIsSelected].chartID, idForNode, indexOfPrevPointForLineMovement, indexOfNextNodeForLineMovement);//Insertion operation
//Now plotting the values
//=================Now refreshing the data =======================//
//indexOfChartSelected = e.RowIndex; //This value is changed
LoadNodeAndLineFromDB(indexOfChartSelected); //Lets make it passing the stirngs
//flagForInsertOrUpdateDataToDB = 1;
//--This is also completed..
ReDrawingLineAndNode(); //Done checking bbk modif: changing to alex db
//====================End of data refresh
}