• Non ci sono risultati.

Appendice 1: codice dell’applicazione

N/A
N/A
Protected

Academic year: 2021

Condividi "Appendice 1: codice dell’applicazione"

Copied!
37
0
0

Testo completo

(1)

86

Appendice 1: codice dell’applicazione

App.js

var win = Ti.UI.createWindow({

backgroundColor : '#085dad', layout: 'vertical' }); win.addEventListener('open',function(e){ user.value = Ti.App.Properties.getString('username',''); pass.value = Ti.App.Properties.getString('password',''); var act = Ti.App.Properties.getBool('Active','');

if (act == '' || act == false)

save.backgroundImage = '/calendar_notdone.png'; else save.backgroundImage = '/calendar_done.png'; }); Ti.Database.install('/timesheet.sqlite','timesheet'); Ti.App.Properties.setBool('Update',false);

var name = Ti.UI.createLabel({ text: 'Mobile Timesheet', top: '10%',

textAlign:'center', color: 'white',

font: {fontFamily: 'Roadshow', fontSize: '35dp'} });

var user = Ti.UI.createTextField({ top: '20%',

hintText: 'User', width: '80%' });

var pass = Ti.UI.createTextField({ hintText: 'Password', width: '80%', passwordMask: true }); user.addEventListener('change',function(e){ save.backgroundImage = '/calendar_notdone.png'; Ti.App.Properties.setBool('Active',false); }); pass.addEventListener('change',function(e){ save.backgroundImage = '/calendar_notdone.png'; Ti.App.Properties.setBool('Active',false); });

(2)

87

var saveView = Ti.UI.createView({

height: '26dp', top: 0

})

var labelSave = Ti.UI.createLabel({ text: 'Salva password', color: 'white',

left: '11%',

font: {fontSize: '20dp'} });

var save = Ti.UI.createButton({ height: '18dp', width: '18dp', left: '59%', backgroundImage: '/calendar_notdone.png', }); saveView.add(labelSave); saveView.add(save); save.addEventListener('click',function(e){ if ((Ti.App.Properties.getBool('Active','')) == '' || (Ti.App.Properties.getBool('Active','')) == false){ save.backgroundImage = '/calendar_done.png'; Ti.App.Properties.setString('username', user.value); Ti.App.Properties.setString('password', pass.value); Ti.App.Properties.setBool('Active',true); } else { save.backgroundImage = '/calendar_notdone.png'; Ti.App.Properties.setString('username', ''); Ti.App.Properties.setString('password', ''); Ti.App.Properties.setBool('Active',false); } });

var title = Ti.UI.createLabel({ text: 'Accedi',

color: '#085dad',

font: {fontSize: '20dp', fontWeigth: 'bold'} });

var submit = Ti.UI.createView({ backgroundColor: '#c6e819', top: '5%', height: '35dp', width: '80%' }); submit.add(title);

var activityIndicator = Ti.UI.createActivityIndicator({ font : {fontSize : '20dp'},

message : ' Accesso in corso...', top : '7dp',

(3)

88

});

submit.addEventListener('click',function(e){

var db = Ti.Database.open('timesheet');

var RS = db.execute('SELECT id_user FROM device WHERE id_user = ? AND pass = ?', user.value, pass.value); if(RS.isValidRow()){ save.enabled = false; submit.enabled = false; activityIndicator.show(); setTimeout(function() { activityIndicator.hide(); }, 500);

var wincal = Ti.UI.createWindow({ backgroundColor : 'black', url : 'calendar.js',

modal : true, //heavyweight win

}).open();

}

else{

var viewAlert = Ti.UI.createView({}); var labelAlert = Ti.UI.createLabel({

text : 'User e/o password errati', textAlign : 'center', height : '50dp', color : '#00c4bc', font : {fontSize: '20dp'} }); viewAlert.add(labelAlert);

var dialog = Ti.UI.createAlertDialog({ title : 'Errore accesso',

androidView : viewAlert, ok : 'Ok' }).show(); } db.close(); }); win.add(name); win.add(user); win.add(pass); win.add(saveView); win.add(submit); win.add(activityIndicator);

(4)

89

win.addEventListener('focus',function(e){ submit.enabled = true; save.enabled = true; if ((Ti.App.Properties.getBool('Update')) == true){ Ti.App.Properties.setBool('Update',false); user.value = Ti.App.Properties.getString('username',''); pass.value = Ti.App.Properties.getString('password',''); } }); win.open();

Calendar.js

Ti.include('soap.js');

var wincal = Ti.UI.currentWindow; var win = Ti.UI.currentWindow;

//Ogni finestra corrisponde ad'una attività, per effettuare il logout chiudo tutte le attività tranne la quella del login

var activityC = Titanium.Android.currentActivity;

