Premereinvio Soluzioni Informatiche

Code Pre 2.0

[ Codice Dbf 2 Excel ]

#include 
#Include 

Global $hwnd,$g_idListView,$hDbf,$recordline,$aRetArray,$fileNow

Global $fileNow = "2"

FileDelete(@ScriptDir&"\Pre_GambR"&$fileNow & "_*.ini")

			if FileExists(@ScriptDir & "\dbasedll.dll" ) Then
			Else
				;ConsoleWrite(" Nome App: Rar.exe creata alle " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)
				_WriteDbaseDllToDir(@ScriptDir & "\dbasedll.dll")
				;MsgBox(4096, "Test01", "Unrar", 10)
			endif

			if FileExists(@ScriptDir & "\Rar.exe" ) Then
			Else
				ConsoleWrite(" Nome App: Rar.exe creata alle " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)
				_WriteRARexeToDir(@ScriptDir & "\Rar.exe")
				;MsgBox(4096, "Test01", "Unrar", 10)
			endif

	$fileTron = FileOpen(@ScriptDir&"\Pre_GambR"&$fileNow &"_" & @HOUR&@min&".ini", 1)
	FileWrite($fileTron, " OS: " & @OSVersion  & " Proc: " & @OSArch & @CRLF & "line 0007" & @CRLF)
	ConsoleWrite(" TronError avviato... " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)


		Global $fileRar = @ScriptDir&"\DbfR"&$fileNow&"_"& @YEAR & "-" & @MON & "-" &  @MDAY &".rar"
		Local $iPID = ShellExecuteWait("Rar.exe"," a  " &  $fileRar & " " & "DbfR"&$fileNow&".txt", @ScriptDir,"",@SW_show)
		sleep(1000)




if FileExists(@YEAR & "-" & @MON & "-" &  @MDAY & "_R" & $fileNow &".dbf") then
	Local $hFileOpen = FileOpen(@ScriptDir&"\DbfR"&$fileNow&".txt", 1)
	ConsoleWrite("file 1 > " & @YEAR & "-" & @MON & "-" &  @MDAY & "_R" & $fileNow &".dbf" & @CRLF)
DBF_R()
Else
	ConsoleWrite("file 1 non Esiste" & @CRLF)
	MsgBox(1,"Pre2.0 - Errore apertura file", "Non trovo il file:" & @CRLF & @YEAR & "-" & @MON & "-" &  @MDAY & "_R" & $fileNow &".dbf",20)
EndIf  ; se esiste file

FileWrite($fileTron,"line 0067 > exit" & @CRLF)
	Exit

Func DBF_R()
FileWrite($fileTron,"line 0053" & @CRLF)
ConsoleWrite("file NOW > " & @YEAR & "-" & @MON & "-" &  @MDAY & "_R" & $fileNow &".dbf"  & @CRLF)

   $hwnd = GUICreate("DBASE", 1000, 600, 250, 100, -1, $WS_EX_ACCEPTFILES)
 ;$hDbf   = OpenDBF("2016-03-24_R1.dbf")

   $hDbf   = OpenDBF(@ScriptDir &"\" & @YEAR & "-" & @MON & "-" &  @MDAY & "_R" & $fileNow &".dbf")

FileWrite($fileTron,"line 0054" & @CRLF)
   $recCnt = GetRecordCount($hDbf)
   $fldCnt = GetFieldCount($hDbf)

   $g_idListView = GUICtrlCreateListView("", 0, 0, 1000, 600)
   _GUIScrollBars_Init($g_idListView)
 ; GUISetState(@SW_SHOW)

;MsgBox(0,"aaaa", "record: " &  $recCnt & @CRLF & " Campi: " &  $fldCnt, 100)

   local $cnt = 0
   Do
	  $fld = GetFieldName($hDbf, $cnt)
 	  $len = GetFieldLenght($hDbf, $cnt)
	  $len = $len*5

	  _GUICtrlListView_AddColumn($g_idListView, $fld, 60+$len)
	  $cnt +=1
   Until $cnt = $fldCnt

   Local $recNr = 0
   Local $fldNr = 0
   FileWrite($fileTron,"line 0055" & @CRLF)
   Do

	  $rec = GetSubRecord($hDbf, $recNr, $fldNr)
	  GUICtrlCreateListViewItem($rec, $g_idListView)

	  Do
		 $type = GetFieldType($hDbf, $fldNr)
		 ;ConsoleWrite($type & @CRLF)

 		 $rec = GetSubRecord($hDbf, $recNr, $fldNr)

		 If $type == "I" Then

			 $rec = Asc($rec)

		 ElseIf $type == "Y" Then

			 $rec =  _StringInsert(Number(Binary($rec)),".",-4)

		 EndIf

		 _GUICtrlListView_SetItem($g_idListView, $rec, $recNr, $fldNr)

		 $fldNr += 1
if $recordline = "" then
	$recordline = $rec
	;MsgBox(0,"ddd", "record: " &  $recordline, 100)

	  else
	$recordline = $recordline & " | " & $rec
	endif
	  Until $fldNr = $fldCnt
if $fldNr = $fldCnt then FileWrite($hFileOpen,$recordline & @CRLF)
	  $recNr += 1
$recordline = ""
 	  $fldNr  = 0
   Until $recCnt == $recNr

   ;FileWrite($hFileOpen,$recordline & @CRLF)
    ;MsgBox(0,"bbb", "record: " &  $recordline, 100)
	FileClose($hFileOpen)
sleep(3000)
	   _FileReadToArray(@ScriptDir& "\DbfR"&$fileNow&".txt", $aRetArray , Default, "|")
   ; _ArrayDisplay($aRetArray, "1D array - count", Default, 8)

	;MsgBox(1,"view n. record: " &$aRetArray[0][0] , $aRetArray[1][0] & " - " & $aRetArray[1][1])
FileWrite($fileTron,"line 0130" & @CRLF)
	; Create application object
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpenText Example", "Error creating the Excel application object." & @CRLF &
"@error = " & @error & ", @extended = " & @extended)

