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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
| Private Sub fct_fill_excel(ByVal lines() As String, ByVal sqltype As String)
Dim line_0() As String
Try
Dim line_1() As String
Dim line_2() As String
Dim line_3() As String
Dim line_x() As String
Dim i As Integer
Dim strsql As String
Dim qty As Decimal
Dim S1, ErrStr As String
Dim po_xl As New Excel.Application
Dim po_book As Excel.Workbook
Dim po_sheet As Excel.Worksheet
If sqltype = "PO" Or sqltype = "MA" Then
'lines(0)
line_0 = Split(Replace(Replace(lines(0), Chr(34), ""), "'", " "), ";")
'lines(1)
line_1 = Split(Replace(Replace(lines(1), Chr(34), ""), "'", " "), ";")
'lines(2)
line_2 = Split(Replace(Replace(lines(2), Chr(34), ""), "'", " "), ";")
'lines(3)
line_3 = Split(Replace(Replace(lines(3), Chr(34), ""), "'", " "), ";")
'Création des settings pour la gestion du po dans excel
po_xl = New Excel.Application
If line_1(1) = "E" Then
po_book = po_xl.Workbooks.Open(Filename:=layout_e)
'po_xl.Workbooks.Open(Filename:=layout_e)
Else
po_book = po_xl.Workbooks.Open(Filename:=layout_f)
'po_xl.Workbooks.Open(Filename:=layout_f)
End If
po_sheet = po_book.ActiveSheet
po_xl.Visible = False
'Création de l'entête du PO
'to
If line_3(1) <> "" And line_3(2) <> "" Then
po_sheet.Cells(2, 7) = line_2(0).ToUpper
po_sheet.Cells(3, 7) = line_3(0).ToUpper
po_sheet.Cells(4, 7) = line_3(1).ToUpper
po_sheet.Cells(5, 7) = line_3(2).ToUpper
po_sheet.Cells(6, 7) = line_3(3).ToUpper & ", " & line_3(4).ToUpper & " " & line_3(5).ToUpper
po_sheet.Cells(7, 7) = line_3(6).ToUpper
ElseIf line_3(1) = "" And line_3(2) = "" Then
po_sheet.Cells(2, 7) = line_2(0).ToUpper
po_sheet.Cells(3, 7) = line_3(0).ToUpper
po_sheet.Cells(4, 7) = line_3(3).ToUpper & ", " & line_3(4).ToUpper & " " & line_3(5).ToUpper
po_sheet.Cells(7, 7) = line_3(6).ToUpper
ElseIf line_3(1) <> "" And line_3(2) = "" Then
po_sheet.Cells(2, 7) = line_2(0).ToUpper
po_sheet.Cells(3, 7) = line_3(0).ToUpper
po_sheet.Cells(4, 7) = line_3(1).ToUpper
po_sheet.Cells(5, 7) = line_3(3).ToUpper & ", " & line_3(4).ToUpper & " " & line_3(5).ToUpper
po_sheet.Cells(7, 7) = line_3(6).ToUpper
ElseIf line_3(1) = "" And line_3(2) <> "" Then
po_sheet.Cells(2, 7) = line_2(0).ToUpper
po_sheet.Cells(3, 7) = line_3(0).ToUpper
po_sheet.Cells(4, 7) = line_3(2).ToUpper
po_sheet.Cells(5, 7) = line_3(3).ToUpper & ", " & line_3(4).ToUpper & " " & line_3(5).ToUpper
po_sheet.Cells(7, 7) = line_3(6).ToUpper
End If
'ship to
If line_2(6) <> "" And line_2(7) <> "" Then
po_sheet.Cells(2, 15) = line_2(21).ToUpper
po_sheet.Cells(3, 15) = line_2(14).ToUpper
po_sheet.Cells(4, 15) = line_2(6).ToUpper
po_sheet.Cells(5, 15) = line_2(7).ToUpper
po_sheet.Cells(6, 15) = line_2(8).ToUpper & ", " & line_2(9).ToUpper & " " & line_2(10).ToUpper
po_sheet.Cells(7, 15) = line_2(12).ToUpper
ElseIf line_2(6) = "" And line_2(7) = "" Then
po_sheet.Cells(2, 15) = line_2(21).ToUpper
po_sheet.Cells(3, 15) = line_2(14).ToUpper
po_sheet.Cells(4, 15) = line_2(8).ToUpper & ", " & line_2(9).ToUpper & " " & line_2(10).ToUpper
po_sheet.Cells(7, 15) = line_2(12).ToUpper
ElseIf line_2(6) <> "" And line_2(7) = "" Then
po_sheet.Cells(2, 15) = line_2(21).ToUpper
po_sheet.Cells(3, 15) = line_2(14).ToUpper
po_sheet.Cells(4, 15) = line_2(6).ToUpper
po_sheet.Cells(5, 15) = line_2(8).ToUpper & ", " & line_2(9).ToUpper & " " & line_2(10).ToUpper
po_sheet.Cells(7, 15) = line_2(12).ToUpper
ElseIf line_2(6) = "" And line_2(7) <> "" Then
po_sheet.Cells(2, 15) = line_2(21).ToUpper
po_sheet.Cells(3, 15) = line_2(14).ToUpper
po_sheet.Cells(4, 15) = line_2(7).ToUpper
po_sheet.Cells(5, 15) = line_2(8).ToUpper & ", " & line_2(9).ToUpper & " " & line_2(10).ToUpper
po_sheet.Cells(7, 15) = line_2(12).ToUpper
End If
'# cmd
po_sheet.Cells(10, 1) = line_2(1).ToUpper
'Date cmd
If line_1(1) = "E" Then
po_sheet.Cells(10, 5) = line_2(2).Substring(3, 2) & "/" & line_2(2).Substring(6, 2) & "/" & line_2(2).Substring(0, 2)
Else
po_sheet.Cells(10, 5) = line_2(2).Substring(6, 2) & "/" & line_2(2).Substring(3, 2) & "/" & line_2(2).Substring(0, 2)
End If
'Date livrais
If line_1(1) = "E" Then
po_sheet.Cells(10, 6) = line_2(3).Substring(3, 2) & "/" & line_2(3).Substring(6, 2) & "/" & line_2(3).Substring(0, 2)
Else
po_sheet.Cells(10, 6) = line_2(3).Substring(6, 2) & "/" & line_2(3).Substring(3, 2) & "/" & line_2(3).Substring(0, 2)
End If
'Ship by
po_sheet.Cells(10, 7) = line_2(17).ToUpper
'FOB
po_sheet.Cells(10, 10) = line_2(13).ToUpper
'tx
po_sheet.Cells(9, 16) = line_2(19).ToUpper
po_sheet.Cells(10, 16) = line_2(20).ToUpper
'# fact
po_sheet.Cells(12, 1) = line_2(4).ToUpper
'Buyer
po_sheet.Cells(12, 5) = line_2(12).ToUpper
'Terms
po_sheet.Cells(12, 8) = line_2(5).ToUpper
'Freight
po_sheet.Cells(12, 11) = line_2(11).ToUpper
'Création des lignes de PO
For i = 4 To lines.GetUpperBound(0) - 1
line_x = Split(Replace(Replace(lines(i), Chr(34), ""), "'", " "), ";")
qty = qty + line_x(1)
'line
po_sheet.Cells(12 + i, 1) = line_x(0).ToUpper
'qte
po_sheet.Cells(12 + i, 2) = line_x(1).ToUpper
'vendor-item
If line_x(2) = "" Then
po_sheet.Cells(12 + i, 4) = line_x(4).ToUpper
Else
po_sheet.Cells(12 + i, 4) = line_x(2).ToUpper
End If
'desc
po_sheet.Cells(12 + i, 6) = line_x(3).ToUpper
'item-number
po_sheet.Cells(12 + i, 11) = "#PHV : " & line_x(4).ToUpper
'udm
po_sheet.Cells(12 + i, 15) = line_x(5).ToUpper
'prix
po_sheet.Cells(12 + i, 16) = CDec(line_x(6))
'amount
po_sheet.Cells(12 + i, 17) = CDec(line_x(7))
Next
po_sheet.Cells(12 + i + 1, 4) = line_x(10).ToUpper & line_x(11).ToUpper & line_x(12).ToUpper & line_x(13).ToUpper & line_x(14).ToUpper & line_x(15).ToUpper & line_x(16).ToUpper & line_x(17).ToUpper & line_x(18).ToUpper & line_x(19).ToUpper & line_x(20).ToUpper & line_x(21).ToUpper & line_x(22).ToUpper & line_x(23).ToUpper
po_sheet.Cells(12 + i + 3, 2) = "________"
po_sheet.Cells(12 + i + 3, 17) = "___________"
If line_1(1) = "E" Then
If line_2(15) = "USD" Then
po_sheet.Cells(12 + i + 3, 5) = "****** AMOUNTS SPECIFIED IN U.S.A CURRENCY ******"
Else
po_sheet.Cells(12 + i + 3, 5) = "******* AMOUNTS SPECIFIED IN CDN CURRENCY *******"
End If
Else
If line_2(15) = "USD" Then
po_sheet.Cells(12 + i + 3, 5) = "****** MONTANTS SPÉCIFIÉS EN DEVISE CDN ******"
Else
po_sheet.Cells(12 + i + 3, 5) = "****** MONTANTS SPÉCIFIÉS EN DEVISE USA ******"
End If
End If
po_sheet.Cells(12 + i + 4, 2) = qty
po_sheet.Cells(12 + i + 4, 16) = "TOTAL : "
po_sheet.Cells(12 + i + 4, 17) = CDec(line_2(16))
If File.Exists(f_out & "po_" & line_0(1) & ".xls") Then
File.Delete(f_out & "po_" & line_0(1) & ".xls")
End If
If line_0(0) = "@" Then
po_sheet.SaveAs(f_out & "ma_" & line_0(1) & ".xls")
Else
po_sheet.SaveAs(f_out & "po_" & line_0(1) & ".xls")
End If
po_xl.Quit()
po_sheet = Nothing
po_book = Nothing
po_xl = Nothing
'Kill du process excel
Dim Processes As Process() = Nothing
Processes = Process.GetProcessesByName("EXCEL")
' Load ID Processes in Array
Dim intProcesses(Processes.GetUpperBound(0)) As Int16
Dim j As Int16
For j = 0 To Processes.GetUpperBound(0)
Process.GetProcessById(CInt(Processes(j).Id.ToString)).Kill()
Next
'Envoi du email si tel est le cas
If line_0(0) = "@" Then
fct_wait_sec(60000)
fct_send_mail(envoyeur, line_1(0), "Purchase Order/Commande d'Achat # " & line_0(1), 1, "<font face=arial size=2 color='black'>Purchase Order/Commande d'Achat # " & line_0(1) & "</font><br><br><img src='" & signature & "'><br><br><b><font face=arial size=2 color='#aaaaaa'>DISCLAIMER: </b><BR>This communication is for use by the intended recipient and contains information that may be privileged, confidential or copyrighted under applicable law. If you are not the intended recipient, you are hereby formally notified that any use, copying or distribution of this e-mail, in whole or in part, is strictly prohibited. Please notify the sender by return e-mail from your system.</font>", "ma_" & line_0(1))
End If
End If
Catch ex As Exception
fct_send_mail(envoyeur, warning, "ERREUR PO VIA MAIL " & line_0(1), 0, ex.ToString, "none")
'# erreur no 8
fct_exec_sql("UPDATE pur_order SET err=8 WHERE pur_order.po_number='" & line_0(1) & "'")
End Try
End Sub
Private Sub procVerifFichier()
Dim i As Integer
Dim sFiles() As String
Dim FreeF As Integer
Dim str() As String
Dim tmp() As String
Do
Try
'System.Threading.Thread.Sleep(5000)
If Not File.Exists(f_in & "\pomail.lock") Then
'pour avoir les noms des fichiers et des sous-répertoires
'fso = Createobject("Scripting.FileSystem")
'f = fso.GetFile(f_in)
sFiles = Directory.GetFiles(f_in)
For i = 0 To sFiles.GetUpperBound(0)
If InStr(sFiles(i), ".txt") > 0 Then
'System.Threading.Thread.Sleep(5000)
FreeF = FreeFile() 'Possibilité de mettre 1************
FileOpen(FreeF, sFiles(i), OpenMode.Input) 'Ouverture du fichier créé**********
str = Split(InputString(FreeF, FileLen(sFiles(i))), Chr(10)) 'Séparation des lignes du fichier***
FileClose(FreeF)
File.Delete(archive & sFiles(i).Substring(27, sFiles(i).Length - 27))
File.Move(sFiles(i), archive & sFiles(i).Substring(27, sFiles(i).Length - 27))
'MsgBox(sFiles(i), archive & sFiles(i))
With txtwatch
.SelectionStart = Len(txtwatch.Text)
.SelectionProtected = False
.SelectionStart = Len(txtwatch.Text) + 1
.SelectionColor = System.Drawing.Color.Red
.SelectedText = "Fichier créé : " & Replace(sFiles(i), f_in, "") & " " & Date.Now & vbCrLf
.SelectionProtected = True
.Focus()
.SelectionStart = txtwatch.Text.Length
.ScrollToCaret()
End With
tmp = Split(Replace(Replace(str(0), Chr(34), ""), "'", " "), ";")
'If tmp(2).ToUpper <> "V" Then
'Exit Sub
'end if
If tmp(2).ToUpper = "V" Then
fct_fill_sql(str, sFiles(i).Substring(27, 2).ToUpper)
fct_fill_excel(str, sFiles(i).Substring(27, 2).ToUpper)
End If
End If
If File.Exists(f_in & "\pomail.lock") Then Exit For
Next
End If
Catch ex As Exception
fct_send_mail(envoyeur, warning, "ERREUR PO VIA MAIL " & Replace(sFiles(i), f_in, ""), 0, ex.ToString, "none")
'# erreur no 1
fct_exec_sql("UPDATE pur_order SET err=1 WHERE pur_order.po_number='0'")
End Try
Exit Do
Loop
End Sub |
Partager