public override void AddSelectedItem(GridRowViewModel selectedRow, RecordEntryViewModelBase recordForm, string subGridReference) { var gridField = GetEntryViewModel(recordForm).GetEnumerableFieldViewModel(subGridReference); var targetPropertyname = GetTargetProperty(recordForm, subGridReference).Name; var newRecord = recordForm.RecordService.NewRecord(GetEnumeratedType(recordForm, subGridReference).AssemblyQualifiedName); var lookup = GetLookupService(recordForm, subGridReference).ToLookup(selectedRow.GetRecord()); newRecord.SetField(targetPropertyname, lookup, recordForm.RecordService); //if (gridField.GridRecords.Any(g => g.GetLookupFieldFieldViewModel(targetPropertyname).Value == lookup)) // return; //gridField.InsertRecord(newRecord, 0); InsertNewItem(recordForm, subGridReference, newRecord); }
public StringFieldViewModel(string fieldName, string label, RecordEntryViewModelBase recordForm) : base(fieldName, label, recordForm) { var autocomplete = FormService?.GetAutocompletesFunction(this); if (autocomplete != null && autocomplete.IsValidForForm(RecordEntryViewModel) && (autocomplete.DisplayInGrid || !(RecordEntryViewModel is GridRowViewModel))) { AutocompleteViewModel = new StringAutocompleteViewModel(this, autocomplete); SearchButton = new XrmButtonViewModel("Search", () => { AutocompleteViewModel.SearchText = Value; Search(); }, ApplicationController); } }
public override IEnumerable <PicklistOption> GetSelectionOptions(RecordEntryViewModelBase recordForm, string subGridReference) { var gridField = GetEntryViewModel(recordForm).GetEnumerableFieldViewModel(subGridReference); var targetPropertyname = GetTargetProperty(recordForm, subGridReference).Name; var gridRecords = gridField.GridRecords; var picklistOptions = recordForm.RecordService.GetPicklistKeyValues(targetPropertyname, gridField.RecordType, subGridReference, null); return(picklistOptions .Where(r => AllowTypeMultipleTimes || (!gridRecords?.Any(g => g.GetRecordTypeFieldViewModel(targetPropertyname).Value?.Key == r.Key) ?? true)) .OrderBy(r => r.Value) .ToArray()); }
public void Load(RecordEntryViewModelBase recordForm, string subGridReference) { var parentForm = recordForm.ParentForm; if (parentForm != null) { parentForm.LoadingViewModel.IsLoading = true; } recordForm.DoOnAsynchThread(() => { try { var mainFormInContext = recordForm; if (recordForm is GridRowViewModel) { mainFormInContext = recordForm.ParentForm; } var closeFunction = new CustomGridFunction("RETURN", "Return", () => mainFormInContext.ClearChildForm()); var targetType = GetTargetType(recordForm, subGridReference); var selectedFunction = new CustomGridFunction("ADDSELECTED", "Add Selected", (g) => AddSelectedItems(g, recordForm, subGridReference) , visibleFunction: (g) => g.GridRecords != null && g.GridRecords.Any()); var addAllFunction = new CustomGridFunction("ADDALLRESULTS", "Add All Results", (g) => AddAllResults(g, recordForm, subGridReference) , visibleFunction: (g) => g.GridRecords != null && g.GridRecords.Any()); var childForm = new QueryViewModel(new[] { targetType }, GetQueryLookupService(recordForm, subGridReference), recordForm.ApplicationController, allowQuery: AllowQuery, loadInitially: !AllowQuery, closeFunction: closeFunction, customFunctions: new[] { selectedFunction, addAllFunction }, allowCrud: false); childForm.TypeAhead = TypeAhead; mainFormInContext.LoadChildForm(childForm); } catch (Exception ex) { recordForm.ApplicationController.ThrowException(ex); } finally { if (parentForm != null) { parentForm.LoadingViewModel.IsLoading = false; } } }); }
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, 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), 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); } 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; } }
public PropertyInfo GetTargetProperty(RecordEntryViewModelBase recordForm, string subGridReference) { PropertyInfo targetPropertyInfo = null; foreach (var enumeratedTypeProperty in GetEnumeratedType(recordForm, subGridReference).GetProperties()) { if (enumeratedTypeProperty.PropertyType == TargetPropertyType) { targetPropertyInfo = enumeratedTypeProperty; } } return(targetPropertyInfo); }
internal override string GetDependantValue(string field, string recordType, RecordEntryViewModelBase viewModel) { var propertyInfo = GetPropertyInfo(field, viewModel.GetRecord().Type); if (propertyInfo != null && propertyInfo.PropertyType == typeof(FileReference)) { var attr = propertyInfo.GetCustomAttribute <FileMask>(); return(attr == null ? null : attr.Mask); } else { return(GetRecordTypeFor(field, viewModel)); } }
public void Load(RecordEntryViewModelBase recordForm, string subGridReference) { recordForm.LoadingViewModel.IsLoading = true; recordForm.DoOnAsynchThread(() => { try { var mainFormInContext = recordForm; if (recordForm is GridRowViewModel) { mainFormInContext = recordForm.ParentForm; } //okay i need to load a dialog //displaying a grid of the selectable options with a checkbox Action <IEnumerable <PicklistOption> > onSave = (selectedOptions) => { mainFormInContext.LoadingViewModel.IsLoading = true; try { AddSelectedItems(selectedOptions, recordForm, subGridReference); mainFormInContext.ClearChildForm(); } catch (Exception ex) { mainFormInContext.ApplicationController.ThrowException(ex); } finally { mainFormInContext.LoadingViewModel.IsLoading = false; } }; var picklistOptions = GetSelectionOptions(recordForm, subGridReference) .OrderBy(o => o.Value) .ToArray(); var initialSelected = GetInitialSelectedOptions(recordForm, subGridReference); var childForm = new MultiSelectDialogViewModel <PicklistOption>(picklistOptions, initialSelected, onSave, () => mainFormInContext.ClearChildForm(), mainFormInContext.ApplicationController, saveButtonLabel: "Add Selections", cancelButtonLabel: "Return"); mainFormInContext.LoadChildForm(childForm); } catch (Exception ex) { recordForm.ApplicationController.ThrowException(ex); } finally { recordForm.LoadingViewModel.IsLoading = false; } }); }
public override IEnumerable <PicklistOption> GetSelectionOptions(RecordEntryViewModelBase recordForm, string subGridReference) { var options = new List <PicklistOption>(); var enumerableField = recordForm.GetEnumerableFieldViewModel(subGridReference); if (enumerableField.Enumerable == null) { throw new NullReferenceException("Error the selectable property is null"); } foreach (var item in enumerableField.Enumerable) { options.Add(GetAsPicklistOption(item)); } return(options); }
public LookupFieldViewModel(string fieldName, string fieldLabel, RecordEntryViewModelBase recordForm, string referencedRecordType, bool usePicklist, bool isEditable) : base(fieldName, fieldLabel, recordForm, usePicklist) { try { if (referencedRecordType != null) { var splitIt = referencedRecordType.Split(','); if (splitIt.Count() == 1) { SelectedRecordType = new RecordType(splitIt.First(), splitIt.First()); } else { var recordTypes = LookupService == null ? new RecordType[0] : splitIt .Select(s => LookupService.GetRecordTypeMetadata(s)) .Select(r => new RecordType(r.SchemaName, r.DisplayName)) .OrderBy(rt => rt.Value) .ToArray(); RecordTypeItemsSource = recordTypes; } } if (Value != null) { if (Value.Name.IsNullOrWhiteSpace()) { Value.Name = "Record Name Not Set"; } SetEnteredTestWithoutClearingValue(Value.Name); RecordTypeToLookup = Value.RecordType; } if (isEditable && SelectedRecordType != null) { SetNewAction(); if (!UsePicklist) { LoadLookupGrid(); } } } catch (Exception ex) { recordForm.ApplicationController.ThrowException(ex); } }
public static Type GetEnumeratedType(RecordEntryViewModelBase recordForm, string subGridReference) { var theRecord = GetEntryViewModel(recordForm).GetRecord() as ObjectRecord; if (theRecord == null) { throw new NullReferenceException(string.Format("Expected Object Of Type {0}. Actual Type Is {1}", typeof(ObjectRecord).Name, GetEntryViewModel(recordForm).GetRecord()?.GetType()?.Name ?? "(null)")); } var theObject = theRecord.Instance; var type = theObject.GetType(); var property = type.GetProperty(subGridReference); var enumeratedType = property.PropertyType.GetGenericArguments()[0]; return(enumeratedType); }
public void AddSelectedItems(IEnumerable <PicklistOption> selectedItems, RecordEntryViewModelBase recordForm, string subGridReference) { var gridField = GetEntryViewModel(recordForm).GetEnumerableFieldViewModel(subGridReference); var targetPropertyname = GetTargetProperty(recordForm, subGridReference).Name; foreach (var item in selectedItems) { var newRecord = recordForm.RecordService.NewRecord(GetEnumeratedType(recordForm, subGridReference).AssemblyQualifiedName); var newPicklistOption = TargetPropertyType.CreateFromParameterlessConstructor(); newPicklistOption.SetPropertyValue(nameof(PicklistOption.Key), item.Key); newPicklistOption.SetPropertyValue(nameof(PicklistOption.Value), item.Value); newRecord.SetField(targetPropertyname, newPicklistOption, recordForm.RecordService); InsertNewItem(recordForm, subGridReference, newRecord); } }
public void Load(RecordEntryViewModelBase recordForm, string subGridReference) { recordForm.DoOnMainThread(() => { try { var mainFormInContext = recordForm; if (recordForm is GridRowViewModel) { mainFormInContext = recordForm.ParentForm; } //okay i need to load a dialog //displaying a grid of the selectable options with a checkbox Action <IEnumerable <PicklistOption> > onSave = (selectedOptions) => { //copy into the mainFormInContext.LoadingViewModel.IsLoading = true; try { AddSelectedItems(selectedOptions, recordForm, subGridReference); mainFormInContext.ClearChildForm(); } catch (Exception ex) { mainFormInContext.ApplicationController.ThrowException(ex); } finally { mainFormInContext.LoadingViewModel.IsLoading = false; } }; var picklistOptions = GetSelectionOptions(recordForm, subGridReference); var childForm = new MultiSelectDialogViewModel <PicklistOption>(picklistOptions, null, onSave, () => mainFormInContext.ClearChildForm(), mainFormInContext.ApplicationController); mainFormInContext.LoadChildForm(childForm); } catch (Exception ex) { recordForm.ApplicationController.ThrowException(ex); } finally { recordForm.LoadingViewModel.IsLoading = false; } }); }
protected FieldViewModelBase(string fieldName, string label, RecordEntryViewModelBase recordForm) : base(recordForm.ApplicationController) { LoadingViewModel = new LoadingViewModel(recordForm.ApplicationController); LoadingViewModel.LoadingMessage = null; RecordEntryViewModel = recordForm; Label = label; FieldName = fieldName; IsVisible = true; IsRecordServiceField = true; DisplayLabel = true; if (FormService != null) { FormService.LoadPropertyChangedEvent(this); } }
public override IEnumerable <PicklistOption> GetSelectionOptions(RecordEntryViewModelBase recordForm, string subGridReference) { var targetPropertyInfo = GetTargetProperty(recordForm, subGridReference); var gridField = GetEntryViewModel(recordForm).GetEnumerableFieldViewModel(subGridReference); var alreadySelected = gridField.DynamicGridViewModel != null ? gridField.GridRecords.Select(g => g.GetRecordFieldFieldViewModel(targetPropertyInfo.Name)?.Value.Key).ToArray() : gridField.Value == null ? new string[0] : gridField.Value.Cast <object>().Select(o => o.GetPropertyValue(targetPropertyInfo.Name)).Cast <RecordField>().Select(f => f.Key).ToArray(); var recordType = recordForm.FormService.GetDependantValue(subGridReference + "." + targetPropertyInfo.Name, GetEnumeratedType(recordForm, subGridReference).AssemblyQualifiedName, recordForm); var lookupService = GetLookupService(recordForm, subGridReference); var limitFields = new string[0]; try { limitFields = gridField .GetRecordService() .GetPicklistKeyValues(targetPropertyInfo.Name, gridField.RecordType, recordType, null) .Select(p => p.Key) .ToArray(); } catch (Exception) { //oh well } //removed field searchable as inadvertently left out fields var fields = lookupService.GetFieldMetadata(recordType) .Where(f => (!alreadySelected?.Any(k => k == f.SchemaName) ?? true)) .OrderBy(r => r.DisplayName) .ToArray(); if (limitFields.Any()) { fields = fields.Where(f => limitFields.Contains(f.SchemaName)).ToArray(); } return(fields .Select(f => new PicklistOption(f.SchemaName, f.DisplayName)) .ToArray()); }
public override Action GetCustomFunction(RecordEntryViewModelBase recordForm, string subGridReference) { var objectFormService = recordForm as ObjectEntryViewModel; if (objectFormService == null) { throw new ArgumentOutOfRangeException(nameof(recordForm), string.Format("Required To Be Type Of {0}. Actual Type Is {1}", typeof(ObjectEntryViewModel).Name, recordForm.GetType().Name)); } var objectToEnter = objectFormService.GetObject(); var thisMethod = new Action(() => objectToEnter.InvokeMethod(FunctionName, recordForm.ApplicationController)); return(() => { objectFormService.LoadSubgridsToObject(); thisMethod(); var subGrid = objectFormService.GetEnumerableFieldViewModel(subGridReference); subGrid.DynamicGridViewModel.ReloadGrid(); }); }
public override IEnumerable <PicklistOption> GetSelectionOptions(RecordEntryViewModelBase recordForm, string subGridReference) { var gridField = GetEntryViewModel(recordForm).GetEnumerableFieldViewModel(subGridReference); var targetPropertyname = GetTargetProperty(recordForm, subGridReference).Name; var gridRecords = gridField.GridRecords; var lookupService = GetLookupService(recordForm, subGridReference); var includeExplicit = new[] { "subject", "uom", "productpricelevel" }; var types = lookupService .GetAllRecordTypes() .Where(r => AllowTypeMultipleTimes || (!gridRecords?.Any(g => g.GetRecordTypeFieldViewModel(targetPropertyname).Value?.Key == r) ?? true)) .Select(r => lookupService.GetRecordTypeMetadata(r)) .Where(r => r.Searchable || includeExplicit.Contains(r.SchemaName)) .OrderBy(r => r.DisplayName) .ToArray(); return(types .Select(f => new PicklistOption(f.SchemaName, f.DisplayName)) .ToArray()); }
public override void AddSelectedItem(GridRowViewModel selectedRow, RecordEntryViewModelBase recordForm, string subGridReference) { var gridField = GetEntryViewModel(recordForm).GetEnumerableFieldViewModel(subGridReference); var targetPropertyname = GetTargetProperty(recordForm, subGridReference).Name; var newRecord = recordForm.RecordService.NewRecord(GetEnumeratedType(recordForm, subGridReference).AssemblyQualifiedName); var selectedRowrecord = selectedRow.GetRecord() as ObjectRecord; if (selectedRowrecord != null) { var newRecordType = new RecordField(); newRecordType.Key = (string)selectedRowrecord.Instance.GetPropertyValue(nameof(IFieldMetadata.SchemaName)); newRecordType.Value = (string)selectedRowrecord.Instance.GetPropertyValue(nameof(IFieldMetadata.DisplayName)); newRecord.SetField(targetPropertyname, newRecordType, recordForm.RecordService); //if (gridField.GridRecords.Any(g => g.GetRecordFieldFieldViewModel(targetPropertyname).Value == newRecordType)) // return; InsertNewItem(recordForm, subGridReference, newRecord); } }
public override Action GetCustomFunction(RecordEntryViewModelBase recordForm, string subGridReference) { return(() => { recordForm.LoadingViewModel.IsLoading = true; recordForm.DoOnAsynchThread(() => { try { Thread.Sleep(100); Load(recordForm, subGridReference); } catch (Exception ex) { recordForm.ApplicationController.ThrowException(ex); recordForm.LoadingViewModel.IsLoading = false; } }); }); }
public override IEnumerable <PicklistOption> GetInitialSelectedOptions(RecordEntryViewModelBase recordForm, string subGridReference) { var options = new List <PicklistOption>(); var enumerableField = recordForm.GetEnumerableFieldViewModel(subGridReference); if (enumerableField.Enumerable != null) { foreach (var item in enumerableField.Enumerable) { if (!(item is ISelectable)) { throw new Exception($"Error the type of object {item.GetType().Name} does not implemented {typeof(ISelectable).Name}"); } if (((ISelectable)item).Selected) { options.Add(GetAsPicklistOption(item)); } } } return(options); }
public override IRecordService GetQueryLookupService(RecordEntryViewModelBase recordForm, string subGridReference) { var gridField = GetEntryViewModel(recordForm).GetEnumerableFieldViewModel(subGridReference); var targetPropertyname = GetTargetProperty(recordForm, subGridReference).Name; var gridRecords = gridField.GridRecords; var lookupService = GetLookupService(recordForm, subGridReference); var includeExplicit = new[] { "subject" }; var types = lookupService .GetAllRecordTypes() .Where(r => !gridRecords?.Any(g => g.GetRecordTypeFieldViewModel(targetPropertyname).Value?.Key == r) ?? true) .Select(r => lookupService.GetRecordTypeMetadata(r)) .Where(r => r.Searchable || includeExplicit.Contains(r.SchemaName)) .OrderBy(r => r.DisplayName) .ToArray(); var queryTypesObject = new RecordTypesObject { RecordTypes = types }; return(new ObjectRecordService(queryTypesObject, recordForm.ApplicationController)); }
public void AddSelectedItems(DynamicGridViewModel grid, RecordEntryViewModelBase recordForm, string subGridReference) { var mainFormInContext = recordForm; if (recordForm is GridRowViewModel) { mainFormInContext = recordForm.ParentForm; } mainFormInContext.ApplicationController.DoOnAsyncThread(() => { if (grid.SelectedRows == null || !grid.SelectedRows.Any()) { mainFormInContext.ApplicationController.UserMessage("You Must Select The Rows To Add For This Function!"); } else { mainFormInContext.LoadingViewModel.IsLoading = true; try { Thread.Sleep(100); foreach (var selectedRow in grid.SelectedRows) { AddSelectedItem(selectedRow.GetRecord(), recordForm, subGridReference); } mainFormInContext.ClearChildForm(); } catch (Exception ex) { mainFormInContext.ApplicationController.ThrowException(ex); } finally { mainFormInContext.LoadingViewModel.IsLoading = false; } } }); }
public static void RefreshFieldGrid(RecordEntryViewModelBase revm) { revm.ApplicationController.DoOnAsyncThread(() => { revm.LoadingViewModel.IsLoading = true; try { var recordType = revm.GetRecordTypeFieldViewModel(nameof(AutonumberNavigator.RecordType)); var recordTypeName = recordType.Value?.Key; var autonumberFieldsField = revm.GetEnumerableFieldViewModel(nameof(AutonumberNavigator.AutonumberFields)); foreach (var gridRow in autonumberFieldsField.GridRecords.ToArray()) { revm.ApplicationController.DoOnMainThread(() => autonumberFieldsField.GridRecords.Remove(gridRow)); } if (!string.IsNullOrWhiteSpace(recordTypeName)) { var fields = revm.RecordService.LookupService .GetFieldMetadata(recordTypeName) .Where(f => !string.IsNullOrWhiteSpace(f.AutonumberFormat)) .ToArray(); foreach (var field in fields) { var newRecord = revm.RecordService.NewRecord(typeof(AutonumberNavigator.AutonumberField).AssemblyQualifiedName); newRecord.SetField(nameof(AutonumberNavigator.AutonumberField.SchemaName), field.SchemaName, revm.RecordService); newRecord.SetField(nameof(AutonumberNavigator.AutonumberField.Format), field.AutonumberFormat, revm.RecordService); autonumberFieldsField.InsertRecord(newRecord, 0); } } revm.ApplicationController.DoOnMainThread(() => autonumberFieldsField.DynamicGridViewModel.RefreshGridButtons()); } finally { revm.LoadingViewModel.IsLoading = false; } }); }
public abstract IEnumerable <PicklistOption> GetSelectionOptions(RecordEntryViewModelBase recordForm, string subGridReference);
protected MultiSelectFieldViewModel(string fieldName, string label, RecordEntryViewModelBase recordForm) : base(fieldName, label, recordForm) { EditAction = LoadMultiSelectDialog; }
internal virtual string GetLookupTargetType(string field, string recordType, RecordEntryViewModelBase recordForm) { return(recordForm.RecordService.GetLookupTargetType(field, recordType)); }
internal virtual string GetDependantValue(string field, string recordType, RecordEntryViewModelBase viewModel) { return(null); }
public virtual RecordEntryFormViewModel GetEditRowViewModel(string subGridName, RecordEntryViewModelBase parentForm, Action <IRecord> onSave, Action onCancel, GridRowViewModel gridRow) { return(null); }
internal virtual RecordEntryFormViewModel GetLoadRowViewModel(string subGridName, RecordEntryViewModelBase parentForm, Action <IRecord> onSave, Action onCancel) { return(null); }
public virtual Action GetBulkAddFunctionFor(string referenceName, RecordEntryViewModelBase recordForm) { return(null); }