Работа с элементом

This commit is contained in:
kotcheshir73 2021-03-30 22:34:31 +04:00
parent da3e126579
commit 1df43b5105
55 changed files with 2143 additions and 181 deletions

View File

@ -21,18 +21,6 @@ namespace DatabaseCore.Models.Security
[MapConfiguration("Password")] [MapConfiguration("Password")]
public string PasswordHash { get; set; } public string PasswordHash { get; set; }
[DataMember]
[MapConfiguration("StudentId")]
public Guid? StudentId { get; set; }
[DataMember]
[MapConfiguration("LecturerId")]
public Guid? LecturerId { get; set; }
[DataMember]
[MapConfiguration("EmployeeId")]
public Guid? EmployeeId { get; set; }
[DataMember] [DataMember]
[MapConfiguration("Avatar")] [MapConfiguration("Avatar")]
public byte[] Avatar { get; set; } public byte[] Avatar { get; set; }

View File

@ -51,13 +51,13 @@ namespace DesktopTools.BaseControls
this.panelControl.Size = new System.Drawing.Size(407, 25); this.panelControl.Size = new System.Drawing.Size(407, 25);
this.panelControl.TabIndex = 1; this.panelControl.TabIndex = 1;
// //
// BaseControl // AbstractBaseControl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.panelControl); this.Controls.Add(this.panelControl);
this.Controls.Add(this.labelTitle); this.Controls.Add(this.labelTitle);
this.Name = "BaseControl"; this.Name = "AbstractBaseControl";
this.Size = new System.Drawing.Size(500, 25); this.Size = new System.Drawing.Size(500, 25);
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -4,6 +4,9 @@ using System.Windows.Forms;
namespace DesktopTools.BaseControls namespace DesktopTools.BaseControls
{ {
/// <summary>
/// Описание контрола для работы со значением свойства класса
/// </summary>
public abstract partial class AbstractBaseControl : UserControl public abstract partial class AbstractBaseControl : UserControl
{ {
/// <summary> /// <summary>
@ -14,17 +17,18 @@ namespace DesktopTools.BaseControls
/// <summary> /// <summary>
/// Необходимость проверки при получении данных /// Необходимость проверки при получении данных
/// </summary> /// </summary>
protected bool _mustCheckValue; protected bool _mustFilling;
/// <summary> /// <summary>
/// Название свойства, по которму идет отображение /// Название свойства, по которму идет отображение
/// </summary> /// </summary>
protected string PropertyName { get; private set; } protected string _propertyName;
#region Событие изменения значения
/// <summary> /// <summary>
/// Событие изменения значения в контроле /// Событие изменения значения в контроле
/// </summary> /// </summary>
protected event Action OnValueChange; private event Action OnValueChange;
/// <summary> /// <summary>
/// Событие изменения значения в контроле /// Событие изменения значения в контроле
@ -35,14 +39,28 @@ namespace DesktopTools.BaseControls
/// Вызов события в дочерних контролах /// Вызов события в дочерних контролах
/// </summary> /// </summary>
protected void CallOnValueChangeEvent() => OnValueChange?.Invoke(); protected void CallOnValueChangeEvent() => OnValueChange?.Invoke();
#endregion
/// <summary>
public AbstractBaseControl(string propertyName) /// Конструктор
/// </summary>
/// <param name="propertyName">Название свойства</param
/// <param name="mustFilling">Должно ли оно быть заполненным обязательно</param>
/// <param name="readOnly">Устанвока контрола в режим только просмотра</param>
public AbstractBaseControl(string propertyName, bool mustFilling, bool readOnly)
{ {
InitializeComponent(); InitializeComponent();
PropertyName = propertyName; _propertyName = propertyName;
_mustFilling = mustFilling;
panelControl.Enabled = !readOnly;
SetDefaultValue();
} }
/// <summary>
/// Установка _originalValue в значение по умолчанию
/// </summary>
protected abstract void SetDefaultValue();
#region Работа с заголовком #region Работа с заголовком
/// <summary> /// <summary>
/// Установка заголовка /// Установка заголовка
@ -67,29 +85,35 @@ namespace DesktopTools.BaseControls
} }
#endregion #endregion
#region Работа со значением
/// <summary> /// <summary>
/// Устанвока контрола в режим только просмотра /// Извлечение значения из свойства объекта
/// </summary> /// </summary>
/// <param name="readOnly"></param> /// <param name="obj"></param>
public abstract void SetReadOnly(bool readOnly); public void SetValue(object obj)
{
if (obj != null && _propertyName.IsNotEmpty())
{
var property = obj.GetType().GetProperty(_propertyName);
if (property != null)
{
_originalValue = property.GetValue(obj);
SetValueToControl(_originalValue);
}
}
}
/// <summary> /// <summary>
/// Установка значения /// Установка значения в контрол
/// </summary> /// </summary>
/// <param name="value"></param> /// <param name="value"></param>
public virtual void SetValueToControl(object value) => _originalValue = value; protected abstract void SetValueToControl(object value);
/// <summary> /// <summary>
/// Сброс значения /// Сброс значения
/// </summary> /// </summary>
public abstract void DropValue(); public abstract void DropValue();
/// <summary>
/// Установка флага необхоидмости проверки
/// </summary>
/// <param name="mustCheckValue"></param>
public void SetMustCheckValue(bool mustCheckValue) => _mustCheckValue = mustCheckValue;
/// <summary> /// <summary>
/// Проверка на заполненность /// Проверка на заполненность
/// </summary> /// </summary>
@ -106,16 +130,17 @@ namespace DesktopTools.BaseControls
/// Заполнение свойства объекта значением из контрола /// Заполнение свойства объекта значением из контрола
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj"></param>
public void FillPropertyToObject(object obj) public void GetValue(object obj)
{ {
if (obj != null && PropertyName.IsNotEmpty()) if (obj != null && _propertyName.IsNotEmpty())
{ {
var property = obj.GetType().GetProperty(PropertyName); var property = obj.GetType().GetProperty(_propertyName);
if (property != null) if (property != null)
{ {
property.SetValue(obj, GetValueFromControl()); property.SetValue(obj, GetValueFromControl());
} }
} }
} }
#endregion
} }
} }

View File

@ -0,0 +1,57 @@

namespace DesktopTools.BaseControls
{
partial class BaseControlBool
{
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.checkBoxNullable = new System.Windows.Forms.CheckBox();
this.checkBox = new System.Windows.Forms.CheckBox();
//
// checkBoxNullable
//
this.checkBoxNullable.AutoSize = true;
this.checkBoxNullable.Location = new System.Drawing.Point(41, 14);
this.checkBoxNullable.Name = "checkBoxNullable";
this.checkBoxNullable.Size = new System.Drawing.Size(83, 19);
this.checkBoxNullable.TabIndex = 1;
this.checkBoxNullable.UseVisualStyleBackColor = true;
this.checkBoxNullable.Dock = System.Windows.Forms.DockStyle.Left;
//
// checkBox
//
this.checkBox.AutoSize = true;
this.checkBox.Location = new System.Drawing.Point(148, 9);
this.checkBox.Name = "checkBox";
this.checkBox.Size = new System.Drawing.Size(83, 19);
this.checkBox.TabIndex = 1;
this.checkBox.UseVisualStyleBackColor = true;
}
#endregion
private System.Windows.Forms.CheckBox checkBoxNullable;
private System.Windows.Forms.CheckBox checkBox;
}
}

View File

