Istruzioni non eseguite nella action del timer

ciao, ho una webapp con un timer con all’interno dell’evento Action le istruzioni sotto.

se tolgo il break nella seconda parte (dettaglio avanzamento) le insert non vengono eseguite.
se lascio il break e faccio subito resume, si.

perchè?

dim data_end as new date
dim recordid as string
dim durata1,durata2 as double


if data_end.Hour=Gestione_Commesse.orasync.mid(1,2).Val and data_end.Minute=Gestione_Commesse.orasync.mid(4,2).Val then
  
  'dobbiamo recuperare i valori
  Dim db As New MSSQLServerDatabase
  Dim db2 As New MSSQLServerDatabase
  
  db.Host =Gestione_Commesse.host // or just the IP if using the default instance
  db.DatabaseName = Gestione_Commesse.dbnm
  db.UserName = Gestione_Commesse.user  // or "Domain\UserID for trusted domain accounts
  db.Password = Gestione_Commesse.pass
  
  If db.Connect Then
    ' ******************************************** AGGIORNAMENTO GG DI RITARDO
    ' recuperiamo l'elenco delle commesse 
    Dim ps As MSSQLServerPreparedStatement
    dim stringa_sql as string
    Dim rs,rs2 As RecordSet 
    
    stringa_sql="Select RecordId,"
    stringa_sql=stringa_sql+"DataSpedizionePrevista,"
    stringa_sql=stringa_sql+"SpedizioneAggiornata,"
    stringa_sql=stringa_sql+"GGRitardo1,"
    stringa_sql=stringa_sql+"GGRitardo2"
    stringa_sql=stringa_sql+" from Gestione_Commesse order by RecordId"
    'break
    rs = db.SQLSelect(stringa_sql)
    if rs <> Nil Then
      ' calcolo giorni di ritardo
      While Not rs.EOF
        recordid=rs.IdxField(1).StringValue
        durata1=0
        durata2=0
        if rs.IdxField(2).StringValue.Trim.Len > 0 then
          dim data_start as new date(rs.IdxField(2).StringValue.mid(7,4).Val,rs.IdxField(2).StringValue.mid(4,2).Val,rs.IdxField(2).StringValue.mid(1,2).Val) 
          durata1=(data_end.TotalSeconds-data_start.TotalSeconds)/86400
          durata1=floor(durata1)
        end if
        ps = db.Prepare("Update Gestione_Commesse set GGRitardo1="+durata1.ToText+" where RecordId='"+recordid+"'")
        rs2 = ps.SQLSelect
        if rs.IdxField(3).StringValue.Trim.Len > 0 then
          dim data_start as new date(rs.IdxField(3).StringValue.mid(7,4).Val,rs.IdxField(3).StringValue.mid(4,2).Val,rs.IdxField(3).StringValue.mid(1,2).Val) 
          durata2=(data_end.TotalSeconds-data_start.TotalSeconds)/86400
          durata2=floor(durata2)
        end if
        ps = db.Prepare("Update Gestione_Commesse set GGRitardo2="+durata2.ToText+" where RecordId='"+recordid+"'")
        rs2 = ps.SQLSelect
        rs.MoveNext
      Wend
      rs.Close
    end if
    
    ' ******************************************** AGGIORNAMENTO AVANZAMENTO PRODUZIONE
    ' recuperiamo l'elenco delle commesse 
    Break
    'MsgBox("Lettura Avanzamento.....")
    
    stringa_sql="Delete from Dettaglio_Avanzamento"
    ps = db.Prepare(stringa_sql)
    rs = ps.SQLSelect
    
    
    db2.Host =Gestione_Commesse.hos2// or just the IP if using the default instance
    db2.DatabaseName = Gestione_Commesse.dbn2
    db2.UserName = Gestione_Commesse.use2  // or "Domain\UserID for trusted domain accounts
    db2.Password = Gestione_Commesse.pas2
    
    If db2.Connect Then
      stringa_sql="select PJT_0 AS COMMESSA,substring(ITMREF_0,1,6) as FAMIGLIA, SUM(EXTQTY_0) AS QTA_PREVISTA,SUM(CPLQTY_0) AS QTA_REALIZZATA,"
      stringa_sql=stringa_sql+" (100*SUM(CPLQTY_0)/SUM(EXTQTY_0)) AS PERCENTUALE from x3.PROD.MFGITM "
      stringa_sql=stringa_sql+"where substring(ITMREF_0,1,6) in('2ASPLL','2SVSSA') "'and PJT_0 ='22731' "
      stringa_sql=stringa_sql+"GROUP BY PJT_0, substring(ITMREF_0,1,6) "
      stringa_sql=stringa_sql+"ORDER BY PJT_0, substring(ITMREF_0,1,6)"
      
      rs = db2.SQLSelect(stringa_sql)
      'break
      if rs <> Nil Then
        ' calcolo AvanzamentoProduzione
        While Not rs.EOF
          ps = db.Prepare("Insert Into Dettaglio_Avanzamento values ('"+rs.IdxField(1).StringValue+"','','"+rs.IdxField(2).StringValue+"',"+rs.IdxField(3).StringValue+","+rs.IdxField(4).StringValue+","+rs.IdxField(5).StringValue+")")
          rs2 = ps.SQLSelect
          'devo aggiornare il dettaglio produzione
          'break
          if rs.IdxField(2).StringValue="2ASPLL" then
            if rs.IdxField(5).IntegerValue=0 then
              ps = db.Prepare("Update Gestione_Commesse set AssSpalle=0 where Commessa='"+rs.IdxField(1).StringValue+"'")
            else
              if rs.IdxField(5).IntegerValue=100 then
                ps = db.Prepare("Update Gestione_Commesse set AssSpalle=1 where Commessa='"+rs.IdxField(1).StringValue+"'")
              else
                ps = db.Prepare("Update Gestione_Commesse set AssSpalle=0.5 where Commessa='"+rs.IdxField(1).StringValue+"'")
              end if
            end if
          end if
          if rs.IdxField(2).StringValue="2SVSSA" then
            if rs.IdxField(5).IntegerValue=0 then
              ps = db.Prepare("Update Gestione_Commesse set Vassoi=0 where Commessa='"+rs.IdxField(1).StringValue+"'")
            else
              if rs.IdxField(5).IntegerValue=100 then
                ps = db.Prepare("Update Gestione_Commesse set Vassoi=1 where Commessa='"+rs.IdxField(1).StringValue+"'")
              else
                ps = db.Prepare("Update Gestione_Commesse set Vassoi=0.5 where Commessa='"+rs.IdxField(1).StringValue+"'")
              end if
            end if
          end if
          rs2 = ps.SQLSelect
          rs.MoveNext
        Wend
        rs.Close
        db2.Close
      end if
    Else
      MsgBox("Connection error:" + db.ErrorMessage)
    End If
    
    db.Close
    
  Else
    MsgBox("Connection error:" + db.ErrorMessage)
  End If
  
end if

Assicurati che il timer non sia impostato su multiplo, altrimenti si accenderà di nuovo e creerà una condizione di gara

1 Like

ciao,
al momento sembra si sia risolto mettendo tra un task e l’altro eseguito nell’evento action

App.SleepCurrentThread(2000)

Non hai messo nessun controllo degli errori, potresti incappare in qualche errore o timeout del db che non intercetti

Mettici un try catch

Oltre a controllare quel che ha già detto Greg