void e_form_JustClose(Task arg1, EditForm arg2) { DialogResult d; d = MessageBox.Show("Хотите сохранить?", "Save", MessageBoxButtons.YesNoCancel); switch (d) { case DialogResult.Yes: { e_form_Save(arg1, arg2); LoadToGrid(dt.SelectAllTasks(tableName)); arg2.Close(); break; } case DialogResult.Cancel: { break; } case DialogResult.No: { arg2.Close(); LoadToGrid(dt.SelectAllTasks(tableName)); break; } } }
//Создание и отображение диалога создания/редактирования void UseE_Form(EditForm.EditType editMode,Task StartValue) { EditForm e_form; e_form = new EditForm(editMode, StartValue); e_form.Cancel += new Action<Task, EditForm>(e_form_Cancel); e_form.JustClose += new Action<Task, EditForm>(e_form_JustClose); e_form.Save += new Action<Task, EditForm>(e_form_Save); e_form.ShowDialog(); }
void e_form_Cancel(Task arg1, EditForm arg2) { arg2.Close(); }
void e_form_Save(Task arg1, EditForm arg2) { if (arg1.ID >= 0) { dt.UpdateTask(arg1, tableName); } else { dt.InsertNewTask(arg1, tableName); } MessageBox.Show("Сохранено"); }