public void InsertUpdateFromTemperatureDeviceSelectionToDBOnlyTempertureUpdate(string nodeid, string temp_deviceInstanceID, string temp_ip, string temp_param1id, string temp_param1info, string temp_param1type)
{
string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string databaseFile = databasePath + @"\db_psychrometric_project.s3db";
string connString = @"Data Source=" + databaseFile + ";Version=3;";
string tableNameDevice = "tbl_" + selectedBuildingList[0].BuildingName + "_device_info_for_node";//currentNodeTableFromDB;
//checking if the data is present or not
SQLiteDataReader reader = null;
string queryString = "SELECT * from " + tableNameDevice + " WHERE nodeID = @id";
bool flag = false;
using (SQLiteConnection cxn = new SQLiteConnection(connString))
{
cxn.Open();
SQLiteCommand command = new SQLiteCommand(queryString, cxn);
command.Parameters.AddWithValue("@id", nodeid);//This is the group id that is used to identify each node
reader = command.ExecuteReader();
while (reader.Read())
{
if (reader["nodeID"].ToString() != "")
{
flag = true;
}
} //Close of while
} //Close of using
if (flag == false)
{
//insert the value
using (SQLiteConnection connection = new SQLiteConnection(connString))
{
connection.Open();
//SQLiteDataReader reader = null;
// MessageBox.Show("Insert the node value flag = false wala and id = "+nodeid);
string sql_string = "insert into " + tableNameDevice + "(nodeID,device_instanceID_for_param1,device_instanceID_for_param2,IP_for_param1,IP_for_param2,param1ID,param2ID,param1_info,param2_info,param1_identifier_type,param2_identifier_type) VALUES(@id,@instanceIDparam1,@deviceInstanceParam2,@IP_param1,@IP_param2,@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", nodeid);
command.Parameters.AddWithValue("@instanceIDparam1", temp_deviceInstanceID);
command.Parameters.AddWithValue("@deviceInstanceParam2", "");//Insert empty value
command.Parameters.AddWithValue("@IP_param1", temp_ip);
command.Parameters.AddWithValue("@IP_param2", "");//Insert empty value
command.Parameters.AddWithValue("@param1", temp_param1id);
command.Parameters.AddWithValue("@param2", "");
command.Parameters.AddWithValue("@param1info", temp_param1info);
command.Parameters.AddWithValue("@param2info", "");
command.Parameters.AddWithValue("@param1_iden_type", temp_param1type);
command.Parameters.AddWithValue("@param2_iden_type", "");
command.ExecuteNonQuery();
}
}
else
{
//Update the value
using (SQLiteConnection connection = new SQLiteConnection(connString))
{
connection.Open();
//SQLiteDataReader reader = null;
// MessageBox.Show("Update mechanism the node value flag = true wala,id = "+nodeid);
string sql_string = "UPDATE " + tableNameDevice + " SET device_instanceID_for_param1 = @instanceID,IP_for_param1 =@IP ,param1ID = @param1 ,param1_info = @param1info,param1_identifier_type= @param1_iden_type where nodeID = @id ";
SQLiteCommand command = new SQLiteCommand(sql_string, connection);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@id", nodeid);
command.Parameters.AddWithValue("@instanceID", temp_deviceInstanceID);
command.Parameters.AddWithValue("@IP", temp_ip);
command.Parameters.AddWithValue("@param1", temp_param1id);
// command.Parameters.AddWithValue("@param2", param2id);
command.Parameters.AddWithValue("@param1info", temp_param1info);
// command.Parameters.AddWithValue("@param2info", param2info);
command.Parameters.AddWithValue("@param1_iden_type", temp_param1type);
// command.Parameters.AddWithValue("@param2_iden_type", param2type);
command.ExecuteNonQuery();
}
}
}