Beispiel #1
0
        private void RecreateGrid()
        {
            if (DynamicGridViewModel != null)
            {
                Controller.RemoveFromUi(DynamicGridViewModel);
            }
            try
            {
                //okay lets somehow load the results for this row into a crud dialog view
                //which loads a dynamic grid - similar to query but no query -
                DynamicGridViewModel = new DynamicGridViewModel(ApplicationController)
                {
                    PageSize       = 25,
                    RecordService  = RecordService,
                    RecordType     = SummaryItem.RecordTypeSchemaName,
                    IsReadOnly     = true,
                    FormController = new FormController(RecordService, null, ApplicationController),
                    GetGridRecords = (b) =>
                    {
                        return(DynamicGridViewModel.GetGridRecord(GetAllTheseRecords(), b));
                    },
                    DisplayTotalCount = true,
                    GetTotalCount     = () => GetAllTheseRecords().Count(),
                    MultiSelect       = true,
                    GridLoaded        = false,
                    FieldMetadata     = ExplicitlySelectedColumns
                };
                var customFunctionList = new List <CustomGridFunction>()
                {
                    new CustomGridFunction("BACKTOSUMMARY", "Back To Summary", Remove),
                    new CustomGridFunction("EDITCOLUMNS", "Edit Columns", (g) => LoadColumnEdit(), (g) => DynamicGridViewModel != null),
                    new CustomGridFunction("DOWNLOAD", "Download", new[]
                    {
                        new CustomGridFunction("DOWNLOADEXCEL", "Excel", (g) => g.DownloadExcel(), (g) => g.GridRecords != null && g.GridRecords.Any()),
                        new CustomGridFunction("DOWNLOADCSV", "CSV", (g) => g.DownloadCsv(), (g) => g.GridRecords != null && g.GridRecords.Any())
                    }),
                    new CustomGridFunction("REPLACE", "Bulk Replace", new []
                    {
                        new CustomGridFunction("BULKREPLACESELECTED", "Selected Only", (g) =>
                        {
                            TriggerBulkReplace(true);
                        }, (g) => g.SelectedRows.Any()),
                        new CustomGridFunction("BULKREPLACEALL", "All Results", (g) =>
                        {
                            TriggerBulkReplace(false);
                        }, (g) => g.GridRecords != null && g.GridRecords.Any()),
                    })
                };

                var formService = RecordService.GetFormService() as FormServiceBase;
                if (formService != null)
                {
                    DynamicGridViewModel.EditRow = (g) =>
                    {
                        var formMetadata   = formService.GetFormMetadata(SummaryItem.RecordTypeSchemaName, RecordService);
                        var formController = new FormController(RecordService, formService, ApplicationController);
                        var selectedRow    = g;
                        if (selectedRow != null)
                        {
                            Action onSave = () =>
                            {
                                ClearChildForm();
                                _cachedRecords = null;
                                DynamicGridViewModel.ReloadGrid();
                            };
                            var record = selectedRow.Record;

                            var newForm = new CreateOrUpdateViewModel(RecordService.Get(record.Type, record.Id), formController, onSave, ClearChildForm);
                            LoadChildForm(newForm);
                        }
                    };
                }
                DynamicGridViewModel.AddGridButtons(customFunctionList);
                DynamicGridViewModel.ReloadGrid();
                Controller.LoadToUi(DynamicGridViewModel);
            }
            catch (Exception ex)
            {
                ApplicationController.ThrowException(ex);
            }
        }