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
| Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Module Module1
Public DBSource = "Data Source=;Initial Catalog=MyCFDIAnalisis;Persist Security Info=True;User ID=sa;Password="
Public DBDest = "Data Source=;Initial Catalog=pospoints;Persist Security Info=True;User ID=sa;Password="
Sub Main()
Dim n As Long = 0
Do While True
Dim ConnexionSource As New SqlConnection
ConnexionSource.ConnectionString = DBSource
ConnexionSource.Open()
Dim ConnexionDest As New SqlConnection
ConnexionDest.ConnectionString = DBDest
ConnexionDest.Open()
Dim m_commandSource = ConnexionSource.CreateCommand
Dim m_commandDest = ConnexionDest.CreateCommand
Try
Dim p = CreateDataTable("SELECT TOP 100 * FROM skus WHERE sincronizado <>1 ORDER BY clave ", DBSource)
For Each row In p.Rows
n = n + 1
Console.WriteLine("Registro número: " & n & " ->" & row("clave") & "<- " & row("descripcion"))
Dim sku = CreateDataTable("SELECT articulo FROM POSPointsmaster WHERE articulo = '" & row("articulo") & "'", DBDest)
If row("clave").ToString.Trim.Length = 13 Or row("clave").ToString.Trim.Length = 8 Then
If Val2(row("clave")) > 0 Then
If sku.Rows.Count > 0 Then
m_commandDest.CommandText = "UPDATE POSPointsmaster SET articulo = @articulo , descripcion = @descripcion , precio = @precio, impuesto = @impuesto, tipoDeImpuesto = @tipoDeImpuesto, unidad = @unidad WHERE articulo = '" & row("articulo") & "'"
Else
m_commandDest.CommandText = "INSERT INTO POSPointsmaster (articulo, descripcion, precio, impuesto, tipoDeImpuesto, unidad) VALUES (@articulo, @descripcion, @precio, @impuesto, @tipoDeImpuesto, @unidad)"
End If
m_commandDest.Parameters.Clear()
m_commandDest.Parameters.AddWithValue("articulo", row("articulo"))
m_commandDest.Parameters.AddWithValue("descripcion", row("descripcion"))
m_commandDest.Parameters.AddWithValue("precio", row("precio"))
m_commandDest.Parameters.AddWithValue("impuesto", row("impuesto"))
m_commandDest.Parameters.AddWithValue("tipoDeImpuesto", row("tipoDeImpuesto"))
m_commandDest.Parameters.AddWithValue("unidad", row("unidad"))
m_commandDest.ExecuteNonQuery()
Console.WriteLine("Insertando producto: " & row("descripcion"))
End If
End If
m_commandSource.CommandText = "UPDATE skus SET sincronizado = 1 WHERE id = " & row("id")
m_commandSource.ExecuteNonQuery()
Next
m_commandSource.Dispose()
m_commandDest.Dispose()
ConnexionSource.Close()
ConnexionSource.Dispose()
ConnexionDest.Close()
ConnexionDest.Dispose()
Catch ex As Exception
logErrorFile(ex.ToString)
End Try
Threading.Thread.Sleep(2000)
Loop
End Sub
Public Function CreateDataTable(ByVal sSQL As String, ByVal strConn As String) As DataTable
Using da As New SqlDataAdapter(sSQL, strConn)
Dim ds As New DataSet()
da.SelectCommand.CommandTimeout = 120000
da.Fill(ds)
Return ds.Tables(0)
End Using
End Function
Public Function Val2(ByVal s As Object) As Decimal
Try
Return Decimal.Parse(s)
Catch ex As Exception
Return 0
End Try
End Function
Public Sub logErrorFile(ByVal sData As String)
sData = sData & vbCrLf
Dim sFileLog = String.Format("{0}\Log{1:yyyyMMdd}.txt", AppDomain.CurrentDomain.BaseDirectory, Now)
File.AppendAllText(sFileLog, sData)
Console.WriteLine(sData)
End Sub
End Module |
Partager