protected override void OnPreRender(EventArgs e) { var visibleAddLink = AccessOptions.CheckPermitAdd(); if (NavigatorControl != null) { visibleAddLink = visibleAddLink && source.View.AllowAddRowForTableTypes(NavigatorControl.Values, MyProductActionsResources.Header).Where(r => string.IsNullOrEmpty(r)).Count() == 0; } if (visibleAddLink) { SetVisibleAddLink(ref visibleAddLink); } AddButton.Visible = visibleAddLink; DeleteSelectedButton.Visible = AccessOptions.CheckPermitDelete(); if (visibleAddLink) { var addUrl = Url.Clone("MyProductActionsEdit", true, string.Empty, false).CreateUrl(); GetAddUrl(ref addUrl); AddButton.Listeners.Click.Handler = GridButtonsColumn.AddButtonHandler(addUrl); } InitGetBrowseFilterParameters(); InitSelectionMode(); OnPreRender(); base.OnPreRender(e); }
bool IAccessControl.CheckPermit(Page page) { return(AccessOptions.CheckPermit()); }
private void DeleteRow(long id, MyProductActionsEdit.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, MyProductActionsResources.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 <MyProductAction, DBDataContext, MyProductActionsJournalDataSourceView.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.MyProductActions.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); } }
private void InitColumnsInternal() { var isKZ = LocalizationHelper.IsCultureKZ; var columns = new List <GridColumn>(); columns.Add(new GridColumn() { ColumnName = "__icons", Visible = false, CanEdit = false, }); columns.Add(new GridButtonsColumn() { ColumnName = "__buttons", EditUrl = "/EmptyPage.aspx/data/MyProductActionsEdit?refMyProductActions={0}", LookUrl = "/EmptyPage.aspx/data/MyProductActionsEdit/read?refMyProductActions={0}", EditVisible = AccessOptions.CheckPermitEdit(), DeleteVisible = AccessOptions.CheckPermitDelete(), CanEdit = false, Width = "84px", }); var column_refProduct = new GridColumn() { Header = MyProductActionsResources.refProduct__Header, Sort = isKZ ? "MyProduct_refProduct.Name" : "MyProduct_refProduct.Name", Group = MyProductActionsResources.refProduct__GridGroup, ColumnName = "refProduct", TableName = "MyProducts", }; column_refProduct.Width = string.Empty; column_refProduct.ModelFieldType = ModelFieldType.String; column_refProduct.DefaultHidden = false; column_refProduct.ColumnNameIndex = "refProduct_Name"; column_refProduct.ColumnNameIndexRefValue = "refProduct"; column_refProduct.ModelFieldTypeRefValue = ModelFieldType.Int; column_refProduct.ServerMappingRefValue = "Item.refProduct"; column_refProduct.StoreId = "Store_refProduct"; column_refProduct.ServerMapping = "Lookup.refProduct_Name"; column_refProduct.IsForeignKey = true; column_refProduct.IsLookup = true; column_refProduct.IsFilterLookup = true; column_refProduct.FilterColumnMapping = isKZ ? "MyProduct_refProduct.Name" : "MyProduct_refProduct.Name"; column_refProduct.TableTitle = SampleDictionaries.Properties.MyProductsResources.Header; column_refProduct.HasFilter = true; columns.Add(column_refProduct); var column_DateTimeAction = new GridColumn() { Header = MyProductActionsResources.DateTimeAction__Header, Sort = "DateTimeAction", Group = MyProductActionsResources.DateTimeAction__GridGroup, ColumnName = "DateTimeAction", Format = "{0:d}", }; column_DateTimeAction.Width = string.Empty; column_DateTimeAction.ModelFieldType = ModelFieldType.Date; column_DateTimeAction.DefaultHidden = false; column_DateTimeAction.ServerMapping = "Item.DateTimeAction"; column_DateTimeAction.HasFilter = true; columns.Add(column_DateTimeAction); var column_AmountChange = new GridColumn() { Header = MyProductActionsResources.AmountChange__Header, Sort = "AmountChange", Group = MyProductActionsResources.AmountChange__GridGroup, ColumnName = "AmountChange", }; column_AmountChange.Width = string.Empty; column_AmountChange.ModelFieldType = ModelFieldType.Float; column_AmountChange.DefaultHidden = false; column_AmountChange.ServerMapping = "Item.AmountChange"; column_AmountChange.DecimalPrecision = 2; column_AmountChange.HasFilter = true; columns.Add(column_AmountChange); var column_Note = new GridColumn() { Header = MyProductActionsResources.Note__Header, Sort = "Note", Group = MyProductActionsResources.Note__GridGroup, ColumnName = "Note", }; column_Note.Width = string.Empty; column_Note.ModelFieldType = ModelFieldType.String; column_Note.DefaultHidden = false; column_Note.ServerMapping = "Item.Note"; column_Note.HasFilter = true; columns.Add(column_Note); columns.Add(new GridColumn() { Header = TableResources.messages__Header, ColumnName = "__messages", Visible = false, CanEdit = false, }); InitColumns(columns); }