11-12-17, 07:23 PM
هذا تعديل لعله يفيد
PHP كود :
Imports MySql.Data.MySqlClient
Public Class Form1
Dim con As New MySqlConnection("Data Source=50.629.2.409;user=newbk;password=Qng;database=bk;port=3306")
Private cmdCheckCount As New MySqlCommand(String.Empty, con)
Private cmdInsert As New MySqlCommand(String.Empty, con)
Dim ErrorCount As Integer = 0
Dim InsertedCount As Integer = 0
Dim i As Integer = 0
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
cmdCheckCount.CommandText = "SELECT COUNT(CALLop) FROM log_log WHERE (station_callsign = @station_callsign) AND (CALLop = @CALLop) AND (DateNumber = @DateNumber) AND (time_on = @time_on)"
cmdCheckCount.Parameters.Clear()
cmdCheckCount.Parameters.Add("@CALLop", MySqlDbType.VarChar)
cmdCheckCount.Parameters.Add("@DateNumber", MySqlDbType.VarChar)
cmdCheckCount.Parameters.Add("@time_on", MySqlDbType.VarChar)
cmdCheckCount.Parameters.Add("@station_callsign", MySqlDbType.VarChar)
'============================================================
cmdInsert.CommandText = "INSERT INTO log_log (CALLop,qso_date,timek,bands,modes,Lfullname,station_callsign,dxcc,cqz,ituz,rst_sent,rst_rcvd,lotw_qsl_sent,lotw_qsl_rcvd,eqsl_qsl_sent,eqsl_qsl_rcvd,qsl_sent,qsl_rcvd,qsl_sent_date,qsl_print,country,qth,LAT,LON,GRIDSQUARE,Lqslmgr,PFX,freq,DateNumber,iota,bk_qsl_sent,time_on,state,operato,nameop,Continent,hamqth_qsl_sent,clublog_qsl_sent) Values (@CALLop,@qso_date,@timek,@bands,@modes,@Lfullname,@station_callsign,@dxcc,@cqz,@ituz,@rst_sent,@rst_rcvd,@lotw_qsl_sent,@lotw_qsl_rcvd,@eqsl_qsl_sent,@eqsl_qsl_rcvd,@qsl_sent,@qsl_rcvd,@qsl_sent_date,@qsl_print,@country,@qth,@LAT,@LON,@GRIDSQUARE,@Lqslmgr,@PFX,@freq,@DateNumber,@iota,@bk_qsl_sent,@time_on,@state,@operato,@nameop,@Continent,@hamqth_qsl_sent,@clublog_qsl_sent)"
cmdInsert.Parameters.Clear()
cmdInsert.Parameters.Add("@CALLop", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@qso_date", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@timek", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@bands", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@modes", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@Lfullname", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@station_callsign", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@dxcc", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@cqz", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@ituz", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@rst_sent", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@rst_rcvd", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@lotw_qsl_sent", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@lotw_qsl_rcvd", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@eqsl_qsl_sent", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@eqsl_qsl_rcvd", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@qsl_sent", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@qsl_rcvd", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@qsl_sent_date", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@qsl_print", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@country", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@qth", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@LAT", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@LON", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@GRIDSQUARE", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@Lqslmgr", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@PFX", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@freq", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@DateNumber", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@iota", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@bk_qsl_sent", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@time_on", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@state", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@operato", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@nameop", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@Continent", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@clublog_qsl_sent", MySqlDbType.VarChar)
cmdInsert.Parameters.Add("@hamqth_qsl_sent", MySqlDbType.VarChar)
ProgressBar1.Style = ProgressBarStyle.Blocks
End Sub
Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
Dim thr As New Threading.Thread(AddressOf task1)
thr.IsBackground = True
thr.Start()
End Sub
Sub task1()
Try
con.Open()
Using transaction = con.BeginTransaction()
cmdCheckCount.Transaction = transaction
cmdInsert.Transaction = transaction
For Each dr As DataGridViewRow In DataGridView1.Rows
ProgressBar1.Invoke(Sub() ProgressBar1.Value = (i / DataGridView1.Rows.Count) * 100)
Label5.Invoke(Sub() Label5.Text = InsertedCount)
Label2.Invoke(Sub() Label2.Text = ErrorCount)
Call addData(i)
i += 1
Next
transaction.Commit()
End Using
Close()
MsgBox("all ok")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub addData(ByVal i As Integer)
Debug.Print(String.Format("{0} | Start Add :{1:mm:ssss}", i, Now))
cmdCheckCount.Parameters("@CALLop").Value = DataGridView1.Rows(i).Cells(1).Value
cmdCheckCount.Parameters("@DateNumber").Value = DataGridView1.Rows(i).Cells(29).Value
cmdCheckCount.Parameters("@time_on").Value = DataGridView1.Rows(i).Cells(32).Value
cmdCheckCount.Parameters("@station_callsign").Value = DataGridView1.Rows(i).Cells(7).Value
If cmdCheckCount.ExecuteScalar = 0 Then
cmdInsert.Parameters("@CALLop").Value = DataGridView1.Rows(i).Cells(1).Value
cmdInsert.Parameters("@qso_date").Value = DataGridView1.Rows(i).Cells(2).Value
cmdInsert.Parameters("@timek").Value = DataGridView1.Rows(i).Cells(3).Value
cmdInsert.Parameters("@bands").Value = DataGridView1.Rows(i).Cells(4).Value
cmdInsert.Parameters("@modes").Value = DataGridView1.Rows(i).Cells(5).Value
cmdInsert.Parameters("@Lfullname").Value = DataGridView1.Rows(i).Cells(6).Value
cmdInsert.Parameters("@station_callsign").Value = DataGridView1.Rows(i).Cells(7).Value
cmdInsert.Parameters("@dxcc").Value = DataGridView1.Rows(i).Cells(8).Value
cmdInsert.Parameters("@cqz").Value = DataGridView1.Rows(i).Cells(9).Value
cmdInsert.Parameters("@ituz").Value = DataGridView1.Rows(i).Cells(10).Value
cmdInsert.Parameters("@rst_sent").Value = DataGridView1.Rows(i).Cells(11).Value
cmdInsert.Parameters("@rst_rcvd").Value = DataGridView1.Rows(i).Cells(12).Value
cmdInsert.Parameters("@lotw_qsl_sent").Value = DataGridView1.Rows(i).Cells(13).Value
cmdInsert.Parameters("@lotw_qsl_rcvd").Value = DataGridView1.Rows(i).Cells(14).Value
cmdInsert.Parameters("@eqsl_qsl_sent").Value = DataGridView1.Rows(i).Cells(15).Value
cmdInsert.Parameters("@eqsl_qsl_rcvd").Value = DataGridView1.Rows(i).Cells(16).Value
cmdInsert.Parameters("@qsl_sent").Value = DataGridView1.Rows(i).Cells(17).Value
cmdInsert.Parameters("@qsl_rcvd").Value = DataGridView1.Rows(i).Cells(18).Value
cmdInsert.Parameters("@qsl_sent_date").Value = DataGridView1.Rows(i).Cells(19).Value
cmdInsert.Parameters("@qsl_print").Value = DataGridView1.Rows(i).Cells(20).Value
cmdInsert.Parameters("@country").Value = DataGridView1.Rows(i).Cells(21).Value
cmdInsert.Parameters("@qth").Value = DataGridView1.Rows(i).Cells(22).Value
cmdInsert.Parameters("@LAT").Value = DataGridView1.Rows(i).Cells(23).Value
cmdInsert.Parameters("@LON").Value = DataGridView1.Rows(i).Cells(24).Value
cmdInsert.Parameters("@GRIDSQUARE").Value = DataGridView1.Rows(i).Cells(25).Value
cmdInsert.Parameters("@Lqslmgr").Value = DataGridView1.Rows(i).Cells(26).Value
cmdInsert.Parameters("@PFX").Value = DataGridView1.Rows(i).Cells(27).Value
cmdInsert.Parameters("@freq").Value = DataGridView1.Rows(i).Cells(28).Value
cmdInsert.Parameters("@DateNumber").Value = DataGridView1.Rows(i).Cells(29).Value
cmdInsert.Parameters("@iota").Value = DataGridView1.Rows(i).Cells(30).Value
cmdInsert.Parameters("@bk_qsl_sent").Value = DataGridView1.Rows(i).Cells(31).Value
cmdInsert.Parameters("@time_on").Value = DataGridView1.Rows(i).Cells(32).Value
cmdInsert.Parameters("@state").Value = DataGridView1.Rows(i).Cells(33).Value
cmdInsert.Parameters("@operato").Value = DataGridView1.Rows(i).Cells(34).Value
cmdInsert.Parameters("@nameop").Value = DataGridView1.Rows(i).Cells(35).Value
cmdInsert.Parameters("@Continent").Value = DataGridView1.Rows(i).Cells(36).Value
'cmdInsert.Parameters("@lotwde").Value = DataGridView1.Rows(i).Cells(37).Value
'cmdInsert.Parameters("@eqsld").Value = DataGridView1.Rows(i).Cells(38).Value
cmdInsert.Parameters("@clublog_qsl_sent").Value = DataGridView1.Rows(i).Cells(39).Value
cmdInsert.Parameters("@hamqth_qsl_sent").Value = DataGridView1.Rows(i).Cells(40).Value
cmdInsert.ExecuteNonQuery()
InsertedCount += 1
Else
ErrorCount += 1
End If
End Sub
End Class

