I have 2 methods Async
to make a Insert
in a database in the cloud ..
For reasons of the internet, the transaction may fail to handle this problem, I am using Commit
and RollBack
, even ai blz.
However, I need to execute a 3 method, but this can only be executed if these two Async
methods have been successfully completed.
I could make a loop
and be testing a return condition, but I do not think that's very correct, and I know there is a method called CallBack
.
But how to implement CallBack
?
Below my methods Async
:
class Upload_RaWeb
{
Conexao_bd consql = new Conexao_bd();
async public void Details_Upload(int id, string cod_item_Crm, int cod_cli, string razao_social, string data_rec, string data_anal, string n_Crm, string n_Nf
, string OF_anterior, string modelo, string material, string arranjo, string diam, string tipo, string inicio_op
, string fim_op, string motivo, string tag, string fabric_bomba, string mod_bomba, string prod_fluido, string temp_fluido
, string rpm, string api, string pres_suc, string pres_desc, string diag_falha, string analise, string conclusao
, string recomend, int nivel)
{
consql.bd_string_nuvem();
SqlConnection sqlconn = new SqlConnection(consql.sqlconn);
try
{
consql._sql = @"INSERT INTO[dbo].[DetailsRaWeb]
([id]
,[cod_item_Crm]
,[cod_cli]
,[razao_social]
,[data_rec]
,[data_anal]
,[n_Crm]
,[n_Nf]
,[OF_anterior]
,[modelo]
,[material]
,[arranjo]
,[diam]
,[tipo]
,[inicio_op]
,[fim_op]
,[motivo]
,[tag]
,[fabric_bomba]
,[mod_bomba]
,[prod_fluido]
,[temp_fluido]
,[rpm]
,[api]
,[pres_suc]
,[pres_desc]
,[diag_falha]
,[analise]
,[conclusao]
,[recomend]
,[nivel])
VALUES
(@id
,@cod_item_Crm
,@cod_cli
,@razao_social
,@data_rec
,@data_anal
,@n_Crm
,@n_Nf
,@OF_anterior
,@modelo
,@material
,@arranjo
,@diam
,@tipo
,@inicio_op
,@fim_op
,@motivo
,@tag
,@fabric_bomba
,@mod_bomba
,@prod_fluido
,@temp_fluido
,@rpm
,@api
,@pres_suc
,@pres_desc
,@diag_falha
,@analise
,@conclusao
,@recomend
,@nivel)";
SqlCommand cmd = new SqlCommand(consql._sql, sqlconn);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
cmd.Parameters.Add("@cod_item_Crm", SqlDbType.VarChar).Value = cod_item_Crm;
cmd.Parameters.Add("@cod_cli", SqlDbType.Int).Value = cod_cli;
cmd.Parameters.Add("@razao_social", SqlDbType.VarChar).Value = razao_social;
cmd.Parameters.Add("@data_rec", SqlDbType.VarChar).Value = data_rec;
cmd.Parameters.Add("@data_anal", SqlDbType.VarChar).Value = data_anal;
cmd.Parameters.Add("@n_Crm", SqlDbType.VarChar).Value = n_Crm;
cmd.Parameters.Add("@n_Nf", SqlDbType.VarChar).Value = n_Nf;
cmd.Parameters.Add("@OF_anterior", SqlDbType.VarChar).Value = OF_anterior;
cmd.Parameters.Add("@modelo", SqlDbType.VarChar).Value = modelo;
cmd.Parameters.Add("@material", SqlDbType.VarChar).Value = material;
cmd.Parameters.Add("@arranjo", SqlDbType.VarChar).Value = arranjo;
cmd.Parameters.Add("@diam", SqlDbType.VarChar).Value = diam;
cmd.Parameters.Add("@tipo", SqlDbType.VarChar).Value = tipo;
cmd.Parameters.Add("@inicio_op", SqlDbType.VarChar).Value = inicio_op;
cmd.Parameters.Add("@fim_op", SqlDbType.VarChar).Value = fim_op;
cmd.Parameters.Add("@motivo", SqlDbType.VarChar).Value = motivo;
cmd.Parameters.Add("@tag", SqlDbType.VarChar).Value = tag;
cmd.Parameters.Add("@fabric_bomba", SqlDbType.VarChar).Value = fabric_bomba;
cmd.Parameters.Add("@mod_bomba", SqlDbType.VarChar).Value = mod_bomba;
cmd.Parameters.Add("@prod_fluido", SqlDbType.VarChar).Value = prod_fluido;
cmd.Parameters.Add("@temp_fluido", SqlDbType.VarChar).Value = temp_fluido;
cmd.Parameters.Add("@rpm", SqlDbType.VarChar).Value = rpm;
cmd.Parameters.Add("@api", SqlDbType.VarChar).Value = api;
cmd.Parameters.Add("@pres_suc", SqlDbType.VarChar).Value = pres_suc;
cmd.Parameters.Add("@pres_desc", SqlDbType.VarChar).Value = pres_desc;
cmd.Parameters.Add("@diag_falha", SqlDbType.VarChar).Value = diag_falha;
cmd.Parameters.Add("@analise", SqlDbType.VarChar).Value = analise;
cmd.Parameters.Add("@conclusao", SqlDbType.VarChar).Value = conclusao;
cmd.Parameters.Add("@recomend", SqlDbType.VarChar).Value = recomend;
cmd.Parameters.Add("@nivel", SqlDbType.VarChar).Value = nivel;
await sqlconn.OpenAsync();
await cmd.ExecuteNonQueryAsync();
}
catch (Exception error)
{
MessageBox.Show("erro" + error);
}
finally
{
sqlconn.Close();
}
}
async public void Foto_Upload(DataTableReader dtr)
{
consql.bd_string_nuvem();
SqlConnection sqlconn = new SqlConnection(consql.sqlconn);
await sqlconn.OpenAsync();
SqlTransaction tran = sqlconn.BeginTransaction();
try
{
consql._sql = @"INSERT INTO [dbo].[FotosRaWeb]
([id]
,[Bfoto]
,[item]
,[foto_seq]
,[zoom]
,[descr_foto])
VALUES
(@id
,@Bfoto
,@item
,@foto_seq
,@zoom
,@descr_foto)";
while (await dtr.ReadAsync())
{
SqlCommand cmd = new SqlCommand(consql._sql, sqlconn, tran);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = (int)dtr["id"];
cmd.Parameters.Add("@Bfoto", SqlDbType.VarBinary).Value = (byte[])dtr["Bfoto"];
cmd.Parameters.Add("@item", SqlDbType.VarChar).Value = dtr["item"].ToString();
cmd.Parameters.Add("@foto_seq", SqlDbType.VarChar).Value = dtr["pic"].ToString();
cmd.Parameters.Add("@zoom", SqlDbType.VarChar).Value = dtr["zoom"].ToString();
cmd.Parameters.Add("@descr_foto", SqlDbType.VarChar).Value = dtr["descricao"].ToString();
await cmd.ExecuteNonQueryAsync();
}
}
catch (Exception error)
{
tran.Rollback();
MessageBox.Show("erro" + error);
}
finally
{
tran.Commit();
sqlconn.Close();
}
}
}