Ejemplo n.º 1
0
 public void AddRow()
 {
     LoadingViewModel.IsLoading = true;
     try
     {
         var viewModel = FormService.GetLoadRowViewModel(SectionIdentifier, RecordForm, (record) =>
                                                         DoOnMainThread(() =>
         {
             InsertRecord(record, 0);
             RecordForm.ClearChildForm();
         }), () => RecordForm.ClearChildForm());
         if (viewModel == null)
         {
             InsertRecord(GetRecordService().NewRecord(RecordType), 0);
         }
         else
         {
             RecordForm.LoadChildForm(viewModel);
         }
     }
     catch (Exception ex)
     {
         ApplicationController.UserMessage(string.Format("Error Adding Row: {0}", ex.DisplayString()));
     }
     finally
     {
         LoadingViewModel.IsLoading = false;
     }
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
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);
            }
        }