public ObjectEntryViewModel GetSubObjectEntryViewModel(RecordEntryFormViewModel entryForm)
 {
     var subEntry = entryForm.ChildForms.First() as ObjectEntryViewModel;
     Assert.IsNotNull(subEntry);
     subEntry.LoadFormSections();
     return subEntry;
 }
 public void EnterAndSaveObject(object objectToEnter, RecordEntryFormViewModel viewModel)
 {
     EnterObject(objectToEnter, viewModel);
     if(!viewModel.Validate())
         throw new Exception(viewModel.GetValidationSummary());
     viewModel.SaveButtonViewModel.Invoke();
 }
        private void DownloadTemplates(RecordEntryFormViewModel viewModel)
        {
            //okay so something to generate one or more csv files with column headings
            //think will just create a child form entry, generate on save then return to the dialog form
            try
            {
                if (viewModel is ObjectEntryViewModel)
                {
                    var oevm = viewModel as ObjectEntryViewModel;

                    var templatesRequest = new GenerateTemplatesRequest();

                    //this is the save function after entering the csvs to generate
                    Action createTemplatesAndReturn = () =>
                    {
                        var serviceConnection = viewModel.RecordService.LookupService;
                        //loop through each csv entered and create
                        foreach (var config in templatesRequest.CsvsToGenerate)
                        {
                            var recordType      = config.RecordType.Key;
                            var fieldsInEntity  = serviceConnection.GetFields(recordType).ToArray();
                            var fieldsToInclude = config.AllFields
                            ? fieldsInEntity
                                                  .Where(f =>
                            {
                                var mt = serviceConnection.GetFieldMetadata(f, recordType);
                                return(mt.Createable || mt.Writeable);
                            }).ToArray()
                                : config.FieldsToInclude.Select(f => f.RecordField.Key).Intersect(fieldsInEntity).ToArray();

                            var columnHeadings = templatesRequest.UseSchemaNames ? fieldsToInclude : fieldsToInclude.Select(f => serviceConnection.GetFieldLabel(f, recordType)).ToArray();

                            var csvText       = string.Join(",", columnHeadings.OrderBy(s => s));
                            var fileNameNoExt = templatesRequest.UseSchemaNames ? recordType : serviceConnection.GetCollectionName(recordType);
                            FileUtility.WriteToFile(templatesRequest.FolderToSaveInto.FolderPath, fileNameNoExt + ".csv", csvText);
                        }
                        viewModel.ApplicationController.StartProcess("explorer", templatesRequest.FolderToSaveInto.FolderPath);
                        //reload the form and notify
                        viewModel.ClearChildForms();
                        viewModel.LoadCustomFunctions();
                    };

                    //load the entry form
                    var os  = new ObjectRecordService(templatesRequest, viewModel.RecordService.LookupService, null, viewModel.ApplicationController, null);
                    var ofs = new ObjectFormService(templatesRequest, os, null);
                    var fc  = new FormController(os, ofs, viewModel.ApplicationController);

                    var vm = new ObjectEntryViewModel(createTemplatesAndReturn, () => viewModel.ClearChildForms(), templatesRequest, fc);
                    viewModel.LoadChildForm(vm);
                }
            }
            catch (Exception ex)
            {
                ApplicationController.ThrowException(ex);
            }
        }
Example #4
0
        public bool AreSavedRequests(RecordEntryFormViewModel re)
        {
            var settingsManager = ApplicationController.ResolveType(typeof(ISettingsManager)) as ISettingsManager;

            if (settingsManager == null)
            {
                throw new NullReferenceException("settingsManager");
            }

            var type          = re.RecordType;
            var savedSettings = settingsManager.Resolve <SavedSettings>(Type.GetType(type));

            return(savedSettings != null && savedSettings.SavedRequests.Any());
        }
Example #5
0
 private void ClearSavedRequests(TestApplication app, RecordEntryFormViewModel entryViewmodel)
 {
     if (entryViewmodel.CustomFunctions.Any(cb => cb.Id == "LOADREQUEST"))
     {
         var loadRequestButton = entryViewmodel.GetButton("LOADREQUEST");
         loadRequestButton.Invoke();
         //enter and save details
         var saveRequestForm = app.GetSubObjectEntryViewModel(entryViewmodel);
         var requestsGrid    = saveRequestForm.GetEnumerableFieldViewModel(nameof(SavedSettings.SavedRequests));
         foreach (var item in requestsGrid.GridRecords.ToArray())
         {
             requestsGrid.DynamicGridViewModel.DeleteRow(item);
         }
         saveRequestForm.SaveButtonViewModel.Invoke();
         Assert.IsFalse(entryViewmodel.ChildForms.Any());
         Assert.IsFalse(entryViewmodel.LoadingViewModel.IsLoading);
     }
 }
