public static FormController CreateForObject(object objectToEnter, IApplicationController applicationController, IRecordService lookupService, IDictionary <string, IEnumerable <string> > optionSetLimitedvalues = null)
        {
            var recordService  = new ObjectRecordService(objectToEnter, lookupService, optionSetLimitedvalues, applicationController);
            var formService    = new ObjectFormService(objectToEnter, recordService);
            var formController = new FormController(recordService, formService, applicationController);

            return(formController);
        }
示例#2
0
        protected override void LoadDialogExtention()
        {
            var recordService = new ObjectRecordService(ObjectToEnter, LookupService, OptionsetLimitedValues, ApplicationController, ObjectTypeMaps);
            var formService   = new ObjectFormService(ObjectToEnter, recordService, ObjectTypeMaps);

            ViewModel = new ObjectEntryViewModel(StartNextAction, OnCancel, ObjectToEnter,
                                                 new FormController(recordService, formService, ApplicationController), OnlyValidate);
            Controller.LoadToUi(ViewModel);
        }
        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);
            }
        }
        public ObjectEntryViewModel LoadToObjectEntryViewModel(object objectToEnter)
        {
            var applicationController = new FakeApplicationController();
            var recordService         = new ObjectRecordService(objectToEnter, applicationController);
            var formService           = new ObjectFormService(objectToEnter, recordService);
            var viewModel             = new ObjectEntryViewModel(EmptyMethod, EmptyMethod, objectToEnter,
                                                                 new FormController(recordService, formService, applicationController));

            viewModel.LoadFormSections();
            Assert.IsNotNull(viewModel.FormSectionsAsync);
            return(viewModel);
        }
示例#5
0
        protected override void LoadDialogExtention()
        {
            LoadingViewModel.LoadingMessage = "Loading Entry Form";
            var recordService = new ObjectRecordService(ObjectToEnter, LookupService, OptionsetLimitedValues, ApplicationController, ObjectTypeMaps);
            var formService   = new ObjectFormService(ObjectToEnter, recordService, ObjectTypeMaps);

            ViewModel = new ObjectEntryViewModel(StartNextAction, OnCancel, ObjectToEnter,
                                                 new FormController(recordService, formService, ApplicationController), OnlyValidate, saveButtonLabel: SaveButtonLabel, cancelButtonLabel: CancelButtonLabel);
            if (InitialMessage != null)
            {
                ViewModel.ValidationPrompt = InitialMessage;
            }
            Controller.LoadToUi(ViewModel);
        }
