public void InsertNodeInfoToDB(string id, double xVal, double yVal, string source, string name, string label, Color colorValue, string showItemText, int nodeSizeValue, string deviceinstance, string deviceip, string param1id, string param2id, string param1info, string param2info, string param1type, string param2type)
{
//This is the name of the table that stores the node information...
string tableName = "tbl_" + selectedBuildingList[0].BuildingName + "_node_value";//currentNodeTableFromDB;
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 sql_string = "insert into " + tableName + "(chart_respective_nodeID,nodeID,xValue,yValue,source,name,label,colorValue,showTextItem,nodeSize) VALUES(@chartid,@id,@xVal,@yVal,@source,@name,@label,@colorVal,@text,@node_size_value)";
SQLiteCommand command = new SQLiteCommand(sql_string, connection);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@chartid", chartDetailList[indexForWhichChartIsSelected].chart_respective_nodeID);
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@xVal", xVal.ToString());
command.Parameters.AddWithValue("@yVal", yVal.ToString());
command.Parameters.AddWithValue("@source", source);
command.Parameters.AddWithValue("@name", name);
command.Parameters.AddWithValue("@label", label);
command.Parameters.AddWithValue("@colorVal", ColorTranslator.ToHtml(colorValue));
command.Parameters.AddWithValue("@text", showItemText);
command.Parameters.AddWithValue("@node_size_value", nodeSizeValue);
command.ExecuteNonQuery();
}
//If we have device we need to store the device info as well
if (source == "Device")
{
// MessageBox.Show("param2 info" + device_param2_info_for_node);
//Device is selected so insert devcie to corresponding able
string tableNameDevice = "tbl_" + selectedBuildingList[0].BuildingName + "_device_info_for_node";//currentNodeTableFromDB;
using (SQLiteConnection connection = new SQLiteConnection(connString))
{
connection.Open();
//SQLiteDataReader reader = null;
string sql_string = "insert into " + tableNameDevice + "(nodeID,device_instanceID,IP,param1ID,param2ID,param1_info,param2_info,param1_identifier_type,param2_identifier_type) VALUES(@id,@instanceID,@IP,@param1,@param2,@param1info, @param2info, @param1_iden_type, @param2_iden_type)";
SQLiteCommand command = new SQLiteCommand(sql_string, connection);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@instanceID", deviceinstance);
command.Parameters.AddWithValue("@IP", deviceip);
command.Parameters.AddWithValue("@param1", param1id);
command.Parameters.AddWithValue("@param2", param2id);
command.Parameters.AddWithValue("@param1info", param1info);
command.Parameters.AddWithValue("@param2info", param2info);
command.Parameters.AddWithValue("@param1_iden_type", param1type);
command.Parameters.AddWithValue("@param2_iden_type", param2type);
//MessageBox.Show("SQL = " + sql_string);
//MessageBox.Show("selected value = " + cb_station_names.SelectedItem.ToString());
command.ExecuteNonQuery();
}
}
}//--close of insertnodeinfotodb fxn