@ -0,0 +1,65 @@
using System;
using System.Windows.Forms;
namespace DesktopTools.BaseControls
{
/// <summary>
/// Контрол, предоставляющий работу с bool-полем
/// </summary>
public partial class BaseControlBool : AbstractBaseControl
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="propertyName"></param>
/// <param name="mustFilling"></param>
/// <param name="readOnly"></param>
public BaseControlBool(string propertyName, bool mustFilling, bool readOnly) : base(propertyName, mustFilling, readOnly)
{
InitializeComponent();
if (!_mustFilling)
{
checkBoxNullable.CheckedChanged += (object sender, EventArgs e) =>
{
checkBox.Enabled = !(sender as CheckBox).Checked;
CallOnValueChangeEvent();
};
panelControl.Controls.Add(checkBoxNullable);
}
checkBox.CheckedChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); };
panelControl.Controls.Add(checkBox);
}
protected override void SetDefaultValue() => _originalValue = _mustFilling ? false : null;
protected override void SetValueToControl(object value)
{
if (value != null)
{
checkBox.Checked = Convert.ToBoolean(value);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
}
public override void DropValue()
{
if (_originalValue != null)
{
checkBox.Checked = Convert.ToBoolean(_originalValue);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
}
public override bool CheckValue() => true;
protected override object GetValueFromControl() => !_mustFilling && checkBoxNullable.Checked ? null : checkBox.Checked;
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,56 @@

namespace DesktopTools.BaseControls
{
partial class BaseControlDateTime
{
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.checkBoxNullable = new System.Windows.Forms.CheckBox();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
//
// checkBoxNullable
//
this.checkBoxNullable.AutoSize = true;
this.checkBoxNullable.Location = new System.Drawing.Point(41, 14);
this.checkBoxNullable.Name = "checkBoxNullable";
this.checkBoxNullable.Size = new System.Drawing.Size(83, 19);
this.checkBoxNullable.TabIndex = 1;
this.checkBoxNullable.UseVisualStyleBackColor = true;
this.checkBoxNullable.Dock = System.Windows.Forms.DockStyle.Left;
//
// dateTimePicker
//
this.dateTimePicker.Dock = System.Windows.Forms.DockStyle.Fill;
this.dateTimePicker.Location = new System.Drawing.Point(123, 16);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(200, 23);
this.dateTimePicker.TabIndex = 0;
}
#endregion
private System.Windows.Forms.CheckBox checkBoxNullable;
private System.Windows.Forms.DateTimePicker dateTimePicker;
}
}

View File

@ -0,0 +1,81 @@
using ModuleTools.Extensions;
using System;
using System.Windows.Forms;
namespace DesktopTools.BaseControls
{
/// <summary>
/// Контрол, предоставляющий работу с датой
/// </summary>
public partial class BaseControlDateTime : AbstractBaseControl
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="propertyName"></param>
/// <param name="mustFilling"></param>
/// <param name="readOnly"></param>
/// <param name="minDate"></param>
/// <param name="maxDate"></param>
/// <param name="customDateFormat"></param>
public BaseControlDateTime(string propertyName, bool mustFilling, bool readOnly, DateTime? minDate, DateTime? maxDate, string customDateFormat) : base(propertyName, mustFilling, readOnly)
{
InitializeComponent();
if (!_mustFilling)
{
checkBoxNullable.CheckedChanged += (object sender, EventArgs e) =>
{
dateTimePicker.Enabled = !(sender as CheckBox).Checked;
CallOnValueChangeEvent();
};
panelControl.Controls.Add(checkBoxNullable);
}
dateTimePicker.ValueChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); };
if (minDate.HasValue)
{
dateTimePicker.MinDate = minDate.Value;
}
if (maxDate.HasValue)
{
dateTimePicker.MaxDate = maxDate.Value;
}
if(customDateFormat.IsNotEmpty())
{
dateTimePicker.CustomFormat = customDateFormat;
}
panelControl.Controls.Add(dateTimePicker);
}
protected override void SetDefaultValue() => _originalValue = _mustFilling ? DateTime.Now : null;
protected override void SetValueToControl(object value)
{
if (value != null)
{
dateTimePicker.Value = Convert.ToDateTime(value);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
}
public override void DropValue()
{
if (_originalValue != null)
{
dateTimePicker.Value = Convert.ToDateTime(_originalValue);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
}
public override bool CheckValue() => true;
protected override object GetValueFromControl() => !_mustFilling && checkBoxNullable.Checked ? null : Convert.ToDateTime(dateTimePicker.Value);
}
}

View File

@ -0,0 +1,58 @@

namespace DesktopTools.BaseControls
{
partial class BaseControlDecimal
{
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.checkBoxNullable = new System.Windows.Forms.CheckBox();
this.numericUpDown = new System.Windows.Forms.NumericUpDown();
//
// checkBoxNullable
//
this.checkBoxNullable.AutoSize = true;
this.checkBoxNullable.Location = new System.Drawing.Point(41, 14);
this.checkBoxNullable.Name = "checkBoxNullable";
this.checkBoxNullable.Size = new System.Drawing.Size(83, 19);
this.checkBoxNullable.TabIndex = 1;
this.checkBoxNullable.UseVisualStyleBackColor = true;
this.checkBoxNullable.Dock = System.Windows.Forms.DockStyle.Left;
//
// numericUpDown
//
this.numericUpDown.Dock = System.Windows.Forms.DockStyle.Fill;
this.numericUpDown.Location = new System.Drawing.Point(148, 9);
this.numericUpDown.Name = "numericUpDown";
this.numericUpDown.Size = new System.Drawing.Size(120, 23);
this.numericUpDown.TabIndex = 2;
this.numericUpDown.Minimum = decimal.MinValue;
this.numericUpDown.Maximum = decimal.MaxValue;
}
#endregion
private System.Windows.Forms.CheckBox checkBoxNullable;
private System.Windows.Forms.NumericUpDown numericUpDown;
}
}

View File