Example #6
0
 private bool IsAllowSaveAndLoad(RecordEntryFormViewModel viewModel)
 {
     try
     {
         //subgrids don't map directly to object so need to unload them to object
         //before saving the record
         if (viewModel is ObjectEntryViewModel)
         {
             var oevm = (ObjectEntryViewModel)viewModel;
             return(oevm.GetObject().GetType().GetCustomAttribute <AllowSaveAndLoad>() != null);
         }
         return(false);
     }
     catch (Exception ex)
     {
         ApplicationController.ThrowException(ex);
         return(false);
     }
 }
Example #7
0
 protected override void ProcessRecordEntryForm(RecordEntryFormViewModel viewModel)
 {
     base.ProcessRecordEntryForm(viewModel);
     foreach (var section in viewModel.FormSectionsAsync)
     {
         if (section is FieldSectionViewModel)
         {
             var fieldSection = (FieldSectionViewModel)section;
             foreach (var field in fieldSection.Fields)
             {
                 PopulateViewModel(field);
             }
         }
     }
     if (!viewModel.Validate())
     {
         throw new ValidationException(string.Format("The Autopopulated Form Did Not Validate:\n{0}", viewModel.GetValidationSummary()));
     }
     if (viewModel.OnSave != null)
     {
         viewModel.OnSave();
     }
 }
 internal virtual IEnumerable <CustomGridFunction> GetCustomFunctionsFor(string referenceName, RecordEntryFormViewModel recordForm)
 {
     return(new CustomGridFunction[0]);
 }
 internal virtual IEnumerable <CustomFormFunction> GetCustomFunctions(string recordType, RecordEntryFormViewModel recordForm)
 {
     return(new CustomFormFunction[0]);
 }
        internal override IEnumerable <CustomFormFunction> GetCustomFunctions(string recordType, RecordEntryFormViewModel recordForm)
        {
            var type = ObjectRecordService.GetClassType(recordType);
            var customGridFunctions = new List <CustomFormFunction>();
            var typesToResolve      = GetTypesToResolve(type);

            foreach (var typeToResolve in typesToResolve)
            {
                var injectedFunctions = recordForm.ApplicationController.ResolveInstance(typeof(CustomFormFunctions), typeToResolve.AssemblyQualifiedName) as CustomFormFunctions;
                customGridFunctions.AddRange(injectedFunctions.CustomFunctions);
            }
            return(customGridFunctions);
        }
        internal override IEnumerable <CustomGridFunction> GetCustomFunctionsFor(string referenceName, RecordEntryFormViewModel recordForm)
        {
            var functions  = new Dictionary <string, Action>();
            var recordType = recordForm.GetEnumerableFieldViewModel(referenceName).RecordType;

            if (recordType == null)
            {
                return(new CustomGridFunction[0]);
            }

            var enumeratedType  = ObjectRecordService.GetClassType(recordType);
            var customFunctions = enumeratedType.GetCustomAttributes <CustomFunction>();

            if (customFunctions != null)
            {
                foreach (var item in customFunctions)
                {
                    functions.Add(item.GetFunctionLabel(), item.GetCustomFunction(recordForm, referenceName));
                }
            }
            var allowDownloadAttribute = ObjectRecordService.GetPropertyInfo(referenceName, recordForm.RecordType).GetCustomAttribute <AllowDownload>();

            if (allowDownloadAttribute != null)
            {
                functions.Add("Download CSV", () => { recordForm.GetEnumerableFieldViewModel(referenceName).DynamicGridViewModel.DownloadCsv(); });
            }
            var customGridFunctions = functions.Select(kv => new CustomGridFunction(kv.Key, kv.Key, kv.Value)).ToList();
            var typesToResolve      = GetTypesToResolve(enumeratedType);

            foreach (var typeToResolve in typesToResolve)
            {
                var injectedFunctions = recordForm.ApplicationController.ResolveInstance(typeof(CustomGridFunctions), typeToResolve.AssemblyQualifiedName) as CustomGridFunctions;
                customGridFunctions.AddRange(injectedFunctions.CustomFunctions);
            }
            return(customGridFunctions);
        }
Example #12
0
 protected virtual void ProcessRecordEntryForm(RecordEntryFormViewModel viewModel)
 {
     viewModel.LoadFormSections();
 }
