WFA_psychometric_chart.Form1_main.InsertForSavingConfiguration_For_Load C# (CSharp) Method

InsertForSavingConfiguration_For_Load() public method

This helps in insertion of the data to db
public InsertForSavingConfiguration_For_Load ( string fileWithPath, string chartTableName, string nodeTableName, string lineTableName, string tableNameDevice, string tableForComfortZoneSetting, string tableForCF_Detail, string tableMixNode ) : void
fileWithPath string file name with path
chartTableName string
nodeTableName string
lineTableName string
tableNameDevice string
tableForComfortZoneSetting string
tableForCF_Detail string
tableMixNode string
return void
        public void InsertForSavingConfiguration_For_Load(string fileWithPath, string chartTableName, string nodeTableName, string lineTableName, string tableNameDevice, string tableForComfortZoneSetting, string tableForCF_Detail,string tableMixNode)
        {

            //--This is where we are going to create all the database  and tables of sqlite
            //   string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            // string databaseFile = databasePath + @"\db_psychrometric_project.s3db";




            //--now lets create the tables
            using (SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=" + fileWithPath + ";Version=3;")) { 
                m_dbConnection.Open();

            //Lets input chart detail id...if we are inserting we need to clear first
            string sql_input1 = null;
            foreach (var ch in chartInfoPulledForSaving_For_Load)
            {
                sql_input1 = "INSERT INTO " + chartTableName + " (chartID,chartName,chart_respective_nodeID,chart_respective_lineID,enableChartStatus) VALUES(@id,@chartname,@cnid,@clid,@enablestatus) ";
                SQLiteCommand cmd = new SQLiteCommand(sql_input1, m_dbConnection);
                cmd.Parameters.AddWithValue("@id", ch.chartID);
                cmd.Parameters.AddWithValue("@chartname", ch.chartName);
                cmd.Parameters.AddWithValue("@cnid", ch.chart_respective_nodeID);
                cmd.Parameters.AddWithValue("@clid", ch.chart_respective_lineID);
                 cmd.Parameters.AddWithValue("@enablestatus", ch.enableChartStatus);
                cmd.ExecuteNonQuery();
            }


            //--Now lest input the node id
            foreach (var ch in nodeInfoPulledForSaving_For_Load)
            {
                string sql_string = "insert into " + nodeTableName + " (chart_respective_nodeID,nodeID,xValue,yValue,temperature_source,humidity_source,name,colorValue,nodeSize,airFlow,lastUpdatedDate) VALUES(@chartid,@id,@xVal,@yVal,@temperature_source,@humidity_source,@name,@colorVal,@node_size_value,@airflow,@lastupdateddate)";
                SQLiteCommand command = new SQLiteCommand(sql_string, m_dbConnection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@chartid", ch.chart_respective_nodeID);
                command.Parameters.AddWithValue("@id", ch.nodeID);
                command.Parameters.AddWithValue("@xVal", ch.xValue.ToString());
                command.Parameters.AddWithValue("@yVal", ch.yValue.ToString());
                //command.Parameters.AddWithValue("@source", ch.source);
                command.Parameters.AddWithValue("@temperature_source", ch.temperature_source);
                command.Parameters.AddWithValue("@humidity_source", ch.humidity_source);
                command.Parameters.AddWithValue("@name", ch.name);
                   //command.Parameters.AddWithValue("@label", ch.label);
                command.Parameters.AddWithValue("@colorVal", ch.colorValue);
                     //command.Parameters.AddWithValue("@text", ch.showTextItem);
                command.Parameters.AddWithValue("@node_size_value", ch.nodeSize);
                command.Parameters.AddWithValue("@airflow", ch.airFlow);
                command.Parameters.AddWithValue("@lastupdateddate", ch.lastUpdatedDate);
                command.ExecuteNonQuery();
            }


            //--Now lets input the line value

            foreach (var ch in lineInfoPulledForSaving_For_Load)
            {
                string sql_string = "insert into  " + lineTableName + "(chart_respective_lineID,lineID,prevNodeId,nextNodeId,lineColorValue,lineSeriesId,thickness,name,status) VALUES(@chartid,@id,@pn,@nn,@lc,@ls,@thicknessValue,@lnName,@lnStatus)";
                SQLiteCommand command = new SQLiteCommand(sql_string, m_dbConnection);
                command.CommandType = CommandType.Text;
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@chartid", ch.chart_respective_lineID);
                command.Parameters.AddWithValue("@id", ch.lineID);
                command.Parameters.AddWithValue("@pn", ch.prevNodeID);
                command.Parameters.AddWithValue("@nn", ch.nextNodeID);
                command.Parameters.AddWithValue("@lc", ch.lineColorValue);
                command.Parameters.AddWithValue("@ls", ch.lineSeriesID);
                command.Parameters.AddWithValue("@thicknessValue", ch.thickness);
                command.Parameters.AddWithValue("@lnName", ch.name);
                command.Parameters.AddWithValue("@lnStatus", ch.status);
                command.ExecuteNonQuery();

                // command.ExecuteNonQuery();
            }


            //--This one is for device input  
            foreach (var ch in deviceInfoPulledForSaving_For_Load)
            {
                string sql_string = "insert into  " + tableNameDevice + "(nodeID,device_instanceID_for_param1,IP_for_param1,device_instanceID_for_param2,IP_for_param2,param1ID,param2ID,param1_info,param2_info,param1_identifier_type,param2_identifier_type) VALUES(@id,@instanceID1,@IP1,@instanceID2,@IP2,@param1,@param2,@param1info, @param2info, @param1_iden_type, @param2_iden_type)";
                SQLiteCommand command = new SQLiteCommand(sql_string, m_dbConnection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@id", ch.nodeID);
                command.Parameters.AddWithValue("@instanceID1", ch.device_instance_id_for_param1);
                command.Parameters.AddWithValue("@IP1", ch.ip_for_param1);
                command.Parameters.AddWithValue("@instanceID2", ch.device_instance_id_for_param2);
                command.Parameters.AddWithValue("@IP2", ch.ip_for_param2);
                command.Parameters.AddWithValue("@param1", ch.param1id);
                command.Parameters.AddWithValue("@param2", ch.param2id);
                command.Parameters.AddWithValue("@param1info", ch.param1info);
                command.Parameters.AddWithValue("@param2info", ch.param2info);
                command.Parameters.AddWithValue("@param1_iden_type", ch.param1_id_type);
                command.Parameters.AddWithValue("@param2_iden_type", ch.param2_id_type);
                command.ExecuteNonQuery();
            }



            //---Now for the comfort zone setting i guess... :)
            foreach (var ch in comfortZoneInforForEachChartForSaving_For_Load)
            {
                string sql_string = "insert into " + tableForComfortZoneSetting + "(chartID,comfort_zone_ID,status) VALUES(@chartid,@comfortzoneid,@status)";
                SQLiteCommand command = new SQLiteCommand(sql_string, m_dbConnection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@chartid", ch.chartid);
                command.Parameters.AddWithValue("@comfortzoneid", ch.comfortzoneid);
                command.Parameters.AddWithValue("@status", ch.status);
                command.ExecuteNonQuery();
            }


            //--Information about detail comfortzone

            foreach (var ch in ComfortZonesDetailForSaving_For_Load)
            {

                string sql_string = "insert into " + tableForCF_Detail + "(id,name,min_temp,max_temp,min_hum,max_hum,colorValue) VALUES(@id,@name,@min_t,@max_t,@min_h,@max_h,@color)";
                SQLiteCommand command = new SQLiteCommand(sql_string, m_dbConnection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@id", ch.id);
                command.Parameters.AddWithValue("@name", ch.name);
                command.Parameters.AddWithValue("@min_t", ch.min_temp.ToString());
                command.Parameters.AddWithValue("@max_t", ch.max_temp.ToString());
                command.Parameters.AddWithValue("@min_h", ch.min_hum.ToString());
                command.Parameters.AddWithValue("@max_h", ch.max_hum.ToString());
                command.Parameters.AddWithValue("@color", ColorTranslator.ToHtml(ch.colorValue));
                command.ExecuteNonQuery();
        
            }


            foreach (var ch in mixNodeList_For_Load)
            {
                string sql_input1x = "insert into  " + tableMixNode + " (chartID,nodeID,previousNodeID,nextNodeID) VALUES(@chartid,@nodeid,@cnid,@clid) ";
                SQLiteCommand cmdx = new SQLiteCommand(sql_input1x, m_dbConnection);
                cmdx.Parameters.AddWithValue("@chartid", ch.ChartID);
                cmdx.Parameters.AddWithValue("@nodeid", ch.nodeID);
                cmdx.Parameters.AddWithValue("@cnid", ch.previousNodeID);
                cmdx.Parameters.AddWithValue("@clid", ch.nextNodeID);
                cmdx.ExecuteNonQuery();
            }

            }//cLOSE OF USING

        }
Form1_main