In de artikelfiche een knop toevoegen die de prijsformules toepast op alle artikels of op de artikels van de actieve filter

0000002030     -      29-03-2019

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:

Zoom
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;
            int n_record = 0;
            using (MercatorSqlConnection oConnSql = new MercatorSqlConnection(Globals.RepData, true)) // Creatie van een verbinding met de SQL DB
            {
                if (oConnSql.Connection == null) // De verbinding is geweigerd.
                    return;
                using (SqlTransaction transac = oConnSql.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("select stock.*,guid,assembly from stock (NOLOCK) inner join assemblies on (assemblies.id='SCR-STOCK '+stock.s_calcul)" + (sigForm.Filter != "" ? " where " + sigForm.Filter : "") + " order by s_calcul", oConnSql, transac, true, true, ref n_record))
                    {
                        transac.Commit();
                        Dialogs.Stop(Api.Iif_langue(Globals.Langue, 14) + "\r\n" + _Divers.Iif_langue(Globals.Langue, "Records affected : ", "Gewijzigde records: ", "Enregistrements concernés : ") + n_record.ToString());
                    }
                    else
                        Api.SafeRollback(transac);
                }
            }
        }
    }
}