I have the code below and I am trying to get the progress bar to update as the files are moved. SO far no luck I am not sure what I am missing or what I have wrong with the code. Any help is appreciated. I am trying to move 500 records for testing purpose
Thanks
RJL
Thanks
RJL
Code:
public WEPK_Data_Mover()
{
InitializeComponent();
}
private void WEPK_Data_Mover_Load(object sender, EventArgs e)
{
percentagelabel.Text = "";
PrepareList();
}
private void PrepareList()
{
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "SP_Move_Shipments_List";
cmd.CommandType = CommandType.StoredProcedure;
cs.Open();
cmd.Connection = cs;
reader = cmd.ExecuteReader();
try
{
rowCount = 0;
if (reader.HasRows)
{
while (reader.Read())
{
rowCount++;
string _InternalNum = (reader.GetString(reader.GetOrdinal("INTERNAL_NUM")));
FileList.Add(_InternalNum);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
reader.Close();
cs.Close();
}
private void btnMove_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i < rowCount; i++)
{
foreach (string _Record in FileList)
{
_IntNum = _Record;
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
SqlParameterCollection sqlParameters = (SqlParameterCollection)cmd.Parameters;
sqlParameters.AddWithValue("@INTERNAL_SHIPMENT_NUM", _IntNum);
cmd.CommandText = "SP_Move_Shipments";
cmd.CommandType = CommandType.StoredProcedure;
cs.Open();
cmd.Connection = cs;
reader = cmd.ExecuteReader();
reader.Close();
cs.Close();
int percentage = (i + 1) * 100 / rowCount;
backgroundWorker1.ReportProgress(percentage);
}
FileList.Clear();
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
percentagelabel.Text = "Moving Shipments " + e.ProgressPercentage.ToString() + " % completed";
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
percentagelabel.Text = "Task completed " + rowCount + " records moved";
}