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)

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

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

IDcentralina = 'ID0079';
DTcatena = 'DT0120';
date = '2021-10-07';
comando = ['delete from ELABDATADISP where UnitName = ''' IDcentralina ...
    ''' and ToolNameID = ''' DTcatena ''' and EventDate >= ''' date ''' '];

curs = exec(conn,comando);
close(conn)
disp('Fatto')

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

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

IDcentralina = 'ID0063';
DTcatena = 'DT0103';
date = '2021-10-18';
time = '00:00:01';

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

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

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

disp('Fine!')

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

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

DTcatena = 'DT0046';
IDcentralina = 'ID0150';
comando = ['delete from ELABDATADISP where ToolNameID = ''' DTcatena ''' and UnitName = ''' IDcentralina ''' '];

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

disp('Fine!')

%% 3
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);

IDcentralina = 'ID0026';
DTcatena = 'DT0042';
date1 = '2019-02-20';
date2 = '2019-05-13';
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