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'.
De in het bestand aangemaakte rayon / familie / subfamilie wordt automatische gekoppeld aan de huidige fiche.
De knopcode "Rayon" is:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorController;
using MercatorUi;
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 (MercatorSqlCommand cmd = new MercatorSqlCommand("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:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorController;
using MercatorUi;
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 (MercatorSqlCommand cmd = new MercatorSqlCommand("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:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorController;
using MercatorUi;
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 (MercatorSqlCommand cmd = new MercatorSqlCommand("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.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
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 (MercatorSqlCommand cmd = new MercatorSqlCommand(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:
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
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 (MercatorSqlCommand cmd = new MercatorSqlCommand("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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
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 (MercatorSqlCommand cmd = new MercatorSqlCommand("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;
}
}
}
}