WFA_psychometric_chart.Form1_main.ClearComfortZone C# (CSharp) Method

ClearComfortZone() public method

Clears the comfortzone that was created based on the min and max temperature and min and max humidity
public ClearComfortZone ( double Tmin, double Tmax, double Hmin, double Hmax ) : void
Tmin double minimum temperature
Tmax double maximum temperature
Hmin double minimum humidity
Hmax double maximum humidity
return void
        public void ClearComfortZone(double Tmin, double Tmax, double Hmin, double Hmax)
        {
            //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));
                }


            }


            //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));
                }

            }

            //This one for refreshing the chart
            chart1.Invalidate();
            chart1.Refresh();
        }

Usage Example

        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
        }
Form1_main