示例#6
0
        private void SetNewAction()
        {
            if (SettingsAttribute.AllowAddNew)
            {
                NewAction = () =>
                {
                    var settingsObject   = GetSettingsObject();
                    var propertyInfo     = settingsObject.GetType().GetProperty(SettingsAttribute.PropertyName);
                    var enumerateType    = propertyInfo.PropertyType.GenericTypeArguments[0];
                    var newSettingObject = enumerateType.CreateFromParameterlessConstructor();

                    var objectRecordService = new ObjectRecordService(newSettingObject, ApplicationController, null);
                    var formService         = new ObjectFormService(newSettingObject, objectRecordService);
                    var formController      = new FormController(objectRecordService, formService, ApplicationController);

                    Action onSave = () =>
                    {
                        //add the new item to the permanent settings
                        var settingsManager = ApplicationController.ResolveType <ISettingsManager>();
                        settingsObject = GetSettingsObject();
                        var settingsService = new ObjectRecordService(settingsObject, ApplicationController);
                        var currentSettings = settingsService.RetrieveAll(enumerateType.AssemblyQualifiedName, null)
                                              .Select(r => ((ObjectRecord)r).Instance)
                                              .ToList();
                        currentSettings.Add(newSettingObject);
                        settingsObject.SetPropertyValue(SettingsAttribute.PropertyName, enumerateType.ToNewTypedEnumerable(currentSettings));
                        settingsManager.SaveSettingsObject(settingsObject);
                        ValueObject = newSettingObject;
                        if (UsePicklist)
                        {
                            //reload the picklist
                            ValueObject = newSettingObject;
                            LoadPicklistItems();
                        }
                        else
                        {
                            SetEnteredTestWithoutClearingValue(ValueObject.ToString());
                        }
                        RecordEntryViewModel.ClearChildForm();
                    };

                    var newSettingForm = new ObjectEntryViewModel(onSave, RecordEntryViewModel.ClearChildForm, newSettingObject, formController);
                    RecordEntryViewModel.LoadChildForm(newSettingForm);
                };
            }
        }
        public void WriteObject(object objectToWrite)
        {
            var objectRecord  = new ObjectRecord(objectToWrite);
            var recordService = new ObjectRecordService(objectToWrite, null);
            var formService   = new ObjectFormService(objectToWrite, recordService);
            var formMetadata  = formService.GetFormMetadata(objectToWrite.GetType().AssemblyQualifiedName);

            foreach (var section in formMetadata.FormSections.OrderBy(s => s.Order))
            {
                if (section is FormFieldSection fieldSection)
                {
                    if (fieldSection.FormFields.Any(f => objectToWrite.IsInContext(f.FieldName)))
                    {
                        _content.AppendLine("<p>");
                        if (fieldSection.DisplayLabel)
                        {
                            AppendSectionHeading(fieldSection.SectionLabel);
                        }
                        foreach (var field in fieldSection.FormFields.OrderBy(f => f.Order))
                        {
                            if (objectToWrite.IsInContext(field.FieldName))
                            {
                                if (field.DisplayLabel)
                                {
                                    AppendFieldHeading(recordService.GetFieldLabel(field.FieldName, objectRecord.Type));
                                }
                                if (recordService.GetFieldType(field.FieldName, objectRecord.Type) == RecordFieldType.Enumerable)
                                {
                                    //okay need to generate a table
                                    var enumerableMetadata = recordService.GetFieldMetadata(field.FieldName, objectRecord.Type) as EnumerableFieldMetadata;
                                    var gridFieldMetadata  = recordService.GetGridFields(enumerableMetadata.EnumeratedTypeQualifiedName, ViewType.AssociatedView);
                                    var table = new StringBuilder();
                                    table.AppendLine("<table>");
                                    table.AppendLine("<thead><tr>");

                                    var fieldJustifies = new Dictionary <string, string>();
                                    foreach (var gridField in gridFieldMetadata)
                                    {
                                        var justify     = recordService.GetFieldType(gridField.FieldName, enumerableMetadata.EnumeratedTypeQualifiedName).GetHorizontalJustify(true);
                                        var htmlJustify = justify == HorizontalJustify.Left
                                            ? "left"
                                            : justify == HorizontalJustify.Middle
                                            ? "center"
                                            : "right";
                                        fieldJustifies.Add(gridField.FieldName, htmlJustify);
                                    }

                                    foreach (var gridField in gridFieldMetadata)
                                    {
                                        table.AppendLine($"<th width={gridField.WidthPart} {thStyle.Replace("left", fieldJustifies[gridField.FieldName])}>{recordService.GetFieldLabel(gridField.FieldName, enumerableMetadata.EnumeratedTypeQualifiedName)}</th>");
                                    }
                                    table.AppendLine("</tr></thead>");

                                    var linkedObjects = recordService
                                                        .GetLinkedRecords(enumerableMetadata.EnumeratedTypeQualifiedName, objectRecord.Type, field.FieldName, objectRecord.Id)
                                                        .Cast <ObjectRecord>()
                                                        .ToArray();
                                    var objectsForTable = linkedObjects
                                                          .Take(MaximumNumberOfEntitiesToList)
                                                          .ToArray();

                                    foreach (var gridRecord in objectsForTable.Take(MaximumNumberOfEntitiesToList))
                                    {
                                        table.AppendLine("<tr>");
                                        foreach (var gridField in gridFieldMetadata
                                                 .Where(gf => objectsForTable.Any(o => o.Instance.IsInContext(gf.FieldName))))
                                        {
                                            table.AppendLine(string.Format("<td {0}>", tdStyle.Replace("left", fieldJustifies[gridField.FieldName])));
                                            table.Append(recordService.GetFieldAsDisplayString(gridRecord, gridField.FieldName));
                                            table.AppendLine("</td>");
                                        }
                                        table.AppendLine("</tr>");
                                    }
                                    table.AppendLine("</table>");
                                    _content.AppendLine(table.ToString());

                                    if (linkedObjects.Count() > MaximumNumberOfEntitiesToList)
                                    {
                                        AppendParagraph(string.Format("Note this list is incomplete as the maximum of {0} items has been listed", MaximumNumberOfEntitiesToList));
                                    }
                                }
                                else
                                {
                                    AppendFieldValue(recordService.GetFieldAsDisplayString(objectRecord, field.FieldName));
                                }
                            }
                        }
                        _content.AppendLine("</p>");
                    }
                }
            }
        }
示例#8
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);
            }
        }
示例#9
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);
            }
        }