Esempio n. 1
0
 public ListViewModel(string recordType, IRecordService recordService, IApplicationController controller, Action <GridRowViewModel> editGridRow, Action addRow, IEnumerable <CustomGridFunction> customFunctions)
     : base(controller)
 {
     DynamicGridViewModel = new DynamicGridViewModel(ApplicationController)
     {
         EditRow        = editGridRow,
         AddRow         = addRow,
         PageSize       = StandardPageSize,
         ViewType       = ViewType.MainApplicationView,
         RecordService  = recordService,
         RecordType     = recordType,
         IsReadOnly     = true,
         FormController = new FormController(recordService, null, controller),
         GetGridRecords = GetGridRecords
     };
     DynamicGridViewModel.AddGridButtons(customFunctions);
     DynamicGridViewModel.ReloadGrid();
 }
Esempio n. 2
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();
            }
        }