WFA_psychometric_chart.Form1_main.ReadDataForSavingConfiguration_For_Load C# (CSharp) Method

ReadDataForSavingConfiguration_For_Load() public method

public ReadDataForSavingConfiguration_For_Load ( string DB_String_path, string chartTableName, string nodeTableName, string lineTableName, string tableNameDevice, string tableForComfortZoneSetting, string tableForCF_Detail, string tableForMixNode ) : void
DB_String_path string
chartTableName string
nodeTableName string
lineTableName string
tableNameDevice string
tableForComfortZoneSetting string
tableForCF_Detail string
tableForMixNode string
return void
        public void ReadDataForSavingConfiguration_For_Load(string DB_String_path, string chartTableName, string nodeTableName, string lineTableName, string tableNameDevice, string tableForComfortZoneSetting, string tableForCF_Detail,string tableForMixNode)
        {

            //--Resetting values first
            chartInfoPulledForSaving_For_Load.Clear();
            nodeInfoPulledForSaving_For_Load.Clear();
            lineInfoPulledForSaving_For_Load.Clear();
            deviceInfoPulledForSaving_For_Load.Clear();
            comfortZoneInforForEachChartForSaving_For_Load.Clear();
            ComfortZonesDetailForSaving_For_Load.Clear();
            mixNodeList_For_Load.Clear();

            string connectionString = DB_String_path;// @"Data Source=" + path + ";Version=3;";
           
            string sql_for_chart_detail = "SELECT * From  " + chartTableName;
            string sql_for_node = "SELECT * From  " + nodeTableName;
            string sql_for_line = "SELECT * From  " + lineTableName;
            string sql_forDevice = "SELECT * From  " + tableNameDevice;
            string sql_for_CF_Setting = "SELECT * From  " + tableForComfortZoneSetting;
            string sql_for_CF_Detail = "SELECT * From  " + tableForCF_Detail;
            string sql_for_mix_node = "SELECT * From  " + tableForMixNode;



            // MessageBox.Show("inside sqlite path =" + path);         
            using (SQLiteConnection conName = new SQLiteConnection(connectionString))
            {

                //MessageBox.Show("BHIRA");
                //conx.Close();
                conName.Open();
                using (SQLiteCommand cmdx = new SQLiteCommand(sql_for_chart_detail, conName))
                {
                    SQLiteDataReader reader = cmdx.ExecuteReader();
                    while (reader.Read())
                    {

                        if (reader["chartID"].ToString() != "")
                        {
                            //--Reading and inserting in a List
                            // if(!chartInfoPulledForSaving_For_Load.Contains())

                            // if(chartInfoPulledForSaving_For_Load)
                            foreach (var items in chartInfoPulledForSaving_For_Load)
                            {
                                if (items.chartID == reader["chartID"].ToString())
                                {
                                    //if contain do not add
                                    return;
                                }
                            }

                            chartInfoPulledForSaving_For_Load.Add(new chartDetailDT_X
                            {
                                chartID = reader["chartID"].ToString(),
                                chartName = reader["chartName"].ToString(),
                                chart_respective_nodeID = reader["chart_respective_nodeID"].ToString(),
                                chart_respective_lineID = reader["chart_respective_lineID"].ToString() ,
                                enableChartStatus = reader["enableChartStatus"].ToString()

                            });
                        }
                    }

                    reader.Close();
                }
            }

           // MessageBox.Show("chart count value = " + chartInfoPulledForSaving_For_Load.Count);

            using (SQLiteConnection conName = new SQLiteConnection(connectionString))
            {
                conName.Open();
                //----Reading the node information 

                using (SQLiteCommand cmd1 = new SQLiteCommand(sql_for_node, conName))
                {
                    SQLiteDataReader reader1 = cmd1.ExecuteReader();
                    while (reader1.Read())
                    {

                        if (reader1["chart_respective_nodeID"].ToString() != "")
                        {

                            //if items present then do not add

                            foreach (var items in nodeInfoPulledForSaving_For_Load)
                            {
                                if (items.nodeID == reader1["nodeID"].ToString())
                                {
                                    //if contain do not add
                                    return;
                                }
                            }


                            //--Reading and inserting in a List
                            nodeInfoPulledForSaving_For_Load.Add(new nodeDataTypeForSaving
                            {

                                ////--count = int.Parse(reader1["count"].ToString()),


                                chart_respective_nodeID = reader1["chart_respective_nodeID"].ToString(),
                                nodeID = reader1["nodeID"].ToString(),
                                xValue = double.Parse(reader1["xValue"].ToString()),
                                yValue = double.Parse(reader1["yValue"].ToString()),
                                //source = reader1["source"].ToString(),
                                temperature_source = reader1["temperature_source"].ToString(),
                                humidity_source = reader1["humidity_source"].ToString(),
                                name = reader1["name"].ToString(),
                                //label = reader1["label"].ToString(),
                                colorValue = reader1["colorValue"].ToString(),
                                //showTextItem = reader1["showTextItem"].ToString(),
                                nodeSize = int.Parse(reader1["nodeSize"].ToString()),
                                airFlow = int.Parse(reader1["airFlow"].ToString()),
                                lastUpdatedDate = reader1["lastUpdatedDate"].ToString()
                            });
                        }

                    }
                    reader1.Close();

                }
            }

           // MessageBox.Show("Node count value = " + nodeInfoPulledForSaving_For_Load.Count);

            using (SQLiteConnection conName = new SQLiteConnection(connectionString))
            {
                conName.Open();
                //--Reading the line information
                using (SQLiteCommand cmd2 = new SQLiteCommand(sql_for_line, conName))
                {
                    SQLiteDataReader reader2 = cmd2.ExecuteReader();
                    while (reader2.Read())
                    {


                        if (reader2["chart_respective_lineID"].ToString() != "")
                        {


                            foreach (var items in lineInfoPulledForSaving_For_Load)
                            {
                                if (items.lineID == reader2["lineID"].ToString())
                                {
                                    //if contain do not add
                                    return;
                                }
                            }


                            //This is the reading part of the data...
                            lineInfoPulledForSaving_For_Load.Add(new lineDataType_X
                            {
                                // count = int.Parse(reader2["count"].ToString()),
                                chart_respective_lineID = reader2["chart_respective_lineID"].ToString(),
                                lineID = reader2["lineID"].ToString(),
                                prevNodeID = reader2["prevNodeID"].ToString(),
                                nextNodeID = reader2["nextNodeID"].ToString(),
                                lineColorValue = reader2["lineColorValue"].ToString(),
                                lineSeriesID = reader2["lineSeriesID"].ToString(),
                                thickness = reader2["thickness"].ToString(),
                                name = reader2["name"].ToString(),
                                status = reader2["status"].ToString()

                            });

                        }
                    }
                    reader2.Close();
                }
            }

          //  MessageBox.Show("Line count value = " + lineInfoPulledForSaving_For_Load.Count);


            using (SQLiteConnection conName = new SQLiteConnection(connectionString))
            {
                conName.Open();
                //--Pulling data for device info

                using (SQLiteCommand cmd3 = new SQLiteCommand(sql_forDevice, conName))
                {
                    SQLiteDataReader reader3 = cmd3.ExecuteReader();
                    while (reader3.Read())
                    {

                        if (reader3["nodeID"].ToString() != "")
                        {

                            foreach (var items in deviceInfoPulledForSaving_For_Load)
                            {
                                if (items.nodeID == reader3["nodeID"].ToString())
                                {
                                    //if contain do not add
                                    return;
                                }
                            }



                            deviceInfoPulledForSaving_For_Load.Add(new dt_for_device_info
                            {
                                nodeID = reader3["nodeID"].ToString(),
                                device_instance_id_for_param1 = reader3["device_instanceID_for_param1"].ToString(),
                               ip_for_param1 = reader3["IP_for_param1"].ToString(),
                                device_instance_id_for_param2 = reader3["device_instanceID_for_param2"].ToString(),
                                ip_for_param2 = reader3["IP_for_param2"].ToString(),
                                param1id = reader3["param1ID"].ToString(),
                                param2id = reader3["param2ID"].ToString(),
                                param1info = reader3["param1_info"].ToString(),
                                param2info = reader3["param2_info"].ToString(),
                                param1_id_type = reader3["param1_identifier_type"].ToString(),
                                param2_id_type = reader3["param2_identifier_type"].ToString()

                            });
                        }
                    }

                    reader3.Close();
                }

            }
           // MessageBox.Show("device count value = " + deviceInfoPulledForSaving_For_Load.Count);


            using (SQLiteConnection conName = new SQLiteConnection(connectionString))
            {
                conName.Open();
                //--Now reading the chart info
                using (SQLiteCommand cmd4 = new SQLiteCommand(sql_for_CF_Detail, conName))
                {
                    SQLiteDataReader reader4 = cmd4.ExecuteReader();
                    while (reader4.Read())
                    {

                        if (reader4["id"].ToString() != "")
                        {
                            foreach (var items in ComfortZonesDetailForSaving_For_Load)
                            {
                                if (items.id == reader4["id"].ToString())
                                {
                                    //if contain do not add
                                    return;
                                }
                            }

                            ComfortZonesDetailForSaving_For_Load.Add(new dataTypeForCF
                            {
                                id = reader4["id"].ToString(),
                                name = reader4["name"].ToString(),
                                min_temp = reader4["min_temp"].ToString(), //this is in string formate
                                max_temp = reader4["max_temp"].ToString(),
                                min_hum = reader4["min_hum"].ToString(),
                                max_hum = reader4["max_hum"].ToString(),
                                colorValue = ColorTranslator.FromHtml(reader4["colorValue"].ToString())
                            });
                        }
                    }
                    reader4.Close();
                }
            }
          //  MessageBox.Show("cf detail count value = " + ComfortZonesDetailForSaving_For_Load.Count);

            using (SQLiteConnection conName = new SQLiteConnection(connectionString))
            {
                conName.Open();
                //--Now reading the last part associated comfortzone with each chart
                using (SQLiteCommand cmdFive = new SQLiteCommand(sql_for_CF_Setting, conName)) { 
                    SQLiteDataReader readerFive = cmdFive.ExecuteReader();

                while (readerFive.Read())
                {
                    if (readerFive["chartID"].ToString() != "")
                    {
                        foreach (var items in comfortZoneInforForEachChartForSaving_For_Load)
                        {
                            if (items.chartid == readerFive["chartID"].ToString())
                            {
                                //if contain do not add
                                return;
                            }
                        }

                        //This is the reading part of the data...
                        comfortZoneInforForEachChartForSaving_For_Load.Add(new datatype_for_comfortzone
                        {
                            
                            chartid = readerFive["chartID"].ToString(),//reader["chartID"].ToString(),
                            comfortzoneid = readerFive["comfort_zone_ID"].ToString(),
                            status = readerFive["status"].ToString()
                        });
                    }
                }
                    readerFive.Close();                
            } //close of using statement
              //  MessageBox.Show("cf single for chart count value = " + comfortZoneInforForEachChartForSaving_For_Load.Count);


            }

            //=============For MXING PART====================//




            using (SQLiteConnection conName = new SQLiteConnection(connectionString))
            {
                conName.Open();
                //--Now reading the chart info
                using (SQLiteCommand cmd5 = new SQLiteCommand(sql_for_mix_node, conName))
                {
                    SQLiteDataReader reader5 = cmd5.ExecuteReader();
                    while (reader5.Read())
                    {

                        if (reader5["chartID"].ToString() != "")
                        {
                            foreach (var items in mixNodeList_For_Load)
                            {
                                if (items.ChartID == reader5["chartID"].ToString())
                                {
                                    //if contain do not add
                                    return;
                                }
                            }

                            mixNodeList_For_Load.Add(new dataTypeFor_mix_node_info
                            {                                                                             
                                ChartID = reader5["chartID"].ToString(),
                                nodeID = reader5["nodeID"].ToString(),
                                previousNodeID = reader5["previousNodeID"].ToString(),
                                nextNodeID = reader5["nextNodeID"].ToString()

                            });
                        }
                    }
                    reader5.Close();
                }
            }

          //=======================END MIXING=========================//



        }
Form1_main