IBM Doors DXL: Helpful Trigger Functions for persistent Triggers to block a module

Problem

The modification (Edit Mode / Edit Share) of a module shall be prevented.
Das Editieren eine Doors Modules (Edit Mode / Share Mode) soll verhindert werden.

Approach

Defining a library and using the existence of a trigger as condition for allowed modifications can be used to block the formal Module for edit/share mode.
Durch das definieren eine Triggers und der zugehörigen Trigger_Library kann man die Existenz eines Triggers als Bedingung für das Erlauben des Edit/Share Modes nehmen.

Solution

void listAllTriggerForMod (Module mod) 
{
	Trigger t;
	for t in mod do 
	{
		print name(t) "\n";	
	}
}

bool checkTriggerIfExistForMod (Module mod, string triggername) 
{
	Trigger t;
	for t in mod do 
	{
		if(name(t) "" == triggername)	
		{
			return true;
		}
	}
	
	return false;
}

string getDXLCodeForModWithTrigger (Module mod, string triggername) 
{
	Trigger t;
	for t in mod do 
	{
		if(name(t) "" == triggername)	
		{
			return dxl(t);
		}
	}
	
	return "not found";
}

void removeTriggerForModWithName(Module mod, string triggername) {

	Trigger t;
	string errorMsg;
	
	// first delete _all possible trigger_
	for t in mod do {
		if (name (t) "" == triggername) {
			errorMsg = delete(t);
		   	if(!null(errorMsg)) {
			  errorBox("Error occurred:\n" errorMsg"");
			  break;
		   }
		}
	}
}

void installTriggerForMod (Module mod) 
{
	string dxlCode = "Module cm = current Module;\n" //-
					"if ((isEdit(cm)||isShare(cm))){\n" //-
					"ack(\"During Wings LDT modifications it is not allowed to modify texts in the UIT/ALM Module.\");\n" //-
					"downgrade(cm)\n" //-
					"}\n";
	 
	string errors = checkDXL(dxlCode)
	
	if(null(errors)) 
	{
		string moduleName = name(mod)
		if(!checkTriggerIfExistForMod(mod, "Text_Tool_Block_Trigger"))
		{
			Trigger t = trigger("Text_Tool_Block_Trigger", project->module->moduleName, post, open, 15, dxlCode);
		}
		else ack "Trigger already exist!";
	}
	
	save(mod);
}

Module uitModule = read("/NDS/20 System/DS/UIT-User Interface Texts", false);
print "Vor der Installation...\n";
print "=======================\n";
listAllTriggerForMod(uitModule);
installTriggerForMod(uitModule);
print "\n\nNach der Installation...\n";
print "=======================\n";
listAllTriggerForMod(uitModule);
removeTriggerForModWithName(uitModule, "Text_Tool_Block_Trigger");
print "\n\nNach dem Entfernen...\n";
print "=======================\n";
listAllTriggerForMod(uitModule);

C#.NET Windows Forms: Allow only numbers and decimals in TextBox

Problem

A Textbox should only allow numbers and decimals

Approach

Using the Keypress method will validate on each key that is entered.
Call the code below onKeyPress Event of each Textbox with

validateNumber(sender, e);

after each

Solution

private void validateNumber(object sender, KeyPressEventArgs e)
{
  if ((e.KeyChar == ',') && (((TextBox)sender).Text.IndexOf(',') > -1))
  {
    e.Handled = true;
    return;
  }

  if (!Char.IsDigit(e.KeyChar))
  {
    if ((e.KeyChar != ',') &&
        (e.KeyChar != Convert.ToChar(Keys.Back)))
    {
        e.Handled = true;
        return;
    }
 }
}