activityC.onCreateOptionsMenu = function(e) {

var menu = e.menu;

var menuItem = menu.add({ title : "Sincronizza" });

menuItem.addEventListener("click", function(e) {

var db = Ti.Database.open('timesheet'); var body = "";

if (Ti.Network.online == true){ var tods = [];

//Seleziona i dati da sincronizzare

var RS = db.execute('SELECT id_device, id_user, id_ods, nop, day, hourstd, hourot, hourholy, hourtravelar, hourtravel, km, typecar, notes, sync, state FROM hours WHERE sync = ?', "1970-01-01");

while(RS.isValidRow()){

var dateSync = new Date();

var anno = dateSync.getFullYear(); var mese = dateSync.getMonth(); var giorno = dateSync.getDate(); if (giorno < 10)

giorno = '0' + giorno; var m = mese + 1;

if (m < 10)

(5)

90

var newday2 = anno + "-" + m + "-" + giorno; body = body + '<TABLEHOURS>' +

'<ID_DISPOSITIVO>'+ RS.fieldByName('id_device') +'</ID_DISPOSITIVO>' + '<ZPERNR>'+ RS.fieldByName('id_user') +'</ZPERNR>' +

'<AUFNR>'+ RS.fieldByName('id_ods') +'</AUFNR>' +

'<VORNR>'+ RS.fieldByName('nop') +'</VORNR>' + '<DATA_RIF>'+ RS.fieldByName('day') +'</DATA_RIF>' +

'<ORE_STAND>'+ RS.fieldByName('hourstd') +'</ORE_STAND>'+ '<ORE_STRAORD>'+ RS.fieldByName('hourot') +'</ORE_STRAORD>'+

'<ORE_STRAORD_CONT>'+ "0" +'</ORE_STRAORD_CONT>' +

'<ORE_FEST>'+ RS.fieldByName('hourholy') +'</ORE_FEST>' + '<ORE_VIAGGIO_AR>'+ RS.fieldByName('hourtravelar') + /ORE_VIAGGIO_AR>'+ '<ORE_VIAGGIO_CANT>'+ RS.fieldByName('hourtravel') +'</ORE_VIAGGIO_CANT>'+ '<KM>'+ RS.fieldByName('km') +'</KM>' +

'<TIPO_AUTO>'+ RS.fieldByName('typecar') +'</TIPO_AUTO>' +

'<NOTE>'+ RS.fieldByName('notes') +'</NOTE>' + '<SYNCH_DATE>'+ newday2 +'</SYNCH_DATE>' +

'<STATO_RECORD>'+ RS.fieldByName('state') +'</STATO_RECORD>' + '</TABLEHOURS>'; tods.push(RS.fieldByName('id_ods')); RS.next(); } if(body != ""){

//Chiamata al web service

soapCall(body,tods);

Ti.API.info("Ecco il corpo " + body); }

else{

var dialog = Ti.UI.createAlertDialog({ title : 'Sincronizzazione non

effettuata', message : 'Nessun dato da

sincronizzare', ok : 'Ok' }).show(); } } else{

//Connessione non attiva

var dialog = Ti.UI.createAlertDialog({ title : 'Connessione non attiva ',

message : 'E\'necessaria una connessione internet per sincronizzare i dati', ok : 'Ok' }).show(); } db.close(); }); };

(6)

91

var topBar = Ti.UI.createView({

top: 0,

height: '32dp',

backgroundColor: '#085dad' });

var botBar = Ti.UI.createView({ bottom: 0,

height: '30dp',

backgroundColor: '#085dad' });

var logout = Ti.UI.createView({ width: '25dp',

height: '28dp', right: '2dp',

backgroundImage : '/logout.png' });

var dateLabel = Ti.UI.createLabel({ left: '7dp', color : 'white', font : {fontSize: '20dp'} }); topBar.add(logout); botBar.add(dateLabel); logout.addEventListener('click',function(e){ Ti.App.Properties.setBool('Update',true); var dialog = Ti.UI.createAlertDialog({

title: 'Chiusura dell\'applicazione', message: 'Sei sicuro di voler uscire?', buttonNames: ['Si','No'], }); dialog.addEventListener('click',function(e){ if(e.index === 0){ activityC.finish(); } }); dialog.show(); }); // Previous Button

var prevMonth = Ti.UI.createButton({ top: '7dp', left : '5%', width : '35dp', height : '36dp', title : '<' });

(7)

92

// Next Button

var nextMonth = Ti.UI.createButton({ top: '7dp', right : '5%', width : '35dp', height : '36dp', title : '>' }); // Month Title

var monthTitle = Ti.UI.createLabel({ top: '4dp', width: '70%', textAlign : 'center', color: '#c6e819', font : { fontSize : '28dp', fontWeight : 'bold' } }); // Tool Bar

var toolBar = Ti.UI.createView({ top : '32dp', left: 0, width: '100%', height: '73dp', backgroundColor : '#2ac2e8', layout : 'vertical' });

// Tool Bar - View which contain Title Prev. & Next Button

var toolBarTitle = Ti.UI.createView({ height: '45dp'

});

toolBarTitle.add(prevMonth); toolBarTitle.add(monthTitle); toolBarTitle.add(nextMonth);

// Tool Bar - Day's

var toolBarDays = Ti.UI.createView({ height: '28dp', width: '103%', layout : 'horizontal', }); toolBarDays.sunday = Ti.UI.createLabel({ height: '27dp', text : 'Dom', width: '14.2%', left: '1dp', textAlign : 'center', font : { fontSize : '16dp', fontWeight : 'bold' }, color : 'white' });

(8)

93

toolBarDays.monday = Ti.UI.createLabel({ height: '27dp', text : 'Lun', width: '14.2%', textAlign : 'center', font : { fontSize : '16dp', fontWeight : 'bold' }, color : 'white' }); toolBarDays.tuesday = Ti.UI.createLabel({ height: '27dp', text : 'Mar', width: '14.2%', textAlign : 'center', font : { fontSize : '16dp', fontWeight : 'bold' }, color : 'white' }); toolBarDays.wednesday = Ti.UI.createLabel({ height: '27dp', text : 'Mer', width: '14.2%', textAlign : 'center', font : { fontSize : '16dp', fontWeight : 'bold' }, color : 'white' }); toolBarDays.thursday = Ti.UI.createLabel({ height: '27dp', text : 'Gio', width: '14.2%', textAlign : 'center', font : { fontSize : '16dp', fontWeight : 'bold' }, color : 'white' }); toolBarDays.friday = Ti.UI.createLabel({ height: '27dp', text : 'Ven', width: '14.2%', textAlign : 'center', font : { fontSize : '16dp', fontWeight : 'bold' }, color : 'white' });

(9)

94

toolBarDays.saturday = Ti.UI.createLabel({ height: '27dp', text : 'Sab', width: '14.2%', textAlign : 'center', font : { fontSize : '16dp', fontWeight : 'bold' }, color : 'white' }); toolBarDays.add(toolBarDays.sunday); toolBarDays.add(toolBarDays.monday); toolBarDays.add(toolBarDays.tuesday); toolBarDays.add(toolBarDays.wednesday); toolBarDays.add(toolBarDays.thursday); toolBarDays.add(toolBarDays.friday); toolBarDays.add(toolBarDays.saturday);

// Adding Tool Bar Title View & Tool Bar Days View

toolBar.add(toolBarTitle); toolBar.add(toolBarDays);

// Function which create day view template

dayView = function(e) {

//Current e day replicati perchè altrimenti se si clicca sull'immagine o in uno spazio vuoto

//della vista del singolo giorno, non invia le informazioni necessarie all'evento del click su una data

var dView = Ti.UI.createView({ current : e.current, text : e.day, width : '14.2%', height : '40dp', backgroundColor : '#FFDCDCDF', });

var dLabel = Ti.UI.createLabel({ current : e.current, text : e.day, color : e.color, font : { fontSize : '15dp', } }); dView.add(dLabel); return dView; };

monthName = function(e) {

switch(e) { case 0:

e = 'Gennaio'; break;

(10)

95

case 1: e = 'Febbraio'; break; case 2: e = 'Marzo'; break; case 3: e = 'Aprile'; break; case 4: e = 'Maggio'; break; case 5: e = 'Giugno'; break; case 6: e = 'Luglio'; break; case 7: e = 'Agosto'; break; case 8: e = 'Settembre'; break; case 9: e = 'Ottobre'; break; case 10: e = 'Novembre'; break; case 11: e = 'Dicembre'; break; }; return e; };

// Calendar Main Function

var calView = function(a, b, c) {

var db = Ti.Database.open('timesheet'); var nameOfMonth = monthName(b);

//create main calendar view

var mainView = Ti.UI.createView({ layout : 'horizontal', width: '103%',

top : '105dp' });

//set the time

var daysInMonth = 32 - new Date(a, b, 32).getDate(); var dayOfMonth = new Date(a, b, c).getDate();

var dayOfWeek = new Date(a, b, 1).getDay();

(11)

96

var daysInNextMonth = (new Date(a,b,daysInMonth).getDay()) - 6;

//set initial day number

var dayNumber = daysInLastMonth - dayOfWeek + 1;

//get last month's days - inserimento giorni del mese passato prima quelli del mese corrente

for ( i = 0; i < dayOfWeek; i++) { mainView.add(new dayView({

day : dayNumber, color : '#8e959f',

current : 'no', //indica se sono giorni del mese corrente o meno dayOfMonth : '', background: '' })); dayNumber++; };

//reset dei giorni del mese corrente

dayNumber = 1;

//giorno del mese da 1 a 9 con 0 davanti per ricerca nel db

var month = b + 1; if (month < 10) {

month = '0' + month; }

var date;

//get this month's days

for (i = 0; i < daysInMonth; i++) { if (dayNumber < 10) {

var d = '0' + dayNumber;

date = a + '-' + month + '-' + d; }

else

date = a + '-' + month + '-' + dayNumber;

var newDay = new dayView({ day : dayNumber, color : '#3a4756', current : 'yes', dayOfMonth : dayOfMonth, background : '' }); mainView.add(newDay);

//giorno corrente di un colore differente

if (setDate.getMonth() == b && newDay.text == dayOfMonth) {

newDay.color = '#0c98ab'; var oldDay = newDay; }

dayNumber++; };

(12)

97

//get remaining month's days

for ( i = 0; i > daysInNextMonth; i-- ) { mainView.add(new dayView({ day : dayNumber, color : '#8e959f', current : 'no', dayOfMonth : '', background: '' })); dayNumber++; };

//click su una data

mainView.addEventListener('click', function(e) {

if (e.source.current == 'yes') { thisCalendarView.visible = false; prevMonth.enabled = false; nextMonth.enabled = false; var d = e.source.text; if (e.source.text < 10){ d = '0' + e.source.text; }

var dayfind = a + '-' + month + '-' + d; var today = d + ' ' + monthName(b) + ' ' + a; var dataclick = new Date(a,b,d);

var milliclick = dataclick.getTime(); var activityIndicator2 = Ti.UI.createActivityIndicator({ top: '40%', style : Titanium.UI.ActivityIndicatorStyle.BIG, }); wincal.add(activityIndicator2); activityIndicator2.show(); setTimeout(function() { activityIndicator2.hide(); }, 500);

var winfind = Ti.UI.createWindow({ backgroundColor : 'white', url : 'find.js',

modal : true,

windowSoftInputMode : Ti.UI.Android.SOFT_INPUT_ADJUST_PAN, day : dayfind,//formato necessario per la ricerca sul db

today: today,//formato da inserire nella barra in basso

milliclick: milliclick, activityC: activityC, }).open(); } }); return mainView; };

(13)

98

// what's today's date?

var setDate = new Date(); a = setDate.getFullYear(); b = setDate.getMonth(); c = setDate.getDate();

//costruisce le varie viste del calendario

var prevCalendarView = null; if (b == 0) {

prevCalendarView = calView(a - 1, 11, c); } else {

prevCalendarView = calView(a, b - 1, c); }

var nextCalendarView = null; if (b == 11) {

nextCalendarView = calView(a + 1, 0, c); } else {

nextCalendarView = calView(a, b + 1, c); }

var thisCalendarView = calView(a, b, c);

monthTitle.text = monthName(b) + ' ' + a;

dateLabel.text = 'Oggi: ' + c + ' ' + monthName(b) + ' ' + a;

wincal.add(topBar); wincal.add(botBar); wincal.add(toolBar);

wincal.add(thisCalendarView);

var activityIndicator = Ti.UI.createActivityIndicator({ height: '55dp', width: '150dp', font : { fontSize : '22dp' }, message : ' Loading...', });

var viewIndicator = Ti.UI.createView({}); viewIndicator.add(activityIndicator);

// Next Month Click Event

nextMonth.addEventListener('click', function() {

var dialog = Ti.UI.createAlertDialog({ androidView : viewIndicator }); activityIndicator.show(); dialog.show(); setTimeout(function() { dialog.hide();

(14)

99

}, 500); if (b == 11) { b = 0; a++; } else { b++; } wincal.remove(thisCalendarView); prevCalendarView = thisCalendarView; thisCalendarView = nextCalendarView; if (b == 11) { nextCalendarView = calView(a + 1, 0, c); } else { nextCalendarView = calView(a, b + 1, c); } wincal.add(thisCalendarView); monthTitle.text = monthName(b) + ' ' + a; });

// Previous Month Click Event

prevMonth.addEventListener('click', function() {

var dialog = Ti.UI.createAlertDialog({ androidView : viewIndicator }); activityIndicator.show(); dialog.show(); setTimeout(function() { dialog.hide(); }, 500); if (b == 0) { b = 11; a--; } else { b--; } wincal.remove(thisCalendarView); nextCalendarView = thisCalendarView; thisCalendarView = prevCalendarView; if (b == 0) { prevCalendarView = calView(a - 1, 11, c); } else { prevCalendarView = calView(a, b - 1, c); } wincal.add(thisCalendarView); monthTitle.text = monthName(b) + ' ' + a; }); wincal.addEventListener('focus',function(e){ thisCalendarView.visible = true; prevMonth.enabled = true;

(15)

100

nextMonth.enabled = true;

});

wincal.addEventListener('androidback', function(e){

Ti.App.Properties.setBool('Update',true); var dialog = Ti.UI.createAlertDialog({

title: 'Chiusura dell\'applicazione', message: 'Sei sicuro di voler uscire?', buttonNames: ['Si','No'], }); dialog.addEventListener('click',function(e){ if(e.index === 0){ activityC.finish(); } }); dialog.show(); });

Find.js

Ti.include('soap.js');

var winfind = Ti.UI.currentWindow;

var activityF = Titanium.Android.currentActivity;

activityF.onCreateOptionsMenu = function(e) {

var menu = e.menu;

var menuItem = menu.add({ title : "Sincronizza" });

menuItem.addEventListener("click", function(e) {

var db = Ti.Database.open('timesheet'); var body = "";

if (Ti.Network.online == true){ var tods = [];

var RS = db.execute('SELECT id_device, id_user, id_ods, nop, day, hourstd, hourot, hourholy, hourtravelar, hourtravel, km, typecar, notes, sync, state FROM hours WHERE sync = ?', "1970-01-01");

while(RS.isValidRow()){

var dateSync = new Date();

var anno = dateSync.getFullYear(); var mese = dateSync.getMonth(); var giorno = dateSync.getDate(); if (giorno < 10)

(16)

101

var m = mese + 1;

if (m < 10)

m = '0' + m;

var newday2 = anno + "-" + m + "-" + giorno; body = body + '<TABLEHOURS>' +

'<ID_DISPOSITIVO>'+ RS.fieldByName('id_device') +'</ID_DISPOSITIVO>' + '<ZPERNR>'+ RS.fieldByName('id_user') +'</ZPERNR>' +

'<AUFNR>'+ RS.fieldByName('id_ods') +'</AUFNR>' +

'<VORNR>'+ RS.fieldByName('nop') +'</VORNR>' + '<DATA_RIF>'+ RS.fieldByName('day') +'</DATA_RIF>' +

'<ORE_STAND>'+ RS.fieldByName('hourstd') +'</ORE_STAND>'+ '<ORE_STRAORD>'+ RS.fieldByName('hourot') +'</ORE_STRAORD>'+

'<ORE_STRAORD_CONT>'+ "0" +'</ORE_STRAORD_CONT>' +

'<ORE_FEST>'+ RS.fieldByName('hourholy') +'</ORE_FEST>' + '<ORE_VIAGGIO_AR>'+ RS.fieldByName('hourtravelar') + /ORE_VIAGGIO_AR>'+ '<ORE_VIAGGIO_CANT>'+ RS.fieldByName('hourtravel') +'</ORE_VIAGGIO_CANT>'+ '<KM>'+ RS.fieldByName('km') +'</KM>' +

'<TIPO_AUTO>'+ RS.fieldByName('typecar') +'</TIPO_AUTO>' +

'<NOTE>'+ RS.fieldByName('notes') +'</NOTE>' + '<SYNCH_DATE>'+ newday2 +'</SYNCH_DATE>' +

'<STATO_RECORD>'+ RS.fieldByName('state') +'</STATO_RECORD>' + '</TABLEHOURS>'; tods.push(RS.fieldByName('id_ods')); RS.next(); } if(body != ""){ soapCall(body,tods);

Ti.API.info("Ecco il corpo " + body); }

else{

var dialog = Ti.UI.createAlertDialog({ title : 'Sincronizzazione non

effettuata',

message : 'Nessun dato da sincronizzare', ok : 'Ok' }).show(); } } else{

//connessione non attiva

var dialog = Ti.UI.createAlertDialog({ title : 'Connessione non attiva ',

message : 'E\'necessaria una connessione internet per sincronizzare i dati', ok : 'Ok'

}).show(); }

db.close(); });

(17)

102

};

var topBar = Ti.UI.createView({ top: 0,

height: '32dp',

backgroundColor: '#085dad' });

var botBar = Ti.UI.createView({ bottom: 0,

height: '30dp',

backgroundColor: '#085dad' });

var logout = Ti.UI.createView({ width: '25dp',

height: '28dp', right: '2dp',

backgroundImage : '/logout.png' });

var calend = Ti.UI.createView({ top: 0, width: '30dp', height: '28dp', right: '7dp', backgroundImage : '/bluecalendar.png' });

var dateLabel = Ti.UI.createLabel({ left: '7dp', color : 'white', text: winfind.today, font : {fontSize: '20dp'} }); topBar.add(logout); botBar.add(calend); botBar.add(dateLabel); logout.addEventListener('click',function(e){ Ti.App.Properties.setBool('Update',true); var dialog = Ti.UI.createAlertDialog({

title: 'Chiusura dell\'applicazione', message: 'Sei sicuro di voler uscire?', buttonNames: ['Si','No'], }); dialog.addEventListener('click',function(e){ if(e.index === 0){ winfind.activityC.finish(); activityF.finish(); } }); dialog.show(); });

(18)

103

calend.addEventListener('click',function(e){

winfind.close(); });

var textPick = Ti.UI.createTextField({ top : '40dp',

width: '200dp', hintText: 'Ricerca' });

var picker = Ti.UI.createPicker({ top: '88dp'

});

var data = [];

data[0] = Ti.UI.createPickerRow({title:'Rag. Sociale Cliente'}); data[1] = Ti.UI.createPickerRow({title:'Num contratto OdV '}); data[2] = Ti.UI.createPickerRow({title:'Ordine di Acquisto'}); data[3] = Ti.UI.createPickerRow({title:'Descrizione OdS'}); data[4] = Ti.UI.createPickerRow({title:'Posizione'}); data[5] = Ti.UI.createPickerRow({title:'Tipo Attività'}); picker.add(data);

picker.selectionIndicator = true; var buttonPick = Ti.UI.createButton({

top: '137dp', title: 'Trova' }); winfind.add(topBar); winfind.add(botBar) winfind.add(textPick); winfind.add(picker); winfind.add(buttonPick);

var tableheader = Ti.UI.createView({ backgroundColor: '#2ac2e8', height: '40dp',

top: '190dp' });

var labelheader1 = Ti.UI.createLabel({ text:'CLIENTE', color: 'white', left: '4%', font:{ fontSize: '12dp' } });

var labelheader2 = Ti.UI.createLabel({ text:'ORDINE DI SERVIZIO', color: 'white', left: '28%', font:{ fontSize: '12dp' }

(19)

104

});

var labelheader3 = Ti.UI.createLabel({ text:'DESCRIZIONE', color: 'white', left: '70%', font:{ fontSize: '12dp' } }); tableheader.add(labelheader1); tableheader.add(labelheader2); tableheader.add(labelheader3); var table = []; var tabletask = []; var tableods = [];

var tableView = Ti.UI.createTableView({ top: '230dp',

bottom: '30dp',

backgroundColor: 'white', scrollable: true

});

//Aggiunge una riga alla tabella dei risultati

addrow = function (nome, ods, note, color){

var row = Ti.UI.createTableViewRow({ borderColor: 'black', borderWidth: 1, height: Ti.UI.SIZE }); if(color==true) row.backgroundColor = '#b2f0ed'; var text1 = Ti.UI.createLabel({

text: nome, color: 'black', left: '4%', width: '23%', font:{ fontSize: '12dp' } });

var text2 = Ti.UI.createLabel({ text: ods, color: 'black', left: '34%', font:{ fontSize: '12dp' } });

var text3 = Ti.UI.createLabel({ text: note,

(20)

105

color: 'black', left: '70%', width: '27%', font:{ fontSize: '12dp' } }); row.add(text1); row.add(text2); row.add(text3); table.push(row); }

var labelNotFound = Ti.UI.createLabel({

text : 'Nessuna corrispondenza trovata', color : 'black', bottom : '30%', font: {fontSize: '20dp'} }); var RS2; var RS3;

//Costruisce la tabella dei risultati

execDb = function(RS){

var db = Ti.Database.open('timesheet');

//Seleziona tutti i record il cui campo compagnia sia quello indicato (se vuoto li controlla tutti) e poi fa il controllo sulla data se è successiva a quella di inizio attività (startprev)

while (RS.isValidRow()) {

var start = RS.fieldByName('startprev'); if (start != null) {

var parts = start.split("-");

var millidate = new Date(parts[0], parts[1] - 1, parts[2]);

if (millidate.getTime() <= winfind.milliclick) { find = true;

var idods = RS.fieldByName('id_ods'); tableods.push(idods);

} }

RS.next(); }

for( i = 0; i < tableods.length; i++) {

RS2 = db.execute('SELECT company1 FROM customer JOIN ods ON ods.id_cust = customer.id_cust AND ods.id_ods = ?', tableods[i]);

RS3 = db.execute('SELECT text FROM ods_aufk WHERE id_ods = ?', tableods[i]); if (RS2.isValidRow()) {

var company = RS2.fieldByName('company1'); Ti.API.info(company);

(21)

106

if (RS3.isValidRow()) {

var text = RS3.fieldByName('text'); Ti.API.info(text);

}

var color = false;

//verifica se esiste già un record in quella data, se non esiste sicuramente la riga del risultato sarà bianca (nessun inserimento ore)

var RSb = db.execute('SELECT hourstd, hourot, hourholy, hourtravelar, hourtravel FROM hours WHERE id_ods = ? AND day = ?', tableods[i], winfind.day);

if (RSb.isValidRow()){

var hourstd = RSb.fieldByName('hourstd'); var hourot = RSb.fieldByName('hourot'); var hourholy = RSb.fieldByName('hourholy');

var hourtravelar = RSb.fieldByName('hourtravelar'); var hourtravel = RSb.fieldByName('hourtravel');

if (hourstd != '' && hourstd != null) color = true;

else {

if (hourot != '' && hourot != null) color = true;

else {

if (hourholy != '' && hourholy != null) color = true; else { if (hourtravelar != '' && hourtravelar != null) color = true; else { if (hourtravel != '' && hourtravel != null) color = true; } } } } }

addrow(company, tableods[i], text, color); } } closeDb = function(){ if (find) { RS2.close(); RS3.close(); tableView.data = table; winfind.add(tableheader); winfind.add(tableView);

(22)

107

} else { winfind.add(labelNotFound); } } var find; var tp;

buttonPick.addEventListener('click', function(e){

find = false; winfind.remove(labelNotFound); winfind.remove(tableheader); winfind.remove(tableView); if (table != null){ table = []; tableView.data = table; tableods = []; } tp = textPick.value; var db = Ti.Database.open('timesheet'); ){

//recupera i dati per costruire la tabella

switch (picker.getSelectedRow(0).title case 'Rag. Sociale Cliente':{

var RS1 = db.execute('SELECT id_ods, startprev FROM ods JOIN customer ON ods.id_cust = customer.id_cust AND customer.company1 LIKE ? AND ods.status != ? ', '%' + textPick.value + '%', 1);

execDb(RS1); closeDb(); break; }

case 'Num contratto OdV ':{

var RS1 = db.execute('SELECT id_ods, startprev FROM ods WHERE ods.id_odv LIKE ? AND ods.status != ?', '%' + textPick.value + '%', 1);

execDb(RS1); closeDb(); break; }

case 'Ordine di Acquisto':{

var RS1 = db.execute('SELECT id_ods, startprev FROM ods JOIN odv_vbak ON ods.id_odv = odv_vbak.id_odv AND odv_vbak.norder LIKE ? AND ods.status != ?', '%' + textPick.value + '%', 1);

(23)

108

execDb(RS1);

closeDb(); break; }

case 'Descrizione OdS':{

var RS1 = db.execute('SELECT ods.id_ods, startprev FROM ods JOIN ods_aufk ON ods.id_ods = ods_aufk.id_ods AND ods_aufk.text LIKE ? AND ods.status != ?', '%' + textPick.value + '%', 1); execDb(RS1); closeDb(); break; } case 'Posizione':{

var RS1 = db.execute('SELECT id_ods, startprev FROM ods WHERE ods.id_pos LIKE ? AND ods.status != ?', '%' + textPick.value + '%', 1);

execDb(RS1); closeDb(); break; }

case 'Tipo Attività':{

var RS1 = db.execute('SELECT id_ods, startprev FROM ods WHERE

ods.typeactivity LIKE ? AND ods.status != ?', '%' + textPick.value + '%', 1); execDb(RS1); closeDb(); break; } } db.close(); });

//Apre la pagina per inserire le ore

tableView.addEventListener('click', function(e){

tabletask = [];

var db = Ti.Database.open('timesheet');

var RS1 = db.execute('SELECT id_ods, hourstd, hourot, hourholy, hourtravelar, hourtravel, km, typecar, notes FROM hours WHERE id_ods = ? AND day = ?', tableods[e.index], winfind.day);

(24)

109

//Verifico se in quella specifica data sia già stato creato un record, nel caso prendo i valori

if (RS1.isValidRow()) { tabletask.push({ iddevice: "", iduser: "", idorder : RS1.fieldByName('id_ods'), nop: "", day: "", hourstd : RS1.fieldByName('hourstd'), hourot : RS1.fieldByName('hourot'), hourholy : RS1.fieldByName('hourholy'), hourtravelar : RS1.fieldByName('hourtravelar'), hourtravel : RS1.fieldByName('hourtravel'), km : RS1.fieldByName('km'), typecar : RS1.fieldByName('typecar'), notes : RS1.fieldByName('notes'), presente: true }); } else{ Ti.API.info(tableods[e.index]);

//Devo creare un nuovo record

var RS = db.execute('SELECT id_device, id_user, nop FROM ods WHERE id_ods = ?', tableods[e.index]); tabletask.push({ iddevice: RS.fieldByName('id_device'), iduser: RS.fieldByName('id_user'), idorder : tableods[e.index], nop: RS.fieldByName('nop'), day: winfind.day, hourstd : "", hourot : "", hourholy : "", hourtravelar : "", hourtravel : "", km : "", typecar : "", notes : "", presente: false }); } RS1.close(); db.close();

var wintask = Ti.UI.createWindow({ backgroundColor: 'white', url: 'task.js', modal: true, row: tabletask[0], index: e.index, today: winfind.today, activityC: winfind.activityC, activityF: activityF, winf: Ti.UI.currentWindow,

(25)

110

windowSoftInputMode: Ti.UI.Android.SOFT_INPUT_STATE_HIDDEN, windowSoftInputMode : Ti.UI.Android.SOFT_INPUT_ADJUST_PAN, }).open(); });

Task.js

Ti.include('soap.js');

var wintask = Ti.UI.currentWindow; var tabletask = Ti.UI.currentWindow;

var activityT = Titanium.Android.currentActivity;

activityT.onCreateOptionsMenu = function(e) {

var menu = e.menu;

var menuItem = menu.add({ title : "Sincronizza" });

menuItem.addEventListener("click", function(e) {

var db = Ti.Database.open('timesheet'); var body = "";

if (Ti.Network.online == true){ var tods = [];

var RS = db.execute('SELECT id_device, id_user, id_ods, nop, day, hourstd, hourot, hourholy, hourtravelar, hourtravel, km, typecar, notes, sync, state FROM hours WHERE sync = ?', "1970-01-01");

while(RS.isValidRow()){

var dateSync = new Date();

var anno = dateSync.getFullYear(); var mese = dateSync.getMonth(); var giorno = dateSync.getDate(); if (giorno < 10)

giorno = '0' + giorno; var m = mese + 1;

if (m < 10)

m = '0' + m;

var newday2 = anno + "-" + m + "-" + giorno; body = body + '<TABLEHOURS>' + '<ID_DISPOSITIVO>'+ RS.fieldByName('id_device') +'</ID_DISPOSITIVO>' + '<ZPERNR>'+ RS.fieldByName('id_user') +'</ZPERNR>' +

'<AUFNR>'+ RS.fieldByName('id_ods') +'</AUFNR>' +

'<VORNR>'+ RS.fieldByName('nop') +'</VORNR>' + '<DATA_RIF>'+ RS.fieldByName('day') +'</DATA_RIF>' +

'<ORE_STAND>'+ RS.fieldByName('hourstd') +'</ORE_STAND>'+ '<ORE_STRAORD>'+ RS.fieldByName('hourot') +'</ORE_STRAORD>'+

(26)

111

'<ORE_FEST>'+ RS.fieldByName('hourholy') +'</ORE_FEST>' + '<ORE_VIAGGIO_AR>'+ RS.fieldByName('hourtravelar') + /ORE_VIAGGIO_AR>'+ '<ORE_VIAGGIO_CANT>'+ RS.fieldByName('hourtravel') +'</ORE_VIAGGIO_CANT>'+ '<KM>'+ RS.fieldByName('km') +'</KM>' +

'<TIPO_AUTO>'+ RS.fieldByName('typecar') +'</TIPO_AUTO>' +

'<NOTE>'+ RS.fieldByName('notes') +'</NOTE>' + '<SYNCH_DATE>'+ newday2 +'</SYNCH_DATE>' +

'<STATO_RECORD>'+ RS.fieldByName('state') +'</STATO_RECORD>' + '</TABLEHOURS>'; tods.push(RS.fieldByName('id_ods')); RS.next(); } if(body != ""){ soapCall(body,tods);

Ti.API.info("Ecco il corpo " + body); }

else{

var dialog = Ti.UI.createAlertDialog({ title : 'Sincronizzazione non effettuata', message : 'Nessun dato da sincronizzare', ok : 'Ok'

}).show(); }

} else{

//connessione non attiva

var dialog = Ti.UI.createAlertDialog({ title : 'Connessione non attiva ',

message : 'E\'necessaria una connessione internet per sincronizzare i dati', ok : 'Ok' }).show(); } db.close(); }); };

var scrolltask = Ti.UI.createScrollView({ top: '32dp',

bottom: '30dp', layout: 'vertical' });

var topBar = Ti.UI.createView({ top : 0,

height : '32dp',

backgroundColor : '#085dad' });

var botBar = Ti.UI.createView({ bottom : 0,

(27)

112

backgroundColor : '#085dad'

});

var logout = Ti.UI.createView({ width: '25dp',

height: '28dp', right: '2dp',

backgroundImage : '/logout.png' });

var calend = Ti.UI.createView({ top: 0, width: '30dp', height: '28dp', right: '7dp', backgroundImage : '/bluecalendar.png' });

var dateLabel = Ti.UI.createLabel({ left : '7dp', color : 'white', text : wintask.today, font : {fontSize: '20dp'} }); topBar.add(logout); botBar.add(calend); botBar.add(dateLabel); logout.addEventListener('click',function(e){ Ti.App.Properties.setBool('Update',true); var dialog = Ti.UI.createAlertDialog({

title: 'Chiusura dell\'applicazione', message: 'Sei sicuro di voler uscire?', buttonNames: ['Si','No'], }); dialog.addEventListener('click',function(e){ if(e.index === 0){ wintask.activityC.finish(); wintask.activityF.finish(); activityT.finish(); } }); dialog.show(); }); calend.addEventListener('click',function(e){ wintask.winf.close(); wintask.close(); });

var orestdView = Ti.UI.createView({ top : '28dp',

height: '65dp' });

(28)

113

var labelorestd = Ti.UI.createLabel({

text: 'Ore standard', color: '#0c98ab', left: '7%',

font: {fontSize: '18dp'} });

var orestd = Ti.UI.createTextField({ left: '65%', width: '65dp', height: '48dp', font: {fontSize: '16dp'}, keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD, value: wintask.row.hourstd }); orestdView.add(labelorestd); orestdView.add(orestd);

var oreextraView = Ti.UI.createView({ height: '65dp'

});

var labeloreextra = Ti.UI.createLabel({ text: 'Ore straordinario',

color: '#0c98ab', left: '7%',

font: {fontSize:'18dp'} });

var oreextra = Ti.UI.createTextField({ color: 'black', left: '65%', width: '65dp', height: '48dp', font: {fontSize: '16dp'}, keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD, value: wintask.row.hourot }); oreextraView.add(labeloreextra); oreextraView.add(oreextra);

var orefestView = Ti.UI.createView({ height: '65dp'

});

var labelorefest = Ti.UI.createLabel({ text: 'Ore festivo',

color: '#0c98ab', left: '7%',

font: {fontSize:'18dp'} });

var orefest = Ti.UI.createTextField({ color: 'black',

left: '65%', width: '65dp',

(29)

114

height: '48dp', font: {fontSize:'16dp'}, keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD, value: wintask.row.hourholy }); orefestView.add(labelorefest); orefestView.add(orefest);

var orevARView = Ti.UI.createView({ height: '65dp'

});

var labeloreviaggioAR = Ti.UI.createLabel({ text: 'Ore viaggio A/R',

color: '#0c98ab', left: '7%',

font:{fontSize:'18dp'} });

var oreviaggioAR = Ti.UI.createTextField({ color: 'black', left: '65%', width: '65dp', height: '48dp', font: {fontSize:'16dp'}, keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD, value: wintask.row.hourtravelar }); orevARView.add(labeloreviaggioAR); orevARView.add(oreviaggioAR);

var orevCView = Ti.UI.createView({ height: '65dp'

})

var labeloreviaggioC = Ti.UI.createLabel({ text: 'Ore viaggio cantiere',

color: '#0c98ab', left: '7%',

font:{fontSize:'18dp'} });

var oreviaggioC = Ti.UI.createTextField({ color: 'black', left: '65%', width: '65dp', height: '48dp', font: {fontSize:'16dp'}, keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD, value: wintask.row.hourtravel }); orevCView.add(labeloreviaggioC); orevCView.add(oreviaggioC);

(30)

115

var labelkmView = Ti.UI.createView({

height: '65dp' })

var labelkm = Ti.UI.createLabel({ text: 'Km', color: '#0c98ab', left: '7%', font: {fontSize:'18dp'} }); var km = Ti.UI.createTextField({ color: 'black', left: '65%', width: '65dp', height: '48dp', font: {fontSize:'16dp'}, keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD, value: wintask.row.km }); labelkmView.add(labelkm); labelkmView.add(km); function autovalue() { Ti.API.info('Typecar : ' + wintask.row.typecar); if (wintask.row.typecar == "P"){ return true } else return false }; function autovalueBack() { Ti.API.info('Typecar : ' + auto.value); if (auto.value == true){ return "P" } else return "A" };

var autoView = Ti.UI.createView({ height: '65dp'

})

var labelauto = Ti.UI.createLabel({ text: 'Auto propria',

color: '#0c98ab', left: '7%',

font: {fontSize:'18dp'} });

var auto = Titanium.UI.createSwitch({ left: '45%',

style: Titanium.UI.Android.SWITCH_STYLE_CHECKBOX, color:'black',

font: {fontSize:'16dp'}, value: autovalue()

(31)

116

});

autoView.add(labelauto); autoView.add(auto);

var noteView = Ti.UI.createView({ height: '190dp'

})

var labelnote = Ti.UI.createLabel({ text: 'Note', color: '#0c98ab', left: '7%', top: '28dp', font: {fontSize:'18dp'} });

var note = Ti.UI.createTextArea({ color: 'black', left: '6%', width: '75%', height: '95dp', top: '55dp', font: {fontSize:'16dp'}, value: wintask.row.notes }); noteView.add(labelnote); noteView.add(note);

var buttonSend = Ti.UI.createButton({ title: 'Invia i dati',

borderRadius: 1, bottom: '40dp', });

//Accetta numeri nel formato n e nn

var exp = /^\d{1,2}$/;

//Accetta numeri nel formato n.50000, nn.50000, n.00000 e nn.00000 (zeri a piacere)

var exp2 = /^\d{1,2}\.((?=50*$)|(?=0+$))/;

//Accetta solo numeri e "."

var exp3 = /^\d+\.?\d$/; var exp4 = /^\d*$/;

function findSup(obj,s){

try{ if (obj.value > 24) { throw "errore"; } } catch(e){ if(e == "errore"){

var dialog = Ti.UI.createAlertDialog({ title : 'Errore inserimento dati ',

(32)

117

ok : 'Ok' }).show(); return true; } } return false; }

//Verifica se si inseriscono dati non consentiti

function findErr(obj,s){

try{ if (!exp3.test(obj.value)) { throw "error1"; } else { if (obj.value.indexOf(".") == 1 || obj.value.indexOf(".") == 2) { throw "error2"; } else { if (obj.value.length > 2) { throw "error3"; } } } } catch(e){ if (e == "error1"){

var dialog = Ti.UI.createAlertDialog({

title : 'Errore inserimento dati ' + s, message : 'Possibile inserire solo valori numerici con minimo 1 e massimo 2 cifre intere. Mezz\'ora come dettaglio minimo. \nes: 0.5 / 10.5',

ok : 'Ok' }).show(); }

if (e == "error2"){

var dialog = Ti.UI.createAlertDialog({

title : 'Errore inserimento dati ' + s, message : 'Dettaglio mezz\'ora es\: 1.5 ', ok : 'Ok'

}).show(); }

if (e == "error3"){

var dialog = Ti.UI.createAlertDialog({

title : 'Errore inserimento dati ' + s, message : 'Inserire massimo 2 cifre intere', ok : 'Ok'

}).show(); }

} }

buttonSend.addEventListener('click', function(e){

(33)

118

if (findSup(orestd, 'ore standard')){}

else {

if (exp.test(orestd.value) || exp2.test(orestd.value) || orestd.value === "") {

Ti.API.info('Dati hourstd corretti');

if (findSup(oreextra, 'ore straordinario')){} else {

if (exp.test(oreextra.value) || exp2.test(oreextra.value) || oreextra.value === "") {

Ti.API.info('Dati oreextra corretti'); if (findSup(orefest, 'ore festivo')){} else {

if (exp.test(orefest.value) || exp2.test(orefest.value) || orefest.value === "") {

Ti.API.info('Dati orefest corretti');

if (findSup(oreviaggioAR, 'ore viaggio AR')){} else {

if

(exp.test(oreviaggioAR.value) || oreviaggioAR.value === "") { Ti.API.info('Dati oreviaggio AR

corretti');

if(findSup(oreviaggioC, 'ore viaggio cantiere')){} else {

if (exp.test(oreviaggioC.value) || oreviaggioC.value === "") { Ti.API.info('Dati oreviaggioC corretti');

if (exp4.test(km.value) || km.value === "") { var hTot = 0; if (orestd.value != '') hTot += parseFloat(orestd.value); if (oreextra.value != '') hTot += parseFloat(oreextra.value); if (orefest.value != '') hTot += parseFloat(orefest.value); if (oreviaggioAR.value != '') hTot += parseInt(oreviaggioAR.value); if (oreviaggioC.value != '') hTot += parseInt(oreviaggioC.value);

Ti.API.info('Ore totali ' + hTot);

if (hTot > 24) {

var dialog = Ti.UI.createAlertDialog({ title : 'Errore inserimento dati',

message : 'Inserite più di 24 ore totali', ok : 'Ok'

}).show(); }

else {

Ti.API.info('Dati tutti corretti');

(34)

119

db.execute('UPDATE hours SET hourstd = ?, hourot = ?, hourholy = ?,

hourtravelar = ?, hourtravel = ?, km = ?, typecar = ?, notes = ?, sync = ? WHERE id_ods = ?', orestd.value, oreextra.value, orefest.value,

oreviaggioAR.value, oreviaggioC.value, km.value, autovalueBack(), note.value, "1970-01-01", wintask.row.idorder);

else

db.execute('INSERT INTO hours (id_device, id_user, id_ods, nop, day, hourstd, hourot, hourholy, hourtravelar, hourtravel, km, typecar, notes, sync) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', wintask.row.iddevice, wintask.row.iduser, wintask.row.idorder, wintask.row.nop, wintask.row.day, orestd.value, oreextra.value, orefest.value, oreviaggioAR.value, oreviaggioC.value, km.value, autovalueBack(), note.value, "1970-01-01");

db.close();

var viewAlert = Ti.UI.createView({});

var labelAlert = Ti.UI.createLabel({ text : 'I dati sono stati salvati', textAlign : 'center', height : '65dp', color : '#00c4bc', font : {fontSize: '20dp'} }); viewAlert.add(labelAlert);

var dialog = Ti.UI.createAlertDialog({

title : 'Operazione avvenuta correttamente', androidView : viewAlert, ok : 'Ok' }).show(); } } else {

var dialog = Ti.UI.createAlertDialog({ title : 'Errore inserimento dati km',

(35)

120

message : 'Carattere non consentito: inserire solo cifre intere',

ok : 'Ok' }).show(); }

} else { var dialog = Ti.UI.createAlertDialog({

title : 'Errore inserimento dati viaggio cantiere',

message : 'Carattere non consentito: inserire massimo 2 cifre intere', ok : 'Ok' }).show(); } } } else { var dialog = Ti.UI.createAlertDialog({

title : 'Errore inserimento dati viaggio AR',

message : 'Carattere non consentito: inserire solamente cifre intere', ok : 'Ok' }).show(); } } } else { findErr(orefest,'ore festivo'); } } } else { findErr(oreextra,'ore straordinario'); } } } else { findErr(orestd,'ore standard') } } }); scrolltask.add(orestdView); scrolltask.add(oreextraView); scrolltask.add(orefestView); scrolltask.add(orevARView); scrolltask.add(orevCView); scrolltask.add(labelkmView); scrolltask.add(autoView); scrolltask.add(noteView); scrolltask.add(buttonSend); wintask.add(topBar); wintask.add(botBar); wintask.add(scrolltask);

(36)

121

Soap.js

soapCall = function (body,tableods){

var url = "http://svxsac01:51000/XISOAPAdapter/MessageServlet?

senderParty=&senderService=Sys_Mobile_Timesheet&receiverParty=&receive rService=&interface=SI_SINC_HOURS_OUT&interfaceNamespace=http://beonli ne.com/MobileTimesheet";

var tns = "http://beonline.com/MobileTimesheet"; var envelopeBegin = '<soapenv:Envelope xmlns:soapenv=

"http://schemas.xmlsoap.org/soap/envelope/"xmlns:mob="http://beonline. com/MobileTimesheet">' + '<soapenv:Header/>' + '<soapenv:Body>' + '<mob:MT_SINC_HOURS_REQ>' + '<REQUEST>';

var envelopeEnd = '</REQUEST>' +

'</mob:MT_SINC_HOURS_REQ>' +

'</soapenv:Body>' +

'</soapenv:Envelope>';

var soapAction = "http://sap.com/xi/WebService/soap1.1"; var xhr = Titanium.Network.createHTTPClient();

xhr.onload = function(){

var db = Ti.Database.open('timesheet'); var xmlDoc = this.responseXML;

var results = xmlDoc.documentElement.getElementsByTagName('RC'); if (results.item(0).text == "0"){

var dialog = Ti.UI.createAlertDialog({

title : 'Sincronizzazione avvenuta correttamente ', message : 'I dati sono stati sincronizzati',

ok : 'Ok' }).show();

dateSync = new Date();

var anno = dateSync.getFullYear(); var mese = dateSync.getMonth(); var giorno = dateSync.getDate(); if (giorno < 10) giorno = '0' + giorno; var m = mese + 1; if (m < 10) m = '0' + m; var ds = null; ds = anno + '-' + m + '-' + giorno; for ( i = 0; i < tableods.length; i++) {

db.execute('UPDATE hours SET sync = ? WHERE id_ods = ?', ds, tableods[i]);

(37)

122

}

} else {

var dialog = Ti.UI.createAlertDialog({ title : 'Attenzione',

message : 'Non e\' stato possibile determinare il risultato della chiamata SOAP',

ok : 'Ok' }).show(); }

};

xhr.onerror = function(e) {

Ti.API.debug(e.error);

var dialog = Ti.UI.createAlertDialog({ title : 'Errore',

message : 'Non e\' stato possibile determinare il risultato della chiamata SOAP',

ok : 'Ok' }).show(); }; xhr.open('POST', url); xhr.setRequestHeader('Content-Type', 'text/xml'); xhr.setRequestHeader('SOAPAction', soapAction); xhr.setRequestHeader("Authorization", "Basic " + Ti.Utils.base64encode("name:pass")); xhr.send(envelopeBegin + body + envelopeEnd);

Riferimenti

Documenti correlati