private void chart1_MouseClick(object sender, MouseEventArgs e)
{
//--Check of enable or dissable the cell click
if (FlagForDissableLeftAndRightClicksInChart == 1)
{
//FlagForDissableLeftAndRightClicksInChart = 0;
return;//DO not proceed forward
}
if(flagForEditComfortZoneGraphically == 1)
{
//First click then 1 second click then 2
if ((Cursor == Cursors.SizeWE || Cursor == Cursors.SizeNS))
{
if (selectedSeriesForMoveForEditComfortZone != "")
{
// Cursor = Cursors.SizeWE;
// selectedSeriesForMoveForEditComfortZone = "Vertical_Temp_Left_Side";
flagForBorderLineSelectedForMoveForEditCF += 1;
comfortZoneBorderSeriesCurrentlySelected = selectedSeriesForMoveForEditComfortZone;
}
}
if (flagForBorderLineSelectedForMoveForEditCF == 0)
{
////If the button is clicked outside then we have flagForBorderLineSelectedForMoveForEditCF = 3
//this should be done only when clicked outside the chart so use condition
double xValue = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.X);
double yValue = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Y);
double hum = CalculateHumidityFromXandYCoordinate(xValue, yValue);//This gets the humidity
if (( hum < int.Parse(listchartComfortZoneInfoSingle[0].min_hum) || hum > int.Parse(listchartComfortZoneInfoSingle[0].max_hum)) ||(xValue < int.Parse(listchartComfortZoneInfoSingle[0].min_temp) || xValue> int.Parse(listchartComfortZoneInfoSingle[0].max_temp)))
{
flagForBorderLineSelectedForMoveForEditCF = 3;
}
}
if (flagForBorderLineSelectedForMoveForEditCF == 3)
{
/*
Means create new chart if the data is updated to new values
*/
//Checking if current value matches with previous values or not if so then do not do anything
if ( ( minTemperatureForNewComfortZoneCreate != 0 )&& ( maxTemperatureForNewComfortZoneCreate != 0) && (minHumidityForNewComfortZoneCreate != 0) &&( maxHumidityForNewComfortZoneCreate != 0))
{
//If the values has changed then default then only change else no change
//Lets get the previous chart value to make new chart
string name = listchartComfortZoneInfoSingle[0].name;
int minTempOfPrevComfortzone = int.Parse(listchartComfortZoneInfoSingle[0].min_temp);
int maxTempOfPrevComfortzone = int.Parse(listchartComfortZoneInfoSingle[0].max_temp);
int minHumidityOfPrevComfortzone = int.Parse(listchartComfortZoneInfoSingle[0].min_hum);
int maxHumidityOfPrevComfortzone = int.Parse(listchartComfortZoneInfoSingle[0].max_hum);
Color prevComfortzoneColor = listchartComfortZoneInfoSingle[0].colorValue;
if (((minTemperatureForNewComfortZoneCreate == minTempOfPrevComfortzone) && (maxTemperatureForNewComfortZoneCreate == maxTempOfPrevComfortzone) && (minHumidityForNewComfortZoneCreate == minHumidityOfPrevComfortzone) && (maxHumidityForNewComfortZoneCreate == maxHumidityOfPrevComfortzone)))
{
//If equal do not do any thing
//Refreshing the chart
if (dataGridView1.Rows.Count > 0) //If there is data then only do this one
{
//set parameters of your event args
var eventArgs = new DataGridViewCellEventArgs(1, dataGridView1.CurrentCell.RowIndex);
// or setting the selected cells manually before executing the function
dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Selected = true;
dataGridView1_CellClick(sender, eventArgs);
}
}
else {
//If they do not match then only create new comfort zone and assign them the value
/*Steps "
1.Clear the existing chart first
2.Create the new chart with new values and new name
3.Update the chart list
*/
// MessageBox.Show("Chart creating and updating");
//Clearing the border lines
ClearSeriesInChart("Vertical_Temp_Left_Side");
ClearSeriesInChart("Vertical_Temp_Right_Side");
ClearSeriesInChart("Horizontal_Hum_Down_Side");
ClearSeriesInChart("Horizontal_Hum_Upper_Side");
//Clearing the chart
ClearComfortZone(double.Parse(listchartComfortZoneInfoSingle[0].min_temp), double.Parse(listchartComfortZoneInfoSingle[0].max_temp), double.Parse(listchartComfortZoneInfoSingle[0].min_hum), double.Parse(listchartComfortZoneInfoSingle[0].max_hum));
//We need to generate name
//First splite if underscore is present
string[] word = name.Split('_');
string newComfortZoneName = "";
do
{
newComfortZoneName = word[0] + "_" + countForComfortZone++;
} while (newComfortZoneName == name);
PlotComfortZone(minTemperatureForNewComfortZoneCreate, maxTemperatureForNewComfortZoneCreate, minHumidityForNewComfortZoneCreate, maxHumidityForNewComfortZoneCreate, prevComfortzoneColor, newComfortZoneName);
//Now we need to insert new comfort zone now
InsertComfortZoneValue(newComfortZoneName, minTemperatureForNewComfortZoneCreate, maxTemperatureForNewComfortZoneCreate, minHumidityForNewComfortZoneCreate, maxHumidityForNewComfortZoneCreate, prevComfortzoneColor);
//After inserting updating the comfort zone info as well
insertOrUpdateComfortChartSetting(chartDetailList[indexOfChartSelected].chartID, temporaryComfortZoneID_Store);
//--Refresh the comfort zone
if (dataGridView1.Rows.Count > 0) //If there is data then only do this one
{
//set parameters of your event args
var eventArgs = new DataGridViewCellEventArgs(1, dataGridView1.CurrentCell.RowIndex);
// or setting the selected cells manually before executing the function
dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Selected = true;
dataGridView1_CellClick(sender, eventArgs);
}
}
flagForEditComfortZoneGraphically = 0;//Resetting flag
}
}
//Now we do others task
//This one is last one when released go back to 0 initial state not selected
if (flagForBorderLineSelectedForMoveForEditCF== 2)
{
flagForBorderLineSelectedForMoveForEditCF = 0;
}
}
else {
//This flagForDisconnectClick is for the line not node
if (flagForDisconnectClick == 1)
{
//--This one is for line
if (flagNodeSelectedForConnect == 1) //Node selected for connect
{
//--Here we need to do the resetting of the datas in the arraylist and replotting it ....
//--This function does the resetting the line properties...
ResettingLines();//--Calling the resetting the lines..
ReDrawingLineAndNode();
//--Again resetting the values as well ..
chart1.Series.Remove(addDottedSeries);//--lets remove the indicator if present
flagForDisconnectClick = 0;
flagNodeSelectedForConnect = 0;
}
}
else {
//--This function is used for nodeSelection and releasing node to desired place
//--This gets triggered based on mouse select and release..
//Updating values in database //This part is of node movement and update not line
if (flagForInsertOrUpdateDataToDB == 1)
{
for (int x = 0; x < menuStripNodeInfoValues.Count; x++)
{
// UpdateNodeInfoToDB(menuStripNodeInfoValues[x].id, menuStripNodeInfoValues[x].xVal, menuStripNodeInfoValues[x].yVal, menuStripNodeInfoValues[x].source, menuStripNodeInfoValues[x].name, menuStripNodeInfoValues[x].label, menuStripNodeInfoValues[x].colorValue, menuStripNodeInfoValues[x].showItemText, menuStripNodeInfoValues[x].marker_Size);
DatabaseOperations Obj1 = new DatabaseOperations();
Obj1.UpdateNodeInfoToDBWithNewParameters(CurrentSelectedBuilding,menuStripNodeInfoValues[x].id, menuStripNodeInfoValues[x].xVal, menuStripNodeInfoValues[x].yVal, menuStripNodeInfoValues[x].temperature_source, menuStripNodeInfoValues[x].humidity_source, menuStripNodeInfoValues[x].name, menuStripNodeInfoValues[x].colorValue, menuStripNodeInfoValues[x].marker_Size,(int)menuStripNodeInfoValues[x].airFlow);
}
}
NodeSelectionAndRelease(e);
//The node update function should be placed here and the calling
//to the redrawing function has to be done after that.
}
}//Close of else of edit mode
}//Close of mouse click event