/// <summary>
 /// Обработчик события нажатия клавиши мыши на кнопку,
 /// который осуществляет добавление нового интерфейса накопителя
 /// </summary>
 private void button2_Click(object sender, EventArgs e)
 {
     StorageInterfaces.AddNew();
     strorageInterfaceBindingSource.MoveLast();
     EnDisFields(true);
     _formMode = FormMode.Add;
 }
 /// <summary>
 /// Обработчик события нажатия клавиши мыши на кнопку,
 /// который производит отмену последнего добавления/редактирования
 /// </summary>
 private void btn_Cancel_Click(object sender, EventArgs e)
 {
     if (_formMode != FormMode.None)
     {
         var result = MessageBox.Show("Изменения не будут сохранены! Продолжить?", "Отмена изменений",
                                      MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
         if (result == DialogResult.Yes)
         {
             try
             {
                 if (_formMode == FormMode.Edit)
                 {
                     int indexOfElement = StorageInterfaces.IndexOf(CurrentStorageInterface);
                     CurrentStorageInterface           = _ctx.CancelChanges(CurrentStorageInterface);
                     StorageInterfaces[indexOfElement] = CurrentStorageInterface;
                 }
                 else
                 {
                     StorageInterfaces.CancelNew(StorageInterfaces.IndexOf(CurrentStorageInterface));
                 }
                 EnDisFields(false);
                 _formMode = FormMode.None;
             }
             catch
             {
                 MessageBox.Show("Произошла ошибка при отмене изменений!", "Ошибка", MessageBoxButtons.OK,
                                 MessageBoxIcon.Error);
             }
         }
     }
 }
        /// <summary>
        /// Обработчик события нажатия клавиши мыши на кнопку,
        /// который выполняет сохранение изменений
        /// </summary>
        private async void btn_Save_Click(object sender, EventArgs e)
        {
            if (_formMode != FormMode.None)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(CurrentStorageInterface.Name))
                    {
                        MessageBox.Show("Введите наименование интерфейса накопителя!", "Предупреждение", MessageBoxButtons.OK,
                                        MessageBoxIcon.Exclamation);
                        return;
                    }

                    bool existed = false;

                    switch (_formMode)
                    {
                    case FormMode.Add:
                        existed = await _ctx.CheckStorageInterfaceForDublicate(CurrentStorageInterface.Name);

                        break;

                    case FormMode.Edit:
                        existed = await _ctx.CheckStorageInterfaceForDublicate(CurrentStorageInterface.Name) && !CurrentStorageInterface.Name.Equals(_storageInterfaceNameBeforeEditing);

                        break;
                    }

                    if (existed)
                    {
                        MessageBox.Show("Интерфейс накопителя с таким наименованием уже существует!", "Ошибка",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (_formMode == FormMode.Add)
                    {
                        StorageInterfaces.EndNew(StorageInterfaces.IndexOf(CurrentStorageInterface));
                    }
                    await _ctx.SaveChangesAsync();

                    EnDisFields(false);
                    Edited       = true;
                    _formMode    = FormMode.None;
                    DialogResult = DialogResult.OK;
                    MessageBox.Show("Изменения успешно сохранены!", "Информация", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Изменения не удалось сохранить!", "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }
        /// <summary>
        /// Обработчик события нажатия клавиши мыши на графический объект,
        /// который производит поиск интерфейса накопителя по наименованию
        /// </summary>
        private void picBtn_FindByCondition_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox_ConditionToFind.Text))
            {
                MessageBox.Show("Введите условие для поиска интерфейса накопителя!", "Предупреждение", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return;
            }

            var firstFoundedElement = StorageInterfaces.FirstOrDefault(x => x.Name.ToUpper().Contains(textBox_ConditionToFind.Text.ToUpper()));

            if (firstFoundedElement != null)
            {
                strorageInterfaceBindingSource.Position = StorageInterfaces.IndexOf(firstFoundedElement);
            }
            else
            {
                MessageBox.Show("Не удалось найти интерфейс накопителя по указанному условию!", "Информация",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }