List<Int64> l = Api.Zselect<Int64>(Globals.RepData, $"exec {MercatorUi.Globals.DatabaseName}.dbo.SP_GET_N_LETTRAGE -1");
if (l != null)
{
Int64 n_lettrage = l[0];
// n = numéro de la ligne
// ligne de l'écriture en cours non déjà sauvegardée -> piece = 0
sbReqSqlLettrage.AppendFormat("insert into lettragtmp (spid,id_doc_ori,journal,piece,dl_id,lettrage) values ({0},'{1}','{2}',0,'{3}',{4}) \r\n", MercatorUi.Globals.CurrentSpId, bookingEngine.Id + bookingEngine.LIGNES_C.Rows[n]["dl_id"].ToString(), bookingEngine.LIGNES_C.Rows[n]["journal"].ToString(), bookingEngine.LIGNES_C.Rows[n]["dl_id"], n_lettrage);
// ligne de l'écriture existante qu'il faut lettrer
sbReqSqlLettrage.AppendFormat("insert into lettragtmp (spid,id_doc_ori,journal,piece,dl_id,lettrage) values ({0},'{1}','{2}',{3},'{4}',{5}) \r\n", MercatorUi.Globals.CurrentSpId, bookingEngine.Id + bookingEngine.LIGNES_C.Rows[n]["dl_id"].ToString(), journal_autre_ecriture, piece_autre_ecriture, dl_id autre_ecriture, n_lettrage);
bookingEngine.LignesCRecords[n].LETTRAGE = n_lettrage;
bookingEngine.LignesCRecords[n].TOT_DV_LET = bookingEngine.LignesCRecords[n].TOT_DV;
bookingEngine.LignesCRecords[n].TOT_LET = bookingEngine.LignesCRecords[n].TOT;
}