/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/usercontrols/dataupload.ascx.vb
174 строки
7 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
Imports System.Data.SqlClient Partial Class UserControls_dataUpload Inherits System.Web.UI.UserControl 'Private Function UploadTable(ByVal tabName As String, _ ' ByVal fileName As String, _ ' Optional ByVal ClearData As Boolean = False, _ ' Optional ByVal FixDecimal As Boolean = False, _ ' Optional ByVal DecimalSeparator As String = ".", _ ' Optional removeBlanks As Boolean = False, ' Optional altFormat As Boolean = False) As Integer ' 'Dim o As Object = CreateObject("Application.Excel") ' Dim batchSize As Integer = 100 ' Dim batchCounter As Integer = 0 ' Dim bCommaFlag1 As Boolean = False ' Dim iUploadedRows As Integer = 0 ' Try ' Dim sf As New SqlFunctions ' Dim SQL As String ' If ClearData Then ' SQL = "DELETE FROM [tmp].[dbo]." & tabName ' sf.NonQuery(SQL) ' End If ' Dim con As New SqlConnection(sf.ConString) ' Dim sqlScript As String = "select name as COLUMN_NAME from [tmp].sys.columns where object_id in ( " & _ ' "select object_id from [tmp].sys.tables " & _ ' "where name = '" & tabName & "' " & _ ' ") order by column_id " ' Dim com As New SqlCommand(sqlScript, con) ' con.Open() ' Dim rr As SqlDataReader = com.ExecuteReader ' '---------------------------------------------- ' Dim i As Integer = 0 ' Dim sColumnsList As String = "" ' Dim iColumnsNumber As Integer = 0 ' While rr.Read ' If rr.Item("COLUMN_NAME") <> "ID" Then ' If i > 0 Then sColumnsList &= "," ' sColumnsList &= rr.Item("COLUMN_NAME") ' i += 1 ' End If ' End While ' iColumnsNumber = i ' rr.Close() ' Dim f As New StreamReader(fileName) ' Dim s As String = "" ' Dim ss() As String ' Dim iRowCount As Integer = 0 ' Dim iaSkipRows() As Integer = {1, 2, 3, 4, 5, 6} ' Dim iaSkipColmns() As Integer ' If altFormat Then ' iaSkipColmns = {1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29} ' Else ' iaSkipColmns = {1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28} ' End If ' Do While f.Peek >= 0 ' SQL = "INSERT INTO [tmp].[dbo]." & tabName & " (" ' SQL &= sColumnsList ' SQL &= ") VALUES " ' bCommaFlag1 = False ' batchCounter = 1 ' Do While f.Peek >= 0 And batchCounter <= batchSize ' s = f.ReadLine ' 'Пропускаем пустые строки и заголовок ' iRowCount += 1 ' If iaSkipRows.Contains(iRowCount) Then Continue Do ' ss = s.Split(vbTab) ' i = 1 ' If bCommaFlag1 Then ' SQL &= ",(" ' Else ' SQL &= "(" ' End If ' Dim iColCount As Integer = 0 ' For Each s In ss ' 'Пропускаеим ненужные колонки ' iColCount += 1 ' If iaSkipColmns.Contains(iColCount) Then Continue For ' If i > iColumnsNumber Then Exit For ' If i > 1 Then SQL &= "," ' If FixDecimal Then s = s.Replace(".", DecimalSeparator).Replace(",", DecimalSeparator) ' If removeBlanks Then s = s.Replace(" ", "") ' SQL &= "'" & s.Replace("'", "") & "'" ' i += 1 ' Next ' SQL &= ")" ' bCommaFlag1 = True ' batchCounter += 1 ' Loop ' If Not sf.NonQuery(SQL, False) Then ' lblInfo.Text = SQL ' Exit Do ' End If ' iUploadedRows += batchCounter - 1 ' Loop ' If Not IsNothing(rr) Then rr.Close() ' If con.State <> Data.ConnectionState.Closed Then con.Close() ' Catch ex As Exception ' lblInfo.Text = ex.Message ' UploadTable = 0 ' Exit Function ' End Try ' lblInfo.Text = "File " & fileName & " was sucessfully uploaded to " & tabName & " table" ' UploadTable = iUploadedRows 'End Function 'Private Function SaveFile(ByVal path As String, ByVal FU As FileUpload) As String ' Dim fileName As String = FU.FileName ' Dim pathToCheck As String = path + fileName ' If Not Directory.Exists(path) Then ' Try ' Directory.CreateDirectory(path) ' Catch ex As Exception ' lblInfo.Text = ex.Message ' End Try ' End If ' If (System.IO.File.Exists(pathToCheck)) Then ' System.IO.File.Delete(pathToCheck) ' SaveFile = "A file with the same name was overwritten " + fileName ' Else ' SaveFile = "Your file was uploaded successfully." ' End If ' FU.SaveAs(pathToCheck) 'End Function 'Protected Sub btnUploadSingleFile_Click(sender As Object, e As System.EventArgs) Handles btnUploadSingleFile.Click ' ' Before attempting to save the file, verify ' ' that the FileUpload control contains a file. ' Try ' If (fuUploadSingleFile.HasFile) Then ' ' Call a helper method routine to save the file. ' lblInfo.Text = SaveFile(SingleFileSavePath, fuUploadSingleFile) '.PostedFile) ' lblUploadedRows.Text = "Rows uploaded to buffer: " & UploadTable(ddlChooseTable.Text, SingleFileSavePath & fuUploadSingleFile.FileName, Not chkAppendTable.Checked, True, ".", True, chkAlternativeFormat.Checked) ' lblUploadedRows.Text &= vbNewLine ' lblUploadedRows.Text &= " Rows uploaded to Price table: " & TransferToWMS() ' Me.DataBind() ' BuildGrid() ' Else ' ' Notify the user that a file was not uploaded. ' lblInfo.Text = "You did not specify a file to upload." ' lblUploadedRows.Text = "0" ' End If ' Catch ex As Exception ' lblInfo.Text = ex.Message ' End Try 'End Sub End Class