I have a Windows Form, that has a Telerik RadGridView with a bunch of records to be imported into our SQL database. The RadGridView just shows the users the records that are going to be imported, in case they see an easy to fix mistake that they could address, before importing the records.
I have the following controls on the Winform form:
rgImport - Telerik RadGridView control
btnSubmit - button control
ProgressBar1 - Progress Bar for when importing the records
Label1 - some text telling the user to review the records presented in rgImport
I am looking to make some of these functions Async/Await, so the UI doesn't get locked, and the progress bar shows what percentage of records have been imported:
The two calls to these functions:
DataAPI.HR_Payroll_TimeCards_Insert(dr)
DataAPI.HR_Payroll_TimeCards_Insert_Double(dr)
do nothing more than inject the records into our database server tables and return a boolean on whether is was successful or failed
Private Sub Import_Payroll_Review_Load(sender As Object, e As EventArgs) Handles Me.Load
rgImport.DataSource = DataAPI.HR_Payroll_Import_GetData()
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 100
ProgressBar1.Visible = False
End Sub
DataAPI.HR_Payroll_Import_GetData() - just returns a DataTable that is used to load up the RadGridView with records
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Select Case MsgBox("Are you sure you are ready to import?", MsgBoxStyle.YesNo, "Import Records")
Case MsgBoxResult.Yes
'Import the records from the import table
Dim dt As DataTable = DataAPI.HR_Payroll_Import_GetRecordsToImport()
Dim iRows As Long = 1
Dim iTotalRows As Long = dt.Rows.Count
'CallTheInsertMethodHere
For Each dr As DataRow In dt.Rows
If dr("AfterHours") = 0 Then
'This is standard time, so import it into the [TimeCards.Current] table
If DataAPI.HR_Payroll_TimeCards_Insert(dr) Then
'Success
Debug.Print("Inserted Row into TimeCard.Current")
Else
'Failed
Debug.Print("Failed to insert row into TimeCard.Current")
End If
Else
'This is double time, so import it into the [TimeCards.Current.Double] table
If DataAPI.HR_Payroll_TimeCards_Insert_Double(dr) Then
'Success
Debug.Print("Inserted Row into TimeCard.Current.Double")
Else
'Failed
Debug.Print("Failed to insert row into TimeCard.Current.Double")
End If
End If
iRows += 1
Next
MsgBox("Inserted " & iRows - 1 & " rows", vbInformation, "Success")
Case Else
'User clicked on no, so exit
Exit Sub
End Select
End Sub
I am just looking for a little help/direction on how to break this up and where to add Async/Await to allow the UI to be free'd up to show what percentage of the records have been inserted using the ProgressBar (The total records is in the variable iTotalRows)
Thank you for your time reviewing this and any input you may provide to me to get this working.