-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathАсти.vb_
114 lines (97 loc) · 3.5 KB
/
Асти.vb_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Option explicit
On Error Resume Next
Dim FSO,Sep,FDir,FLD,ArrayInp,FF,FL,St
Dim DeviceInp,DeviceOut
Dim TableName,dbfPrice,dbfSum,dbfConn
Const InExt="dbf"
Const OutExt="sas"
Const OutPath="C:\Mail\Programs\In\"
Set FSO = CreateObject("Scripting.FileSystemObject")
FDir="C:\Mail\Invoice\"&Mid(WScript.ScriptName,1,InStr(LCase(WScript.ScriptName),".vbs")-1)&"\"
ArrayInp=Split(FDir,";")
FDir=ArrayInp(0)
Set FLD = FSO.GetFolder(FDir)
Set FL = FLD.Files
For Each FF in FL 'Ñìîòðèì âñå ôàéëû è óáèðàåì ãîä
if InStr(LCase(FF.Name),"."&InExt) then
if InStr(FF.Name,Year(Now)) then
FSO.CopyFile FDir&FF.Name, FDir&Mid(FF.Name,InStr(FF.Name,Year(Now))+Len(Year(Now)),Len(FF.Name))
FSO.DeleteFile FDir&FF.Name
end if
end if
next
Set FLD = Nothing
SET FL = Nothing
Set FLD = FSO.GetFolder(FDir)
Set FL = FLD.Files
For Each FF in FL
if InStr(LCase(FF.Name),"."&InExt) AND (FF.Size<50000) then
TableName=Mid(LCase(FF.Name),1,InStr(LCase(FF.Name),"."&InExt)-1)
Set dbfConn = CreateObject("ADODB.Connection")
With dbfConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Extended Properties") = "dBase IV"
.Properties("Data Source") = FDir
.Open
End With
Set dbfPrice = CreateObject("ADODB.Recordset")
Set dbfPrice.ActiveConnection = dbfConn
Set dbfSum = CreateObject("ADODB.Recordset")
Set dbfSum.ActiveConnection = dbfConn
Sep = ";"
dbfPrice.Open "SELECT * FROM ["&TableName&"]"
dbfSum.Open "SELECT Sum(SUMMA) AS Summ FROM ["&TableName&"]"
St= Year(Now)&TableName&Sep & Date & Sep & dbfSum("Summ")
Set DeviceOut = FSO.CreateTextFile(FDir&"\"&TableName&"."&OutExt, True)
DeviceOut.WriteLine "[Header]"
DeviceOut.WriteLine(St)
DeviceOut.WriteLine "[Body]"
Do While Not dbfPrice.Eof
St=Trim(dbfPrice.Fields("KOD")) & Sep & Trim(dbfPrice.Fields("NAME")) & Sep & Trim(dbfPrice.Fields("PROIZV")) & Sep & Trim(dbfPrice.Fields("COUNTRY")) & Sep &_
dbfPrice.Fields("KOLVO") & Sep & dbfPrice.Fields("SUMMA")/dbfPrice.Fields("KOLVO") & Sep & Sep & dbfPrice.Fields("SUMMA")/dbfPrice.Fields("KOLVO")/(dbfPrice.Fields("NDSPOSTAV")+100)*100 & Sep &_
Sep & Sep & Sep & Sep & Trim(dbfPrice.Fields("SERTIF")) & "^" &_
Trim(dbfPrice.Fields("N_DECLAR")) & "^" & Trim(dbfPrice.Fields("DATAREGSE")) & " " & Trim(dbfPrice.Fields("DATAREGCR")) & Sep & Trim(dbfPrice.Fields("SERII")) & Sep & Sep & Trim(dbfPrice.Fields("DATAEND")) & Sep & Sep & Sep &_
Sep & Sep & Trim(dbfPrice.Fields("SUMMA")) & Sep & ""
DeviceOut.WriteLine (St)
dbfPrice.MoveNext
if Err.Number then Exit Do
Loop
dbfConn.Close
DeviceOut.close
'åñëè âîçíèêëè îøèáêè òî óäàëèì ñîçäàííûé ôàéë
if Err.Number then
FSO.DeleteFile (FDir&"\"&TableName&"."&OutExt)
Dim FOut
if not FSO.FileExists("error.log") then
Set FOut=FSO.CreateTextFile("error.log")
else
Set Fout=FSO.OpenTextFile("error.log",8,true)
end if
FOut.WriteLine("["&Now()&"] "&Err.Description&" ->"&WScript.ScriptName)
FOut.Close() : FOut=nothing
end if
Err.clear()
end if
next
dbfPrice = null
dbfSum = null
dbfConn = null
CopyFiles()
DeviceOut = null
fso = null
Function GetParm()
Set DeviceInp = FSO.OpenTextFile("mail.tmp")
GetParm=DeviceInp.ReadLine()
DeviceInp.Close: Set DeviceInp = nothing
End Function
Function CopyFiles()
Set FL = FLD.Files
For Each FF in FL
if InStr(LCase(FF.Name),"."&OutExt) then
FSO.CopyFile FDir&FF.Name, OutPath&FF.Name
FSO.DeleteFile FDir&FF.Name
else
FSO.DeleteFile FDir&FF.Name
end if
Next
End Function