DTcatena = input('Digitare il nome della catena: ','s');

dbname = 'ase_lar';
username = 'matlab';
password = 'Ase@2014';
driver = 'com.mysql.jdbc.Driver';
dburl = ['jdbc:mysql://160.78.21.55:3306/' dbname];
tablename = 'ELABDATADISP';
colnames = {'ToolNameID','NodeNum','EventDate','EventTime','XShift','YShift'};
% javaclasspath('C:\Program Files\MATLAB\R2008a\java\mysql-connector-java-3.1.14-bin.jar');
conn = database(dbname, username, password, driver, dburl);

comando = ['delete from ELABDATADISP where ToolNameID = ''' DTcatena ''''];
curs = exec(conn,comando);
close(conn)

%% 
% dbname = 'ase_lar';
% username = 'matlab';
% password = 'Ase@2014';
% driver = 'com.mysql.jdbc.Driver';
% dburl = ['jdbc:mysql://160.78.21.55:3306/' dbname];
% 
% conn = database(dbname, username, password, driver, dburl);
% 
% DTcatena = 'DT0094';
% date = '2019-07-02';
% comando = ['delete from ELABDATADISP where ToolNameID = ''' DTcatena ''' and EventDate >= ''' date ''''];
% 
% curs = exec(conn,comando);
% close(conn)
% disp('Fatto')

%% 1 Cancello dati prima della data X di un determinato nodo
dbname = 'ase_lar';
username = 'matlab';
password = 'Ase@2014';
driver = 'com.mysql.jdbc.Driver';
dburl = ['jdbc:mysql://212.237.30.90:3306/' dbname];

conn = database(dbname, username, password, driver, dburl);

IDcentralina = 'ID0243';
DTcatena = 'DT0252';
date = '2023-07-24';
NodeNum = '10';

comando = ['delete from ELABDATADISP where UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena...
    ''' and EventDate <= ''' date ''' and NodeNum = ''' NodeNum ''''];

curs = exec(conn,comando);
close(conn)

disp('Fine!')

%% 2 Cancello dati alla data X prima dell'ora Y di un determinato nodo
dbname = 'ase_lar';
username = 'matlab';
password = 'Ase@2014';
driver = 'com.mysql.jdbc.Driver';
dburl = ['jdbc:mysql://212.237.30.90:3306/' dbname];

conn = database(dbname, username, password, driver, dburl);

IDcentralina = 'ID0239';
DTcatena = 'DT0003';
date = '2023-07-24';
time = '11:40:00';
NodeNum = '4';

comando = ['delete from ELABDATADISP where UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena...
    ''' and EventDate = ''' date ''' and EventTime <= ''' time ''' and NodeNum = ''' NodeNum ''''];

curs = exec(conn,comando);
close(conn)

disp('Fine!')

%% Tempo
dbname = 'ase_lar';
username = 'matlab';
password = 'Ase@2014';
driver = 'com.mysql.jdbc.Driver';
dburl = ['jdbc:mysql://212.237.30.90:3306/' dbname];

conn = database(dbname, username, password, driver, dburl);

IDcentralina = 'ID0226';
DTcatena = 'DT0244';
date = '2023-07-25';
time = '12:00:00';

comando = ['delete from ELABDATADISP where UnitName = ''' IDcentralina ''' and ToolNameID = ''' ...
    DTcatena ''' and EventDate = ''' date ''' and EventTime >= ''' time ''''];

curs = exec(conn,comando);
close(conn)

disp('Fine!')

%% 2 Cancello tutti i dati
dbname = 'ase_lar';
username = 'matlab';
password = 'Ase@2014';
driver = 'com.mysql.jdbc.Driver';
dburl = ['jdbc:mysql://212.237.30.90:3306/' dbname];

conn = database(dbname, username, password, driver, dburl);

DTcatena = '13489-S07';
IDcentralina = 'TEPBA';
comando = ['delete from ELABDATADISP where ToolNameID = ''' DTcatena ''' and UnitName = ''' IDcentralina ''' '];

curs = exec(conn,comando);
close(conn)

disp('Fine!')

% TEPBA-13489-S07	


%% 3 Cancello dati di un intervallo temporale
dbname = 'ase_lar';
username = 'matlab';
password = 'Ase@2014';
driver = 'com.mysql.jdbc.Driver';
dburl = ['jdbc:mysql://212.237.30.90:3306/' dbname];

conn = database(dbname, username, password, driver, dburl);

IDcentralina = 'ID0236';
DTcatena = 'DT0177';
date1 = '2023-07-31';
date2 = '2023-08-27';
comando = ['delete from ELABDATADISP where ToolNameID = ''' DTcatena ''' and Unitname = '''...
    IDcentralina ''' and EventDate >= ''' date1 ''' and EventDate <= ''' date2 ''' '];

curs = exec(conn,comando);
close(conn)

disp('Fine!')

%% 4
INI = 1;
for i = INI:INI+6
    DatiInPlaceLink(1,i) = cellstr(num2str(DatiRaw(end,i+1)));
end

INI = 1;
for i = INI:INI+5
    DatiInPlaceLinkHR(1,i) = cellstr(num2str(DatiRaw(end,i+1)));
end