예제 #1
0
        /// <summary>
        /// If deletion is to be confirmed, checks deletion with the user before continuing.
        /// This applies only to the default delete behaviour where a full row is selected
        /// by clicking on the column.
        /// </summary>
        private void ConfirmRowDeletion(object sender, DataGridViewRowCancelEventArgs e)
        {
            try
            {
                CheckRowEvent(e);
                if (ConfirmDeletion && !CheckUserConfirmsDeletionDelegate())
                {
                    e.Cancel = true;
                    return;
                }
                var             rowObjectIDValue = GetRowObjectIDValue(e.Row);
                IBusinessObject businessObject   = this.DataSetProvider.Find(rowObjectIDValue);
                if (businessObject == null)
                {
                    //this.RefreshGrid();
                    //GlobalUIRegistry.ControlFactory.ShowMessageBox(
                    //    "There was a problem deleting the selected item please try again");

                    _logger.Log("ConfirmRowDeletion - Row Index :" + e.Row.Index + " - No business object found", LogCategory.Debug);
                    e.Cancel = true;
                    return;
                }
                string message;
                if (!businessObject.IsDeletable(out message))
                {
                    e.Cancel = true;
                    throw new BusObjDeleteException(businessObject, message);
                }
            }
            catch (Exception ex)
            {
                GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error ");
            }
        }
예제 #2
0
        /// <summary>
        /// Handles the event of a row being deleted
        /// </summary>
        /// <param name="sender">The object that notified of the event</param>
        /// <param name="e">Attached arguments regarding the event</param>
        private void RowDeletedHandler(object sender, DataRowChangeEventArgs e)
        {
            DataRow row = e.Row;

            try
            {
                IBusinessObject changedBo = GetBusinessObjectForRow(row);
                if (changedBo == null)
                {
                    return;
                }
                try
                {
                    string message;
                    if (changedBo.IsDeletable(out message))
                    {
                        DeregisterForBOEvents();
                        changedBo.MarkForDelete();
                        changedBo.Save();
                    }
                    else
                    {
                        row.RejectChanges();
                    }
                }
                finally
                {
                    RegisterForBOEvents();
                }
            }
            catch (Exception ex)
            {
                string message = "There was a problem saving. : " + ex.Message;
                row.RowError = message;
                GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error ");
            }
        }