private void SetNewAction()
        {
            if (RecordEntryViewModel.AllowNewLookup && LookupFormService != null && LookupFormService.GetFormMetadata(RecordTypeToLookup, LookupService) != null && FormService != null && FormService.AllowAddNew(FieldName, GetRecordType()))
            {
                NewAction = () =>
                {
                    var formController = new FormController(LookupService, LookupFormService, ApplicationController);
                    var newRecord      = LookupService.NewRecord(RecordTypeToLookup);

                    Action onSave = () =>
                    {
                        Value = LookupService.ToLookup(newRecord);
                        if (UsePicklist)
                        {
                            var newPicklistItem = new ReferencePicklistItem(newRecord, Value.Name);
                            ItemsSource = ItemsSource
                                          .Union(new[] { newPicklistItem })
                                          .OrderBy(r => r.Name)
                                          .ToArray();
                            SelectedItem = newPicklistItem;
                        }
                        SetEnteredTestWithoutClearingValue(Value.Name);
                        RecordEntryViewModel.ClearChildForm();
                    };

                    var newForm = new CreateOrUpdateViewModel(newRecord, formController, onSave, RecordEntryViewModel.ClearChildForm);
                    RecordEntryViewModel.LoadChildForm(newForm);
                };
            }
            else
            {
                NewAction = null;
            }
        }
 protected override IEnumerable <IRecord> GetSearchResults()
 {
     if (LookupService == null)
     {
         throw new NullReferenceException(string.Format("Error searching field {0}. {1} is null", FieldName, "LookupService"));
     }
     if (UsePicklist)
     {
         return(FormService.GetLookupPicklist(FieldName, RecordEntryViewModel.GetRecordType(),
                                              RecordEntryViewModel.ParentFormReference, RecordEntryViewModel.GetRecord(), LookupService, RecordTypeToLookup));
     }
     else
     {
         var primaryField = LookupService.GetPrimaryField(RecordTypeToLookup);
         var conditions   = FormService.GetLookupConditions(FieldName, RecordEntryViewModel.GetRecordType(),
                                                            RecordEntryViewModel.ParentFormReference, RecordEntryViewModel.GetRecord());
         if (!EnteredText.IsNullOrWhiteSpace())
         {
             conditions =
                 conditions.Union(new[] { new Condition(primaryField, ConditionType.BeginsWith, EnteredText) });
         }
         return(LookupService.GetFirstX(RecordTypeToLookup, UsePicklist ? -1 : MaxRecordsForLookup, null,
                                        conditions, new[] { new SortExpression(primaryField, SortType.Ascending) }));
     }
 }
        public void LoadGridEditDialog()
        {
            //this loads a form for this row
            //but with the form metadata set to only include this specific field
            //so basically loads a child form for this fields row with only this enumerable field
            RecordEntryViewModel.DoOnMainThread(() =>
            {
                try
                {
                    var mainFormInContext = RecordEntryViewModel;
                    if (RecordEntryViewModel is GridRowViewModel)
                    {
                        mainFormInContext = RecordEntryViewModel.ParentForm;

                        var gridRow = RecordEntryViewModel as GridRowViewModel;
                        if (gridRow != null)
                        {
                            var enumerableFieldThisFieldIsIn = mainFormInContext.GetEnumerableFieldViewModel(gridRow.ParentFormReference);
                            var viewModel = FormService.GetEditEnumerableViewModel(gridRow.ParentFormReference, FieldName, mainFormInContext, (record) =>
                            {
                                mainFormInContext.ClearChildForm();
                                var index = enumerableFieldThisFieldIsIn.DynamicGridViewModel.GridRecords.IndexOf(gridRow);
                                DoOnMainThread(() =>
                                {
                                    enumerableFieldThisFieldIsIn.RemoveRow(gridRow);
                                    enumerableFieldThisFieldIsIn.InsertRecord(record, index == -1 ? 0 : index);
                                });
                            }, () => mainFormInContext.ClearChildForm(), gridRow);
                            if (viewModel == null)
                            {
                                throw new NotImplementedException("No Form For Type");
                            }
                            else
                            {
                                viewModel.IsReadOnly = IsReadOnly;
                                mainFormInContext.LoadChildForm(viewModel);
                            }
                        }
                    }
                    else
                    {
                        var viewModel        = FormService.GetFullScreenEnumerableViewModel(FieldName, RecordEntryViewModel);
                        viewModel.IsReadOnly = IsReadOnly;
                        mainFormInContext.LoadChildForm(viewModel);
                    }
                }
                catch (Exception ex)
                {
                    RecordEntryViewModel.ApplicationController.ThrowException(ex);
                }
                finally
                {
                    RecordEntryViewModel.LoadingViewModel.IsLoading = false;
                }
            });
        }
        private PropertyInfo GetPropertyInfo()
        {
            var record = RecordEntryViewModel.GetRecord();

            if (!(record is ObjectRecord))
            {
                throw new NotImplementedException(string.Format("Only Implemented For {0} Of Type {1}", typeof(IRecord).Name, typeof(ObjectRecord).Name));
            }

            return(((ObjectRecord)record).Instance.GetType().GetProperty(FieldName));
        }
        public EnumerableFieldViewModel(string fieldName, string label, RecordEntryViewModelBase recordForm, string linkedRecordType)
            : base(fieldName, label, recordForm)
        {
            if (recordForm is RecordEntryFormViewModel)
            {
                LinkedRecordType = linkedRecordType;
                RecordForm       = (RecordEntryFormViewModel)recordForm;

                DynamicGridViewModel = new DynamicGridViewModel(ApplicationController)
                {
                    PageSize          = RecordForm.GridPageSize,
                    DisplayTotalCount = RecordForm.GridPageSize > 0,
                    GetTotalCount     = () => GetGridRecords(true).Records.Count(),
                    ViewType          = ViewType.AssociatedView,
                    DeleteRow         = !recordForm.IsReadOnly && FormService.AllowDelete(ReferenceName, GetRecordType()) ? RemoveRow : (Action <GridRowViewModel>)null,
                    EditRow           = FormService.AllowGridOpen(ReferenceName, RecordForm) ? EditRow : (Action <GridRowViewModel>)null,
                    AddRow            = !recordForm.IsReadOnly && FormService.AllowAddNew(ReferenceName, GetRecordType()) ? AddRow : (Action)null,
                    AddMultipleRow    = FormService.GetBulkAddFunctionFor(ReferenceName, RecordEntryViewModel),
                    ExpandGrid        = FormService.AllowGridFullScreen(FieldName) ? LoadGridEditDialog : (Action)null,
                    IsReadOnly        = !FormService.AllowGridFieldEditEdit(FieldName) || recordForm.IsReadOnly,
                    ParentForm        = recordForm,
                    ReferenceName     = ReferenceName,
                    RecordType        = linkedRecordType,
                    RecordService     = recordForm.RecordService,
                    GetGridRecords    = GetGridRecords,
                    LoadRecordsAsync  = true,
                    FormController    = recordForm.FormController,
                    OnReloading       = () =>
                    {
                        _isLoaded = false;
                    },
                    LoadedCallback = () =>
                    {
                        _isLoaded = true;
                        RecordForm.OnSectionLoaded();
                    },
                    OnlyValidate       = recordForm.OnlyValidate,
                    MaxHeight          = 600,
                    LoadDialog         = (d) => { RecordEntryViewModel.LoadChildForm(d); },
                    RemoveParentDialog = () => { RecordEntryViewModel.ClearChildForms(); }
                };
                DynamicGridViewModel.AddMultipleRow = FormService.GetBulkAddFunctionFor(ReferenceName, RecordEntryViewModel);
                DynamicGridViewModel.ExpandGrid     = FormService.AllowGridFullScreen(FieldName) ? LoadGridEditDialog : (Action)null;
            }
            else
            {
                var bulkAddFunction = FormService.GetBulkAddFunctionFor(ReferenceName, RecordEntryViewModel);
                if (bulkAddFunction != null)
                {
                    BulkAddButton = new XrmButtonViewModel("BULKADD", "BULK ADD", bulkAddFunction, ApplicationController);
                }
                EditAction = !RecordEntryViewModel.IsReadOnly && FormService.AllowNestedGridEdit(RecordEntryViewModel.ParentFormReference, FieldName) ? LoadGridEditDialog : (Action)null;
            }
        }
