powered by simpleCommunicator - 2.0.54     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Проблемы с кодом!
6 сообщений из 6, страница 1 из 1
Проблемы с кодом!
    #38890924
DKasimov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Народ привет!
Я вообще с VB дружу немного, а так занимаюсь СУБД, но тут возникла проблема!
Есть код:

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports Sherp

Namespace UserForm

Public Class EGRUL_PROJECT_NEW
Public connection As System.Data.SqlClient.SqlConnection
Public AnotherThreadStop As Boolean = False
Public IsUpload As Boolean = False
Public Thread1 As System.Threading.Thread

Public archWithExtension As String = ""
Public FileName As String = ""
Public FileFullName As String = ""

Public FileUploadNumber As Int32 = 0

Private Sub btn_choice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_choice.Click
Dim dlg As New System.Windows.Forms.OpenFileDialog
dlg.Filter = "RAR файлы (*.rar)|*.rar|ZIP файлы (*.zip)|*.zip"

If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
foldername.Text = dlg.FileName
End If
End Sub

Private Sub btn_download_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_download.Click

If Me.foldername.Text = "" Then
MsgBox("Выберите архив!", MsgBoxStyle.Critical, "Ошибка")
Exit Sub
End If

Dim arch As System.IO.FileInfo = New System.IO.FileInfo(TextBoxGetText(foldername))
Dim FileName As String = Mid(arch.Name, 1, Len(arch.Name) - Len(arch.Extension))
Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(arch.DirectoryName & "\" & FileName & "\")

If dir.Exists Then
Try
Kill(arch.DirectoryName & "\" & FileName & "\" & "\*.*")
Catch ex As Exception
End Try
Try
dir.Delete()
Catch ex As Exception
End Try
Else
dir.Create()
End If

connection = New System.Data.SqlClient.SqlConnection(Me.connstr.Text)
Try
If connection.State = System.Data.ConnectionState.Closed Then
connection.Open()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Ошибка")
Exit Sub
End Try

AnotherThreadStop = False
Try
Thread1 = New System.Threading.Thread(AddressOf AnotherThread)
Thread1.Start()
Catch
End Try
End Sub


Public Sub AnotherThread()

Dim command1 As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
command1.CommandType = System.Data.CommandType.StoredProcedure
command1.CommandTimeout = 0
GetSqlParameters(command1)
If connection.State = System.Data.ConnectionState.Closed Then
connection.Open()
End If
command1.Parameters("@Action").Value = 7
command1.Parameters("@FileName").Value = ""
If command1.ExecuteScalar() = "0,7" Then
MsgBox("Запущена процедура удаления дубликатов записей, ждите завершения!", MsgBoxStyle.Critical, "Загрузка файлов EGRUL невозможна")
Exit Sub
End If

Dim arch As System.IO.FileInfo = New System.IO.FileInfo(TextBoxGetText(foldername))
archWithExtension = Mid(arch.Name, 1, Len(arch.Name) - Len(arch.Extension))
Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(arch.DirectoryName & "\" & archWithExtension & "\")
Try
Dim myProcess As New System.Diagnostics.Process
SetText(Label1, "Распаковка архива " & arch.Name)
Dim iswinrar As String = ""
iswinrar = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\WinRAR\shell\open\command", "", Nothing)
If iswinrar = "" Then
SetText(Label1, "Архиватор Winrar не установлен в системе!" & arch.Name)
Exit Sub
End If
Dim f As System.IO.FileInfo = New System.IO.FileInfo(iswinrar.Substring(1, InStr(iswinrar, """%") - 4))
If f.Exists = False Then
SetText(Label1, "winrar.exe не найден в директории " + f.DirectoryName)
Exit Sub
End If
Dim f1 As System.IO.FileInfo = New System.IO.FileInfo(f.DirectoryName + "\WINRAR.EXE")
If f1.Exists = True Then
Dim startInfo As New System.Diagnostics.ProcessStartInfo(f1.FullName)
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
startInfo.Arguments = " e -ibck -o+ -inul " + arch.FullName + " " + dir.FullName
myProcess = System.Diagnostics.Process.Start(startInfo)
myProcess.WaitForExit()
Else
SetText(Label1, "unrar.exe не найден в директории " + f1.DirectoryName)
Exit Sub
End If
SetText(Label1, "Архив " & arch.Name & " распакован успешно")
Catch ex As Exception
SetText(Label1, "Ошибка распаковки архива " & arch.Name)
Exit Sub
End Try
Dim strError As String = ""
Try
ProgressBarSetValue(ProgressBar1, 0)
SetEnabled(btn_choice, False)
SetEnabled(btn_download, False)
SetMaximum(ProgressBar1, dir.GetFiles("*.xml", IO.SearchOption.AllDirectories).Length)
Application.DoEvents()

If AnotherThreadStop = True Then
Exit Sub
End If
For Each FileXML As System.IO.FileInfo In dir.GetFiles("*.xml", IO.SearchOption.AllDirectories)
If AnotherThreadStop = True Then
Exit Sub
End If
IsUpload = True
ProgressBarSetValue(ProgressBar1, ProgressBarGetValue(ProgressBar1) + 1)
SetText(Label1, "Загрузка файла " + FileXML.Name + ": " + ProgressBarGetValue(ProgressBar1).ToString + " из " + dir.GetFiles("*.xml", IO.SearchOption.AllDirectories).Length.ToString)

FileName = FileXML.Name
FileFullName = FileXML.FullName

ProgressBarSetValue(ProgressBar2, 0)

Dim commandPROV As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
commandPROV.CommandType = System.Data.CommandType.StoredProcedure
commandPROV.CommandTimeout = 0
GetSqlParameters(commandPROV)
If connection.State = System.Data.ConnectionState.Closed Then
connection.Open()
End If
commandPROV.Parameters("@Action").Value = 1
commandPROV.Parameters("@FileName").Value = FileXML.Name
If commandPROV.ExecuteScalar() = "0,1" Then
commandPROV = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
commandPROV.CommandType = System.Data.CommandType.StoredProcedure
commandPROV.CommandTimeout = 0
GetSqlParameters(commandPROV)
commandPROV.Parameters("@Action").Value = 2
commandPROV.Parameters("@FileName").Value = FileXML.Name
If commandPROV.ExecuteScalar() = "0,3" Then
commandPROV = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
commandPROV.CommandType = System.Data.CommandType.StoredProcedure
commandPROV.CommandTimeout = 0
GetSqlParameters(commandPROV)
commandPROV.Parameters("@Action").Value = 3
commandPROV.Parameters("@FileName").Value = FileXML.Name
FileUploadNumber = commandPROV.ExecuteScalar()
ElseIf commandPROV.ExecuteScalar() = "0,4" Then
If connection.State = System.Data.ConnectionState.Open Then
connection.Close()
End If
Continue For
End If
ElseIf commandPROV.ExecuteScalar() = "0,2" Then
commandPROV = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
commandPROV.CommandType = System.Data.CommandType.StoredProcedure
commandPROV.CommandTimeout = 0
GetSqlParameters(commandPROV)
commandPROV.Parameters("@Action").Value = 4
commandPROV.Parameters("@FileName").Value = FileXML.Name
FileUploadNumber = commandPROV.ExecuteScalar()
End If

Dim commandStart As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
commandStart.CommandType = System.Data.CommandType.StoredProcedure
commandStart.CommandTimeout = 0
GetSqlParameters(commandStart)
If connection.State = System.Data.ConnectionState.Closed Then
connection.Open()
End If
commandStart.Parameters("@Action").Value = 5
commandStart.Parameters("@FileName").Value = FileName
commandStart.ExecuteNonQuery()

Dim stream As IO.Stream = IO.File.Open(FileFullName, IO.FileMode.Open, IO.FileAccess.Read)
Try
Dim binReader As New IO.StreamReader(stream, System.Text.Encoding.Default)
Dim N As Integer = 2000000 'объем который мы читаем из файла
Dim Xbyte() As Char ' массив считаных символов из файла
Dim XMLResult As String ' Строка читаемая из файла
Dim s As String = "" ' остатки строки которую мы не обработали
Dim Valuemax As Integer = binReader.BaseStream.Length
Dim RABytes As Int64 = 0 ' сколько байт было прочитано
Dim RBytes As Int64 = 0 ' сколько байт надо прочитать
Dim SReturn As String = ""
SetText(Label2, "Обработка данных: " + (CInt(RABytes * 100 / Valuemax)).ToString + "%")
While Not binReader.EndOfStream
Application.DoEvents()
If binReader.BaseStream.Length - RABytes > N - s.Length Then
RBytes = N - s.Length
Else : RBytes = binReader.BaseStream.Length - RABytes
End If
ReDim Xbyte(RBytes - 1)
binReader.Read(Xbyte, 0, RBytes)
XMLResult = Nothing
XMLResult = Xbyte
XMLResult = XMLResult.Replace(Chr(63), "")
If Array.IndexOf(Xbyte, Nothing) > 0 Then
XMLResult = XMLResult.Substring(0, Array.IndexOf(Xbyte, Nothing))
End If
If XMLResult.IndexOf("<HEADER") >= 0 Then
XMLResult = XMLResult.Substring(XMLResult.IndexOf("</HEADER>") + 9, XMLResult.Length() - XMLResult.IndexOf("</HEADER>") - 9)
End If
XMLResult = s + XMLResult
While XMLResult <> ""
If XMLResult.IndexOf("<UL ") >= 0 Then
If XMLResult.IndexOf("</UL>") > 0 Then
SReturn = XMLResult.Substring(XMLResult.IndexOf("<UL "), XMLResult.IndexOf("</UL>") - XMLResult.IndexOf("<UL ") + 5)
Try
XMLResult = XMLResult.Substring(SReturn.Length + 2, XMLResult.Length() - SReturn.Length - 2)
Catch ex As Exception
XMLResult = XMLResult.Substring(SReturn.Length + 1, XMLResult.Length() - SReturn.Length - 1)
If XMLResult = "" Then
s = ""
End If
End Try
Dim commandFileXMLParsing As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.EGRUL_FileXMLParsing", connection)
commandFileXMLParsing.CommandType = System.Data.CommandType.StoredProcedure
commandFileXMLParsing.CommandTimeout = 0
GetSqlParameters(commandFileXMLParsing)
If connection.State = System.Data.ConnectionState.Closed Then
connection.Open()
End If
commandFileXMLParsing.Parameters("@FileXMLText").Value = "<?xml version=""1.0"" encoding=""windows-1251""?>" + SReturn
commandFileXMLParsing.Parameters("@FileName").Value = FileName
commandFileXMLParsing.Parameters("@IdFile").Value = FileUploadNumber
Try
commandFileXMLParsing.ExecuteNonQuery()
Catch ex1 As Exception
MsgBox(FileFullName & vbCrLf & ex1.ToString(), MsgBoxStyle.Critical, "Ошибка")
stream.Close()
Exit Sub
End Try
If connection.State = System.Data.ConnectionState.Open Then
connection.Close()
End If
Else
s = XMLResult
Exit While
End If
ElseIf XMLResult.IndexOf("<IP ") >= 0 Then
s = ""
Exit While
Else
s = XMLResult
Exit While
End If
End While
If XMLResult = "" Then
s = ""
End If
RABytes = RABytes + RBytes
SetText(Label2, "Обработка данных: " + (CInt(RABytes * 100 / Valuemax)).ToString + "%")
ProgressBarSetValue(ProgressBar2, (CInt(RABytes * 100 / Valuemax)))
End While

stream.Close()

Dim commandEnd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
commandEnd.CommandType = System.Data.CommandType.StoredProcedure
commandEnd.CommandTimeout = 0
GetSqlParameters(commandEnd)
If connection.State = System.Data.ConnectionState.Closed Then
connection.Open()
End If
commandEnd.Parameters("@Action").Value = 6
commandEnd.Parameters("@FileName").Value = FileName
Try
commandEnd.ExecuteNonQuery()
Catch exEnd As Exception
End Try
Catch ex As Exception
stream.Close()
MsgBox("Ошибка: " & ex.Message, 16, "Внимание")
End Try
Next
Try
Kill(dir.FullName & "*.*")
Catch ex As Exception
End Try
dir.Delete()
SetText(Label1, "Директория " & arch.DirectoryName & "\" & archWithExtension & "\" & " успешно удалена")
Application.DoEvents()
Catch ex As Exception
MsgBox("The process failed: " & vbCrLf & "Ошибка в файле " & FileFullName & vbCrLf & ex.ToString(), MsgBoxStyle.Critical, "Ошибка")
Finally
Try
Kill(arch.DirectoryName & "\" & archWithExtension & "\" & "\*.*")
Catch ex As Exception
End Try
Try
dir.Delete()
Catch ex As Exception
End Try
TextBoxSetText(foldername, "")
SetText(Label1, "Статус обработки архива")
SetText(Label2, "Статус обработки данных XML файла")
ProgressBarSetValue(ProgressBar1, 0)
ProgressBarSetValue(ProgressBar2, 0)
SetEnabled(btn_choice, True)
SetEnabled(btn_download, True)
End Try
End Sub

Private Delegate Sub StDelegateTextBoxSetText(ByVal Info As TextBox, ByVal Text As String)
Private Sub TextBoxSetText(ByVal Info As TextBox, ByVal Text As String)
If (Info.InvokeRequired) Then
Dim la As StDelegateTextBoxSetText = New StDelegateTextBoxSetText(AddressOf TextBoxSetText)
Info.Invoke(la, New Object() {Info, Text})
Else
Info.Text = Text
End If
End Sub

Private Delegate Function StDelegateTextBoxGetText(ByVal Info As TextBox)
Private Function TextBoxGetText(ByVal Info As TextBox)
If (Info.InvokeRequired) Then
Dim la As StDelegateTextBoxGetText = New StDelegateTextBoxGetText(AddressOf TextBoxGetText)
Info.Invoke(la, New Object() {Info})
End If
Return Info.Text
End Function

Private Delegate Sub StDelegateLable(ByVal Info As Label, ByVal Text As String)
Private Sub SetText(ByVal Info As Label, ByVal Text As String)
If (Info.InvokeRequired) Then
Dim la As StDelegateLable = New StDelegateLable(AddressOf SetText)
Info.Invoke(la, New Object() {Info, Text})
Else
Info.Text = Text
End If
End Sub

Private Delegate Function StDelegateGetLableText(ByVal Info As Label)
Private Function LableGetText(ByVal Info As Label)
If (Info.InvokeRequired) Then
Dim la As StDelegateGetLableText = New StDelegateGetLableText(AddressOf LableGetText)
Info.Invoke(la, New Object() {Info})
End If
Return Info.Text
End Function

Private Delegate Sub StDelegateProgressBarSetValue(ByVal Info As ProgressBar, ByVal value As Int32)
Private Sub ProgressBarSetValue(ByVal Info As ProgressBar, ByVal value As Int32)
If (Info.InvokeRequired) Then
Dim la As StDelegateProgressBarSetValue = New StDelegateProgressBarSetValue(AddressOf ProgressBarSetValue)
Info.Invoke(la, New Object() {Info, value})
Else
Info.Value = value
End If
End Sub

Private Delegate Sub StDelegateProgressBarMaximum(ByVal Info As ProgressBar, ByVal Maximum As Int32)

Private Sub SetMaximum(ByVal Info As ProgressBar, ByVal Maximum As Int32)
If (Info.InvokeRequired) Then
Dim la As StDelegateProgressBarMaximum = New StDelegateProgressBarMaximum(AddressOf SetMaximum)
Info.Invoke(la, New Object() {Info, Maximum})
Else
Info.Maximum = Maximum
End If
End Sub

Private Delegate Function StDelegateProgressBarGetValue(ByVal Info As ProgressBar)
Private Function ProgressBarGetValue(ByVal Info As ProgressBar)
If (Info.InvokeRequired) Then
Dim la As StDelegateProgressBarGetValue = New StDelegateProgressBarGetValue(AddressOf ProgressBarGetValue)
Info.Invoke(la, New Object() {Info})
End If
Return Info.Value
End Function

Private Delegate Function StDelegateButtonGetEnabled(ByVal Info As Button)
Private Function GetEnabled(ByVal Info As Button)
If (Info.InvokeRequired) Then
Dim la As StDelegateButtonGetEnabled = New StDelegateButtonGetEnabled(AddressOf GetEnabled)
Info.Invoke(la, New Object() {Info})
End If
Return Info.Enabled
End Function

Private Delegate Sub StDelegateButtonSetEnabled(ByVal Info As Button, ByVal enabled As Boolean)
Private Sub SetEnabled(ByVal Info As Button, ByVal Enabled As Boolean)
If (Info.InvokeRequired) Then
Dim la As StDelegateButtonSetEnabled = New StDelegateButtonSetEnabled(AddressOf SetEnabled)
Info.Invoke(la, New Object() {Info, Enabled})
Else
Info.Enabled = Enabled
End If
End Sub


Private Shared Sub GetSqlParameters(ByVal command As System.Data.SqlClient.SqlCommand)

Dim adapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(" Select syscolumns.name As ParamName, systypes.name ParamType FROM sysobjects INNER JOIN syscolumns On sysobjects.id = syscolumns.id INNER JOIN systypes On syscolumns.xusertype = systypes.xusertype WHERE sysobjects.name = @ProcedureName", command.Connection.ConnectionString)
adapter.SelectCommand.Parameters.Add("@ProcedureName", System.Data.SqlDbType.NVarChar).Value = command.CommandText.Replace("dbo.", "")

Dim dt As System.Data.DataTable = New System.Data.DataTable()
adapter.Fill(dt)

Dim row As System.Data.DataRow
For Each row In dt.Rows
command.Parameters.Add(row("ParamName").ToString(), SetSqlDbType(row("ParamType").ToString()))
Next
End Sub

Private Shared Sub SetSqlParameters(ByVal command As System.Data.SqlClient.SqlCommand, ByVal row As System.Data.DataRow, ByVal columns As System.Data.DataColumnCollection)

If command Is DBNull.Value Or row Is DBNull.Value Then
Exit Sub
End If

Dim column As System.Data.DataColumn
For Each column In columns
Try
command.Parameters("@" + column.ColumnName).Value = row(column.ColumnName)
Catch
End Try
Next
End Sub

Private Shared Function SetSqlDbType(ByVal type As String) As System.Data.SqlDbType
type = type.ToLower
Select Case type
Case "bigint"
Return System.Data.SqlDbType.BigInt
Case "binary"
Return System.Data.SqlDbType.Binary
Case "bit"
Return System.Data.SqlDbType.Bit
Case "Char"
Return System.Data.SqlDbType.Char
Case "datetime"
Return System.Data.SqlDbType.DateTime
Case "Decimal"
Return System.Data.SqlDbType.Decimal
Case "numeric"
Return System.Data.SqlDbType.Decimal
Case "float"
Return System.Data.SqlDbType.Float
Case "int"
Return System.Data.SqlDbType.Int
Case "money"
Return System.Data.SqlDbType.Money
Case "nchar"
Return System.Data.SqlDbType.NChar
Case "nvarchar"
Return System.Data.SqlDbType.NVarChar
Case "smalldatetime"
Return System.Data.SqlDbType.SmallDateTime
Case "tinyint"
Return System.Data.SqlDbType.TinyInt
Case "uniqueidentifier"
Return System.Data.SqlDbType.UniqueIdentifier
Case "varchar"
Return System.Data.SqlDbType.VarChar
Case Else
Return System.Data.SqlDbType.VarChar
End Select

End Function

Private Sub btn_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cancel.Click
If MsgBox("Вы уверены что хотите прервать загрузку?", MsgBoxStyle.YesNo, "Предупреждение") = MsgBoxResult.Yes Then
Try
Thread1.Interrupt()
Thread1 = Nothing
AnotherThreadStop = True
Catch ex As Exception

End Try
End If
End Sub
End Class

End Namespace



Так вот в нем есть кусок цикла

While Not binReader.EndOfStream
Application.DoEvents()
If binReader.BaseStream.Length - RABytes > N - s.Length Then
RBytes = N - s.Length
Else : RBytes = binReader.BaseStream.Length - RABytes
End If
ReDim Xbyte(RBytes - 1)
binReader.Read(Xbyte, 0, RBytes)
XMLResult = Nothing
XMLResult = Xbyte
XMLResult = XMLResult.Replace(Chr(63), "")
If Array.IndexOf(Xbyte, Nothing) > 0 Then
XMLResult = XMLResult.Substring(0, Array.IndexOf(Xbyte, Nothing))
End If
If XMLResult.IndexOf("<HEADER") >= 0 Then
XMLResult = XMLResult.Substring(XMLResult.IndexOf("</HEADER>") + 9, XMLResult.Length() - XMLResult.IndexOf("</HEADER>") - 9)
End If
XMLResult = s + XMLResult
If RBytes <= 0 Then
MsgBox("RBytes <0",64,"Ошибка ввода")
Exit Sub

End If

While XMLResult <> ""
If XMLResult.IndexOf("<UL ") >= 0 Then
If XMLResult.IndexOf("</UL>") > 0 Then
SReturn = XMLResult.Substring(XMLResult.IndexOf("<UL "), XMLResult.IndexOf("</UL>") - XMLResult.IndexOf("<UL ") + 5)
Try
XMLResult = XMLResult.Substring(SReturn.Length + 2, XMLResult.Length() - SReturn.Length - 2)
Catch ex As Exception
XMLResult = XMLResult.Substring(SReturn.Length + 1, XMLResult.Length() - SReturn.Length - 1)
If XMLResult = "" Then
s = ""
End If
End Try
Dim commandFileXMLParsing As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.EGRUL_FileXMLParsing", connection)
commandFileXMLParsing.CommandType = System.Data.CommandType.StoredProcedure
commandFileXMLParsing.CommandTimeout = 0
GetSqlParameters(commandFileXMLParsing)
If connection.State = System.Data.ConnectionState.Closed Then
connection.Open()
End If
commandFileXMLParsing.Parameters("@FileXMLText").Value = "<?xml version=""1.0"" encoding=""windows-1251""?>" + SReturn
commandFileXMLParsing.Parameters("@FileName").Value = FileName
commandFileXMLParsing.Parameters("@IdFile").Value = FileUploadNumber
Try
commandFileXMLParsing.ExecuteNonQuery()
Catch ex1 As Exception
MsgBox(FileFullName & vbCrLf & ex1.ToString(), MsgBoxStyle.Critical, "Ошибка")
stream.Close()
Exit Sub
End Try
If connection.State = System.Data.ConnectionState.Open Then
connection.Close()
End If
Else
s = XMLResult
Exit While
End If
ElseIf XMLResult.IndexOf("<IP ") >= 0 Then
s = ""
Exit While
Else
s = XMLResult
Exit While
End If
End While
If XMLResult = "" Then
s = ""
End If
RABytes = RABytes + RBytes
SetText(Label2, "Обработка данных: " + (CInt(RABytes * 100 / Valuemax)).ToString + "%")
ProgressBarSetValue(ProgressBar2, (CInt(RABytes * 100 / Valuemax)))
End While


Ошибку
If RBytes <= 0 Then
MsgBox("RBytes <0",64,"Ошибка ввода")
Exit Sub

End If
Я сам добавил! Не могу понять откуда там появляются число 0 или менее 0?
Самый большой файл весит (83 380 786 байт)
Подскажи плиз
...
Рейтинг: 0 / 0
Проблемы с кодом!
    #38890931
Фотография Shocker.Pro
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Учимся использовать тэги оформления кода - FAQ
...
Рейтинг: 0 / 0
Проблемы с кодом!
    #38890947
DKasimov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Народ привет!
Я вообще с VB дружу немного, а так занимаюсь СУБД, но тут возникла проблема!
Есть код:
Код: vbnet
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.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
446.
447.
448.
449.
450.
451.
452.
453.
454.
455.
456.
457.
458.
459.
460.
461.
462.
463.
464.
465.
466.
467.
468.
469.
470.
471.
472.
473.
474.
475.
476.
477.
478.
479.
480.
481.
482.
483.
484.
485.
486.
487.
488.
489.
490.
491.
492.
493.
494.
495.
496.
497.
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports Sherp

Namespace UserForm

Public Class EGRUL_PROJECT_NEW
    Public connection As System.Data.SqlClient.SqlConnection
    Public AnotherThreadStop As Boolean = False
    Public IsUpload As Boolean = False
    Public Thread1 As System.Threading.Thread

    Public archWithExtension As String = ""
    Public FileName As String = ""
    Public FileFullName As String = ""

    Public FileUploadNumber As Int32 = 0

 Private Sub btn_choice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_choice.Click
        Dim dlg As New System.Windows.Forms.OpenFileDialog
        dlg.Filter = "RAR файлы (*.rar)|*.rar|ZIP файлы (*.zip)|*.zip"

        If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
            foldername.Text = dlg.FileName
        End If
    End Sub

    Private Sub btn_download_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_download.Click

        If Me.foldername.Text = "" Then
            MsgBox("Выберите архив!", MsgBoxStyle.Critical, "Ошибка")
            Exit Sub
        End If

        Dim arch As System.IO.FileInfo = New System.IO.FileInfo(TextBoxGetText(foldername))
        Dim FileName As String = Mid(arch.Name, 1, Len(arch.Name) - Len(arch.Extension))
        Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(arch.DirectoryName & "\" & FileName & "\")

        If dir.Exists Then
            Try
                Kill(arch.DirectoryName & "\" & FileName & "\" & "\*.*")
            Catch ex As Exception
            End Try
            Try
                dir.Delete()
            Catch ex As Exception
            End Try
        Else
            dir.Create()
        End If

        connection = New System.Data.SqlClient.SqlConnection(Me.connstr.Text)
        Try
            If connection.State = System.Data.ConnectionState.Closed Then
                connection.Open()
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Ошибка")
            Exit Sub
        End Try

        AnotherThreadStop = False
        Try
            Thread1 = New System.Threading.Thread(AddressOf AnotherThread)
            Thread1.Start()
        Catch
        End Try
    End Sub


    Public Sub AnotherThread()

        Dim command1 As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
        command1.CommandType = System.Data.CommandType.StoredProcedure
        command1.CommandTimeout = 0
        GetSqlParameters(command1)
        If connection.State = System.Data.ConnectionState.Closed Then
            connection.Open()
        End If
        command1.Parameters("@Action").Value = 7
        command1.Parameters("@FileName").Value = ""
        If command1.ExecuteScalar() = "0,7" Then
            MsgBox("Запущена процедура удаления дубликатов записей, ждите завершения!", MsgBoxStyle.Critical, "Загрузка файлов EGRUL невозможна")
            Exit Sub
        End If

        Dim arch As System.IO.FileInfo = New System.IO.FileInfo(TextBoxGetText(foldername))
        archWithExtension = Mid(arch.Name, 1, Len(arch.Name) - Len(arch.Extension))
        Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(arch.DirectoryName & "\" & archWithExtension & "\")
        Try
            Dim myProcess As New System.Diagnostics.Process
            SetText(Label1, "Распаковка архива " & arch.Name)
            Dim iswinrar As String = ""
            iswinrar = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\WinRAR\shell\open\command", "", Nothing)
            If iswinrar = "" Then
                SetText(Label1, "Архиватор Winrar не установлен в системе!" & arch.Name)
                Exit Sub
            End If
            Dim f As System.IO.FileInfo = New System.IO.FileInfo(iswinrar.Substring(1, InStr(iswinrar, """%") - 4))
            If f.Exists = False Then
                SetText(Label1, "winrar.exe не найден в директории " + f.DirectoryName)
                Exit Sub
            End If
            Dim f1 As System.IO.FileInfo = New System.IO.FileInfo(f.DirectoryName + "\WINRAR.EXE")
            If f1.Exists = True Then
                Dim startInfo As New System.Diagnostics.ProcessStartInfo(f1.FullName)
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
                startInfo.Arguments = " e -ibck -o+ -inul " + arch.FullName + " " + dir.FullName
                myProcess = System.Diagnostics.Process.Start(startInfo)
                myProcess.WaitForExit()
            Else
                SetText(Label1, "unrar.exe не найден в директории " + f1.DirectoryName)
                Exit Sub
            End If
            SetText(Label1, "Архив " & arch.Name & " распакован успешно")
        Catch ex As Exception
            SetText(Label1, "Ошибка распаковки архива " & arch.Name)
            Exit Sub
        End Try
        Dim strError As String = ""
        Try
            ProgressBarSetValue(ProgressBar1, 0)
            SetEnabled(btn_choice, False)
            SetEnabled(btn_download, False)
            SetMaximum(ProgressBar1, dir.GetFiles("*.xml", IO.SearchOption.AllDirectories).Length)
            Application.DoEvents()

            If AnotherThreadStop = True Then
                Exit Sub
            End If
            For Each FileXML As System.IO.FileInfo In dir.GetFiles("*.xml", IO.SearchOption.AllDirectories)
                If AnotherThreadStop = True Then
                    Exit Sub
                End If
                IsUpload = True
                ProgressBarSetValue(ProgressBar1, ProgressBarGetValue(ProgressBar1) + 1)
                SetText(Label1, "Загрузка файла " + FileXML.Name + ": " + ProgressBarGetValue(ProgressBar1).ToString + " из " + dir.GetFiles("*.xml", IO.SearchOption.AllDirectories).Length.ToString)

                FileName = FileXML.Name
                FileFullName = FileXML.FullName

                ProgressBarSetValue(ProgressBar2, 0)

                Dim commandPROV As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
                commandPROV.CommandType = System.Data.CommandType.StoredProcedure
                commandPROV.CommandTimeout = 0
                GetSqlParameters(commandPROV)
                If connection.State = System.Data.ConnectionState.Closed Then
                    connection.Open()
                End If
                commandPROV.Parameters("@Action").Value = 1
                commandPROV.Parameters("@FileName").Value = FileXML.Name
                If commandPROV.ExecuteScalar() = "0,1" Then
                    commandPROV = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
                    commandPROV.CommandType = System.Data.CommandType.StoredProcedure
                    commandPROV.CommandTimeout = 0
                    GetSqlParameters(commandPROV)
                    commandPROV.Parameters("@Action").Value = 2
                    commandPROV.Parameters("@FileName").Value = FileXML.Name
                    If commandPROV.ExecuteScalar() = "0,3" Then
                        commandPROV = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
                        commandPROV.CommandType = System.Data.CommandType.StoredProcedure
                        commandPROV.CommandTimeout = 0
                        GetSqlParameters(commandPROV)
                        commandPROV.Parameters("@Action").Value = 3
                        commandPROV.Parameters("@FileName").Value = FileXML.Name
                        FileUploadNumber = commandPROV.ExecuteScalar()
                    ElseIf commandPROV.ExecuteScalar() = "0,4" Then
                        If connection.State = System.Data.ConnectionState.Open Then
                            connection.Close()
                        End If
                        Continue For
                    End If
                ElseIf commandPROV.ExecuteScalar() = "0,2" Then
                    commandPROV = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
                    commandPROV.CommandType = System.Data.CommandType.StoredProcedure
                    commandPROV.CommandTimeout = 0
                    GetSqlParameters(commandPROV)
                    commandPROV.Parameters("@Action").Value = 4
                    commandPROV.Parameters("@FileName").Value = FileXML.Name
                    FileUploadNumber = commandPROV.ExecuteScalar()
                End If

                Dim commandStart As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
                commandStart.CommandType = System.Data.CommandType.StoredProcedure
                commandStart.CommandTimeout = 0
                GetSqlParameters(commandStart)
                If connection.State = System.Data.ConnectionState.Closed Then
                    connection.Open()
                End If
                commandStart.Parameters("@Action").Value = 5
                commandStart.Parameters("@FileName").Value = FileName
                commandStart.ExecuteNonQuery()

                Dim stream As IO.Stream = IO.File.Open(FileFullName, IO.FileMode.Open, IO.FileAccess.Read)
                Try
                    Dim binReader As New IO.StreamReader(stream, System.Text.Encoding.Default)
                    Dim N As Integer = 2000000 'объем который мы читаем из файла
                    Dim Xbyte() As Char ' массив считаных символов из файла
                    Dim XMLResult As String ' Строка читаемая из файла
                    Dim s As String = "" ' остатки строки которую мы не обработали
                    Dim Valuemax As Integer = binReader.BaseStream.Length
                    Dim RABytes As Int64 = 0 ' сколько байт было прочитано
                    Dim RBytes As Int64 = 0 ' сколько байт надо прочитать
                    Dim SReturn As String = ""
                    SetText(Label2, "Обработка данных: " + (CInt(RABytes * 100 / Valuemax)).ToString + "%")
                    While Not binReader.EndOfStream
                        Application.DoEvents()
                        If binReader.BaseStream.Length - RABytes > N - s.Length Then
                            RBytes = N - s.Length
                        Else : RBytes = binReader.BaseStream.Length - RABytes
                        End If
                        ReDim Xbyte(RBytes - 1)
                        binReader.Read(Xbyte, 0, RBytes)
                        XMLResult = Nothing
                        XMLResult = Xbyte
                        XMLResult = XMLResult.Replace(Chr(63), "")
                        If Array.IndexOf(Xbyte, Nothing) > 0 Then 
                          XMLResult = XMLResult.Substring(0, Array.IndexOf(Xbyte, Nothing))
                        End If
                        If XMLResult.IndexOf("<HEADER") >= 0 Then
                            XMLResult = XMLResult.Substring(XMLResult.IndexOf("</HEADER>") + 9, XMLResult.Length() - XMLResult.IndexOf("</HEADER>") - 9)
                        End If
                        XMLResult = s + XMLResult
                        While XMLResult <> ""
                            If XMLResult.IndexOf("<UL ") >= 0 Then
                                If XMLResult.IndexOf("</UL>") > 0 Then
                                    SReturn = XMLResult.Substring(XMLResult.IndexOf("<UL "), XMLResult.IndexOf("</UL>") - XMLResult.IndexOf("<UL ") + 5) 
                                    Try
                                        XMLResult = XMLResult.Substring(SReturn.Length + 2, XMLResult.Length() - SReturn.Length - 2)
                                    Catch ex As Exception
                                        XMLResult = XMLResult.Substring(SReturn.Length + 1, XMLResult.Length() - SReturn.Length - 1)
                                        If XMLResult = "" Then 
                                            s = ""
                                        End If
                                    End Try
                                     Dim commandFileXMLParsing As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.EGRUL_FileXMLParsing", connection)
                                    commandFileXMLParsing.CommandType = System.Data.CommandType.StoredProcedure
                                    commandFileXMLParsing.CommandTimeout = 0
                                    GetSqlParameters(commandFileXMLParsing)
                                    If connection.State = System.Data.ConnectionState.Closed Then
                                        connection.Open()
                                    End If
                                    commandFileXMLParsing.Parameters("@FileXMLText").Value = "<?xml version=""1.0"" encoding=""windows-1251""?>" + SReturn
                                    commandFileXMLParsing.Parameters("@FileName").Value = FileName
                                    commandFileXMLParsing.Parameters("@IdFile").Value = FileUploadNumber
                                    Try
                                        commandFileXMLParsing.ExecuteNonQuery()
                                    Catch ex1 As Exception
                                        MsgBox(FileFullName & vbCrLf & ex1.ToString(), MsgBoxStyle.Critical, "Ошибка")
                                        stream.Close()
                                        Exit Sub
                                    End Try
                                    If connection.State = System.Data.ConnectionState.Open Then
                                        connection.Close()
                                    End If
                                Else
                                    s = XMLResult
                                    Exit While
                                End If
                            ElseIf XMLResult.IndexOf("<IP ") >= 0 Then
                                s = ""
                                Exit While
                            Else
                                s = XMLResult
                                Exit While
                            End If
                        End While
                        If XMLResult = "" Then 
                            s = ""
                        End If
                        RABytes = RABytes + RBytes
                        SetText(Label2, "Обработка данных: " + (CInt(RABytes * 100 / Valuemax)).ToString + "%")
                        ProgressBarSetValue(ProgressBar2, (CInt(RABytes * 100 / Valuemax)))
                    End While
                    
                    stream.Close()

                    Dim commandEnd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.FileInWork_u", connection)
                    commandEnd.CommandType = System.Data.CommandType.StoredProcedure
                    commandEnd.CommandTimeout = 0
                    GetSqlParameters(commandEnd)
                    If connection.State = System.Data.ConnectionState.Closed Then
                        connection.Open()
                    End If
                    commandEnd.Parameters("@Action").Value = 6
                    commandEnd.Parameters("@FileName").Value = FileName
                    Try
                        commandEnd.ExecuteNonQuery()
                    Catch exEnd As Exception
                    End Try
                Catch ex As Exception
                    stream.Close()
                    MsgBox("Ошибка: " & ex.Message, 16, "Внимание")
                End Try
            Next
            Try
                Kill(dir.FullName & "*.*")
            Catch ex As Exception
            End Try
            dir.Delete()
            SetText(Label1, "Директория " & arch.DirectoryName & "\" & archWithExtension & "\" & " успешно удалена")
            Application.DoEvents()
        Catch ex As Exception
            MsgBox("The process failed: " & vbCrLf & "Ошибка в файле " & FileFullName & vbCrLf & ex.ToString(), MsgBoxStyle.Critical, "Ошибка")
        Finally
            Try
                Kill(arch.DirectoryName & "\" & archWithExtension & "\" & "\*.*")
            Catch ex As Exception
            End Try
            Try
                dir.Delete()
            Catch ex As Exception
            End Try
            TextBoxSetText(foldername, "")
            SetText(Label1, "Статус обработки архива")
            SetText(Label2, "Статус обработки данных XML файла")
            ProgressBarSetValue(ProgressBar1, 0)
            ProgressBarSetValue(ProgressBar2, 0)
            SetEnabled(btn_choice, True)
            SetEnabled(btn_download, True)
        End Try
    End Sub
        
    Private Delegate Sub StDelegateTextBoxSetText(ByVal Info As TextBox, ByVal Text As String)
    Private Sub TextBoxSetText(ByVal Info As TextBox, ByVal Text As String)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateTextBoxSetText = New StDelegateTextBoxSetText(AddressOf TextBoxSetText)
            Info.Invoke(la, New Object() {Info, Text})
        Else
            Info.Text = Text
        End If
    End Sub

    Private Delegate Function StDelegateTextBoxGetText(ByVal Info As TextBox)
    Private Function TextBoxGetText(ByVal Info As TextBox)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateTextBoxGetText = New StDelegateTextBoxGetText(AddressOf TextBoxGetText)
            Info.Invoke(la, New Object() {Info})
        End If
        Return Info.Text
    End Function

    Private Delegate Sub StDelegateLable(ByVal Info As Label, ByVal Text As String)
    Private Sub SetText(ByVal Info As Label, ByVal Text As String)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateLable = New StDelegateLable(AddressOf SetText)
            Info.Invoke(la, New Object() {Info, Text})
        Else
            Info.Text = Text
        End If
    End Sub

    Private Delegate Function StDelegateGetLableText(ByVal Info As Label)
    Private Function LableGetText(ByVal Info As Label)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateGetLableText = New StDelegateGetLableText(AddressOf LableGetText)
            Info.Invoke(la, New Object() {Info})
        End If
        Return Info.Text
    End Function

    Private Delegate Sub StDelegateProgressBarSetValue(ByVal Info As ProgressBar, ByVal value As Int32)
    Private Sub ProgressBarSetValue(ByVal Info As ProgressBar, ByVal value As Int32)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateProgressBarSetValue = New StDelegateProgressBarSetValue(AddressOf ProgressBarSetValue)
            Info.Invoke(la, New Object() {Info, value})
        Else
            Info.Value = value
        End If
    End Sub

    Private Delegate Sub StDelegateProgressBarMaximum(ByVal Info As ProgressBar, ByVal Maximum As Int32)

    Private Sub SetMaximum(ByVal Info As ProgressBar, ByVal Maximum As Int32)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateProgressBarMaximum = New StDelegateProgressBarMaximum(AddressOf SetMaximum)
            Info.Invoke(la, New Object() {Info, Maximum})
        Else
            Info.Maximum = Maximum
        End If
    End Sub

    Private Delegate Function StDelegateProgressBarGetValue(ByVal Info As ProgressBar)
    Private Function ProgressBarGetValue(ByVal Info As ProgressBar)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateProgressBarGetValue = New StDelegateProgressBarGetValue(AddressOf ProgressBarGetValue)
            Info.Invoke(la, New Object() {Info})
        End If
        Return Info.Value
    End Function

    Private Delegate Function StDelegateButtonGetEnabled(ByVal Info As Button)
    Private Function GetEnabled(ByVal Info As Button)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateButtonGetEnabled = New StDelegateButtonGetEnabled(AddressOf GetEnabled)
            Info.Invoke(la, New Object() {Info})
        End If
        Return Info.Enabled
    End Function

    Private Delegate Sub StDelegateButtonSetEnabled(ByVal Info As Button, ByVal enabled As Boolean)
    Private Sub SetEnabled(ByVal Info As Button, ByVal Enabled As Boolean)
        If (Info.InvokeRequired) Then
            Dim la As StDelegateButtonSetEnabled = New StDelegateButtonSetEnabled(AddressOf SetEnabled)
            Info.Invoke(la, New Object() {Info, Enabled})
        Else
            Info.Enabled = Enabled
        End If
    End Sub
    

Private Shared Sub GetSqlParameters(ByVal command As System.Data.SqlClient.SqlCommand)

        Dim adapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(" Select syscolumns.name As ParamName, systypes.name ParamType FROM sysobjects  INNER JOIN syscolumns On sysobjects.id = syscolumns.id INNER JOIN systypes On syscolumns.xusertype = systypes.xusertype  WHERE sysobjects.name = @ProcedureName", command.Connection.ConnectionString)
        adapter.SelectCommand.Parameters.Add("@ProcedureName", System.Data.SqlDbType.NVarChar).Value = command.CommandText.Replace("dbo.", "")

        Dim dt As System.Data.DataTable = New System.Data.DataTable()
        adapter.Fill(dt)

        Dim row As System.Data.DataRow
        For Each row In dt.Rows
            command.Parameters.Add(row("ParamName").ToString(), SetSqlDbType(row("ParamType").ToString()))
        Next
    End Sub

    Private Shared Sub SetSqlParameters(ByVal command As System.Data.SqlClient.SqlCommand, ByVal row As System.Data.DataRow, ByVal columns As System.Data.DataColumnCollection)

        If command Is DBNull.Value Or row Is DBNull.Value Then
            Exit Sub
        End If

        Dim column As System.Data.DataColumn
        For Each column In columns
            Try
                command.Parameters("@" + column.ColumnName).Value = row(column.ColumnName)
            Catch
            End Try
        Next
    End Sub

    Private Shared Function SetSqlDbType(ByVal type As String) As System.Data.SqlDbType
        type = type.ToLower
        Select Case type
            Case "bigint"
                Return System.Data.SqlDbType.BigInt
            Case "binary"
                Return System.Data.SqlDbType.Binary
            Case "bit"
                Return System.Data.SqlDbType.Bit
            Case "Char"
                Return System.Data.SqlDbType.Char
            Case "datetime"
                Return System.Data.SqlDbType.DateTime
            Case "Decimal"
                Return System.Data.SqlDbType.Decimal
            Case "numeric"
                Return System.Data.SqlDbType.Decimal
            Case "float"
                Return System.Data.SqlDbType.Float
            Case "int"
                Return System.Data.SqlDbType.Int
            Case "money"
                Return System.Data.SqlDbType.Money
            Case "nchar"
                Return System.Data.SqlDbType.NChar
            Case "nvarchar"
                Return System.Data.SqlDbType.NVarChar
            Case "smalldatetime"
                Return System.Data.SqlDbType.SmallDateTime
            Case "tinyint"
                Return System.Data.SqlDbType.TinyInt
            Case "uniqueidentifier"
                Return System.Data.SqlDbType.UniqueIdentifier
            Case "varchar"
                Return System.Data.SqlDbType.VarChar
            Case Else
                Return System.Data.SqlDbType.VarChar
        End Select

    End Function
    
    Private Sub btn_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cancel.Click
        If MsgBox("Вы уверены что хотите прервать загрузку?", MsgBoxStyle.YesNo, "Предупреждение") = MsgBoxResult.Yes Then
            Try
                Thread1.Interrupt()
                Thread1 = Nothing
                AnotherThreadStop = True
            Catch ex As Exception

            End Try
        End If
    End Sub
End Class

End Namespace


Так вот в нем есть кусок цикла


Код: vbnet
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.
While Not binReader.EndOfStream
                        Application.DoEvents()
                        If binReader.BaseStream.Length - RABytes > N - s.Length Then
                            RBytes = N - s.Length
                        Else : RBytes = binReader.BaseStream.Length - RABytes
                        End If
                        ReDim Xbyte(RBytes - 1)
                        binReader.Read(Xbyte, 0, RBytes)
                        XMLResult = Nothing
                        XMLResult = Xbyte
                        XMLResult = XMLResult.Replace(Chr(63), "")
                        If Array.IndexOf(Xbyte, Nothing) > 0 Then 
                          XMLResult = XMLResult.Substring(0, Array.IndexOf(Xbyte, Nothing))
                        End If
                        If XMLResult.IndexOf("<HEADER") >= 0 Then
                            XMLResult = XMLResult.Substring(XMLResult.IndexOf("</HEADER>") + 9, XMLResult.Length() - XMLResult.IndexOf("</HEADER>") - 9)
                        End If
                        XMLResult = s + XMLResult
If RBytes <= 0 Then
 MsgBox("RBytes <0",64,"Ошибка ввода")
            Exit Sub

End If
          
                        While XMLResult <> ""
                            If XMLResult.IndexOf("<UL ") >= 0 Then
                                If XMLResult.IndexOf("</UL>") > 0 Then
                                    SReturn = XMLResult.Substring(XMLResult.IndexOf("<UL "), XMLResult.IndexOf("</UL>") - XMLResult.IndexOf("<UL ") + 5) 
                                    Try
                                        XMLResult = XMLResult.Substring(SReturn.Length + 2, XMLResult.Length() - SReturn.Length - 2)
                                    Catch ex As Exception
                                        XMLResult = XMLResult.Substring(SReturn.Length + 1, XMLResult.Length() - SReturn.Length - 1)
                                        If XMLResult = "" Then 
                                            s = ""
                                        End If
                                    End Try
                                     Dim commandFileXMLParsing As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("dbo.EGRUL_FileXMLParsing", connection)
                                    commandFileXMLParsing.CommandType = System.Data.CommandType.StoredProcedure
                                    commandFileXMLParsing.CommandTimeout = 0
                                    GetSqlParameters(commandFileXMLParsing)
                                    If connection.State = System.Data.ConnectionState.Closed Then
                                        connection.Open()
                                    End If
                                    commandFileXMLParsing.Parameters("@FileXMLText").Value = "<?xml version=""1.0"" encoding=""windows-1251""?>" + SReturn
                                    commandFileXMLParsing.Parameters("@FileName").Value = FileName
                                    commandFileXMLParsing.Parameters("@IdFile").Value = FileUploadNumber
                                    Try
                                        commandFileXMLParsing.ExecuteNonQuery()
                                    Catch ex1 As Exception
                                        MsgBox(FileFullName & vbCrLf & ex1.ToString(), MsgBoxStyle.Critical, "Ошибка")
                                        stream.Close()
                                        Exit Sub
                                    End Try
                                    If connection.State = System.Data.ConnectionState.Open Then
                                        connection.Close()
                                    End If
                                Else
                                    s = XMLResult
                                    Exit While
                                End If
                            ElseIf XMLResult.IndexOf("<IP ") >= 0 Then
                                s = ""
                                Exit While
                            Else
                                s = XMLResult
                                Exit While
                            End If
                        End While




Ошибку
Код: vbnet
1.
2.
3.
4.
5.
If RBytes <= 0 Then
 MsgBox("RBytes <0",64,"Ошибка ввода")
            Exit Sub

End If



Я сам добавил! Не могу понять откуда там появляются число 0 или менее 0?
Самый большой файл весит (83 380 786 байт)
Подскажите плиз
...
Рейтинг: 0 / 0
Проблемы с кодом!
    #38890953
Фотография Axeleron
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
DKasimov,

Неее, столько кода, да еще на VB.NET я осилить не в состоянии. Совет: дебажить и смотреть где этот 0 как раз и появляется. Как найдете, тогда приходите и спросите почему оно стало 0 там, если сами не разберетесь.
...
Рейтинг: 0 / 0
Проблемы с кодом!
    #38890976
DKasimov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Axeleron,
Код там вообще адский))) Ему лет уже)))
Я уже про него забыл, а тут нет)) сервис лег и решили поднять старый механизм загрузки из архива))


Ну похоже нашел проблему! Все это дело берет кусок кода весом максимум 2 метра, причем с указанием куска откуда и докуда брать))
вот этот кусок может быть больше 2-х метров и поэтому просто непонятно что делать)))
Сейчас проверю и посмотрим
...
Рейтинг: 0 / 0
Проблемы с кодом!
    #38890985
Фотография Axeleron
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
DKasimov,

Пилите, Шура, пилите!
...
Рейтинг: 0 / 0
6 сообщений из 6, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Проблемы с кодом!
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]