De hier geïllustreerde module laat toe de prijsformules (informatiebestandscripts) opnieuw toe te passen op alle artikels of op de artikels van de actieve filter. Ze wordt uitgevoerd via een knop toegevoegd in de "Artikels"-fiche.
De in deze knop te plaatsen code ziet er als volgt uit:
using System.Text;
using System.Data;
using MercatorApi;
using MercatorController;
using System.Data.SqlClient;
namespace MercatorUi.MovableControls.ButtonsCodes
{
public static class Script
{
public static void Exec(MercatorUi.MovableControls.MovableButton clickedButton)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)clickedButton.Form;
if (!sigForm.Sig.Write(sigForm)) // Voorstellen om de actieve fiche op te slaan, indien nodig.
return;
using (MercatorSqlConnection connSql = new MercatorSqlConnection(Globals.RepData, true)) // Creatie van een verbinding met de SQL DB
{
if (connSql.Connection == null) // De SQL-verbinding is geweigerd.
return;
using (SqlTransaction transac = connSql.Connection.BeginTransaction()) // We gaan het geheel uitvoeren onder transactie. Dat is niet verplicht: we kunnen ook null invoeren in plaats van transac bij ScriptsApplyToSomeRecords.
{
if (sigForm.Sig.ScriptsApplyToSomeRecords(sigForm.Filter, connSql, transac, showProgressBar: true))
{
transac.Commit();
Dialogs.Stop(Api.Iif_langue(Globals.Langue, 14));
}
else
Api.SafeRollback(transac);
}
}
}
}
}