public bool GenericEditEvent(IEditable _geditForm, BindingSource actualEvents, bool isNew = false) { ulog = UserLog.Instance; try { DataRowView eventDataRowView; eventDataRowView = (isNew == false) ? (DataRowView)actualEvents.Current : (DataRowView)actualEvents.AddNew(); if (eventDataRowView == null) throw new Exception("Нет записей для редактирования."); using (IEditable editForm = _geditForm) { if (editForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { actualEvents.EndEdit(); DateTime dt; string _edit = (isNew == false) ? "Изменено " : "Добавлено "; if (eventDataRowView.Row.Table.Columns.Contains("ActionDate")) { dt = Convert.ToDateTime(eventDataRowView["ActionDate"]); _edit += "мероприятие на " + dt.ToShortDateString() + "."; } else if (eventDataRowView.Row.Table.Columns.Contains("DayID")) { _edit += "календарное мероприятие. День недели: " + DatabaseConstant.LocalDayOfWeek[Convert.ToInt32(eventDataRowView["DayID"]) - 1] + "."; } ulog.Message(_edit, UserLogMessageLevel.Warning); return true; } else { actualEvents.CancelEdit(); return false; } } } catch (Exception ex) { ulog.Message(ex.Message, UserLogMessageLevel.Error); return false; } }
public bool GenericEditAction(IEditable _geditForm, BindingSource actualActions, BindingSource groupHeadersList, bool isNew = false) { ulog = UserLog.Instance; try { DataRowView actionDataRowView; actionDataRowView = (isNew == false) ? (DataRowView)actualActions.Current : (DataRowView)actualActions.AddNew(); if (actionDataRowView == null) throw new Exception("Нет записей для редактирования."); using (IEditable editActForm = _geditForm) {//открываем форму и сохраняем изменения if (editActForm.ShowDialog() == DialogResult.OK) { actualActions.EndEdit(); return true; } else { actualActions.CancelEdit(); return false; } } } catch (Exception ex) { actualActions.CancelEdit(); ulog.Message(ex.Message, UserLogMessageLevel.Error); return false; } finally { groupHeadersList.RemoveFilter(); groupHeadersList.Filter = "[InList] = 1"; } }