WFA_psychometric_chart.Form1_main.InsertForSavingConfiguration C# (CSharp) Method

InsertForSavingConfiguration() public method

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

            //--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)
            {
                sql_input1 = "INSERT INTO "+ chartTableName + " (chartID,chartName,chart_respective_nodeID,chart_respective_lineID,enableChartStatus) VALUES(@id,@chartname,@cnid,@clid,@enableChartSt) ";
                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("@enableChartSt", ch.enableChartStatus);
                    cmd.ExecuteNonQuery();
            }


            //--Now lest input the node id
            foreach (var ch in nodeInfoPulledForSaving)
            {
                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,@tempsource,@humsource,@name,@colorVal,@node_size_value,@airflow,@lastUpdatedValue)";
                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("@tempsource", ch.temperature_source);
                    command.Parameters.AddWithValue("@humsource", 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("@lastUpdatedValue", ch.lastUpdatedDate);
                    command.ExecuteNonQuery();
            }


            //--Now lets input the line value

            foreach (var ch in lineInfoPulledForSaving)
            {
                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)
            {
            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,@instanceID_param1,@IP_param1,@instanceID_param2,@IP_param2,@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("@instanceID_param1", ch.device_instance_id_for_param1);
            command.Parameters.AddWithValue("@IP_param1",ch.ip_for_param1);
            command.Parameters.AddWithValue("@instanceID_param2", ch.device_instance_id_for_param2);
            command.Parameters.AddWithValue("@IP_param2", 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)
            {
                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)
            {
             
                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();



            }

                //================MixNodeInfo=====================//
                foreach (var ch in mixNodeInfoListForSaveConfiguration)
                {

                    string sql_string1 = "insert into " + tableForMixNode + "(chartID,nodeID,previousNodeID,nextNodeID) VALUES(@chartid,@nodeid,@prevnodeid,@nextnodeid)";
                    SQLiteCommand command = new SQLiteCommand(sql_string1, m_dbConnection);
                    command.CommandType = CommandType.Text;

                    command.Parameters.AddWithValue("@chartid", ch.ChartID);
                    command.Parameters.AddWithValue("@nodeid", ch.nodeID);
                    command.Parameters.AddWithValue("@prevnodeid", ch.previousNodeID.ToString());
                    command.Parameters.AddWithValue("@nextnodeid", ch.nextNodeID.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();



                }


            } //Close of using




        }
Form1_main