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

0000002230     -      08-04-2025

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;
            }
        }
    }
}

Voor meervoudige categorieën

De code is vergelijkbaar met de vorige, pas gewoon het laatste blok als volgt aan:

Zoom
List<Control> l = clickedButton.Form.FindMovableControlsBySource("S_CAT" + catNo);
if (l.Count > 0)
{
    MercatorUi.MovableControls.MovableListBox listBox = (MercatorUi.MovableControls.MovableListBox)l[0];
    listBox.AddItem(newCatId, newCatLib);
}

Voor de gammatypes

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;
using System.ComponentModel;


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;

            string newGamtyp = Dialogs.AskString("Welk nieuw gammatype?", "");
            if (string.IsNullOrEmpty(newGamtyp))
                return;
            newGamtyp = newGamtyp.Trim();
            if (MercatorController.xFunctions.xLookUpString("GAMTYP", "LIB", newGamtyp, "ID").TrimEnd() != "")
            {
                Dialogs.Stop("Dit gammatype bestaat al!");
                return;
            }
            string newGamtypId = Api.Ident();
            using (SqlCommand cmd = new SqlCommand("insert into GAMTYP (id,lib) values (@id,@lib)"))
            {
                cmd.Parameters.AddWithValue("id", newGamtypId).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("lib", newGamtyp).SqlDbType = SqlDbType.Char;
                if (!Api.SqlExec(Globals.RepData, cmd))
                    return;
            }
            List<Control> l = clickedButton.Form.FindMovableControlsBySource("S_GAMTYP1");
            if (l.Count > 0)
            {
                MovableControls.MovableComboBox combo = (MovableControls.MovableComboBox)l[0];
                BindingList<MercatorUi._BaseClasses.MercatorComboItem> itemList = (BindingList<MercatorUi._BaseClasses.MercatorComboItem>)combo.DataSource;
                itemList.Add(new MercatorUi._BaseClasses.MercatorComboItem(newGamtyp, newGamtypId));
                combo.SelectedValue = newGamtypId;
            }
        }
    }
}

Voor de gammaelementen

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;
using System.ComponentModel;


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.StockRecord.S_GAMTYP1 == "")
            {
                Dialogs.Stop("U moet eerst een gamma kiezen!");
                return;
            }

            string newGamenum = Dialogs.AskString("Welk nieuw gammatype ?", "");
            if (string.IsNullOrEmpty(newGamenum))
                return;
            newGamenum = newGamenum.Trim();
            if (MercatorController.xFunctions.xLookUpString("GAMENUM", "LIB", newGamenum, "ID", string.Format("id_type='{0}'", Api.UnquoteSql(sigForm.StockRecord.S_GAMTYP1))).TrimEnd() != "")
            {
                Dialogs.Stop("Dit element bestaat al!");
                return;
            }
            string newGamenumId = Api.Ident();
            using (SqlCommand cmd = new SqlCommand("insert into GAMENUM (id,lib,id_type) values (@id,@lib,@id_type)"))
            {
                cmd.Parameters.AddWithValue("id", newGamenumId).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("lib", newGamenum).SqlDbType = SqlDbType.Char;
                cmd.Parameters.AddWithValue("id_type", sigForm.StockRecord.S_GAMTYP1).SqlDbType = SqlDbType.Char;
                if (!Api.SqlExec(Globals.RepData, cmd))
                    return;
            }
            List<Control> l = clickedButton.Form.FindMovableControlsBySource("S_GAMENUM1");
            if (l.Count > 0)
            {
                MovableControls.MovableComboBox combo = (MovableControls.MovableComboBox)l[0];
                BindingList<MercatorUi._BaseClasses.MercatorComboItem> itemList = (BindingList<MercatorUi._BaseClasses.MercatorComboItem>)combo.DataSource;
                itemList.Add(new MercatorUi._BaseClasses.MercatorComboItem(newGamenum, newGamenumId));
                combo.SelectedValue = newGamenumId;
            }
        }
    }
}


Functionele cookies: Cookies die nodig zijn voor het gebruik van de website en voorkeurscookies. Ze bevatten geen persoonsgegevens. (Meer informatie)

Analytische cookies: Verzamelen van statistieken met betrekking tot het gedrag van internetgebruikers. (Meer informatie)

Marketingcookies: Om bezoekers op verschillende websites te volgen voor advertentiedoeleinden. (Meer informatie)