@ -0,0 +1,80 @@
using System;
using System.Windows.Forms;
namespace DesktopTools.BaseControls
{
/// <summary>
/// Контрол, предоставляющий работу с вещественным полем
/// </summary>
public partial class BaseControlDecimal : AbstractBaseControl
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="propertyName"></param>
/// <param name="mustFilling"></param>
/// <param name="readOnly"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <param name="decimalPlaces"></param>
public BaseControlDecimal(string propertyName, bool mustFilling, bool readOnly, decimal? minValue, decimal? maxValue, int? decimalPlaces) : base(propertyName, mustFilling, readOnly)
{
InitializeComponent();
if (!_mustFilling)
{
checkBoxNullable.CheckedChanged += (object sender, EventArgs e) =>
{
numericUpDown.Enabled = !(sender as CheckBox).Checked;
CallOnValueChangeEvent();
};
panelControl.Controls.Add(checkBoxNullable);
}
numericUpDown.ValueChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); };
if (minValue.HasValue)
{
numericUpDown.Minimum = minValue.Value;
}
if (maxValue.HasValue)
{
numericUpDown.Maximum = maxValue.Value;
}
if (decimalPlaces.HasValue)
{
numericUpDown.DecimalPlaces = decimalPlaces.Value;
}
panelControl.Controls.Add(numericUpDown);
}
protected override void SetDefaultValue() => _originalValue = _mustFilling ? 0 : null;
protected override void SetValueToControl(object value)
{
if (value != null)
{
numericUpDown.Value = Convert.ToDecimal(value);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
}
public override void DropValue()
{
if (_originalValue != null)
{
numericUpDown.Value = Convert.ToDecimal(_originalValue);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
}
public override bool CheckValue() => true;
protected override object GetValueFromControl() => !_mustFilling && checkBoxNullable.Checked ? null : Convert.ToDouble(numericUpDown.Value);
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,59 @@

namespace DesktopTools.BaseControls
{
partial class BaseControlEnum
{
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.checkBoxNullable = new System.Windows.Forms.CheckBox();
this.comboBox = new System.Windows.Forms.ComboBox();
//
// checkBoxNullable
//
this.checkBoxNullable.AutoSize = true;
this.checkBoxNullable.Location = new System.Drawing.Point(41, 14);
this.checkBoxNullable.Name = "checkBoxNullable";
this.checkBoxNullable.Size = new System.Drawing.Size(83, 19);
this.checkBoxNullable.TabIndex = 1;
this.checkBoxNullable.UseVisualStyleBackColor = true;
this.checkBoxNullable.Dock = System.Windows.Forms.DockStyle.Left;
//
// comboBox
//
this.comboBox.Cursor = System.Windows.Forms.Cursors.Hand;
this.comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox.FormattingEnabled = true;
this.comboBox.Location = new System.Drawing.Point(100, 10);
this.comboBox.Name = "comboBox";
this.comboBox.Size = new System.Drawing.Size(121, 23);
this.comboBox.TabIndex = 0;
this.comboBox.Dock = System.Windows.Forms.DockStyle.Fill;
}
#endregion
private System.Windows.Forms.CheckBox checkBoxNullable;
private System.Windows.Forms.ComboBox comboBox;
}
}

View File

@ -0,0 +1,86 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DesktopTools.BaseControls
{
/// <summary>
/// Контрол, предоставляющий работу с перечислениями
/// </summary>
public partial class BaseControlEnum : AbstractBaseControl
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="propertyName"></param>
/// <param name="mustFilling"></param>
/// <param name="readOnly"></param>
/// <param name="enumType"></param>
public BaseControlEnum(string propertyName, bool mustFilling, bool readOnly, Type enumType) : base(propertyName, mustFilling, readOnly)
{
InitializeComponent();
if (!_mustFilling)
{
checkBoxNullable.CheckedChanged += (object sender, EventArgs e) =>
{
comboBox.Enabled = !(sender as CheckBox).Checked;
CallOnValueChangeEvent();
};
panelControl.Controls.Add(checkBoxNullable);
}
comboBox.Items.Clear();
foreach (var val in Enum.GetValues(enumType))
{
comboBox.Items.Add(val);
}
comboBox.SelectedIndexChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); };
panelControl.Controls.Add(comboBox);
}
protected override void SetDefaultValue() => _originalValue = null;
protected override void SetValueToControl(object value)
{
if (value != null)
{
comboBox.SelectedIndex = comboBox.Items.IndexOf(value);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
}
public override void DropValue()
{
if (_originalValue != null)
{
comboBox.SelectedIndex = comboBox.Items.IndexOf(_originalValue);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
}
public override bool CheckValue()
{
if (_mustFilling && comboBox.SelectedIndex == -1)
{
BackColor = Color.OrangeRed;
return false;
}
return true;
}
protected override object GetValueFromControl()
{
if (_mustFilling && comboBox.SelectedIndex == -1)
{
throw new ArgumentNullException($"Поле свойства '{labelTitle.Text}' должно быть заполнено");
}
return checkBoxNullable.Checked ? null : comboBox.SelectedItem;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,70 @@

namespace DesktopTools.BaseControls
{
partial class BaseControlGuid
{
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.buttonClear = new System.Windows.Forms.Button();
this.buttonSelect = new System.Windows.Forms.Button();
this.textBox = new System.Windows.Forms.TextBox();
//
// buttonClear
//
this.buttonClear.BackgroundImage = global::DesktopTools.Properties.Resources.Clear;
this.buttonClear.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonClear.Dock = System.Windows.Forms.DockStyle.Right;
this.buttonClear.Location = new System.Drawing.Point(74, 12);
this.buttonClear.Name = "buttonClear";
this.buttonClear.Size = new System.Drawing.Size(25, 25);
this.buttonClear.TabIndex = 0;
this.buttonClear.Text = "...";
this.buttonClear.UseVisualStyleBackColor = true;
//
// buttonSelect
//
this.buttonSelect.Dock = System.Windows.Forms.DockStyle.Right;
this.buttonSelect.Location = new System.Drawing.Point(74, 12);
this.buttonSelect.Name = "buttonSelect";
this.buttonSelect.Size = new System.Drawing.Size(25, 25);
this.buttonSelect.TabIndex = 0;
this.buttonSelect.Text = "...";
this.buttonSelect.UseVisualStyleBackColor = true;
//
// textBox
//
this.textBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox.Location = new System.Drawing.Point(0, 0);
this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(1000, 1000);
this.textBox.TabIndex = 1;
}
#endregion
private System.Windows.Forms.Button buttonSelect;
private System.Windows.Forms.Button buttonClear;
private System.Windows.Forms.TextBox textBox;
}
}

View File

@ -0,0 +1,106 @@
using DesktopTools.Controls;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DesktopTools.BaseControls
{
public partial class BaseControlGuid : AbstractBaseControl
{
private AbstractControlViewEntityList _control;
public BaseControlGuid(string propertyName, bool mustFilling, bool readOnly, AbstractControlViewEntityList controlType) : base(propertyName, mustFilling, readOnly)
{
InitializeComponent();
_control = controlType;
panelControl.Controls.Add(textBox);
if (!_mustFilling)
{
buttonClear.Click += (object sender, EventArgs e) =>
{
textBox.Text = string.Empty;
textBox.Tag = null;
CallOnValueChangeEvent();
};
panelControl.Controls.Add(buttonClear);
}
buttonSelect.Click += (object sender, EventArgs e) =>
{
var form = new Form
{
Height = controlType.Height,
Width = controlType.Width,
Text = $"{controlType.Title}. Выбор",
StartPosition = FormStartPosition.CenterParent,
ControlBox = false
};
var clone = controlType.Clone();
form.Controls.Add(clone);
clone.Dock = DockStyle.Fill;
clone.FormForSelected = form;
clone.Open();
if (form.ShowDialog() == DialogResult.OK)
{
textBox.Tag = clone.SelectedId;
textBox.Text = clone.SelectedText;
CallOnValueChangeEvent();
}
};
panelControl.Controls.Add(buttonSelect);
}
protected override void SetDefaultValue() => _originalValue = null;
protected override void SetValueToControl(object value)
{
if (value != null)
{
var id = new Guid(value.ToString());
textBox.Tag = id;
textBox.Text = _control?.GetTitleFromId(id);
}
else if (!_mustFilling)
{
textBox.Tag = null;
}
}
public override void DropValue()
{
if (_originalValue != null)
{
var id = new Guid(_originalValue.ToString());
textBox.Tag = id;
textBox.Text = _control?.GetTitleFromId(id);
}
else if (!_mustFilling)
{
textBox.Tag = null;
textBox.Text = string.Empty;
}
}
public override bool CheckValue()
{
if (_mustFilling && textBox.Tag == null)
{
BackColor = Color.OrangeRed;
return false;
}
return true;
}
protected override object GetValueFromControl()
{
if (_mustFilling && textBox.Tag == null)
{
throw new ArgumentNullException($"Поле свойства '{labelTitle.Text}' должно быть заполнено");
}
return textBox.Tag == null ? null : new Guid(textBox.Tag.ToString());
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,60 @@

namespace DesktopTools.BaseControls
{
partial class BaseControlImage
{
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.pictureBox = new System.Windows.Forms.PictureBox();
this.buttonLoad = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
//
// buttonLoad
//
this.buttonLoad.Dock = System.Windows.Forms.DockStyle.Bottom;
this.buttonLoad.Location = new System.Drawing.Point(74, 12);
this.buttonLoad.Name = "buttonLoad";
this.buttonLoad.Size = new System.Drawing.Size(25, 25);
this.buttonLoad.TabIndex = 0;
this.buttonLoad.Text = "Загрузить";
this.buttonLoad.UseVisualStyleBackColor = true;
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(111, 19);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(100, 50);
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
}
#endregion
private System.Windows.Forms.Button buttonLoad;
private System.Windows.Forms.PictureBox pictureBox;
}
}

View File

@ -0,0 +1,101 @@
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace DesktopTools.BaseControls
{
/// <summary>
/// Контрол, предоставляющий работу с изображением
/// </summary>
public partial class BaseControlImage : AbstractBaseControl
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="propertyName"></param>
/// <param name="mustFilling"></param>
/// <param name="readOnly"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public BaseControlImage(string propertyName, bool mustFilling, bool readOnly, int? width, int? height) : base(propertyName, mustFilling, readOnly)
{
InitializeComponent();
if (width.HasValue)
{
Width = width.Value;
}
if (height.HasValue)
{
Height = height.Value;
}
buttonLoad.Click += (object sender, EventArgs e) =>
{
var dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.ClientSize = new Size(150, 150);
pictureBox.Image = new Bitmap(dialog.FileName);
CallOnValueChangeEvent();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке файла", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
};
panelControl.Controls.Add(pictureBox);
}
protected override void SetDefaultValue() => _originalValue = null;
protected override void SetValueToControl(object value)
{
if (value != null)
{
using MemoryStream mStream = new(value as byte[]);
pictureBox.Image = Image.FromStream(mStream);
}
else if (!_mustFilling)
{
pictureBox.Image = null;
}
}
public override void DropValue()
{
if (_originalValue != null)
{
using MemoryStream mStream = new(_originalValue as byte[]);
pictureBox.Image = Image.FromStream(mStream);
}
else if (!_mustFilling)
{
pictureBox.Image = null;
}
}
public override bool CheckValue()
{
if (_mustFilling && pictureBox.Image == null)
{
BackColor = Color.OrangeRed;
return false;
}
return true;
}
protected override object GetValueFromControl()
{
if (_mustFilling && pictureBox.Image == null)
{
throw new ArgumentNullException($"Поле свойства '{labelTitle.Text}' должно быть заполнено");
}
var converter = new ImageConverter();
return (byte[])converter.ConvertTo(pictureBox.Image, typeof(byte[]));
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,64 +1,75 @@
using System; using System;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace DesktopTools.BaseControls namespace DesktopTools.BaseControls
{ {
/// <summary>
/// Контрол, предоставляющий работу с целочисленным полем
/// </summary>
public partial class BaseControlInt : AbstractBaseControl public partial class BaseControlInt : AbstractBaseControl
{ {
public BaseControlInt(string propertyName) : base(propertyName) /// <summary>
/// Конструктор
/// </summary>
/// <param name="propertyName"></param>
/// <param name="mustFilling"></param>
/// <param name="readOnly"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
public BaseControlInt(string propertyName, bool mustFilling, bool readOnly, decimal? minValue, decimal? maxValue) : base(propertyName, mustFilling, readOnly)
{ {
InitializeComponent(); InitializeComponent();
checkBoxNullable.Visible = false;
panelControl.Controls.Add(checkBoxNullable); if (!_mustFilling)
checkBoxNullable.CheckedChanged += (object sender, EventArgs e) =>
{ {
numericUpDown.Enabled = !(sender as CheckBox).Checked; checkBoxNullable.CheckedChanged += (object sender, EventArgs e) =>
CallOnValueChangeEvent(); {
}; numericUpDown.Enabled = !(sender as CheckBox).Checked;
CallOnValueChangeEvent();
};
panelControl.Controls.Add(checkBoxNullable);
}
panelControl.Controls.Add(numericUpDown);
numericUpDown.ValueChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); }; numericUpDown.ValueChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); };
_originalValue = 0; if (minValue.HasValue)
{
numericUpDown.Minimum = minValue.Value;
}
if (maxValue.HasValue)
{
numericUpDown.Maximum = maxValue.Value;
}
panelControl.Controls.Add(numericUpDown);
} }
public override void SetReadOnly(bool readOnly) protected override void SetDefaultValue() => _originalValue = _mustFilling ? 0 : null;
{
numericUpDown.Enabled = !readOnly;
checkBoxNullable.Enabled = !readOnly;
}
public override void SetValueToControl(object value) protected override void SetValueToControl(object value)
{ {
base.SetValueToControl(value);
if (value != null) if (value != null)
{ {
numericUpDown.Value = Convert.ToInt32(value); numericUpDown.Value = Convert.ToInt32(value);
} }
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
} }
public override void DropValue() public override void DropValue()
{ {
numericUpDown.Value = _originalValue != null ? Convert.ToInt32(_originalValue) : 0; if (_originalValue != null)
{
numericUpDown.Value = Convert.ToInt32(_originalValue);
}
else if (!_mustFilling)
{
checkBoxNullable.Checked = true;
}
} }
public override bool CheckValue() public override bool CheckValue() => true;
{
if (_mustCheckValue && checkBoxNullable.Checked)
{
BackColor = Color.OrangeRed;
return false;
}
return true;
}
protected override object GetValueFromControl() protected override object GetValueFromControl() => !_mustFilling && checkBoxNullable.Checked ? null : Convert.ToInt32(numericUpDown.Value);
{
if (_mustCheckValue && checkBoxNullable.Checked)
{
throw new ArgumentNullException($"Поле свойства '{labelTitle.Text}' должно быть заполнено");
}
return checkBoxNullable.Checked? null : Convert.ToInt32(numericUpDown.Value);
}
} }
} }

View File

@ -0,0 +1,44 @@

namespace DesktopTools.BaseControls
{
partial class BaseControlString
{
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.textBox = new System.Windows.Forms.TextBox();
//
// textBox
//
this.textBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox.Location = new System.Drawing.Point(0, 0);
this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(1000, 1000);
this.textBox.TabIndex = 0;
}
#endregion
private System.Windows.Forms.TextBox textBox;
}
}

View File

@ -0,0 +1,55 @@
using ModuleTools.Extensions;
using System;
using System.Drawing;
namespace DesktopTools.BaseControls
{
/// <summary>
/// Контрол, предоставляющий работу с однострочным текстовым полем
/// </summary>
public partial class BaseControlString : AbstractBaseControl
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="propertyName"></param>
/// <param name="mustFilling"></param>
/// <param name="readOnly"></param>
/// <param name="maxLength"></param>
public BaseControlString(string propertyName, bool mustFilling, bool readOnly, int? maxLength) : base(propertyName, mustFilling, readOnly)
{
InitializeComponent();
if (maxLength.HasValue)
{
textBox.MaxLength = maxLength.Value;
}
textBox.TextChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); };
panelControl.Controls.Add(textBox);
}
protected override void SetDefaultValue() => _originalValue = string.Empty;
protected override void SetValueToControl(object value) => textBox.Text = value?.ToString();
public override void DropValue() => textBox.Text = _originalValue?.ToString();
public override bool CheckValue()
{
if (_mustFilling && textBox.Text.IsEmpty())
{
BackColor = Color.OrangeRed;
return false;
}
return true;
}
protected override object GetValueFromControl()
{
if (_mustFilling && textBox.Text.IsEmpty())
{
throw new ArgumentNullException($"Поле свойства '{labelTitle.Text}' должно быть заполнено");
}
return textBox.Text;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -24,6 +24,8 @@ namespace DesktopTools.BaseControls
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.textBox = new System.Windows.Forms.TextBox(); this.textBox = new System.Windows.Forms.TextBox();
// //
// textBox // textBox
@ -32,7 +34,8 @@ namespace DesktopTools.BaseControls
this.textBox.Location = new System.Drawing.Point(0, 0); this.textBox.Location = new System.Drawing.Point(0, 0);
this.textBox.Name = "textBox"; this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(1000, 1000); this.textBox.Size = new System.Drawing.Size(1000, 1000);
this.textBox.TabIndex = 1; this.textBox.Multiline = true;
this.textBox.TabIndex = 0;
} }
#endregion #endregion

