protected override void OnPreRender(EventArgs e) { var visibleAddLink = AccessOptions.CheckPermitAdd(); if (NavigatorControl != null) { visibleAddLink = visibleAddLink && source.View.AllowAddRowForTableTypes(NavigatorControl.Values, DIC_MySecondDictionaryResources.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("DIC_MySecondDictionaryEdit", true, string.Empty, false).CreateUrl(); GetAddUrl(ref addUrl); AddButton.Listeners.Click.Handler = GridButtonsColumn.AddButtonHandler(addUrl); } SaveButton.Visible = AccessOptions.CheckPermitEdit(); InitGetBrowseFilterParameters(); InitSelectionMode(); OnPreRender(); base.OnPreRender(e); }
private void DeleteRow(long id, DIC_MySecondDictionaryEdit.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, DIC_MySecondDictionaryResources.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 <DIC_MySecondDictionary, DBDataContext, DIC_MySecondDictionaryJournalDataSourceView.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.DIC_MySecondDictionaries.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/DIC_MySecondDictionaryEdit?refDIC_MySecondDictionary={0}", LookUrl = "/EmptyPage.aspx/data/DIC_MySecondDictionaryEdit/read?refDIC_MySecondDictionary={0}", EditVisible = AccessOptions.CheckPermitEdit(), DeleteVisible = AccessOptions.CheckPermitDelete(), CanEdit = false, Width = "84px", }); var column_Name = new GridColumn() { Header = DIC_MySecondDictionaryResources.Name__Header, Sort = "Name", Group = DIC_MySecondDictionaryResources.Name__GridGroup, ColumnName = "Name", }; column_Name.Width = string.Empty; column_Name.ModelFieldType = ModelFieldType.String; column_Name.DefaultHidden = false; column_Name.ServerMapping = "Item.Name"; column_Name.HasFilter = true; column_Name.CanEdit = true; column_Name.ControlID = "Name_{0}"; columns.Add(column_Name); var column_refFirstDictionary = new GridColumn() { Header = DIC_MySecondDictionaryResources.refFirstDictionary__Header, Sort = isKZ ? "DIC_MyFirstDictionary_refFirstDictionary.Name" : "DIC_MyFirstDictionary_refFirstDictionary.Name", Group = DIC_MySecondDictionaryResources.refFirstDictionary__GridGroup, ColumnName = "refFirstDictionary", TableName = "DIC_MyFirstDictionary", }; column_refFirstDictionary.Width = string.Empty; column_refFirstDictionary.ModelFieldType = ModelFieldType.String; column_refFirstDictionary.DefaultHidden = false; column_refFirstDictionary.ColumnNameIndex = "refFirstDictionary_Name"; column_refFirstDictionary.ColumnNameIndexRefValue = "refFirstDictionary"; column_refFirstDictionary.ModelFieldTypeRefValue = ModelFieldType.Int; column_refFirstDictionary.ServerMappingRefValue = "Item.refFirstDictionary"; column_refFirstDictionary.StoreId = "Store_refFirstDictionary"; column_refFirstDictionary.ServerMapping = "Lookup.refFirstDictionary_Name"; column_refFirstDictionary.IsForeignKey = true; column_refFirstDictionary.IsLookup = true; column_refFirstDictionary.IsFilterLookup = true; column_refFirstDictionary.FilterColumnMapping = isKZ ? "DIC_MyFirstDictionary_refFirstDictionary.Name" : "DIC_MyFirstDictionary_refFirstDictionary.Name"; column_refFirstDictionary.TableTitle = SampleDictionaries.Properties.DIC_MyFirstDictionaryResources.Header; column_refFirstDictionary.SetEditorComboBox(); column_refFirstDictionary.HasFilter = true; column_refFirstDictionary.CanEdit = true; column_refFirstDictionary.ControlID = "refFirstDictionary_{0}"; columns.Add(column_refFirstDictionary); var column_DecimalValue = new GridColumn() { Header = DIC_MySecondDictionaryResources.DecimalValue__Header, Sort = "DecimalValue", Group = DIC_MySecondDictionaryResources.DecimalValue__GridGroup, ColumnName = "DecimalValue", }; column_DecimalValue.Width = string.Empty; column_DecimalValue.ModelFieldType = ModelFieldType.Float; column_DecimalValue.DefaultHidden = false; column_DecimalValue.ServerMapping = "Item.DecimalValue"; column_DecimalValue.DecimalPrecision = 2; column_DecimalValue.HasFilter = true; column_DecimalValue.CanEdit = true; column_DecimalValue.ControlID = "DecimalValue_{0}"; columns.Add(column_DecimalValue); var column_BoolValue = new GridColumn() { Header = DIC_MySecondDictionaryResources.BoolValue__Header, Sort = "BoolValue", Group = DIC_MySecondDictionaryResources.BoolValue__GridGroup, ColumnName = "BoolValue", }; column_BoolValue.Width = string.Empty; column_BoolValue.ModelFieldType = ModelFieldType.Boolean; column_BoolValue.DefaultHidden = false; column_BoolValue.ServerMapping = "Item.BoolValue"; column_BoolValue.TrueText = DIC_MySecondDictionaryResources.BoolValue__TrueText; column_BoolValue.FalseText = DIC_MySecondDictionaryResources.BoolValue__FalseText; column_BoolValue.HasFilter = true; column_BoolValue.CanEdit = true; column_BoolValue.ControlID = "BoolValue_{0}"; columns.Add(column_BoolValue); columns.Add(new GridColumn() { Header = TableResources.messages__Header, ColumnName = "__messages", Visible = false, CanEdit = false, }); InitColumns(columns); }