----http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(v=vs.90).aspx----
private void btnProcess_Click(object sender, EventArgs e)
{
if (BackGroundWorkerPhaseI.IsBusy != true)
{
BackGroundWorkerPhaseI.RunWorkerAsync();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (BackGroundWorkerPhaseI.WorkerSupportsCancellation == true)
{
BackGroundWorkerPhaseI.CancelAsync();
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void BackGroundWorkerPhaseI_DoWork(object sender, DoWorkEventArgs e)
{
try
{
for (int i = 1; (i <= 100); i++)
{
if ((BackGroundWorkerPhaseI.CancellationPending == true))
{
e.Cancel = true;
for (int j = i; j >= 0; j--)
{
if (j == 10)
{
SqlQuery = "truncate table tbl_Complete_Teacher_Configuration";
}
if (j == 20)
{
SqlQuery = "truncate table tbl_Complete_Teacher_Configuration; truncate table tbl_Complete_Class_Configuration";
}
if (j == 30)
{
SqlQuery = "truncate table tbl_Complete_Teacher_Configuration; truncate table tbl_Complete_Class_Configuration;truncate table tbl_Configuration_master ";
}
if (j == 40)
{
SqlQuery = "truncate table tbl_Complete_Teacher_Configuration; truncate table tbl_Complete_Class_Configuration;truncate table tbl_Configuration_master; truncate table tbl_Allotment_Master ";
}
flag = deleteData.DeleteDataValues(SqlQuery);
BackGroundWorkerPhaseI.ReportProgress(j);
}
break;
}
else
{
// Wait 100 milliseconds.
if (i == 10)
{
SqlQuery = "sp_CreateTeacherConfigurtion";
flag = insertData.InsertDataValues(SqlQuery);
}
if (i == 20)
{
SqlQuery = "sp_CreateClassConfigurtion";
flag = insertData.InsertDataValues(SqlQuery);
}
if (i == 30)
{
SqlQuery = "sp_CreateConfigurationMaster";
flag = insertData.InsertDataValues(SqlQuery);
}
// Report progress.
if (i == 40)
{
SqlQuery = "sp_FillAlotmentsFromCombinedConditions";
flag = insertData.InsertDataValues(SqlQuery);
}
if (i == 50)
{
flag = ReflectCombinedConditions();
}
if (i == 60)
{
flag = GenerateAllotments();
}
//if (i == 90)
//{
// flag = ReflectCombinedConditions();
//}
BackGroundWorkerPhaseI.ReportProgress(i);
}
}
}
catch (Exception ex)
{
}
}
private void BackGroundWorkerPhaseI_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
PhaseIProgressBar.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString() + "%";
}
private void BackGroundWorkerPhaseI_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if ((e.Cancelled == true))
{
MessageBox.Show("Operation Aborted.!", "Time Table", MessageBoxButtons.OK, MessageBoxIcon.Error);
PhaseIProgressBar.Value = 0;
this.Text = "Operation Aborted";
}
else if (!(e.Error == null))
{
MessageBox.Show("Error: " + e.Error.Message, "Time Table", MessageBoxButtons.OK, MessageBoxIcon.Error);
PhaseIProgressBar.Value = 0;
}
else
{
MessageBox.Show("PHASE-I Generation Completed.", "Time Table", MessageBoxButtons.OK, MessageBoxIcon.Information);
PhaseIProgressBar.Value = 0;
}
}
private void btnProcess_Click(object sender, EventArgs e)
{
if (BackGroundWorkerPhaseI.IsBusy != true)
{
BackGroundWorkerPhaseI.RunWorkerAsync();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (BackGroundWorkerPhaseI.WorkerSupportsCancellation == true)
{
BackGroundWorkerPhaseI.CancelAsync();
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void BackGroundWorkerPhaseI_DoWork(object sender, DoWorkEventArgs e)
{
try
{
for (int i = 1; (i <= 100); i++)
{
if ((BackGroundWorkerPhaseI.CancellationPending == true))
{
e.Cancel = true;
for (int j = i; j >= 0; j--)
{
if (j == 10)
{
SqlQuery = "truncate table tbl_Complete_Teacher_Configuration";
}
if (j == 20)
{
SqlQuery = "truncate table tbl_Complete_Teacher_Configuration; truncate table tbl_Complete_Class_Configuration";
}
if (j == 30)
{
SqlQuery = "truncate table tbl_Complete_Teacher_Configuration; truncate table tbl_Complete_Class_Configuration;truncate table tbl_Configuration_master ";
}
if (j == 40)
{
SqlQuery = "truncate table tbl_Complete_Teacher_Configuration; truncate table tbl_Complete_Class_Configuration;truncate table tbl_Configuration_master; truncate table tbl_Allotment_Master ";
}
flag = deleteData.DeleteDataValues(SqlQuery);
BackGroundWorkerPhaseI.ReportProgress(j);
}
break;
}
else
{
// Wait 100 milliseconds.
if (i == 10)
{
SqlQuery = "sp_CreateTeacherConfigurtion";
flag = insertData.InsertDataValues(SqlQuery);
}
if (i == 20)
{
SqlQuery = "sp_CreateClassConfigurtion";
flag = insertData.InsertDataValues(SqlQuery);
}
if (i == 30)
{
SqlQuery = "sp_CreateConfigurationMaster";
flag = insertData.InsertDataValues(SqlQuery);
}
// Report progress.
if (i == 40)
{
SqlQuery = "sp_FillAlotmentsFromCombinedConditions";
flag = insertData.InsertDataValues(SqlQuery);
}
if (i == 50)
{
flag = ReflectCombinedConditions();
}
if (i == 60)
{
flag = GenerateAllotments();
}
//if (i == 90)
//{
// flag = ReflectCombinedConditions();
//}
BackGroundWorkerPhaseI.ReportProgress(i);
}
}
}
catch (Exception ex)
{
}
}
private void BackGroundWorkerPhaseI_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
PhaseIProgressBar.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString() + "%";
}
private void BackGroundWorkerPhaseI_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if ((e.Cancelled == true))
{
MessageBox.Show("Operation Aborted.!", "Time Table", MessageBoxButtons.OK, MessageBoxIcon.Error);
PhaseIProgressBar.Value = 0;
this.Text = "Operation Aborted";
}
else if (!(e.Error == null))
{
MessageBox.Show("Error: " + e.Error.Message, "Time Table", MessageBoxButtons.OK, MessageBoxIcon.Error);
PhaseIProgressBar.Value = 0;
}
else
{
MessageBox.Show("PHASE-I Generation Completed.", "Time Table", MessageBoxButtons.OK, MessageBoxIcon.Information);
PhaseIProgressBar.Value = 0;
}
}
No comments:
Post a Comment