public PlotComfortZone ( double Tmin, double Tmax, double Hmin, double Hmax, Color c, string name ) : void | ||
Tmin | double | |
Tmax | double | |
Hmin | double | |
Hmax | double | |
c | Color | |
name | string | |
Résultat | void |
public void PlotComfortZone(double Tmin, double Tmax, double Hmin, double Hmax, Color c, string name)
{
//This function will help to plot the values in the chart.
for (int i = (int)Tmin; i <= (int)Tmax; i++)
//for (double i = Tmin; i <= Tmax; i+=0.25)
{
//First reset the series if present and the re add them
Series s = new Series("vertical_temp" + i);
if (chart1.Series.IndexOf(s.Name) != -1)
{
//MessageBox.Show("Series exits");
//--This means the series is present....
chart1.Series.RemoveAt(chart1.Series.IndexOf(s.Name));
}
}
//MessageBox.Show("Plot comfort zone");
//NOw add horizontal series.
for (int i = (int)Hmin; i <= (int)Hmax; i += 1)
{
// for (double i = Hmin; i <= Hmax; i += 0.25)
//{
//remove if first present
Series s = new Series("horizontal_hum" + i);
if (chart1.Series.IndexOf(s.Name) != -1)
{
//--This means the series is present....
chart1.Series.RemoveAt(chart1.Series.IndexOf(s.Name));
}
}
//add both types of series
for (int i = (int)Tmin; i <= (int)Tmax; i++)
{
// for (double i = Tmin; i <= Tmax; i += 0.25)
//{
Series s = new Series("vertical_temp" + i);
s.Color = c;
s.ChartType = SeriesChartType.Line;
// s.MarkerSize = 5;
//s.BorderWidth = 10;
chart1.Series.Add(s);
}
//Refresh the chart now
chart1.Invalidate();
chart1.Refresh();//This is for refresh
for (int i = (int)Hmin; i <= (int)Hmax; i += 1)
{
// for (double i = Hmin; i <= Hmax; i += 0.25)
// {
//add now
Series s = new Series("horizontal_hum" + i);
s.Color = c;
s.ChartType = SeriesChartType.Spline;
//s.MarkerSize = 15;
s.BorderWidth = 5;
chart1.Series.Add(s);
}
//Now lets do the actual plotting part.
double phi_min = Hmin / 100;//need to change to decimal
double phi_max = Hmax / 100;
//This one is for adding horizontal lines
double phi = phi_min; //0.1;
double x2 = 0;
// int ival = 2;
//int indexValue = (int)Hmin;
double indexValue = Hmin;
double patm = AirPressureFromDB * 0.001;//101.325; ;//thsi need tochange
for (phi = phi_min; phi <= phi_max; phi += 0.01) //increment by 2 value
// for (phi = phi_min; phi <= phi_max; phi += 0.0025) //increment by 2 value
{
for (int temp = (int)Tmin; temp <= (int)Tmax; temp++)
//for (double temp = Tmin; temp <Tmax;temp+=0.25)
{
double pg_value = Double.Parse(pg[temp].ToString());
double wg_calc = (622 * phi * pg_value / (patm - phi * pg_value));
double y = wg_calc;
x2 = temp;//double.Parse(t[i].ToString());
chart1.Series["horizontal_hum" + indexValue].Points.AddXY(x2, y);
}//close of for
//MessageBox.Show(s1);
indexValue += 1;
//indexValue += 0.25;
} //close fo the second for loop
//Now this one is for adding vertical line for lines
for (int temp = (int)Tmin; temp <= (int)Tmax; temp++)
// for (double temp =Tmin; temp < Tmax; temp+=0.25)
{
double xx1, yy1, xx2, yy2;
double pg_value = Double.Parse(pg[temp].ToString());
double wg_calc = (622 * phi_min * pg_value / (patm - phi_min * pg_value));
yy1 = wg_calc;
xx1 = temp;//double.Parse(t[i].ToString());
xx2 = xx1; //here xx1 =xx2 same ony y value changes
double wg_calc2 = (622 * phi_max * pg_value / (patm - phi_max * pg_value));
yy2 = wg_calc2;
chart1.Series["vertical_temp" + temp].Points.AddXY(xx1, yy1);
chart1.Series["vertical_temp" + temp].Points.AddXY(xx2, yy2);
}//close of for
} //Close of our function
private void button1_Click(object sender, EventArgs e) { //When ok button is clicked the there should be plotting of the comfort zone. //This has basically two function... /* * 1.insert the comfort zone info to database * 2. Plot the comfort zone based on the value passed. */ if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "") { //chart id string chartid = bs.chartDetailList[bs.indexOfChartSelected].chartID; string comfortzoneid = bs.listComfortZoneDetail[comboBox1.SelectedIndex].id; bs.InsertChartComfortzoneInfo(chartid, comfortzoneid); //now second part call the plot function // bs.PlotComfortZone() double mint = double.Parse(textBox1.Text); double maxt = double.Parse(textBox2.Text); double minh = double.Parse(textBox3.Text); double maxh = double.Parse(textBox4.Text); Color c = bs.listComfortZoneDetail[comboBox1.SelectedIndex].colorValue; string name = bs.listComfortZoneDetail[comboBox1.SelectedIndex].name; if (bs.default_comfort_zone_of_chart.Count > 0) { if (bs.listchartComfortZoneInfoSingle.Count > 0) { //If default comfort zone is present then //Clear previous one //MessageBox.Show("Clear previous comfortzone"); bs.ClearComfortZone(double.Parse(bs.listchartComfortZoneInfoSingle[0].min_temp), double.Parse(bs.listchartComfortZoneInfoSingle[0].max_temp), double.Parse(bs.listchartComfortZoneInfoSingle[0].min_hum), double.Parse(bs.listchartComfortZoneInfoSingle[0].max_hum)); } } bs.PlotComfortZone(mint, maxt, minh, maxh, c, name); //insert of update database value bs.insertOrUpdateComfortChartSetting(chartid, comfortzoneid); if (bs.dataGridView1.Rows.Count > 0) //If there is data then only do this one { //set parameters of your event args var eventArgs = new DataGridViewCellEventArgs(1, bs.dataGridView1.CurrentCell.RowIndex); // or setting the selected cells manually before executing the function bs.dataGridView1.Rows[bs.dataGridView1.CurrentCell.RowIndex].Cells[1].Selected = true; bs.dataGridView1_CellClick(sender, eventArgs); } this.Close(); }//close of if }