Exemplo n.º 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);
            }
        }
        public void RecreateGrid(bool resetQueryRun = true)
        {
            if (RecordType != null)
            {
                DynamicGridViewModel = new DynamicGridViewModel(ApplicationController)
                {
                    PageSize          = StandardPageSize,
                    ViewType          = ViewType.MainApplicationView,
                    RecordService     = RecordService,
                    RecordType        = RecordType,
                    IsReadOnly        = true,
                    FormController    = new FormController(RecordService, null, ApplicationController),
                    GetGridRecords    = (b) => GetGridRecords(b),
                    DisplayTotalCount = false,
                    GetTotalCount     = GetGridTotalCount,
                    MultiSelect       = true,
                    GridLoaded        = false,
                    FieldMetadata     = ExplicitlySelectedColumns
                };
                var customFunctionList = new List <CustomGridFunction>()
                {
                    new CustomGridFunction("QUERY", "Run Query", QuickFind),
                    new CustomGridFunction("BACKTOQUERY", "Back To Query", (g) => { ResetToQueryEntry(); }, (g) => !IsQuickFind && QueryRun),
                    new CustomGridFunction("EDITCOLUMNS", "Edit Columns", (g) => LoadColumnEdit(), (g) => DynamicGridViewModel != null),
                    new CustomGridFunction("DISPLAYTOTALS", (g) => g.DisplayTotalCount ? "Hide Totals" : "Display Totals", (g) => { g.DisplayTotalCount = !g.DisplayTotalCount; g.ReloadGrid(); }, (g) => DynamicGridViewModel != null)
                };
                if (FormService != null && AllowCrud)
                {
                    DynamicGridViewModel.EditRow = (g) =>
                    {
                        var formMetadata   = FormService.GetFormMetadata(RecordType, RecordService);
                        var formController = new FormController(RecordService, FormService, ApplicationController);
                        var selectedRow    = g;
                        if (selectedRow != null)
                        {
                            Action onSave = () =>
                            {
                                ClearChildForm();
                                ClearNotInIds();
                                DynamicGridViewModel.ReloadGrid();
                            };
                            var record = selectedRow.Record;
                            var createOrUpdateRecord = RecordService.Get(record.Type, record.Id);
                            new[] { createOrUpdateRecord }.PopulateEmptyLookups(RecordService, null);
                            var newForm = new CreateOrUpdateViewModel(createOrUpdateRecord, formController, onSave, ClearChildForm);
                            ClearNotInIds();
                            LoadChildForm(newForm);
                        }
                    };
                    DynamicGridViewModel.EditRowNew = (g) =>
                    {
                        var formMetadata   = FormService.GetFormMetadata(RecordType, RecordService);
                        var formController = new FormController(RecordService, FormService, ApplicationController);
                        var selectedRow    = g;
                        if (selectedRow != null)
                        {
                            var record = selectedRow.Record;
                            CreateOrUpdateViewModel vmRef = null;
                            var createOrUpdateRecord      = RecordService.Get(record.Type, record.Id);
                            new[] { createOrUpdateRecord }.PopulateEmptyLookups(RecordService, null);
                            vmRef = new CreateOrUpdateViewModel(createOrUpdateRecord, formController, () => {
                                vmRef.ValidationPrompt = "Changes Have Been Saved";
                                ClearNotInIds();
                                DynamicGridViewModel.ReloadGrid();
                            }, () => ApplicationController.Remove(vmRef), cancelButtonLabel: "Close");
                            ApplicationController.NavigateTo(vmRef);
                            //LoadChildForm(newForm);
                        }
                    };
                    DynamicGridViewModel.AddRow = () =>
                    {
                        var    formMetadata   = FormService.GetFormMetadata(RecordType, RecordService);
                        var    formController = new FormController(RecordService, FormService, ApplicationController);
                        Action onSave         = () =>
                        {
                            ClearChildForm();
                            ClearNotInIds();
                            DynamicGridViewModel.ReloadGrid();
                        };
                        var newForm = new CreateOrUpdateViewModel(RecordService.NewRecord(RecordType), formController, onSave, ClearChildForm, explicitIsCreate: true);
                        LoadChildForm(newForm);
                    };
                }
                customFunctionList.Add(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())
                }));

                if (CustomFunctions != null)
                {
                    foreach (var item in CustomFunctions)
                    {
                        customFunctionList.Add(item);
                    }
                }

                DynamicGridViewModel.AddGridButtons(customFunctionList);
                if (LoadInitially)
                {
                    DynamicGridViewModel.ReloadGrid();
                }

                RefreshConditionButtons();
                RefreshConditionButtons(isNotIn: true);

                if (resetQueryRun)
                {
                    QueryRun = false;
                }
            }
        }
Exemplo n.º 3
0
        public void RecreateGrid()
        {
            if (RecordType != null)
            {
                DynamicGridViewModel = new DynamicGridViewModel(ApplicationController)
                {
                    PageSize       = StandardPageSize,
                    ViewType       = ViewType.MainApplicationView,
                    RecordService  = RecordService,
                    RecordType     = RecordType,
                    IsReadOnly     = true,
                    FormController = new FormController(RecordService, null, ApplicationController),
                    GetGridRecords = GetGridRecords,
                    MultiSelect    = true,
                    GridLoaded     = false
                };
                var customFunctionList = new List <CustomGridFunction>()
                {
                    new CustomGridFunction("QUERY", "Run Query", QuickFind)
                };
                if (FormService != null)
                {
                    DynamicGridViewModel.EditRow = (g) =>
                    {
                        var formMetadata   = FormService.GetFormMetadata(RecordType, RecordService);
                        var formController = new FormController(this.RecordService, FormService, ApplicationController);
                        var selectedRow    = g;
                        if (selectedRow != null)
                        {
                            Action onSave = () =>
                            {
                                ClearChildForm();
                                DynamicGridViewModel.ReloadGrid();
                            };
                            var record = selectedRow.Record;

                            var newForm = new CreateOrUpdateViewModel(RecordService.Get(record.Type, record.Id), formController, onSave, ClearChildForm);
                            LoadChildForm(newForm);
                        }
                    };
                    DynamicGridViewModel.AddRow = () =>
                    {
                        var    formMetadata   = FormService.GetFormMetadata(RecordType, RecordService);
                        var    formController = new FormController(RecordService, FormService, ApplicationController);
                        Action onSave         = () =>
                        {
                            ClearChildForm();
                            DynamicGridViewModel.ReloadGrid();
                        };
                        var newForm = new CreateOrUpdateViewModel(RecordService.NewRecord(RecordType), formController, onSave, ClearChildForm, explicitIsCreate: true);
                        LoadChildForm(newForm);
                    };
                }
                customFunctionList.Add(new CustomGridFunction("CSV", "Download CSV", (g) => g.DownloadCsv(), (g) => g.GridRecords != null && g.GridRecords.Any()));

                if (CustomFunctions != null)
                {
                    foreach (var item in CustomFunctions)
                    {
                        customFunctionList.Add(item);
                    }
                }

                DynamicGridViewModel.AddGridButtons(customFunctionList);
                if (LoadInitially)
                {
                    DynamicGridViewModel.ReloadGrid();
                }

                RefreshConditionButtons();
            }
        }