πŸ“œ ⬆️ ⬇️

Tips for beginners in the design of modular production systems

In this article I will try to share my experience in designing custom business logic. This clearly does not pretend to a full-fledged educational program, since I just remember what I personally went through, what mistakes I made, and how I managed (or failed) to correct them in the future. Surely, experienced system architects have already passed everything and know, but I hope that some tips will still be useful.
We used (and use) the client part on WPF / Silverlight, WCF services and Oracle, Postrges, MsSQL. The code is written in MVVM, Prism is used for modularity and navigation. I can not say exactly which of theses are suitable for other platforms and languages.

It so happened that at some point I, a programmer who was quite ordinary at that time, had the task of designing a large and complex data accounting system with a large number of conditions, transitions, stages of work. The system was designed to enter data about residents, regular meetings on issuing passes and denials, renewing passes, terminating their activities, fines, and many other trifles. Now the core of the system is mostly rewritten, the shitty code has disappeared, new and recent technologies and platforms have been used.

So let's go.

1. The desire to get rid of the repetition of the code should be reasonable


It turned out that in two different assemblies (speaking of the interface - in two different modules of the system that are called at different points in time), it was necessary to select a similar list of entities from the database, say, using the GetComissions() method. Programmer Peter, having seen Vasya, the programmer, had already written the GetComissions() method on the service (and then we had one service with one endpoint), without thinking twice, took it and used it. Everything would be fine, it took only a couple of weeks for the customer to show, in one of the places other than the commissions, their statistics, statuses, decisions, and much more. As a result, the second module immediately began to fall with an error.
Alas, there were obviously more than one such cases, and later, it took a lot of effort to separate the service methods into different endpoint services, or at least into separate partial classes (in the case of one service).
Conclusion: two projects can use the same function on the service if and only if it is known in advance that these projects will always work the same way with this function. In this case, the method should be imposed in a general class, which is connected to each project.
In all other cases, the principle of writing code on the server should follow something similar to the Single Responsibility principle (one of the SOLID principles).
')

2. Try not to write logic in datacontracts


In my experience, the solution is always always easier if all datacontracts (in the case of RiaServices - entity classes) are always pristine clean, and coincide 1k1 with the database schema. Everything can begin with the harmless code of concatenation of the employee’s full name into one variable, and this ends with huge calculations of some incomprehensible coefficients (necessary, as a rule, only in one place). As a result, datacontracts have become 80% composed either of methods (yes, if some code is written in the property getter, I also consider this method), or from fields in other tables that were needed by someone alone at some point. It is always better to make heirs or wrappers on the service or on the client (depending on the task), which will be used exclusively for the purposes of this module. About the problems with them - in the next paragraph.

3. What is better on the client - heir, partial?


Alas, we did not find the perfect solution. Consider a few cases:

a) Modules work with one client reference for service. Classes on the server are divided into partial classes from one service.
Minuses:

Pros:



b) Each module independently makes a client reference for service.
Minuses:


We often choose option a), because transferring objects between modules is quite a useful thing. We now return to the title: it is in option a) the difference between the heirs and the parties becomes very noticeable.


Suppose we have the labels Person and Document in the database. According to the canons, in the datacontraction, the Person class will have a List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .
List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .
List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .
List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .
  1. List, .. Document Person . Person Documents , . , Person List.
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
     List, ..  Document     Person .          Person    Documents ,        .     ,    Person    List. 
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
    List, .. Document Person . Person Documents , . , Person List.
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
  2. List, .. Document Person . Person Documents , . , Person List.
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
     List, ..  Document     Person .          Person    Documents ,        .     ,    Person    List. 
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
    List, .. Document Person . Person Documents , . , Person List.
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
  3. List, .. Document Person . Person Documents , . , Person List.
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
     List, ..  Document     Person .          Person    Documents ,        .     ,    Person    List. 
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
    List, .. Document Person . Person Documents , . , Person List.
    , , (, , Person
    Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

    4. , , -
    , , . , , - , , – .
    , – , - , , ( – ).
    - , , .
    Hint: date_insert
    date_update , - .

    5. ,
    , , -, - . , . , ..:
    , - . - , , , , . , .. .
    – Β« Β», - .
    , «» () , - ( ) .

    6.
    .

    , - ( - ). , ParentDiapason , ChildDiapason - .
    , .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
    :
    :
    , – .
    .
    Hint: MsSQL Server 2012 - , -, .

    7.
    - , . , :
    , ( – , – )
    public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
    StatusBase – , (-),
    public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
    , , ,
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

    , , , .
    . , - .
List, .. Document Person . Person Documents , . , Person List.
, , (, , Person
Document ), PersonEx DocumentEx , PersonEx List! , – , . -, , - , .. .

4. , , -
, , . , , - , , – .
, – , - , , ( – ).
- , , .
Hint: date_insert
date_update , - .

5. ,
, , -, - . , . , ..:
, - . - , , , , . , .. .
– Β« Β», - .
, «» () , - ( ) .

6.
.

, - ( - ). , ParentDiapason , ChildDiapason - .
, .. 245 300 400. , quantity , , quantity (startSeries, endSeries, startNumber, endNumber) . , :
:
:
, – .
.
Hint: MsSQL Server 2012 - , -, .

7.
- , . , :
, ( – , – )
public class Users { public class Status : StatusBase<Status> { /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Active = 1; /// <summary> /// ( ) /// </summary> [StringStatus("")] public const int Inactive = 0; } }
StatusBase – , (-),
public class StatusBase<T> where T : class { private static Dictionary<int, string> statusesDictionary; public static string GetStringStatus(int key) { if (statusesDictionary == null) { CreateStatusDictionary(); } string result = statusesDictionary.ContainsKey(key) ? statusesDictionary[key] : " "; return result; } private static void CreateStatusDictionary() { statusesDictionary = new Dictionary<int, string>(); FieldInfo[] fields = typeof(T).GetFields(); foreach (FieldInfo field in fields) { string TextStatus = ((StringStatusAttribute)field.GetCustomAttributes(typeof(StringStatusAttribute), false)[0]). TextStatus; int statusKey = (int)field.GetValue(null); statusesDictionary.Add(statusKey, TextStatus); } } }
, , ,
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Data.Statuses.Users.Status.GetStringStatus((int)value); return result; }

, , , .
. , - .

Source: https://habr.com/ru/post/182132/


All Articles