WFA_psychometric_chart.Form1_main.heat_map_button_click C# (CSharp) Method

heat_map_button_click() public method

public heat_map_button_click ( int index_selected_heat_map, System.DateTime from1, System.DateTime to1 ) : void
index_selected_heat_map int
from1 System.DateTime
to1 System.DateTime
return void
        public void heat_map_button_click(int index_selected_heat_map,DateTime from1,DateTime to1)
        {

            //-- resetting chart series and plotting again..

             //plot_new_graph();

          //Series  series1_heat_map = new Series("My_Series_heat_map");//changed form "My Series"
            //chart1.Series.Add(series1_heat_map);


            if (chart1.Series.IndexOf(series1_heat_map)!= -1) 
            {
                //chart1.Series.Remove(series1_heat_map);//--Removing the series that already exist...
                //chart1.Series.Add(series1_heat_map);

                //    series1_heat_map.Points.Clear();//--This is for resetting the values ...
                //    index_series_heat_map = 0;//--Resetting the index...
                //series1.Points.Clear();
                //chart1.Series.RemoveAt(chart1.Series.IndexOf(series1));
                series1_heat_map.Points.Clear();//--We can clear all the poingt over here and add new one later..
                index_series_heat_map = 0;//--Resetting the values of the series...

            }
            //SeriesCount = 1;

            //--lest reset soem values..
            hist_temp_hum_list.Clear();

            //this  is going to plot the heat map...
            /*Steps:
            1.Get the database values..
            2.filter those values ..
            3.plot those values in the map..       
            */
            DateTime from = from1;//dtp_From.Value;
            DateTime to = to1;/// dtp_To.Value;

            //2.database connection ..

            if (to > from)
            {

                //   string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                //  string connString1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + @"\T3000.mdb;Persist Security Info=True";
                //sql connection string is this..
                //     string connString1 = @"Data Source=GREENBIRD;Initial Catalog=db_psychrometric_project;Integrated Security=True";


                //--changing all the database to the sqlite database...
                string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string databaseFile = databasePath + @"\db_psychrometric_project.s3db";

                string connString1 = @"Data Source=" + databaseFile + ";Version=3;";



                using (SQLiteConnection connection1 = new SQLiteConnection(connString1))
                {
                    connection1.Open();



                    //string sql_query = "Select * from tbl_data_stored_temp_hum_one_year WHERE date_current = " + day_list[i] + " , hour_current = " + hour_al[h] + " AND station_name = "+ station_name +" ; ";
                    //lets pass this string to a query which does the pulling part.
                    SQLiteDataReader reader1 = null;
                    SQLiteCommand command1 = new SQLiteCommand("Select * from tbl_historical_data WHERE date_current BETWEEN @date_first AND @date_second AND ID=@id_value", connection1);
                    command1.Parameters.AddWithValue("@date_first", from);
                    command1.Parameters.AddWithValue("@date_second", to);
                    command1.Parameters.AddWithValue("@id_value", index_selected_heat_map);//--This index selected is required to see which location is seleccted
                    //command1.Parameters.AddWithValue("@station_name", station_name);
                    reader1 = command1.ExecuteReader();
                    while (reader1.Read())
                    {                                                       
                        hist_temp_hum_list.Add(
                            new data_type_hum_temp
                            {
                                temp = double.Parse(reader1["temperature"].ToString()),
                                hum = double.Parse(reader1["humidity"].ToString())

                            });
                    }//close of while loop       
                     // connection1.Close();
                }//close of database using statement 
            }//closing of if statement
            else
            {
                MessageBox.Show(Properties.Resources.Please_select_correct_date_for);
            }


            //this will only be done when the data is returned

            if (hist_temp_hum_list.Count > 0)
            {
                //MessageBox.Show("value counted " + hist_temp_hum_list.Count);
                //after we have the data we do the actual part of heat map plotting...
                //setting up maximum and minimum value to use in color value calculation..

                ArrayList temporary_val_temp = new ArrayList();
                max_value = hist_temp_hum_list[0].temp;
                min_value = hist_temp_hum_list[0].temp;
                for (int i = 1; i < hist_temp_hum_list.Count; i++)//this is done because we are counting from 1 index no error 
                {                                                  //as we are comparing the first index value with all the vlues in the index  

                    if (max_value < hist_temp_hum_list[i].temp)
                    {
                        max_value = hist_temp_hum_list[i].temp;
                    }
                    if (min_value > hist_temp_hum_list[i].temp)
                    {
                        min_value = hist_temp_hum_list[i].temp;
                    }

                }



                //min_value = hist_temp_hum_list.Min<data_type_hum_temp>().temp;

                //MessageBox.Show("max = " + max_value + " ,min = " + min_value);//--printng of min value
                //callin gthe method.
                //lets increase th performance first... this below code if from plot_by_dbt_hr

                //--Lets reset the values first and then re-add the values
                //temperature_value.Clear();
                //pg_value_from_txtfile.Clear();//--Clearing the part of the series



                //string line1;

                //string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                //string file = dir + @"\t_pg.txt";
                //string path1 = file;

                //using (StreamReader st = new StreamReader(path1))
                //{

                //    while ((line1 = st.ReadLine()) != null)
                //    {

                //        string[] value = line1.Split(',');
                //        try
                //        {
                //            double temp1 = Double.Parse(value[0]);
                //            double temp2 = Double.Parse(value[1]);
                //            //now lets add to temperature and pg array..                     
                //            temperature_value.Add(temp1);
                //            pg_value_from_txtfile.Add(temp2);


                //        }
                //        catch (Exception ex)
                //        {
                //            MessageBox.Show(ex.ToString());
                //        }


                //    }//close of while

                //}//close of using

                temperature_value = t;
                pg_value_from_txtfile = pg;



                //this series is used to add to the 
            //    chart1.Series.Add(series1_heat_map);
              


                for (int i = 0; i < hist_temp_hum_list.Count; i++)
                {
                    plot_by_DBT_HR_heat_map(hist_temp_hum_list[i].temp, hist_temp_hum_list[i].hum / 100);

                }

               // MessageBox.Show(Properties.Resources.Success_final);
            }//close of if
            else
            {
                MessageBox.Show(Properties.Resources.No_data_found_in_database);
            }

            if (max_value != min_value)
            {
                marker();
            }
            else
            {
                //make indicator for same color
                marker_for_same_min_max_value();
            }





        }

Usage Example

Example #1
0
        int index_series     = 0; //this index is used by  plot_on_graph_values method

        private void button1_Click(object sender, EventArgs e)
        {
            //initially resetting values to empty

            //resetting ends...
            DateTime fromDate = dtp_From.Value;
            DateTime toDate   = dtp_To.Value;


            //--Calling part here.....
            form1.heat_map_button_click(index_selected, fromDate, toDate);
        }//closing of the buttton...
Form1_main