Beispiel #6
0
 public void OnChangeBase()
 {
     //this should just defer these onloads to the on changes
     RecordEntryViewModel.RefreshVisibility();
     OnPropertyChanged("ValueObject");
     OnPropertyChanged("Value");
     //Removed On Change Validation Because Some Do Service Connections (XrmRecordConfiguration) To Validate
     //And Caused Selection To Delay
     //So Just Validate On Save
     //Validate();
     OnChange();
     OnChangeDelegate(this);
 }
        public void LoadMultiSelectDialog()
        {
            RecordEntryViewModel.DoOnMainThread(() =>
            {
                try
                {
                    //previously this was a popup grid for selection - but seemed to affect performance
                    //with heap of rows each with heap of bindings in the popup grid
                    //so changed to a child dialog when selected

                    var mainFormInContext = RecordEntryViewModel;
                    if (RecordEntryViewModel is GridRowViewModel)
                    {
                        mainFormInContext = RecordEntryViewModel.ParentForm;
                    }

                    //okay i need to load a dialog
                    //displaying a grid of the selectable options with a checkbox
                    Action <IEnumerable <T> > onSave = (selectedOptions) =>
                    {
                        //copy into the
                        mainFormInContext.LoadingViewModel.IsLoading = true;
                        try
                        {
                            RefreshSelectedItemsIntoValue(selectedOptions);
                            mainFormInContext.ClearChildForm();
                        }
                        catch (Exception ex)
                        {
                            RecordEntryViewModel.ApplicationController.ThrowException(ex);
                        }
                        finally
                        {
                            mainFormInContext.LoadingViewModel.IsLoading = false;
                        }
                    };

                    var childForm = new MultiSelectDialogViewModel <T>(ItemsSource, Value, onSave, () => mainFormInContext.ClearChildForm(), ApplicationController);
                    mainFormInContext.LoadChildForm(childForm);
                }
                catch (Exception ex)
                {
                    RecordEntryViewModel.ApplicationController.ThrowException(ex);
                }
                finally
                {
                    RecordEntryViewModel.LoadingViewModel.IsLoading = false;
                }
            });
        }
