# Setting Helper

## General information

"SettingHelper.cs" is the class that is used to get values related to Application Settings (e.g. enable or disable Email Notifications). It reads the values from the "SettingStore" data table based on the Key that is found in the "Key" column of the data table. The settings of an application are individually set by each Plant. This way, hard code can be avoided.&#x20;

## Setting Store data table

All the values related to application settings are stored in the "SettingStore" data table. As with all data tables, the columns are defined in a class of the same name under the "Entities" directory and the records can be accessed via the [SQL Server Management Studio (SSMS)](../../environment/database-server).

The "SettingStore" data table consists of 8 columns: Key, UserName, Password, Location, Value, Value1, Value2, Timestamp.

* The **Key** column contains the Key by which the settings are identified. All Keys are defined in "SettingKey.cs", so if you want to add a new Setting, you need to add the corresponding Key in "SettingKey.cs". If you want to change an existing Key, you also do that in "SettingKey.cs".
* The **UserName** column contains the user name required to edit the setting. If no login is required, the field remains empty.
* The **Password** column contains the corresponding password to the user name used to log in to edit this setting. If no login is required, the field remains empty.
* The **Location** column contains the Plant this setting belongs to.
* The **Value** is the default column where the value of the setting is stored.&#x20;
* The **Value1** and **Value2** columns are supplementary places for additional values that are related to this setting.
* The **Timestamp** column is provided for the case that it makes sense to store the last time the setting has been changed.

So if you want to add a new Setting, you define a new Key in the "SettingKey.cs" and add the relevant information in the "SettingStore" Data Table inserting the Key value in the column "Key". If you want to change the information of an existing Setting, you do that in the "SettingStore" Data Table.

## Setting Helper class

### Get method

The Get method returns a whole record from the SettingStore data table based on the Key that is passed as input parameter.

### GetValue methods

The Setting Helper class provides many different methods to access the Value, Value1 or Value2 column of a Setting. Because all of them are stored as string although their meaning may actually correspond to another data type, Setting Helper has methods that converts that string to a specific data type if the string content indeed matches with that data type.&#x20;

The following methods are available:

* **GetValue, GetValue1, GetValue2** to return as string
* **GetBoolean, GetBoolean1, GetBoolean2** to return as boolean
* **GetDouble** to return as double
* **GetInt1, GetInt2, GetInt3** to return as integer

### GetAccount

The GetAccount method returns a user name from the SettingStore data table based on the Key that is passed as input parameter.

### GetUserName

The GetAccount method returns a user name from the SettingStore data table based on the Key that is passed as input parameter.&#x20;

In contrast to the Get Account method, it additionally covers the case that the value in the data table does not only contain the real user name but the whole URI where the real user name comes after the last backslash ("\\").

### GetPassword

The GetPassword method returns a password from the SettingStore data table based on the Key that is passed as input parameter.

### IsExist

The IsExist method returns true if the Key that is passed as input parameter exists in the SettingStore data table and returns false if it doesn't.

## How to use

### Example 1: GetBoolean

The following code illustrates the function call of GetBoolean and how the value converted into a boolean is used for further processing:

```
bool isFilterSpecialOrder = SettingHelper.GetBoolean(SettingKey.FILTERSPECIALORDER);

if (isFilterSpecialOrder)
{
    ...
}
```

### Example 2: GetUserName and GetPassword

The following code illustrates the function call of GetUserName and GetPassword:

```
UserName = SettingHelper.GetUserName(SettingKey.MAILSERVER);
Password = SettingHelper.GetPassword(SettingKey.MAILSERVER);
```