Example #13
0
        /// <summary>
        /// Load a form for saving the details
        /// </summary>
        public void SaveObject(RecordEntryFormViewModel viewModel)
        {
            try
            {
                //subgrids don't map directly to object so need to unload them to object
                //before saving the record
                if (viewModel is ObjectEntryViewModel)
                {
                    var oevm = viewModel as ObjectEntryViewModel;
                    oevm.LoadSubgridsToObject();
                    var theObject     = oevm.GetObject();
                    var theObjectType = theObject.GetType();
                    if (!theObjectType.IsTypeOf(typeof(IAllowSaveAndLoad)))
                    {
                        throw new Exception(string.Format("type {0} is not of type {1}", theObjectType.Name, typeof(IAllowSaveAndLoad).Name));
                    }

                    ApplicationController.LogEvent("Save Request Loaded", new Dictionary <string, string> {
                        { "Type", theObjectType.Name }
                    });
                    //this is an object specifically for entering the name and autoload properties
                    //they are mapped into the IAllowSaveAndLoad object after entry then it is saved
                    var saveObject = new SaveAndLoadFields();

                    Action saveSettings = () =>
                    {
                        //map the entered properties into the new object we are saving
                        var mapper = new ClassSelfMapper();
                        mapper.Map(saveObject, theObject);

                        var settingsManager = viewModel.ApplicationController.ResolveType(typeof(ISettingsManager)) as ISettingsManager;
                        var settings        = settingsManager.Resolve <SavedSettings>(theObjectType);

                        //if we selected autoload then set it false for the others
                        if (saveObject.Autoload)
                        {
                            foreach (var item in settings.SavedRequests.Cast <IAllowSaveAndLoad>())
                            {
                                item.Autoload = false;
                            }
                        }
                        //add the one and save
                        settings.SavedRequests = settings.SavedRequests.Union(new[] { theObject }).ToArray();
                        settingsManager.SaveSettingsObject(settings, theObjectType);
                        ApplicationController.LogEvent("Save Request Completed", new Dictionary <string, string> {
                            { "Type", theObjectType.Name }, { "Is Completed Event", true.ToString() }, { "Autoload", saveObject.Autoload.ToString() }
                        });
                        //reload the form and notify
                        viewModel.ClearChildForms();
                        viewModel.LoadCustomFunctions();
                        viewModel.ApplicationController.UserMessage($"You Input Has Been Saved. To Load A Saved Input Or Generate A Bat Executable Click The '{LoadButtonLabel}' Button");
                    };

                    //load the entry form
                    var os  = new ObjectRecordService(saveObject, viewModel.ApplicationController, null);
                    var ofs = new ObjectFormService(saveObject, os, null);
                    var fc  = new FormController(os, ofs, viewModel.ApplicationController);

                    var vm = new ObjectEntryViewModel(saveSettings, () => viewModel.ClearChildForms(), saveObject, fc);
                    viewModel.LoadChildForm(vm);
                }
            }
            catch (Exception ex)
            {
                ApplicationController.ThrowException(ex);
            }
        }
Example #14
0
        /// <summary>
        /// Load a form displaying the saved requests for selection
        /// </summary>
        public void LoadObject(RecordEntryFormViewModel re)
        {
            try
            {
                if (re is ObjectEntryViewModel)
                {
                    var oevm          = re as ObjectEntryViewModel;
                    var theObject     = oevm.GetObject();
                    var theObjectType = theObject.GetType();
                    ApplicationController.LogEvent("Edit Saved Requests Loaded", new Dictionary <string, string> {
                        { "Type", theObjectType.Name }
                    });

                    var settingsManager = ApplicationController.ResolveType(typeof(ISettingsManager)) as ISettingsManager;
                    if (settingsManager == null)
                    {
                        throw new NullReferenceException("settingsManager");
                    }

                    //get the saved requests
                    var savedSettings = settingsManager.Resolve <SavedSettings>(theObjectType);
                    if (!savedSettings.SavedRequests.Any())
                    {
                        ApplicationController.UserMessage(string.Format("There are no saved {0} records", theObjectType.GetDisplayName()));
                        return;
                    }
                    //set the dsaved requests to display the saved request details
                    foreach (var savedSetting in savedSettings.SavedRequests)
                    {
                        var casted = savedSetting as IAllowSaveAndLoad;
                        if (casted != null)
                        {
                            casted.DisplaySavedSettingFields = true;
                        }
                    }

                    //this tells the form to use this type for the properties list of objects
                    var objectTypeMaps = new Dictionary <string, Type>()
                    {
                        { nameof(SavedSettings.SavedRequests), theObjectType }
                    };

                    //this tells the form to only validate the name property of saved requests
                    var onlyValidate = new Dictionary <string, IEnumerable <string> >()
                    {
                        { theObjectType.AssemblyQualifiedName, new [] { nameof(IAllowSaveAndLoad.Name) } }
                    };

                    //on save any changes should be saved in the settings
                    Action savedLoadForm = () =>
                    {
                        settingsManager.SaveSettingsObject(savedSettings, theObjectType);
                        oevm.LoadCustomFunctions();
                        oevm.ClearChildForms();
                    };

                    //load the form
                    var dialogController = new DialogController(ApplicationController);
                    var recordService    = new ObjectRecordService(savedSettings, null, null, ApplicationController, objectTypeMaps);
                    var formService      = new ObjectFormService(savedSettings, recordService, objectTypeMaps);
                    formService.AllowLookupFunctions = false;

                    var vm = new ObjectEntryViewModel(savedLoadForm, oevm.ClearChildForms, savedSettings,
                                                      new FormController(recordService, formService, ApplicationController), re, "LOADING", onlyValidate: onlyValidate);

                    oevm.LoadChildForm(vm);
                    ApplicationController.LogEvent("Edit Saved Requests Completed", new Dictionary <string, string> {
                        { "Type", theObjectType.Name }, { "Is Completed Event", true.ToString() }
                    });
                }
            }
            catch (Exception ex)
            {
                ApplicationController.ThrowException(ex);
            }
        }