WFA_psychometric_chart.Form1_main.LoadNodeAndLineFromDB C# (CSharp) Method

LoadNodeAndLineFromDB() public method

We need have three parameters
public LoadNodeAndLineFromDB ( int indexValue ) : void
indexValue int
return void
        public void LoadNodeAndLineFromDB(int indexValue)
        {
            //Based on this row index we need to update the values and redraw lines..

            try { 
            // listForDataFromDB.Clear();//Lets clear the node...
            if(indexValue < 0)
            {
                return;
            }
            if(chartDetailList.Count <= 0)
                {
                    return;
                }

            if(selectedBuildingList.Count <= 0)
                {
                    return;
                }
            //Lets identify the node
            // int id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
            //int id = e.RowIndex;//This index is used to identify which cell or chart is clicked.
            int id = indexValue;//This index is used to identify which cell or chart is clicked.
            /*
            Now lets find the chart line id and chart node id 
            */
            string chartNodeGroupID = chartDetailList[id].chart_respective_nodeID;//This is for the node
            string chartLineGroupID = chartDetailList[id].chart_respective_lineID;//This is for the line

            string selectedChartID = chartDetailList[id].chartID;

            //--Reset the context menu stip first..
            menuStripNodeInfoValues.Clear();
            //--Reset the context menu stip first..
            menuStripNodeLineInfoValues.Clear();
            //--Now lets clear the mix node list first and then refill agiain
            mixNodeInfoList.Clear();


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

            /*
            Table name for line and node values...
            ie: 
            "tbl_"+ buildingname+ "_node_value"
            "tbl_"+ buildingname+ "_line_value"
            */
            string nodeTableName = "tbl_" + selectedBuildingList[0].BuildingName + "_node_value";
            string lineTableName = "tbl_" + selectedBuildingList[0].BuildingName + "_line_value";
            string tableMixNode = "tbl_" + selectedBuildingList[0].BuildingName + "_mix_node_info";

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

                SQLiteDataReader reader = null;
                string queryString = "SELECT *  from " + nodeTableName + " WHERE chart_respective_nodeID = @chartnodeID";

                SQLiteCommand command = new SQLiteCommand(queryString, connection);
                command.Parameters.AddWithValue("@chartnodeID", chartNodeGroupID);//This is the group id that is used to identify each node



                int count = 0;
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    //editied for reading from alex db
                    menuStripNodeInfoValues.Add(new TempDataType
                    {
                        id = reader["nodeID"].ToString(), //This is just changed code : bbk305
                        xVal = double.Parse(reader["xValue"].ToString()),
                        yVal = double.Parse(reader["yValue"].ToString()),
                        temperature_source = reader["temperature_source"].ToString(),
                        humidity_source = reader["humidity_source"].ToString(),
                        name = reader["name"].ToString(),
                        
                       // label = reader["label"].ToString(),
                        colorValue = ColorTranslator.FromHtml(reader["colorValue"].ToString()),
                       // showItemText = reader["showTextItem"].ToString(),
                        marker_Size = int.Parse(reader["nodeSize"].ToString()),
                        airFlow = int.Parse(reader["airFlow"].ToString()),
                        lastUpdatedDate = reader["lastUpdatedDate"].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; //Index is set to the count values of the node

                //--Now we can find the previous id values as follows:
                //=====================================Finding previous id value=================================//

                previousNodeIndexForLineInput= IndexOfPreviousNodeForLineFunction();
                //==================================End of previous id=======================================//

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

                SQLiteCommand command2x = new SQLiteCommand(queryString2x, connection);
                command2x.Parameters.AddWithValue("@lineID", chartLineGroupID);//This is the group id that is used to identify each node

                //int count2 = 0;
                reader2x = command2x.ExecuteReader();
                while (reader2x.Read())
                {
                    menuStripNodeLineInfoValues.Add(new lineNodeDataType
                    {
                        ID = reader2x["lineID"].ToString(),//This is just change code :bbk305
                        prevNodeId = reader2x["prevNodeId"].ToString(),
                        nextNodeId = reader2x["nextNodeId"].ToString(),
                        lineColorValue = ColorTranslator.FromHtml(reader2x["lineColorValue"].ToString()),
                        lineSeriesID = new Series(reader2x["lineSeriesId"].ToString()),
                        lineThickness = int.Parse(reader2x["thickness"].ToString())   ,
                        name= reader2x["name"].ToString(),
                        status = int.Parse(reader2x["status"].ToString())
                    });

                }
                //count2 = menuStripNodeLineInfoValues.Count-1; //--This is used for udpdating the index values..

                //   MessageBox.Show("count line data in menuStripNodeLineInfoValues = " + menuStripNodeLineInfoValues.Count);


                //===============================Loading Mix NODE info===================================//


                SQLiteDataReader readerMix = null;
                string queryStringMix = "SELECT *  from " + tableMixNode + " WHERE chartID = @chartID";

                SQLiteCommand commandMix = new SQLiteCommand(queryStringMix, connection);
                commandMix.Parameters.AddWithValue("@chartID",selectedChartID );//This is the group id that is used to identify each node



                // int count = 0;
                readerMix = commandMix.ExecuteReader();
                while (readerMix.Read())
                {
                    //editied for reading from alex db
                    mixNodeInfoList.Add(new  TempDataTypeForMixNode
                    {
                        chartID = readerMix["chartID"].ToString(),
                         nodeID = readerMix["nodeID"].ToString(), //This is just changed code : bbk305
                        previousNodeID = readerMix["previousNodeID"].ToString(),
                        nextNodeID = readerMix["nextNodeID"].ToString(),
                       

                    });

                }



                //=================================End of loading mix node============================//










            }//close of using..
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
Form1_main