Imports System.Net
Imports System.IO
Public Class Form1
Public Const XML_REQUEST_POST
As String = "http://xi01.ede.de/sap/xi/adapter_plain?namespace=http%3A%2f%2fede%2ede%2fxi%2fANFRAGE&interface=SalesOrderSimulate_Sync_Out&bs=ANFRAGE_TEST&sap-user=xit_ext_conn&sap-password=4f346yzr&qos=BE&sap-client=100&sap-language=D"
Public Const XML_REQUEST_HEADER
As String = _
"<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & _
"<n:SalesOrderSimulateRequest xmlns:n=""http://ede.de/xi/ANFRAGE"">" & vbCrLf & _
"<MemberID>0000100081</MemberID>" & vbCrLf & _
"<MemberPIN>1234567890</MemberPIN>" & vbCrLf & _
"<MemberSerial>SeriennummerWWSKundensystem</MemberSerial>" & vbCrLf & _
"<ServiceID>WWSTEST</ServiceID>"
Public Const XML_REQUEST_FOOTER
As String = "</n:SalesOrderSimulateRequest>"
Public Const DataSource
As String = "C:\temp\bestand.txt"
Public Const TmpPath
As String = "C:\temp"
Public Const CommandLineDelimiter
As Char = ";"
Dim ean, art, plant
As New Stack
Private Function BuildXmlFromFile(
ByVal PathFile
As String)
As String
Dim AllXml
As String
Dim MyFileReader
As StreamReader, ParamArr()
As String, i
As Integer
MyFileReader =
New StreamReader(PathFile)
AllXml = XML_REQUEST_HEADER & vbNewLine
Do Until MyFileReader.EndOfStream
i = i + 1
ParamArr = MyFileReader.ReadLine().Split(CommandLineDelimiter)
AllXml = AllXml & "<Item>" & vbNewLine
AllXml = AllXml & "<ID>" & i * 10 & "</ID>" & vbNewLine
AllXml = AllXml & "<ProductID>" & ParamArr(0) & "</ProductID>" & vbNewLine
AllXml = AllXml & "<Quantity>1</Quantity>" & vbNewLine
AllXml = AllXml & "<
Date>" & Now.ToString("yyyy-MM-dd"
![;)](./smiles/animated/4.gif)
& "</
Date>" & vbNewLine
AllXml = AllXml & "<PlantID>" & ParamArr(1) & "</PlantID>" & vbNewLine
AllXml = AllXml & "</Item>" & vbNewLine
ean.Push(ParamArr(0))
plant.Push(ParamArr(1))
art.Push(ParamArr(2))
Loop
MyFileReader.Close()
AllXml = AllXml & vbNewLine & XML_REQUEST_FOOTER & vbNewLine
Return AllXml
End Function
Private Function BuildXml(
ByVal ProductID
As String,
ByVal PlantID
As String,
Optional ByVal ArtNr
As String = ""
As String
Dim AllXml
As String
ean.Push(ProductID)
plant.Push(PlantID)
art.Push(ArtNr)
AllXml = XML_REQUEST_HEADER & vbNewLine
AllXml = AllXml & "<Item>" & vbNewLine
AllXml = AllXml & "<ID>1</ID>" & vbNewLine
AllXml = AllXml & "<ProductID>" & ProductID & "</ProductID>" & vbNewLine
AllXml = AllXml & "<Quantity>1</Quantity>" & vbNewLine
AllXml = AllXml & "<
Date>" & Now.ToString("yyyy-MM-dd"
![;)](./smiles/animated/4.gif)
& "</
Date>" & vbNewLine
AllXml = AllXml & "<PlantID>" & PlantID & "</PlantID>" & vbNewLine
AllXml = AllXml & "</Item>" & vbNewLine
AllXml = AllXml & vbNewLine & XML_REQUEST_FOOTER & vbNewLine
Return AllXml
End Function
Private Sub Form1_Load(
ByVal sender
As System.
Object,
ByVal e
As System.EventArgs)
Handles MyBase.Load
Dim StrRequest
As String
Dim Request
As HttpWebRequest
On Error GoTo e
Me.Show()
Label1.Refresh()
If Command() = ""
Then
If FileSystem.FileLen(DataSource) = 0
Then
MsgBox("Файл " & DataSource & " не существует или он пустой", MsgBoxStyle.Exclamation, "Ошибка при загрузке файла данных"
Application.
Exit()
End If
StrRequest = BuildXmlFromFile(DataSource)
ElseIf Command().IndexOf(CommandLineDelimiter) = 0
Then
Dim ParamArr(2)
As String
ParamArr = Command().Split(CommandLineDelimiter)
StrRequest = BuildXml(ParamArr(0), ParamArr(1), ParamArr(2))
Else
If FileSystem.FileLen(Command()) = 0
Then
MsgBox("Файл " & Command() & " не существует или он пустой", MsgBoxStyle.Exclamation, "Ошибка при загрузке файла данных"
Application.
Exit()
End If
StrRequest = BuildXmlFromFile(Command())
End If
Request = HttpWebRequest.Create(XML_REQUEST_POST)
Request.Method = "POST"
Request.ContentType = "text/xml"
Request.Accept = "application/*"
Dim POSTData
As Byte() = System.Text.Encoding.UTF8.GetBytes(StrRequest.ToCharArray())
Request.GetRequestStream().
Write(POSTData, 0, POSTData.Length)
Request.GetRequestStream().Close()
Dim Response
As WebResponse = Request.GetResponse()
Dim Reader
As New StreamReader(Response.GetResponseStream, System.Text.Encoding.UTF8)
Dim txtResponse
As String = Reader.ReadToEnd
txtResponse = txtResponse.Substring(txtResponse.IndexOf("<Item>"
![;)](./smiles/animated/4.gif)
)
txtResponse = txtResponse.Replace("<Protocol></Protocol>", ""
txtResponse = txtResponse.Replace("</ns1:SalesOrderSimulateConfirmation>", ""
txtResponse = "<Items>" & txtResponse & "</Items>"
 
![;D](./smiles/animated/46.gif)
ataGridView1.Columns.Add("EAN", "EAN Code"
 
![;D](./smiles/animated/46.gif)
ataGridView1.Columns.Add("PlantID", "PlantID"
 
![;D](./smiles/animated/46.gif)
ataGridView1.Columns.Add("Art", "Art Nr"
WriteToDW(txtResponse)
Dim i
As Byte
i = ean.Count
Do Until ean.Count = 0
 
![;D](./smiles/animated/46.gif)
ataGridView1.Rows(i - 1).Cells(0).Value =
CStr(ean.Pop)
i = i - 1
Loop
i = plant.Count
Do Until plant.Count = 0
 
![;D](./smiles/animated/46.gif)
ataGridView1.Rows(i - 1).Cells(1).Value =
CStr(plant.Pop)
i = i - 1
Loop
i = art.Count
Do Until art.Count = 0
 
![;D](./smiles/animated/46.gif)
ataGridView1.Rows(i - 1).Cells(2).Value =
CStr(art.Pop)
i = i - 1
Loop
Reader.Close()
Response.Close()
 
![;D](./smiles/animated/46.gif)
ataGridView1.Visible =
True
Exit Sub
e:
MsgBox(Err.Description, MsgBoxStyle.Critical, "Произошла ошибка"
Application.
Exit()
End Sub
Private Sub WriteToDW(
ByVal XmlData
As String)
Dim myDS
As DataSet =
New DataSet
Dim xmlSR
As System.IO.StringReader =
New System.IO.StringReader(XmlData)
myDS.ReadXml(xmlSR)
Dim myBS
As New BindingSource
myBS.DataSource = myDS.Tables(0)
 
![;D](./smiles/animated/46.gif)
ataGridView1.DataSource = myBS
End Sub
Private Sub Button1_Click(
ByVal sender
As System.
Object,
ByVal e
As System.EventArgs)
Handles Button1.Click
Application.
Exit()
End Sub
End Class