Beispiel #8
0
        public EnumerableFieldViewModel(string fieldName, string label, RecordEntryViewModelBase recordForm, string linkedRecordType)
            : base(fieldName, label, recordForm)
        {
            if (recordForm is RecordEntryFormViewModel)
            {
                RecordForm       = (RecordEntryFormViewModel)recordForm;
                LinkedRecordType = linkedRecordType;

                DynamicGridViewModel = new DynamicGridViewModel(ApplicationController)
                {
                    PageSize         = RecordForm.GridPageSize,
                    ViewType         = ViewType.AssociatedView,
                    DeleteRow        = !recordForm.IsReadOnly && FormService.AllowDelete(ReferenceName, GetRecordType()) ? RemoveRow :(Action <GridRowViewModel>)null,
                    EditRow          = EditRow,
                    AddRow           = !recordForm.IsReadOnly && FormService.AllowAddNew(ReferenceName, GetRecordType()) ? AddRow : (Action)null,
                    AddMultipleRow   = FormService.GetBulkAddFunctionFor(ReferenceName, RecordEntryViewModel),
                    IsReadOnly       = recordForm.IsReadOnly,
                    ParentForm       = recordForm,
                    ReferenceName    = ReferenceName,
                    RecordType       = linkedRecordType,
                    RecordService    = recordForm.RecordService,
                    GetGridRecords   = GetGridRecords,
                    LoadRecordsAsync = true,
                    FormController   = recordForm.FormController,
                    OnReloading      = () =>
                    {
                        _isLoaded = false;
                    },
                    LoadedCallback = () =>
                    {
                        _isLoaded = true;
                        RecordForm.OnSectionLoaded();
                    },
                    OnlyValidate = recordForm.OnlyValidate,
                    MaxHeight    = 600,
                    LoadDialog   = (d) => { RecordEntryViewModel.LoadChildForm(d); }
                };
                DynamicGridViewModel.AddMultipleRow = FormService.GetBulkAddFunctionFor(ReferenceName, RecordEntryViewModel);
            }
            else
            {
                var bulkAddFunction = FormService.GetBulkAddFunctionFor(ReferenceName, RecordEntryViewModel);
                if (bulkAddFunction != null)
                {
                    BulkAddButton = new XrmButtonViewModel("BULKADD", "BULK ADD", bulkAddFunction, ApplicationController);
                }
            }
        }
 public void OnChangeBase()
 {
     //this should just defer these onloads to the on changes
     RecordEntryViewModel.RefreshVisibility();
     CallOnPropertyChangeEvents();
     //Removed On Change Validation Because Some Do Service Connections (XrmRecordConfiguration) To Validate
     //And Caused Selection To Delay
     //So Just Validate On Save
     //Validate();
     OnChange();
     OnChangeDelegate(this);
     if (!lastValidationResult)
     {
         DoOnAsynchThread(() => Validate());
     }
 }
Beispiel #10
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);
                };
            }
        }