In my application I'm getting data from another source and uploading those data to the tables.
So I wrote it as,(there are some codes before that, but I start with what I want to ask)
StartProcess();
FirstMonth();
SecondMonth();
ThirdMonth();
private async void StartProcess()
{
try
{
var progress = new Progress<int>(value => { progressBar1.Value = value; });
await System.Threading.Tasks.Task.Run(() => SaveData(progress));
MessageBox.Show("Upload Complete");
}
catch (Exception ex)
{
throw ex;
}
}
private void SaveData(IProgress<int> progress)
{
for (int i = 0; i < dataGridView1.RowCount; i++)//data reading one by one from excel
{
string PartNo = dataGridView1.Rows[i].Cells[0].Value.ToString();
string PartDescription = "";
string PartModel = "";
int AvaQty = int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
DbLoad obj = new DbLoad();
if (obj.UploadStock(PartNo, PartDescription, PartModel, AvaQty))
{
}
else
{
MessageBox.Show("An unexpected error has occurred.Please contact your system administrator");
}
}
MessageBox.Show("Upload Success");
}
This is the FirstMonth Method
private void FirstMonth()
{
try
{
OracleConnection con = new OracleConnection("OraConnection");
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "Query";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
dataGridView1.DataSource = dt.DefaultView;
UploadFirstMonth();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("error" + ex);
}
}
private void UploadFirstMonth()
{
for (int i = 0; i < dataGridView1.RowCount; i++)
{
string PartNo = dataGridView1.Rows[i].Cells[0].Value.ToString();
int AvaQty = int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
DbLoad obj = new DbLoad();
if (obj.UpdateFirstMonth(PartNo, AvaQty))
{}
else
{
MessageBox.Show("An unexpected error has occurred on First Month Upload.Please contact your system administrator");
}
}
}
Normally this has more than 15000 records to be upload to the database. Once it uploaded to the database I want to trigger the second method FirstMonth to start the method.
But the current Issue is before finishing the StartProcess() the second method is starting to process. How I stop that ? I want to trigger second method once the first method is completely finished.