Imports System.Security.Cryptography
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Private Sub FolderBrowserDialog1_HelpRequest(sender As Object, e As EventArgs) Handles FolderBrowserDialog1.HelpRequest
Private Sub Button7_Click(sender As Object, e As System.EventArgs) Handles Button7.Click
If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
TextBox1.Text = FolderBrowserDialog1.SelectedPath
Public Shared Function from852(ByVal inString As String) As String
Dim iso_8859_1 As Integer = 28591
Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(iso_8859_1)
Dim cp852 As System.Text.Encoding = System.Text.Encoding.GetEncoding("ibm852")
Dim bytes = System.Text.Encoding.Default.GetBytes(inString)
Return cp852.GetString(bytes)
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim vstup, vystup As String
Dim win1250 As VariantType
If (Not System.IO.Directory.Exists(vystup)) Then
System.IO.Directory.CreateDirectory(vystup)
Dim files() As String = IO.Directory.GetFiles(vstup)
For Each file As String In files
Dim text As String = IO.File.ReadAllText(file)
For i As Integer = 1 To files.Count - 1
Dim obsah As New List(Of String)
Dim reader As System.IO.StreamReader
reader = New StreamReader(files(i), System.Text.Encoding.Default)
radek = reader.ReadLine()
Do While (Not radek Is Nothing)
If IsNothing(radek) Then GoTo EOL_souboru
Case i > 999 And i < 10000
Case i > 9999 And i < 100000
Dim FileName As String = TextBox2.Text & j & i & ".txt"
System.IO.Directory.CreateDirectory(vystup)
IO.File.WriteAllLines(FileName, obsah)
Private Sub Button8_Click(sender As Object, e As System.EventArgs) Handles Button8.Click
If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
TextBox2.Text = FolderBrowserDialog1.SelectedPath
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim myDir As DirectoryInfo = New DirectoryInfo(TextBox2.Text)
If (myDir.EnumerateFiles().Any()) Then
CheckBox2.Checked = False
MsgBox("Výstupní složka není prázdná")
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim vstup, vystup, DD, xml_slozka As String
Dim hodina, minuta, vterina, rok, mesic, den As String
Dim pocet, nazev, cena As String
Dim poradi_xml As Integer
xml_slozka = TextBox2.Text & "xml\"
If (Not System.IO.Directory.Exists(vystup)) Then
System.IO.Directory.CreateDirectory(vystup)
Dim files() As String = IO.Directory.GetFiles(vystup)
For Each file As String In files
Dim text As String = IO.File.ReadAllText(file)
If (Not System.IO.Directory.Exists(xml_slozka)) Then
System.IO.Directory.CreateDirectory(xml_slozka)
If CheckBox4_smazat.Checked = True And xx < 2 Then
For Each deletefile In Directory.GetFiles(TextBox2.Text & "xml\", "*.xml", SearchOption.TopDirectoryOnly)
For i As Integer = 0 To files.Count - 1
Dim obsah, pocet2, nazev2, cena2 As New List(Of String)
Dim id1(), id1a(), id1b() As String
Dim reader As System.IO.StreamReader
Dim pocet_predch As Boolean = False
Dim pos As Boolean = False, A As Boolean = False
Dim poloha_pokladna As Byte
Dim c_uctu, bkp, pkp, fik As String
Dim radek_predch As String
Dim kredit As Boolean = False
reader = New StreamReader(files(i))
radek = reader.ReadLine()
poradi_xml = poradi_xml + 1
Do While (Not radek Is Nothing)
If IsNothing(radek) Then GoTo EOL_souboru
If InStr(radek, "S:POS") <> 0 Then
If nazev2.Count <> 0 Then
poradi_xml = poradi_xml + 1
pole_to_xml(TextBox2.Text & "xml\", poradi_xml & ".xml", L, nazev2.Count, rok, mesic, den, c_uctu, bkp, pkp, fik)
For m = 0 To nazev2.Count - 1
polozky(TextBox2.Text & "xml\" & poradi_xml & ".xml", pocet2(m), nazev2(m), cena2(m))
paticka_xml(TextBox2.Text & "xml\" & poradi_xml & ".xml", cena)
If InStr(radek, "Provozovna") <> 0 Then
If InStr(radek, "BKP:") <> 0 Then
If InStr(radek, "PKP:") <> 0 Then
If InStr(radek, "FIK:") <> 0 Then
If InStr(radek, "Předběžný") <> 0 Then
If InStr(radek, ":") <> 0 And InStr(radek, "S:P") = 0 And InStr(radek, "RNO:") = 0 And InStr(radek, ": ") = 0 And InStr(radek, " :") = 0 _
And InStr(radek, "Hotovost") = 0 And InStr(radek, "Karta") = 0 Then
vterina = Convert.ToInt32((Strings.Right(radek, 2)))
minuta = Convert.ToInt32(Mid(radek, Len(radek) - 4, 2))
hodina = Convert.ToInt32(Mid(radek, Len(radek) - 7, 2))
rok = Convert.ToInt32(Mid(radek, Len(radek) - 12, 4))
mesic = Convert.ToInt32(Mid(radek, Len(radek) - 15, 2))
den = Convert.ToInt32(Mid(radek, Len(radek) - 18, 2))
DD = Strings.Left(radek, 2)
If InStr(radek, "placeno") <> 0 Or InStr(radek, "POS:P") <> 0 Then pocet_predch = False
If pocet_predch = True And Not InStr(radek, "elkem") <> 0 And InStr(radek, "S:P") = 0 _
And InStr(radek, "RNO:") = 0 And InStr(radek, ": ") = 0 And InStr(radek, " :") = 0 _
And InStr(radek, "Mezisou") = 0 And InStr(radek, "Hotovost") = 0 And InStr(radek, "Karta") = 0 _
And InStr(radek, "Kredit") = 0 And InStr(radek, "Předběžný") = 0 And Not radek = "" Then
pocet2.Add(Mid(radek, 1, InStr(radek, " ") - 1))
Case InStr(radek, " á ") <> 0
nazev2.Add(Trim(Mid(radek, InStr(radek, " "), InStr(radek, " á ") - 6)))
Case InStr(radek, " á ") <> 0
nazev2.Add(Trim(Mid(radek, InStr(radek, " "), InStr(radek, " á ") - 2)))
Case Len(Trim(Replace(radek, Chr(&HA0), ""))) < 8 And Len(Trim(Replace(radek, Chr(&HA0), ""))) > 0
radek = Trim(Replace(radek, Chr(&HA0), ""))
cena2(cena2.Count - 1) = radek
nazev2.Add(Trim(Mid(radek, InStr(radek, " "), InStrRev(Trim(radek), " ") - 1)))
Case InStr(radek, " á ") <> 0
cena2.Add(Trim(Mid(radek, InStr(radek, " á ") + 3, 8)))
cena2.Add(Trim(Strings.Right(radek.Trim(), 9)))
If InStr(radek, "Celkem pl") <> 0 Then
cena = Strings.Right(radek.Trim(), 9)
If InStr(radek, "Počet") <> 0 Then
If InStr(radek, "Předběžný") <> 0 Or InStr(radek, "Kredit") <> 0 Then
Sub pole_to_xml(cesta As String, soubor As String, id As Integer, n As Byte, rok As String, mesic As String,
den As String, c_uctu As String, bkp As String, pkp As String, fik As String)
Dim xml_soubor As New IO.StreamWriter(cesta & soubor, True)
If mesic.Length = 1 Then mesic = "0" & mesic
If den.Length = 1 Then den = "0" & den
x(1) = "<dat:dataPack xmlns:dat=" & Chr(34) & "http://www.stormware.cz/schema/version_2/data.xsd" & Chr(34) &
" xmlns:vch=" & Chr(34) & "http://www.stormware.cz/schema/version_2/voucher.xsd" & Chr(34) & " xmlns:typ=" &
Chr(34) & "http://www.stormware.cz/schema/version_2/type.xsd" & Chr(34) & " version=" & Chr(34) & "2.0" & Chr(34) & " id=" & Chr(34) &
"po001" & Chr(34) & " ico=" & Chr(34) & "04914414 " & Chr(34) & " application=" & Chr(34) & "StwGamitech" & Chr(34) & " note=" & Chr(34) &
"Import Pokladního dokladu" & Chr(34) & ">"
x(2) = "<!-- Pokladní doklad s polozkami bez vazby -->"
x(3) = "<dat:dataPackItem version= " & Chr(34) & "2.0" & Chr(34) & " id =" & Chr(34) & id & Chr(34) & ">"
x(4) = "<vch:voucher version=" & Chr(34) & "2.0" & Chr(34) & ">"
x(5) = "<vch:voucherHeader>"
x(6) = "<vch:voucherType>receipt</vch:voucherType>"
x(7) = "<vch:cashAccount>"
x(8) = "<typ:ids>HP</typ:ids>"
x(9) = "</vch:cashAccount>"
x(10) = "<vch:Date>" & rok & "-" & mesic & "-" & den & "</vch:Date>"
x(11) = "<vch:datePayment>" & rok & "-" & mesic & "-" & den & "</vch:datePayment>"
x(12) = "<vch:dateTax>" & rok & "-" & mesic & "-" & den & "</vch:dateTax>"
x(13) = "<vch:accounting>"
x(14) = "<typ:ids>1Pp</typ:ids>"
x(15) = "</vch:accounting>"
x(16) = "<vch:classificationVAT>"
x(17) = "<typ:classificationVATType>nonSubsume</typ:classificationVATType>"
x(18) = "</vch:classificationVAT>"
x(19) = "<vch:Text> </vch:Text>"
x(20) = "<!-- adresa bez vazby na program POHODA -->"
x(21) = "<vch:partnerIdentity>"
x(23) = "<typ:Name>Zakazník</typ:Name>"
x(24) = "<typ:city></typ:city>"
x(25) = "<typ:street></typ:street>"
x(26) = "<typ:zip></typ:zip>"
x(28) = "</vch:partnerIdentity>"
x(30) = "<typ:ids></typ:ids>"
x(32) = "<vch:note>načteno z XML." & "c. uctu:" & c_uctu & "/BKP:" & bkp & "/PKP:" & pkp & "/FIK:" & fik & "/" & "</vch:note>"
x(33) = "<vch:intNote>Import Pokladního dokladu bez položek.</vch:intNote>"
x(34) = "</vch:voucherHeader>"
x(35) = "<vch:voucherDetail>"
x(36) = "<!-- textova polozka -->"
xml_soubor.WriteLine(x(i))
Sub polozky(soubor As String, pocet As String, nazev As String, cena As String)
x(0) = "<vch:voucherItem>" & Environment.NewLine
x(1) = "<vch:text>" & nazev & "</vch:text>" & Environment.NewLine
x(2) = "<vch:quantity>" & pocet & "</vch:quantity>" & Environment.NewLine
x(3) = "<vch:rateVAT>none</vch:rateVAT>" & Environment.NewLine
x(4) = "<vch:homeCurrency>" & Environment.NewLine
x(5) = "<typ:Price>" & cena & "</typ:Price>" & Environment.NewLine
x(6) = "<typ:priceVAT>0</typ:priceVAT>" & Environment.NewLine
x(7) = "</vch:homeCurrency>" & Environment.NewLine
x(8) = "<vch:note>""</vch:note>" & Environment.NewLine
x(9) = "</vch:voucherItem>" & Environment.NewLine
My.Computer.FileSystem.WriteAllText(soubor, x(i), True)
Sub paticka_xml(soubor As String, cena_celkem As String)
x(0) = "</vch:voucherDetail>" & Environment.NewLine
x(1) = "</vch:voucher>" & Environment.NewLine
x(2) = "<vch:voucherSummary>" & Environment.NewLine
x(3) = "<vch:homeCurrency>" & Environment.NewLine
x(4) = "<typ:priceNone>" & Trim(cena_celkem) & "</typ:priceNone>" & Environment.NewLine
x(5) = "</vch:homeCurrency>" & Environment.NewLine
x(6) = "</vch:voucherSummary>" & Environment.NewLine
x(7) = "</vch:voucher>" & Environment.NewLine
x(8) = "</dat:dataPackItem>" & Environment.NewLine
x(9) = "</dat:dataPack>" & Environment.NewLine
My.Computer.FileSystem.WriteAllText(soubor, x(i), True)
Partial Class NativeMethods
<DllImport("shlwapi.dll", CharSet:=CharSet.Unicode)>
Private Shared Function StrCmpLogicalW(s1 As String, s2 As String) As Int32
Friend Shared Function NaturalStringCompare(str1 As String, str2 As String) As Int32
Return StrCmpLogicalW(str1, str2)
Public Class NaturalStringComparer
Implements IComparer(Of String)
Public Function Compare(x As String, y As String) As Integer Implements IComparer(Of String).Compare
Return NativeMethods.NaturalStringCompare(x, y)