U bevindt zich nu op een technische pagina over de software Mercator. Deze pagina bevat specifieke informatie die bestemd is voor professionals van de software Mercator. Wenst u naar algemenere informatie over Mercator door te gaan?


   Deze vraag niet meer stellen

In het informatiebestand van de artikels worden er knoppen geplaatst waarmee nieuwe rayons, families, subfamilies of categorie├źn kunnen worden aangemaakt

0000002230     -      13-03-2024

Het objectief van deze programmering is om het rechtstreeks toevoegen van rayons, families en subfamilies mogelijk te maken vanuit het informatiebestand van de artikels. Dat gebeurt door als volgt drie knoppen toe te voegen via de instellingen van het scherm 'artikels'.

buttons_new_rfs

De in het bestand aangemaakte rayon / familie / subfamilie wordt automatische gekoppeld aan de huidige fiche.

De knopcode "Rayon" is:

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorController;
using MercatorUi;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace MercatorUi.MovableControls.ButtonsCodes
{
    public static class Script
    {

        public static void Exec(MercatorUi.MovableControls.MovableButton clickedButton)
        {
            string newRayonLib = Dialogs.AskString(("Welke nieuwe rayon?"), "");
            if (string.IsNullOrEmpty(newRayonLib))
                return;
            newRayonLib = newRayonLib.Trim();
            if (MercatorController.xFunctions.xLookUpString("RAYONS", "NOM", newRayonLib, "ID").TrimEnd() != "")
            {
                Dialogs.Stop("Deze rayon bestaat al!");
                return;
            }
            string newRayonId = Api.Ident();
            using (SqlCommand cmd = new SqlCommand("insert into RAYONS (id,nom) values (@id,@nom)"))
            {
                cmd.Parameters.AddWithValue("id", newRayonId).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("nom", newRayonLib).SqlDbType = SqlDbType.Char;
                if (!Api.SqlExec(Globals.RepData, cmd))
                    return;
            }
            List<Control> l = clickedButton.Form.FindMovableControlsBySource("S_ID_RAYON");
            if (l.Count > 0)
            {
                MovableControls.MovableComboBox combo = (MovableControls.MovableComboBox)l[0];
                DataTable dt_rayons = (DataTable)combo.DataSource;
                DataRow dr_new = dt_rayons.NewRow();
                Api.DataRowResetContent(dr_new);
                dr_new["id"] = newRayonId;
                dr_new["naam"] = newRayonLib;
                dt_rayons.Rows.Add(dr_new);
                combo.SelectedValue = newRayonId;
            }

        }
    }
}

De knopcode "Familie" is:

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorController;
using MercatorUi;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.ComponentModel;

namespace MercatorUi.MovableControls.ButtonsCodes
{
    public static class Script
    {

        public static void Exec(MercatorUi.MovableControls.MovableButton clickedButton)
        {
            string s_id_rayon = clickedButton.Form.DataSource.Rows[0]["s_id_rayon"].ToString();
            if (s_id_rayon == "")
            {
                Dialogs.Stop("U moet eerst een rayon selecteren!");
                return;
            }

            string newFamilleLib = Dialogs.AskString(("Welke nieuwe familie?"), "");
            if (string.IsNullOrEmpty(newFamilleLib))
                return;
            newFamilleLib = newFamilleLib.Trim();
            if (MercatorController.xFunctions.xLookUpString("FAMILIES", "NOM", newFamilleLib, "ID", string.Format("id_rayon='{0}'", Api.UnquoteSql(s_id_rayon))).TrimEnd() != "")
            {
                Dialogs.Stop("Deze familie bestaat al!");
                return;
            }
            string newFamilleId = Api.Ident();
            using (SqlCommand cmd = new SqlCommand("insert into FAMILLES (id,nom,id_rayon) values (@id,@nom,@id_rayon)"))
            {
                cmd.Parameters.AddWithValue("id", newFamilleId).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("nom", newFamilleLib).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("id_rayon", s_id_rayon).SqlDbType = SqlDbType.Char;
                if (!Api.SqlExec(Globals.RepData, cmd))
                    return;
            }
            List<Control> l = clickedButton.Form.FindMovableControlsBySource("S_ID_FAMIL");
            if (l.Count > 0)
            {
                MovableControls.MovableComboBox combo = (MovableControls.MovableComboBox)l[0];
                BindingList<MercatorUi._BaseClasses.MercatorComboItem> l_familles = (BindingList<MercatorUi._BaseClasses.MercatorComboItem>)combo.DataSource;
                l_familles.Add(new MercatorUi._BaseClasses.MercatorComboItem(newFamilleLib, newFamilleId));
                combo.SelectedValue = newFamilleId;
            }

        }
    }
}

