WFA_psychometric_chart.Form_handler.LoadNodeAndLineFromDB C# (CSharp) Method

LoadNodeAndLineFromDB() private method

private LoadNodeAndLineFromDB ( int idOfChart ) : void
idOfChart int
return void
        private void LoadNodeAndLineFromDB( int idOfChart)
        {
            //Based on this row index we need to update the values and redraw lines..

            // listForDataFromDB.Clear();//Lets clear the node...

            //Lets identify the node
            int id = idOfChart;//int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());

            string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string databaseFile = databasePath + @"\db_psychrometric_project.s3db";
            string connString = @"Data Source=" + databaseFile + ";Version=3;";

            using (SQLiteConnection connection = new SQLiteConnection(connString))
            {
                connection.Open();
                SQLiteDataReader reader = null;
                string queryString = "SELECT *  from tbl_air_handler_details where id = @id_value";

                SQLiteCommand command = new SQLiteCommand(queryString, connection);
                command.Parameters.AddWithValue("@id_value", id);
                //SqlDataAdapter dataAdapter = new SqlDataAdapter(queryString, connection.ConnectionString); //connection.ConnectionString is the connection string

                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    currentNodeTableFromDB = reader["node_table"].ToString();
                    currentLineTableFromDB = reader["line_table"].ToString();
                }
            }//close of using..

            if (CountingDB_Item(currentNodeTableFromDB) > 0) {

            //--=============================================start of the if statement===================//
            //IF no data dont precess futher

            //Since it it done..
            //nwo pulling the data of different values...

            using (SQLiteConnection connection = new SQLiteConnection(connString))
            {
                connection.Open();

                SQLiteDataReader reader = null;
                string queryString = "SELECT *  from " + currentNodeTableFromDB + " ";

                SQLiteCommand command = new SQLiteCommand(queryString, connection);

                //--Reset the context menu stip first..
                menuStripNodeInfoValues.Clear();

                int count = 0;
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    menuStripNodeInfoValues.Add(new TempDataType
                    {
                        id = int.Parse(reader["id"].ToString()),
                        xVal = double.Parse(reader["xValue"].ToString()),
                        yVal = double.Parse(reader["yValue"].ToString()),
                        source = reader["source"].ToString(),
                        name = reader["name"].ToString(),
                        label = reader["label"].ToString(),
                        colorValue = ColorTranslator.FromHtml(reader["colorValue"].ToString()),
                        showItemText = reader["showItemText"].ToString()

                    });

                }

                //--Resetting the index value...

                if(menuStripNodeInfoValues.Count > 0) {
                count = menuStripNodeInfoValues.Count ;//--This is used for udpdating the index values..
                }
                else
                {
                    count = 0;
                }
                //--Resetting the actual index value
                index = count;

                //--Adding data form the line node values...
                SQLiteDataReader reader2x = null;
                string queryString2x = "SELECT *  from  " + currentLineTableFromDB + " ";
                    //--Testing..
                 //   MessageBox.Show("CurrentLineTableFromDB = " + currentLineTableFromDB);

                SQLiteCommand command2x = new SQLiteCommand(queryString2x, connection);

                //--Reset the context menu stip first..
                menuStripNodeLineInfoValues.Clear();

                //int count2 = 0;
                reader2x = command2x.ExecuteReader();
                while (reader2x.Read())
                {
                    menuStripNodeLineInfoValues.Add(new lineNodeDataType
                    {
                        ID = int.Parse(reader2x["id"].ToString()),
                        prevNodeId = int.Parse(reader2x["prevNodeId"].ToString()),
                        nextNodeId = int.Parse(reader2x["nextNodeId"].ToString()),
                        lineColorValue = ColorTranslator.FromHtml(reader2x["lineColorValue"].ToString()),
                        lineSeriesID = new Series(reader2x["lineSeriesId"].ToString()),
                    });

                }

            }//close of using..

            }//closing here...
            //--==================================Close of the if stat=====================================//
        }