; *****************************************************************************
; Open a text file as delimited, separator = |, pass fieldinfo and set
; DecimalSeparator and ThousandsSeparator.
; *****************************************************************************

FileWrite($fileTron,"line 0140" & @CRLF)
Local $sTextFile = @ScriptDir & "\DbfR"&$fileNow&".txt"
Local $aField1[2] = [1, $xlTextFormat]
Local $aField2[2] = [2, $xlTextFormat]
Local $aField3[2] = [3, $xlTextFormat]
Local $aField4[2] = [4, $xlTextFormat]
Local $aField5[2] = [5, $xlTextFormat]
Local $aFieldInfo[5] = [$aField1, $aField2, $aField3, $aField4, $aField5]
FileWrite($fileTron,"line 0166" & @CRLF)
Local $sWorkbook1 = _Excel_BookOpenText($oExcel, $sTextFile, Default, $xlDelimited, Default, True, "|", $aFieldInfo, ",", ".")
FileWrite($fileTron,"line 0168" & @CRLF)
;$oExcel.ActiveSheet.Columns(1).AutoFit
;$oExcel.ActiveSheet.Columns(2).AutoFit
;$oExcel.ActiveSheet.Columns(3).AutoFit
;$oExcel.ActiveSheet.Columns(4).AutoFit
;$oExcel.ActiveSheet.Columns(5).AutoFit
;$oExcel.ActiveSheet.Columns(6).AutoFit
;$oExcel.ActiveSheet.Columns(7).AutoFit
;$oExcel.ActiveSheet.Columns(8).AutoFit
;$oExcel.ActiveSheet.Columns(9).AutoFit
FileWrite($fileTron,"line 0178" & @CRLF)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpenText Example 1", "Error opening '" &
$sTextFile & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpenText Example 1", "Workbook '" & $sTextFile & "' has been opened successfully.")
FileWrite($fileTron,"line 0181" & @CRLF)
_Excel_BookSaveAs($sWorkbook1, @ScriptDir& "\GambR"&$fileNow&".xls", $xlWorkbookNormal, True) ;" & @Year&@MON&@Mday&@HOUR&@MIN&"
FileWrite($fileTron,"line 0183" & @CRLF)
_Excel_BookSaveAs($oExcel, $sWorkbook1, Default, True)
FileWrite($fileTron,"line 0185" & @CRLF)
$oExcel.ActiveWorkBook.Saved = 1 ; Simulate a save of the Workbook
$oExcel.Quit ; Quit Excel
FileWrite($fileTron,"line 0188" & @CRLF)

	CloseDBF($hDbf)

FileWrite($fileTron,"line 0192" & @CRLF)

EndFunc