View File

@ -4,29 +4,43 @@ using System.Drawing;
namespace DesktopTools.BaseControls namespace DesktopTools.BaseControls
{ {
/// <summary>
/// Контрол, предоставляющий работу с текстовым полем на несколько строк
/// </summary>
public partial class BaseControlText : AbstractBaseControl public partial class BaseControlText : AbstractBaseControl
{ {
public BaseControlText(string propertyName) : base(propertyName) /// <summary>
/// Конструктор
/// </summary>
/// <param name="propertyName"></param>
/// <param name="mustFilling"></param>
/// <param name="readOnly"></param>
/// <param name="maxLength"></param>
/// <param name="height"></param>
public BaseControlText(string propertyName, bool mustFilling, bool readOnly, int? maxLength, int? height) : base(propertyName, mustFilling, readOnly)
{ {
InitializeComponent(); InitializeComponent();
panelControl.Controls.Add(textBox); if (maxLength.HasValue)
{
textBox.MaxLength = maxLength.Value;
}
if (height.HasValue)
{
textBox.Height = height.Value;
}
textBox.TextChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); }; textBox.TextChanged += (object sender, EventArgs e) => { CallOnValueChangeEvent(); };
_originalValue = string.Empty; panelControl.Controls.Add(textBox);
} }
public override void SetReadOnly(bool readOnly) => textBox.Enabled = !readOnly; protected override void SetDefaultValue() => _originalValue = string.Empty;
public override void SetValueToControl(object value) protected override void SetValueToControl(object value) => textBox.Text = value?.ToString();
{
base.SetValueToControl(value);
textBox.Text = value.ToString();
}
public override void DropValue() => textBox.Text = _originalValue.ToString(); public override void DropValue() => textBox.Text = _originalValue?.ToString();
public override bool CheckValue() public override bool CheckValue()
{ {
if(_mustCheckValue && textBox.Text.IsEmpty()) if(_mustFilling && textBox.Text.IsEmpty())
{ {
BackColor = Color.OrangeRed; BackColor = Color.OrangeRed;
return false; return false;
@ -36,7 +50,7 @@ namespace DesktopTools.BaseControls
protected override object GetValueFromControl() protected override object GetValueFromControl()
{ {
if (_mustCheckValue && textBox.Text.IsEmpty()) if (_mustFilling && textBox.Text.IsEmpty())
{ {
throw new ArgumentNullException($"Поле свойства '{labelTitle.Text}' должно быть заполнено"); throw new ArgumentNullException($"Поле свойства '{labelTitle.Text}' должно быть заполнено");
} }

View File

@ -1,7 +1,7 @@
 
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
partial class BaseControlViewEntityElement partial class AbstractControlViewEntityElement
{ {
/// <summary> /// <summary>
/// Обязательная переменная конструктора. /// Обязательная переменная конструктора.

View File

@ -5,7 +5,7 @@ using System.Windows.Forms;
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
public partial class BaseControlViewEntityElement : UserControl public abstract partial class AbstractControlViewEntityElement : UserControl
{ {
/// <summary> /// <summary>
/// Признак налиичия изменений /// Признак налиичия изменений
@ -25,12 +25,12 @@ namespace DesktopTools.Controls
/// <summary> /// <summary>
/// Открытие формы /// Открытие формы
/// </summary> /// </summary>
public virtual void Open() { } public abstract void Open(Guid? id);
/// <summary> /// <summary>
/// Закрытие формы /// Закрытие формы
/// </summary> /// </summary>
public virtual void Close() public void Close()
{ {
if(_haveChages && DialogHelper.MessageQuestion("Имеется несохраненные данные, вы действительно хотите закрыть элемент?", "Закрытие элемента") == if(_haveChages && DialogHelper.MessageQuestion("Имеется несохраненные данные, вы действительно хотите закрыть элемент?", "Закрытие элемента") ==
DialogResult.Yes) DialogResult.Yes)
@ -45,13 +45,7 @@ namespace DesktopTools.Controls
Dispose(); Dispose();
} }
protected virtual bool Save() { return true; } protected abstract bool Save();
/// <summary>
/// Дубликат контрола
/// </summary>
/// <returns></returns>
public virtual BaseControlViewEntityElement Clone() { return null; }
/// <summary> /// <summary>
/// Установка флага, что есть изменения /// Установка флага, что есть изменения
@ -96,7 +90,7 @@ namespace DesktopTools.Controls
/// <summary> /// <summary>
/// Констркутор /// Констркутор
/// </summary> /// </summary>
public BaseControlViewEntityElement() public AbstractControlViewEntityElement()
{ {
InitializeComponent(); InitializeComponent();
} }

View File

@ -1,7 +1,7 @@
 
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
partial class BaseControlViewEntityList partial class AbstractControlViewEntityList
{ {
/// <summary> /// <summary>
/// Обязательная переменная конструктора. /// Обязательная переменная конструктора.

View File

@ -4,7 +4,7 @@ using System.Windows.Forms;
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
public partial class BaseControlViewEntityList : UserControl public abstract partial class AbstractControlViewEntityList : UserControl
{ {
/// <summary> /// <summary>
/// Событие, вызываемое при закрытии контрола /// Событие, вызываемое при закрытии контрола
@ -19,14 +19,19 @@ namespace DesktopTools.Controls
/// <summary> /// <summary>
/// Открытие формы /// Открытие формы
/// </summary> /// </summary>
public virtual void Open() { } public abstract void Open();
/// <summary> /// <summary>
/// Закрытие формы /// Закрытие формы
/// </summary> /// </summary>
public virtual void Close() public void Close()
{ {
CloseEvent?.Invoke(ControlId); CloseEvent?.Invoke(ControlId);
if (FormForSelected != null)
{
FormForSelected.DialogResult = DialogResult.Cancel;
FormForSelected.Close();
}
Dispose(); Dispose();
} }
@ -34,7 +39,7 @@ namespace DesktopTools.Controls
/// Дубликат контрола /// Дубликат контрола
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public virtual BaseControlViewEntityList Clone() { return null; } public abstract AbstractControlViewEntityList Clone();
/// <summary> /// <summary>
/// Идентификатор контрола /// Идентификатор контрола
@ -56,11 +61,31 @@ namespace DesktopTools.Controls
/// </summary> /// </summary>
public AccessOperation AccessOperation { get; protected set; } public AccessOperation AccessOperation { get; protected set; }
/// <summary>
/// Идентификатор выбранной записи
/// </summary>
public Guid? SelectedId { get; set; }
/// <summary>
/// Название выбранной записи
/// </summary>
public string SelectedText { get; set; }
/// <summary>
/// Ссылка на форму, в который открыевается контрол для выбора значения
/// </summary>
public Form FormForSelected { get; set; }
/// <summary>
/// Получение названиия объекта по его идентификатору
/// </summary>
/// <param name="id"></param>
public abstract string GetTitleFromId(Guid id);
/// <summary> /// <summary>
/// Констркутор /// Констркутор
/// </summary> /// </summary>
public BaseControlViewEntityList() public AbstractControlViewEntityList()
{ {
InitializeComponent(); InitializeComponent();
} }

View File

@ -1,6 +1,6 @@
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
partial class GenericControlEntityList<G, S, L, E, BL> partial class AbstractGenericControlEntityList<G, S, L, E, BL>
{ {
/// <summary> /// <summary>
/// Освободить все используемые ресурсы. /// Освободить все используемые ресурсы.

View File

@ -13,7 +13,7 @@ using System.Windows.Forms;
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
public partial class GenericControlEntityList<G, S, L, E, BL> : BaseControlViewEntityList public abstract partial class AbstractGenericControlEntityList<G, S, L, E, BL> : AbstractControlViewEntityList
where G : GetBindingModel, new() where G : GetBindingModel, new()
where S : SetBindingModel, new() where S : SetBindingModel, new()
where L : ListViewModel<E> where L : ListViewModel<E>
@ -28,7 +28,7 @@ namespace DesktopTools.Controls
/// <summary> /// <summary>
/// Констркутор /// Констркутор
/// </summary> /// </summary>
public GenericControlEntityList() public AbstractGenericControlEntityList()
{ {
InitializeComponent(); InitializeComponent();
InitEvents(); InitEvents();
@ -37,7 +37,6 @@ namespace DesktopTools.Controls
public override async void Open() public override async void Open()
{ {
base.Open();
if (dataGridViewList.Columns.Count == 0) if (dataGridViewList.Columns.Count == 0)
{ {
Configurate(GetConfig()); Configurate(GetConfig());
@ -45,10 +44,7 @@ namespace DesktopTools.Controls
await LoadListAsync(); await LoadListAsync();
} }
public override void Close() public override string GetTitleFromId(Guid id) => _businessLogic.GetElement(new G { Id = id })?.ToString();
{
base.Close();
}
/// <summary> /// <summary>
/// Конфигуратор контрола /// Конфигуратор контрола
@ -150,6 +146,9 @@ namespace DesktopTools.Controls
{ {
toolStripFooter.Visible = false; toolStripFooter.Visible = false;
} }
// при вызове контрола для выбора элемента, делаем возможность выбора только одной записи
dataGridViewList.MultiSelect = FormForSelected == null;
} }
/// <summary> /// <summary>
@ -184,6 +183,14 @@ namespace DesktopTools.Controls
}; };
dataGridViewList.CellDoubleClick += (object sender, DataGridViewCellEventArgs e) => dataGridViewList.CellDoubleClick += (object sender, DataGridViewCellEventArgs e) =>
{ {
if (FormForSelected != null && dataGridViewList.SelectedRows.Count > 0)
{
SelectedId = new Guid(dataGridViewList.SelectedRows[0].Cells[0].Value.ToString());
SelectedText = _businessLogic.GetElement(new G { Id = SelectedId })?.ToString();
FormForSelected.DialogResult = DialogResult.OK;
FormForSelected.Close();
return;
}
CallUpdElementEvent(); CallUpdElementEvent();
}; };
@ -343,8 +350,8 @@ namespace DesktopTools.Controls
{ {
try try
{ {
var control = new GenericControlEntityElement<G, S, L, E, BL>(id); var control = new GenericControlEntityElement<G, S, L, E, BL>();
control.Open(); control.Open(id);
var form = new Form var form = new Form
{ {
Height = control.Height, Height = control.Height,
@ -364,12 +371,12 @@ namespace DesktopTools.Controls
} }
} }
protected virtual ControlViewEntityListConfiguration GetConfig() => new(); protected abstract ControlViewEntityListConfiguration GetConfig();
protected virtual L GetData() { return null; } protected abstract L GetData();
protected virtual L GetDataWithPageName(string key) { return null; } protected abstract L GetDataWithPageName(string key);
protected virtual L GetDataWithPageNumber(int page, int count) { return null; } protected abstract L GetDataWithPageNumber(int page, int count);
} }
} }

View File

@ -2,6 +2,8 @@
using ModuleTools.Attributes; using ModuleTools.Attributes;
using ModuleTools.BindingModels; using ModuleTools.BindingModels;
using ModuleTools.BusinessLogics; using ModuleTools.BusinessLogics;
using ModuleTools.Enums;
using ModuleTools.Extensions;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
using System; using System;
using System.Linq; using System.Linq;
@ -10,7 +12,7 @@ using System.Windows.Forms;
namespace DesktopTools.Controls namespace DesktopTools.Controls
{ {
public partial class GenericControlEntityElement<G, S, L, E, BL> : BaseControlViewEntityElement public partial class GenericControlEntityElement<G, S, L, E, BL> : AbstractControlViewEntityElement
where G : GetBindingModel, new() where G : GetBindingModel, new()
where S : SetBindingModel, new() where S : SetBindingModel, new()
where L : ListViewModel<E> where L : ListViewModel<E>
@ -24,30 +26,31 @@ namespace DesktopTools.Controls
private event Action<int> SetTitleWidth; private event Action<int> SetTitleWidth;
private event Action<object> SetValues;
private event Action DropValues; private event Action DropValues;
private event Func<bool> CheckValues; private event Func<bool> CheckValues;
private event Action<object> GetValues; private event Action<object> GetValues;
private E Element { get; set; }
public GenericControlEntityElement(Guid? id) private E _element = null;
private E Element { get { return _element; } set { _element = value; SetValues?.Invoke(_element); _haveChages = false; } }
public GenericControlEntityElement()
{ {
InitializeComponent(); InitializeComponent();
InitEvents(); InitEvents();
_businessLogic = DependencyManager.Instance.Resolve<BL>(); _businessLogic = DependencyManager.Instance.Resolve<BL>();
Element = _businessLogic.GetElement(new G { Id = id });
} }
public override void Open(Guid? id)
public override void Open()
{ {
base.Open();
if (panelContainer.Controls.Count == 0) if (panelContainer.Controls.Count == 0)
{ {
Configurate(); Configurate();
} }
//LoadList(); Element = _businessLogic.GetElement(new G { Id = id });
} }
private void InitEvents() private void InitEvents()
@ -71,23 +74,46 @@ namespace DesktopTools.Controls
if (attribute != null) if (attribute != null)
{ {
AbstractBaseControl control = null; AbstractBaseControl control = null;
switch (property.PropertyType.Name.ToLower()) switch (attribute.ControlType)
{ {
case "string": case ControlType.ControlString:
control = new BaseControlText(property.Name); control = new BaseControlString(property.Name, attribute.MustHaveValue, attribute.ReadOnly, attribute.MaxLength);
break; break;
case "int32": case ControlType.ControlText:
control = new BaseControlInt(property.Name); control = new BaseControlText(property.Name, attribute.MustHaveValue, attribute.ReadOnly, attribute.MaxLength, attribute.Height);
break;
case ControlType.ControlInt:
control = new BaseControlInt(property.Name, attribute.MustHaveValue, attribute.ReadOnly, attribute.MinValue, attribute.MaxValue);
break;
case ControlType.ControlDecimal:
control = new BaseControlDecimal(property.Name, attribute.MustHaveValue, attribute.ReadOnly, attribute.MinValue,
attribute.MaxValue, attribute.DecimalPlaces);
break;
case ControlType.ControlBool:
control = new BaseControlBool(property.Name, attribute.MustHaveValue, attribute.ReadOnly);
break;
case ControlType.ControlDateTime:
control = new BaseControlDateTime(property.Name, attribute.MustHaveValue, attribute.ReadOnly, attribute.MinDate,
attribute.MaxDate, attribute.CustomDateFormat);
break;
case ControlType.ControlImage:
control = new BaseControlImage(property.Name, attribute.MustHaveValue, attribute.ReadOnly, attribute.Width, attribute.Height);
break;
case ControlType.ControlEnum:
control = new BaseControlEnum(property.Name, attribute.MustHaveValue, attribute.ReadOnly, property.PropertyType);
break;
case ControlType.ControlGuid:
if (attribute.ControlTypeObject.IsNotEmpty())
{
control = new BaseControlGuid(property.Name, attribute.MustHaveValue, attribute.ReadOnly,
DependencyManager.Instance.Resolve(Type.GetType(attribute.ControlTypeObject)) as AbstractControlViewEntityList);
}
break; break;
} }
if (control == null) if (control == null)
{ {
continue; continue;
} }
if (Element != null)
{
control.SetValueToControl(property.GetValue(Element));
}
var widthTitle = control.SetTitle(attribute.DisplayName); var widthTitle = control.SetTitle(attribute.DisplayName);
if (widthTitle > titleWidth) if (widthTitle > titleWidth)
@ -96,19 +122,17 @@ namespace DesktopTools.Controls
} }
control.OnValueChangeEvent += ValueChange; control.OnValueChangeEvent += ValueChange;
SetValues += control.SetValue;
DropValues += control.DropValue; DropValues += control.DropValue;
CheckValues += control.CheckValue; CheckValues += control.CheckValue;
SetTitleWidth += control.SetTitleWidth; SetTitleWidth += control.SetTitleWidth;
GetValues += control.FillPropertyToObject; GetValues += control.GetValue;
control.Location = new System.Drawing.Point(positionX, positionY); control.Location = new System.Drawing.Point(positionX, positionY);
control.Width = Width - positionX * 2; control.Width = Width - positionX * 2;
control.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left; control.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left;
positionY += control.Height + interval; positionY += control.Height + interval;
control.SetReadOnly(attribute.ReadOnly);
control.SetMustCheckValue(attribute.MustHaveValue);
panelContainer.Controls.Add(control); panelContainer.Controls.Add(control);
} }
} }
@ -141,6 +165,7 @@ namespace DesktopTools.Controls
throw new Exception($"Ошибка при сохранении: {_businessLogic.Errors.LastOrDefault().Message}"); throw new Exception($"Ошибка при сохранении: {_businessLogic.Errors.LastOrDefault().Message}");
} }
_haveChages = false;
MessageBox.Show("Сохранение прошло успешно", "", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true; return true;
} }

View File

@ -11,6 +11,6 @@ namespace DesktopTools.Models
public string Title { get; set; } public string Title { get; set; }
public BaseControlViewEntityList Control { get; set; } public AbstractControlViewEntityList Control { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using ModuleTools.Enums;
using System;
namespace ModuleTools.Attributes namespace ModuleTools.Attributes
{ {
@ -14,6 +15,11 @@ namespace ModuleTools.Attributes
/// </summary> /// </summary>
public string DisplayName { get; set; } public string DisplayName { get; set; }
/// <summary>
/// Через какой тип контрола отображать свойство
/// </summary>
public ControlType ControlType { get; set; }
/// <summary> /// <summary>
/// Поле должно быть обязательно заполнено /// Поле должно быть обязательно заполнено
/// </summary> /// </summary>
@ -27,31 +33,80 @@ namespace ModuleTools.Attributes
/// <summary> /// <summary>
/// Ширина /// Ширина
/// </summary> /// </summary>
public int? Width { get; set; } public int? Width { get; set; } = null;
/// <summary> /// <summary>
/// Высота /// Высота
/// </summary> /// </summary>
public int? Height { get; set; } public int? Height { get; set; } = null;
/// <summary>
/// Максимальное длина строки
/// </summary>
public int? MaxLength { get; set; } = null;
/// <summary>
/// Минимальное значение для числового параметра
/// </summary>
public decimal? MinValue { get; set; } = null;
/// <summary>
/// Максимальное значение для числового параметра
/// </summary>
public decimal? MaxValue { get; set; } = null;
/// <summary>
/// Количество знаков после запятой
/// </summary>
public int? DecimalPlaces { get; set; } = null;
/// <summary>
/// Минимальное значение для даты
/// </summary>
public DateTime? MinDate { get; set; } = null;
/// <summary>
/// Максимальное значение для даты
/// </summary>
public DateTime? MaxDate { get; set; } = null;
/// <summary>
/// Пользовательский формат отображения даты
/// </summary>
public string CustomDateFormat { get; set; } = null;
/// <summary>
/// Имя контрола (включая namespace) для вызова формы выбора элемента-объекта другого класса
/// </summary>
public string ControlTypeObject { get; set; } = string.Empty;
/// <summary>
/// Имя свйоства, где лежит текстовое значение для ссылочного типа (опсанного через Id на другую сущность)
/// </summary>
public string PropertyNameForTitle { get; set; }
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="displayName">Название на форме</param> /// <param name="displayName">Название на форме</param>
public ViewModelOnElementPropertyAttribute(string displayName) /// <param name="controlType">Через какой тип контрола отображать свойство</param>
public ViewModelOnElementPropertyAttribute(string displayName, ControlType controlType)
{ {
DisplayName = displayName; DisplayName = displayName;
ControlType = controlType;
} }
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="displayName">Название на форме</param> /// <param name="displayName">Название на форме</param>
/// <param name="controlType">Через какой тип контрола отображать свойство</param>
/// <param name="width">Ширина</param> /// <param name="width">Ширина</param>
/// <param name="height">Высота</param> /// <param name="height">Высота</param>
public ViewModelOnElementPropertyAttribute(string displayName, int width, int height) public ViewModelOnElementPropertyAttribute(string displayName, ControlType controlType, int width, int height)
{ {
DisplayName = displayName; DisplayName = displayName;
ControlType = controlType;
Width = width; Width = width;
Height = height; Height = height;
} }

View File

@ -58,5 +58,12 @@ namespace ModuleTools.BusinessLogics
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <returns></returns> /// <returns></returns>
public T Resolve<T>() => _dependencyManager.Resolve<T>(); public T Resolve<T>() => _dependencyManager.Resolve<T>();
/// <summary>
/// Получение класса со всеми зависмостями
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public object Resolve(Type t) => _dependencyManager.Resolve(t);
} }
} }

View File

@ -1,4 +1,5 @@
using ModuleTools.Interfaces; using ModuleTools.Interfaces;
using System;
using Unity; using Unity;
using Unity.Lifetime; using Unity.Lifetime;
@ -18,5 +19,7 @@ namespace ModuleTools.BusinessLogics
public void RegisterType<T>() => _unityContainer.RegisterType<T>(new HierarchicalLifetimeManager()); public void RegisterType<T>() => _unityContainer.RegisterType<T>(new HierarchicalLifetimeManager());
public T Resolve<T>() => _unityContainer.Resolve<T>(); public T Resolve<T>() => _unityContainer.Resolve<T>();
public object Resolve(Type t) => _unityContainer.Resolve(t);
} }
} }

View File

@ -0,0 +1,53 @@
namespace ModuleTools.Enums
{
/// <summary>
/// Тип контрола, через который следует отображать свойство с ViewModel
/// </summary>
public enum ControlType
{
/// <summary>
/// Простое однострочное текстовое поле
/// </summary>
ControlString = 0,
/// <summary>
/// Текстовое поле в несколько строк
/// </summary>
ControlText = 1,
/// <summary>
/// Поле для целочисленного значения
/// </summary>
ControlInt = 2,
/// <summary>
/// Поле для вещественного значения
/// </summary>
ControlDecimal = 3,
/// <summary>
/// Поле для bool-значения
/// </summary>
ControlBool = 4,
/// <summary>
/// Поле для даты
/// </summary>
ControlDateTime = 5,
/// <summary>
/// Поле для изображения
/// </summary>
ControlImage = 6,
/// <summary>
/// Поле для пеерчисления
/// </summary>
ControlEnum = 7,
/// <summary>
/// Поле для идентифкатора на другую сущность
/// </summary>
ControlGuid = 8
}
}

View File

@ -1,4 +1,6 @@
namespace ModuleTools.Interfaces using System;
namespace ModuleTools.Interfaces
{ {
/// <summary> /// <summary>
/// Интерфейс установки зависмости между элементами /// Интерфейс установки зависмости между элементами
@ -25,5 +27,12 @@
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <returns></returns> /// <returns></returns>
T Resolve<T>(); T Resolve<T>();
/// <summary>
/// Получение класса со всеми зависмостями
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
object Resolve(Type t);
} }
} }

View File

@ -9,15 +9,15 @@ namespace DepartmentPortalDesctop
{ {
public partial class FormMain : Form public partial class FormMain : Form
{ {
private readonly Dictionary<Guid, BaseControlViewEntityList> _baseControls; private readonly Dictionary<Guid, AbstractControlViewEntityList> _baseControls;
private readonly Dictionary<Guid, BaseControlViewEntityList> _controls; private readonly Dictionary<Guid, AbstractControlViewEntityList> _controls;
public FormMain() public FormMain()
{ {
InitializeComponent(); InitializeComponent();
_baseControls = new Dictionary<Guid, BaseControlViewEntityList>(); _baseControls = new Dictionary<Guid, AbstractControlViewEntityList>();
_controls = new Dictionary<Guid, BaseControlViewEntityList>(); _controls = new Dictionary<Guid, AbstractControlViewEntityList>();
var extensions = DesktopLoader.GetWindowDesktopExtensions(); var extensions = DesktopLoader.GetWindowDesktopExtensions();
foreach (var extens in extensions) foreach (var extens in extensions)
@ -28,7 +28,7 @@ namespace DepartmentPortalDesctop
var menu = new ToolStripMenuItem { Text = list[0].Title }; var menu = new ToolStripMenuItem { Text = list[0].Title };
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
if (list[i].Control is BaseControlViewEntityList control) if (list[i].Control is AbstractControlViewEntityList control)
{ {
if (_baseControls.ContainsKey(list[i].Id)) if (_baseControls.ContainsKey(list[i].Id))
{ {

View File

@ -22,17 +22,9 @@ namespace SecurityBusinessLogic.BindingModels
public string Login { get; set; } public string Login { get; set; }
[Required(ErrorMessage = "required")] [Required(ErrorMessage = "required")]
[MapConfiguration("Password")]
public string Password { get; set; } public string Password { get; set; }
[MapConfiguration("StudentId")]
public Guid? StudentId { get; set; }
[MapConfiguration("LecturerId")]
public Guid? LecturerId { get; set; }
[MapConfiguration("EmployeeId")]
public Guid? EmployeeId { get; set; }
[MapConfiguration("Avatar")] [MapConfiguration("Avatar")]
public byte[] Avatar { get; set; } public byte[] Avatar { get; set; }

View File

@ -12,4 +12,8 @@
<ProjectReference Include="..\..\Common\ModuleTools\ModuleTools.csproj" /> <ProjectReference Include="..\..\Common\ModuleTools\ModuleTools.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(TargetDir)*.dll&quot; &quot;$(SolutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project> </Project>

View File

@ -16,6 +16,7 @@ namespace SecurityBusinessLogic.ViewModels
public class AccessViewModel : ElementViewModel public class AccessViewModel : ElementViewModel
{ {
[MapConfiguration("RoleId", AllowCopyWithoutRigth = false)] [MapConfiguration("RoleId", AllowCopyWithoutRigth = false)]
[ViewModelOnElementProperty("Роль", ControlType.ControlGuid, MustHaveValue = true, ControlTypeObject = "SecurityWindowsDesktop.Controls.RolesControl, SecurityWindowsDesktop")]
public Guid RoleId { get; set; } public Guid RoleId { get; set; }
[ViewModelOnListProperty("Роль", 100)] [ViewModelOnListProperty("Роль", 100)]
@ -23,12 +24,14 @@ namespace SecurityBusinessLogic.ViewModels
public string RoleName { get; set; } public string RoleName { get; set; }
[MapConfiguration("AccessOperation", AllowCopyWithoutRigth = false)] [MapConfiguration("AccessOperation", AllowCopyWithoutRigth = false)]
[ViewModelOnElementProperty("Операция", ControlType.ControlEnum, MustHaveValue = true)]
public AccessOperation AccessOperation { get; set; } public AccessOperation AccessOperation { get; set; }
[ViewModelOnListProperty("Операция")] [ViewModelOnListProperty("Операция")]
public string AccessOperationTitle => AccessOperation.ToString("G"); public string AccessOperationTitle => AccessOperation.ToString("G");
[MapConfiguration("AccessType", AllowCopyWithoutRigth = false)] [MapConfiguration("AccessType", AllowCopyWithoutRigth = false)]
[ViewModelOnElementProperty("Тип", ControlType.ControlEnum, MustHaveValue = true)]
public AccessType AccessType { get; set; } public AccessType AccessType { get; set; }
[ViewModelOnListProperty("Тип", 150)] [ViewModelOnListProperty("Тип", 150)]

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using ModuleTools.Attributes;
using ModuleTools.Enums;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
namespace SecurityBusinessLogic.ViewModels namespace SecurityBusinessLogic.ViewModels
@ -14,17 +15,17 @@ namespace SecurityBusinessLogic.ViewModels
public class EnviromentSettingViewModel : ElementViewModel public class EnviromentSettingViewModel : ElementViewModel
{ {
[ViewModelOnListProperty("Ключ")] [ViewModelOnListProperty("Ключ")]
[ViewModelOnElementProperty("Ключ", MustHaveValue = true, ReadOnly = true)] [ViewModelOnElementProperty("Ключ", ControlType.ControlString, MustHaveValue = true, ReadOnly = true)]
[MapConfiguration("Key", AllowCopyWithoutRigth = false)] [MapConfiguration("Key", AllowCopyWithoutRigth = false)]
public string Key { get; set; } public string Key { get; set; }
[ViewModelOnListProperty("Значение")] [ViewModelOnListProperty("Значение")]
[ViewModelOnElementProperty("Значение", MustHaveValue = true)] [ViewModelOnElementProperty("Значение", ControlType.ControlString, MustHaveValue = true)]
[MapConfiguration("Value", AllowCopyWithoutRigth = false)] [MapConfiguration("Value", AllowCopyWithoutRigth = false)]
public string Value { get; set; } public string Value { get; set; }
[ViewModelOnListProperty("Описание")] [ViewModelOnListProperty("Описание")]
[ViewModelOnElementProperty("Описание")] [ViewModelOnElementProperty("Описание", ControlType.ControlText, 0, 200)]
[MapConfiguration("Description", AllowCopyWithoutRigth = false)] [MapConfiguration("Description", AllowCopyWithoutRigth = false)]
public string Description { get; set; } public string Description { get; set; }

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using ModuleTools.Attributes;
using ModuleTools.Enums;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
namespace SecurityBusinessLogic.ViewModels namespace SecurityBusinessLogic.ViewModels
@ -14,12 +15,12 @@ namespace SecurityBusinessLogic.ViewModels
public class RoleViewModel : ElementViewModel public class RoleViewModel : ElementViewModel
{ {
[ViewModelOnListProperty("Название роли")] [ViewModelOnListProperty("Название роли")]
[ViewModelOnElementProperty("Название роли")] [ViewModelOnElementProperty("Название роли", ControlType.ControlString, MustHaveValue = true)]
[MapConfiguration("RoleName")] [MapConfiguration("RoleName")]
public string RoleName { get; set; } public string RoleName { get; set; }
[ViewModelOnListProperty("Приоритет", 100)] [ViewModelOnListProperty("Приоритет", 100)]
[ViewModelOnElementProperty("Приоритет")] [ViewModelOnElementProperty("Приоритет", ControlType.ControlInt, MustHaveValue = true)]
[MapConfiguration("RolePriority")] [MapConfiguration("RolePriority")]
public int RolePriority { get; set; } public int RolePriority { get; set; }

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes; using ModuleTools.Attributes;
using ModuleTools.Enums;
using ModuleTools.ViewModels; using ModuleTools.ViewModels;
using System; using System;
@ -15,23 +16,15 @@ namespace SecurityBusinessLogic.ViewModels
public class UserViewModel : ElementViewModel public class UserViewModel : ElementViewModel
{ {
[ViewModelOnListProperty("Пользователь")] [ViewModelOnListProperty("Пользователь")]
[ViewModelOnElementProperty("Логин")] [ViewModelOnElementProperty("Логин", ControlType.ControlString, MustHaveValue = true)]
[MapConfiguration("UserName")] [MapConfiguration("UserName")]
public string Login { get; set; } public string Login { get; set; }
[MapConfiguration("PasswordHash", AllowCopyWithoutRigth = false)] [MapConfiguration("PasswordHash", AllowCopyWithoutRigth = false)]
public string Password { get; set; } public string Password { get; set; }
[MapConfiguration("StudentId")]
public Guid? StudentId { get; set; }
[MapConfiguration("LecturerId")]
public Guid? LecturerId { get; set; }
[MapConfiguration("EmployeeId")]
public Guid? EmployeeId { get; set; }
[MapConfiguration("Avatar")] [MapConfiguration("Avatar")]
[ViewModelOnElementProperty("Фото", ControlType.ControlImage, 200, 200)]
public byte[] Avatar { get; set; } public byte[] Avatar { get; set; }
[ViewModelOnListProperty("Посл. визит", 100)] [ViewModelOnListProperty("Посл. визит", 100)]
@ -39,18 +32,21 @@ namespace SecurityBusinessLogic.ViewModels
public DateTime? DateLastVisit { get; set; } public DateTime? DateLastVisit { get; set; }
[MapConfiguration("IsBanned", AllowCopyWithoutRigth = false)] [MapConfiguration("IsBanned", AllowCopyWithoutRigth = false)]
[ViewModelOnElementProperty("Заблокирован", ControlType.ControlBool, MustHaveValue = true)]
public bool IsBanned { get; set; } public bool IsBanned { get; set; }
[ViewModelOnListProperty("Блокир.", 80)] [ViewModelOnListProperty("Блокир.", 80)]
public string Banned => IsBanned ? "Да" : "Нет"; public string Banned => IsBanned ? "Да" : "Нет";
[MapConfiguration("DateBanned", AllowCopyWithoutRigth = false)] [MapConfiguration("DateBanned", AllowCopyWithoutRigth = false)]
[ViewModelOnElementProperty("Дата блокировки", ControlType.ControlDateTime, ReadOnly = true)]
public DateTime? DateBanned { get; set; } public DateTime? DateBanned { get; set; }
[ViewModelOnListProperty("Дата Б.", 100)] [ViewModelOnListProperty("Дата Б.", 100)]
public string DateBannedTitle => DateBanned.HasValue ? DateBanned.Value.ToShortDateString() : string.Empty; public string DateBannedTitle => DateBanned.HasValue ? DateBanned.Value.ToShortDateString() : string.Empty;
[MapConfiguration("CountAttempt", AllowCopyWithoutRigth = false)] [MapConfiguration("CountAttempt", AllowCopyWithoutRigth = false)]
[ViewModelOnElementProperty("Попытки входа", ControlType.ControlInt , ReadOnly = true)]
public int CountAttempt { get; set; } public int CountAttempt { get; set; }
public override string ToString() => Login; public override string ToString() => Login;

View File

@ -132,6 +132,11 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{ {
return OperationResultModel.Error("Error:", "Элемент был удален", ResultServiceStatusCode.WasDelete); return OperationResultModel.Error("Error:", "Элемент был удален", ResultServiceStatusCode.WasDelete);
} }
if(entity.IsBanned && !model.IsBanned)
{
model.DateBanned = null;
model.CountAttempt = 0;
}
entity = Mapper.MapToClass(model, entity, true); entity = Mapper.MapToClass(model, entity, true);
context.SaveChanges(); context.SaveChanges();

View File

@ -11,7 +11,7 @@ using System.Linq;
namespace SecurityWindowsDesktop.Controls namespace SecurityWindowsDesktop.Controls
{ {
public partial class AccessesControl : GenericControlEntityList<AccessGetBindingModel, AccessSetBindingModel, AccessListViewModel, AccessViewModel, AccessBusinessLogic> public partial class AccessesControl : AbstractGenericControlEntityList<AccessGetBindingModel, AccessSetBindingModel, AccessListViewModel, AccessViewModel, AccessBusinessLogic>
{ {
private readonly RoleBusinessLogic _roleBusinessLogic; private readonly RoleBusinessLogic _roleBusinessLogic;
@ -25,7 +25,7 @@ namespace SecurityWindowsDesktop.Controls
AccessOperation = AccessOperation.Доступы; AccessOperation = AccessOperation.Доступы;
} }
public override BaseControlViewEntityList Clone() => new AccessesControl() { ControlId = Guid.NewGuid() }; public override AbstractControlViewEntityList Clone() => new AccessesControl() { ControlId = Guid.NewGuid() };
protected override ControlViewEntityListConfiguration GetConfig() => new() protected override ControlViewEntityListConfiguration GetConfig() => new()
{ {
@ -33,10 +33,20 @@ namespace SecurityWindowsDesktop.Controls
PageNamesForPagination = _roleBusinessLogic.GetList(new RoleGetBindingModel())?.List?.Select(x => x.RoleName)?.ToList() PageNamesForPagination = _roleBusinessLogic.GetList(new RoleGetBindingModel())?.List?.Select(x => x.RoleName)?.ToList()
}; };
protected override AccessListViewModel GetData()
{
throw new NotImplementedException();
}
protected override AccessListViewModel GetDataWithPageName(string key) protected override AccessListViewModel GetDataWithPageName(string key)
{ {
var list = _businessLogic.GetList(new AccessGetBindingModel { RoleName = key }); var list = _businessLogic.GetList(new AccessGetBindingModel { RoleName = key });
return list; return list;
} }
protected override AccessListViewModel GetDataWithPageNumber(int page, int count)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -9,7 +9,7 @@ using System;
namespace SecurityWindowsDesktop.Controls namespace SecurityWindowsDesktop.Controls
{ {
public partial class EnviromentSettingControl : GenericControlEntityList<EnviromentSettingGetBindingModel, EnviromentSettingSetBindingModel, EnviromentSettingListViewModel, EnviromentSettingViewModel, EnviromentSettingBusinessLogic> public partial class EnviromentSettingControl : AbstractGenericControlEntityList<EnviromentSettingGetBindingModel, EnviromentSettingSetBindingModel, EnviromentSettingListViewModel, EnviromentSettingViewModel, EnviromentSettingBusinessLogic>
{ {
public EnviromentSettingControl() public EnviromentSettingControl()
{ {
@ -20,7 +20,7 @@ namespace SecurityWindowsDesktop.Controls
AccessOperation = AccessOperation.НастройкиСреды; AccessOperation = AccessOperation.НастройкиСреды;
} }
public override BaseControlViewEntityList Clone() => new EnviromentSettingControl() { ControlId = Guid.NewGuid() }; public override AbstractControlViewEntityList Clone() => new EnviromentSettingControl() { ControlId = Guid.NewGuid() };
protected override ControlViewEntityListConfiguration GetConfig() => new() protected override ControlViewEntityListConfiguration GetConfig() => new()
{ {
@ -32,5 +32,15 @@ namespace SecurityWindowsDesktop.Controls
var list = _businessLogic.GetList(new EnviromentSettingGetBindingModel()); var list = _businessLogic.GetList(new EnviromentSettingGetBindingModel());
return list; return list;
} }
protected override EnviromentSettingListViewModel GetDataWithPageName(string key)
{
throw new NotImplementedException();
}
protected override EnviromentSettingListViewModel GetDataWithPageNumber(int page, int count)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -9,7 +9,7 @@ using System;
namespace SecurityWindowsDesktop.Controls namespace SecurityWindowsDesktop.Controls
{ {
public partial class RolesControl : GenericControlEntityList<RoleGetBindingModel, RoleSetBindingModel, RoleListViewModel, RoleViewModel, RoleBusinessLogic> public partial class RolesControl : AbstractGenericControlEntityList<RoleGetBindingModel, RoleSetBindingModel, RoleListViewModel, RoleViewModel, RoleBusinessLogic>
{ {
public RolesControl() : base() public RolesControl() : base()
{ {
@ -20,7 +20,7 @@ namespace SecurityWindowsDesktop.Controls
AccessOperation = AccessOperation.Роли; AccessOperation = AccessOperation.Роли;
} }
public override BaseControlViewEntityList Clone() => new RolesControl() { ControlId = Guid.NewGuid() }; public override AbstractControlViewEntityList Clone() => new RolesControl() { ControlId = Guid.NewGuid() };
protected override ControlViewEntityListConfiguration GetConfig() => new() protected override ControlViewEntityListConfiguration GetConfig() => new()
{ {
@ -32,5 +32,15 @@ namespace SecurityWindowsDesktop.Controls
var list = _businessLogic.GetList(new RoleGetBindingModel()); var list = _businessLogic.GetList(new RoleGetBindingModel());
return list; return list;
} }
protected override RoleListViewModel GetDataWithPageName(string key)
{
throw new NotImplementedException();
}
protected override RoleListViewModel GetDataWithPageNumber(int page, int count)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -1,6 +1,5 @@
using DesktopTools.Controls; using DesktopTools.Controls;
using DesktopTools.Models; using DesktopTools.Models;
using ModuleTools.BusinessLogics;
using ModuleTools.Enums; using ModuleTools.Enums;
using SecurityBusinessLogic.BindingModels; using SecurityBusinessLogic.BindingModels;
using SecurityBusinessLogic.BusinessLogics; using SecurityBusinessLogic.BusinessLogics;
@ -9,7 +8,7 @@ using System;
namespace SecurityWindowsDesktop.Controls namespace SecurityWindowsDesktop.Controls
{ {
public partial class UsersControl : GenericControlEntityList<UserGetBindingModel, UserSetBindingModel, UserListViewModel, UserViewModel, UserBusinessLogic> public partial class UsersControl : AbstractGenericControlEntityList<UserGetBindingModel, UserSetBindingModel, UserListViewModel, UserViewModel, UserBusinessLogic>
{ {
public UsersControl() : base() public UsersControl() : base()
{ {
@ -20,7 +19,7 @@ namespace SecurityWindowsDesktop.Controls
AccessOperation = AccessOperation.Пользователи; AccessOperation = AccessOperation.Пользователи;
} }
public override BaseControlViewEntityList Clone() => new UsersControl() { ControlId = Guid.NewGuid() }; public override AbstractControlViewEntityList Clone() => new UsersControl() { ControlId = Guid.NewGuid() };
protected override ControlViewEntityListConfiguration GetConfig() => new() protected override ControlViewEntityListConfiguration GetConfig() => new()
{ {
@ -28,6 +27,16 @@ namespace SecurityWindowsDesktop.Controls
CountElementsOnPage = 40 CountElementsOnPage = 40
}; };
protected override UserListViewModel GetData()
{
throw new NotImplementedException();
}
protected override UserListViewModel GetDataWithPageName(string key)
{
throw new NotImplementedException();
}
protected override UserListViewModel GetDataWithPageNumber(int page, int count) protected override UserListViewModel GetDataWithPageNumber(int page, int count)
{ {
var list = _businessLogic.GetList(new UserGetBindingModel var list = _businessLogic.GetList(new UserGetBindingModel

View File

@ -31,7 +31,7 @@ namespace SecurityWindowsDesktop
{ {
new WindowDesktopExtensionControlModel { Order = 0, Title = "Администрирование" } new WindowDesktopExtensionControlModel { Order = 0, Title = "Администрирование" }
}; };
List<BaseControlViewEntityList> _controls = new() List<AbstractControlViewEntityList> _controls = new()
{ {
new UsersControl(), new UsersControl(),
new RolesControl(), new RolesControl(),
@ -53,6 +53,10 @@ namespace SecurityWindowsDesktop
}); });
} }
} }
DependencyManager.Instance.RegisterType<UsersControl>();
DependencyManager.Instance.RegisterType<RolesControl>();
DependencyManager.Instance.RegisterType<AccessesControl>();
DependencyManager.Instance.RegisterType<EnviromentSettingControl>();
return list; return list;
} }