private void btnOk_Click(object sender, EventArgs e) { btnOk.Enabled = false; try { DateTime nextStartTime = (cbSheduleType.SelectedIndex == 0 ? dtpDateOnce.Value.Date.Add(dtpTimeOnce.Value.TimeOfDay) : dtbDateFrequency.Value.Date.Add(dtbTimeFrequency.Value.TimeOfDay)).ToUniversalTime(); #region InputChecks if (string.IsNullOrEmpty(tbTaskName.Text)) { MessageBox.Show($"Отсутствует имя задания.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); _dontCloseForm = true; return; } if (MQueryCommand.CheckTaskExistsByName(tbTaskName.Text, new int[1] { _pluginTaskId })) { MessageBox.Show($"Задание с именем [{tbTaskName.Text}] уже существует, введите другое имя.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); _dontCloseForm = true; return; } if (cbSheduleType.SelectedItem == null) { MessageBox.Show($"Не выбран тип расписания.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); _dontCloseForm = true; return; } if (string.IsNullOrEmpty(tbDllFileName.Text)) { MessageBox.Show($"Не указано имя файла плагин-операции [Имя dll - файла с расширением]", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); _dontCloseForm = true; return; } else if (!tbDllFileName.Text.Contains(".dll")) { MessageBox.Show($"Не указано расширение в имени файла для плагин-операции [.dll]", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); _dontCloseForm = true; return; } if (nextStartTime <= DateTime.UtcNow) { MessageBox.Show($"Дата следующего выполнения должна быть больше текущей даты!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); _dontCloseForm = true; return; } if (nextStartTime > DateTime.UtcNow && nextStartTime.AddMinutes(-10) <= DateTime.UtcNow) { if (MessageBox.Show($"Задание будет выполнено менее чем через 10 минут. Продолжить?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { _dontCloseForm = true; return; } } #endregion _shedulerPluginTask.Enabled = chbTaskEnabled.Checked; _shedulerPluginTask.Name = tbTaskName.Text; _shedulerPluginTask.PluginFileName = tbDllFileName.Text; _shedulerPluginTask.Description = rtbTaskDescription.Text; _shedulerPluginTask.Mode = cbSheduleType.SelectedIndex == 0 ? 0 : Convert.ToInt32(cbOccurs.SelectedValue); _shedulerPluginTask.NextStartTime = nextStartTime; _shedulerPluginTask.RepeatValue = Convert.ToInt32(nudRecurs.Value); _shedulerPluginTask.CreatedUserLogin = Environment.UserName; _shedulerPluginTask.CreationDateUtc = DateTime.UtcNow; //TODO var tryDeleteInsertUpdateTaskFromFormRes = MQueryCommand.TryInsertUpdatePluginTaskFromForm(_shedulerPluginTask); if (!tryDeleteInsertUpdateTaskFromFormRes.IsComplete) { MessageBox.Show(tryDeleteInsertUpdateTaskFromFormRes.Message); } } finally { btnOk.Enabled = true; } }