Features methods of specifying the value default

Set default values available when you edit a class diagram and in the code. Consider the main features of these methods.

Assignment default values on the class diagram

Scalar types

To indicate the class diagram the default value for fields scalar types it is sufficient to define it in the DefaultValue in the appropriate fields (note the peculiarities of generation for the DefaultValue).

nullable Scalar types

The job defaults to class diagram for nullable scalar-types is similar to scalar types.

Generic Nullable types can be initialized with values that accrue from the internal types. For example, if you assign a value Now Default in the field for the attribute on the class diagram, you can obtain this code:

private System.Nullable<System.DateTime> fRelease = System.DateTime.Now;

Complex types

To set the default value on the class diagram for the field of complex type (for example specified by the class with the stereotype Types of data classes with the stereotype-type-and-their-properties) in the General case impossible.

type Synonyms

Synonyms types set a default value on the class diagram, is similar to how it occurs in types, synonyms, which they are.

Task default values in the code

Admission Advantages Disadvantages
Set the default values in the form’s code Allows for each form to define their default values - Requires to initialize the default values in each form  
Set the default values in the data object Allows you to set the default value in one place - Complication of code if each form requires its own defaults
Set the default values in the business server sets the value default in one place and separate logic from UI - Complication of code if each form requires its own defaults

Task default values in the form’s code

public class WinformC__ПациентE : ICSSoft.STORMNET.UI.BaseWinEdit, IIS.BSTest.DPDIC__ПациентE
{
	private void WinformC__ПациентE_DataObjectOnFormLoaded(object sender, EventArgs e)
	{
		((Пациент) this.DataObject).ФИО = "Vipasyana"; //set default values 
		...
	}
	//... 
}

Task default values in the data object

public class Пациент : ICSSoft.STORMNET.DataObject
{
	private fФИО = "Vipasyana"; //setting default values 
	public string ФИО 
	{
		get
		{
			return fФИО;
		}
		
		set
		{
			fФИО = value;
		}
	}
	//... 
}

specify a default business server

Form code:

public class WinformC__ЗаписьНаПриёмE : ICSSoft.STORMNET.UI.BaseWinEdit, IIS.BSTest.DPDIC__ЗаписьНаПриёмE
{
	private void WinformC__ЗаписьНаПриёмE_DataObjectOnFormLoaded(object sender, EventArgs e)
	{
		//define which business servers defined for the object type "Zapolarie" 
		BusinessServer[] businessServers = BusinessServerProvider.GetBusinessServer(typeof(ЗаписьНаПриём), DataServiceObjectEvents.OnAllEvents, DataServiceProvider.DataService);
		if (businessServers.Length>0) 
		{
			TestBS curBS = (TestBS) businessServers[0]; //get first and only (in this case only) 
			curBS.InitializeRecord(this.DataObject as ЗаписьНаПриём); //set default values 
			EditManager.Change(); //apply the changes 
		}
	}
	//... 
}

Code business server:

public class TestBS : ICSSoft.STORMNET.Business.BusinessServer
{
	public void InitializeRecord(IIS.BSTest.ЗаписьНаПриём RecordToInitialize)
	{
		RecordToInitialize.Дата = new DateTime(2012,12,12); //setting default values 
	}
	//... 
}
Переведено сервисом «Яндекс.Переводчик» http://translate.yandex.ru