public void DeleteRow(string strKey) { long id = Convert.ToInt64(strKey); var recordEvents = new MyProductsEdit.RecordEvents { Page = Page, Control = this, }; recordEvents.InitializeValues(NavigatorControl.Values); DeleteRow(id, recordEvents, false); }
protected void DeleteSelected(object sender, DirectEventArgs e) { var sm = (RowSelectionModel)grid.GetSelectionModel(); foreach (var item in sm.SelectedRows.Where(r => string.IsNullOrEmpty(r.RecordID)).Reverse()) { store.RemoveAt(item.RowIndex); } foreach (var id in GetGridSelectedValues()) { var recordEvents = new MyProductsEdit.RecordEvents { Page = Page, Control = this, }; recordEvents.InitializeValues(NavigatorControl.Values); DeleteRow(id, recordEvents, true); } }
private void DeleteRow(long id, MyProductsEdit.RecordEvents recordEvents, bool loadRoot) { var item = source.GetRecord(id); if (item != null) { var args = new RecordEventArgs(); recordEvents.RecordDeleting(args, id); if (args.Cancel) { AddErrorMessage(args.GetFullErrorMessage()); return; } if (!AccessOptions.CheckPermitDelete() || (item.Information != null && !item.Information.CanDelete)) { AddErrorMessage(Nat.Web.Controls.Properties.Resources.ENoPermitToDeleteRecord); return; } if (!item.CanDelete) { var messages = source.View.GetDeleteErrors(id, MyProductsResources.Header); if (messages.All(string.IsNullOrEmpty)) { AddErrorMessage(Nat.Web.Controls.Properties.Resources.ENoPermitToDeleteRecord); } else { AddErrorMessage(messages.Where(r => !string.IsNullOrEmpty(r))); } return; } BeforeDelete(item); var contextInfo = new DeleteRowContext <MyProduct, DBDataContext, MyProductsJournalDataSourceView.Row, long> { Row = item, Key = item.id, TableItem = item.Item, DB = source.View.DB, }; BeforeDelete(contextInfo); if (contextInfo.Cancel) { AfterDelete(false, item); AddErrorMessage(contextInfo.CancelMessage); return; } try { var delArgs = new DeleteEventArgs <long>(); contextInfo.DeleteEventArgs = delArgs; if (contextInfo.SuccessfullRowDeleted != null && !contextInfo.SuccessfullRowDeleted.Value) { AfterDelete(false, item); AddErrorMessage(contextInfo.FailedRowDeletedMessage); return; } if (!delArgs.IsDeleted) { DeleteRow(item, delArgs); } if (!delArgs.IsDeleted) { source.View.DB.MyProducts.DeleteOnSubmit(item.Item); source.View.DB.SubmitChanges(); } contextInfo.SuccessfullRowDeleted = true; AfterDelete(true, item); if (delArgs.IsDeleted) { if (delArgs.NewSelectedValue != null) { ResetSelectedIndex(delArgs.NewSelectedValue.Value); } else { EmptySelectedIndex(); } } } catch (SqlException exception) { contextInfo.SuccessfullRowDeleted = false; AfterDelete(false, item); if (exception.Number != 547) { AddErrorMessage(exception.ToString()); } else { AddErrorMessage(Nat.Web.Controls.Properties.Resources.ECanNotDeleteUseInSystem); } } store.Reload(); OnSelectedIndexChanged(EventArgs.Empty); } }