De knopcode 'Subfamilie' is:

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorController;
using MercatorUi;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.ComponentModel;

namespace MercatorUi.MovableControls.ButtonsCodes
{
    public static class Script
    {

        public static void Exec(MercatorUi.MovableControls.MovableButton clickedButton)
        {
            string s_id_famil = clickedButton.Form.DataSource.Rows[0]["s_id_famil"].ToString();
            if (s_id_famil == "")
            {
                Dialogs.Stop("U moet eerst een familie kiezen!");
                return;
            }

            string newSsFamilleLib = Dialogs.AskString(("Welke nieuwe subfamilie?"), "");
            if (string.IsNullOrEmpty(newSsFamilleLib))
                return;
            newSsFamilleLib = newSsFamilleLib.Trim();
            if (MercatorController.xFunctions.xLookUpString("SS_FAMIL", "NOM", newSsFamilleLib, "ID", string.Format("id_famille='{0}'", Api.UnquoteSql(s_id_famil))).TrimEnd() != "")
            {
                Dialogs.Stop("Deze subfamilie bestaat al!");
                return;
            }
            string newSsFamilleId = Api.Ident();
            using (SqlCommand cmd = new SqlCommand("insert into SS_FAMIL (id,nom,id_famille) values (@id,@nom,@id_famille)"))
            {
                cmd.Parameters.AddWithValue("id", newSsFamilleId).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("nom", newSsFamilleLib).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("id_famille", s_id_famil).SqlDbType = SqlDbType.Char;
                if (!Api.SqlExec(Globals.RepData, cmd))
                    return;
            }
            List<Control> l = clickedButton.Form.FindMovableControlsBySource("S_ID_SSFAM");
            if (l.Count > 0)
            {
                MovableControls.MovableComboBox combo = (MovableControls.MovableComboBox)l[0];
                BindingList<MercatorUi._BaseClasses.MercatorComboItem> l_familles = (BindingList<MercatorUi._BaseClasses.MercatorComboItem>)combo.DataSource;
                l_familles.Add(new MercatorUi._BaseClasses.MercatorComboItem(newSsFamilleLib, newSsFamilleId));
                combo.SelectedValue = newSsFamilleId;
            }

        }
    }
}

De code voor de categorieën is:

U moet de waarde van de constante catNo aan het categorienummer aanpassen.

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using MercatorApi;
using System.Windows.Forms;


namespace MercatorUi.MovableControls.ButtonsCodes
{
    public static class Script
    {
        const int catNo = 1;

        public static void Exec(MercatorUi.MovableControls.MovableButton clickedButton)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)clickedButton.Form;
            string catTb = sigForm.Sig.Module == MercatorUi.Sig._SigEnum.STOCK ? "CAT_STCK" : "CAT_" + sigForm.Sig.Module;

            string newCatLib = Dialogs.AskString((string.Format("Welke nieuwe categorie {0} {1} ?", catNo, sigForm.Sig.Caption[MercatorUi.Globals.Langue])), "");
            if (string.IsNullOrEmpty(newCatLib))
                return;
            newCatLib = newCatLib.Trim();
            if (MercatorController.xFunctions.xLookUpString(catTb, "NOM", newCatLib, "ID", "type=" + catNo).TrimEnd() != "")
            {
                Dialogs.Stop("Deze categorie bestaat al!");
                return;
            }
            string newCatId = Api.Ident();
            using (SqlCommand cmd = new SqlCommand(string.Format("insert into {0} (id,nom,type) values (@id,@nom,@type)", catTb)))
            {
                cmd.Parameters.AddWithValue("id", newCatId).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("nom", newCatLib).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("type", catNo);
                if (!Api.SqlExec(Globals.RepData, cmd))
                    return;
            }
            List<Control> l = clickedButton.Form.FindMovableControlsBySource("S_CAT" + catNo);
            if (l.Count > 0)
            {
                MovableControls.MovableComboBox combo = (MovableControls.MovableComboBox)l[0];
                System.ComponentModel.BindingList<MercatorUi._BaseClasses.MercatorComboItem> itemList = (System.ComponentModel.BindingList<MercatorUi._BaseClasses.MercatorComboItem>)combo.DataSource;
                itemList.Add(new MercatorUi._BaseClasses.MercatorComboItem(newCatLib, newCatId));
                combo.SelectedValue = newCatId;
            }
        }
    }
}