예제 #1
0
        public QueryViewModel(IEnumerable <string> recordTypes, IRecordService recordService, IApplicationController controller, bool allowQuery = false, bool loadInitially = false, CustomGridFunction closeFunction = null
                              , IEnumerable <CustomGridFunction> customFunctions = null, bool allowCrud = true)
            : base(controller)
        {
            AllowCrud       = allowCrud;
            CustomFunctions = customFunctions;
            LoadInitially   = loadInitially;
            AllowQuery      = allowQuery;
            RecordService   = recordService;
            if (closeFunction != null)
            {
                ReturnButton = new XrmButtonViewModel(closeFunction.LabelFunc(null), () => { closeFunction.Function(DynamicGridViewModel); }, controller);
            }
            QueryTypeButton = new XrmButtonViewModel("Change Query Type", ChangeQueryType, ApplicationController);
            DeleteSelectedConditionsButton = new XrmButtonViewModel("Delete Selected", () => DeleteSelected(), ApplicationController);
            GroupSelectedConditionsOr      = new XrmButtonViewModel("Group Selected Or", () => GroupSelected(FilterOperator.Or), ApplicationController);
            GroupSelectedConditionsAnd     = new XrmButtonViewModel("Group Selected And", () => GroupSelected(FilterOperator.And), ApplicationController);
            UngroupSelectedConditions      = new XrmButtonViewModel("Ungroup Selected", () => UnGroupSelected(), ApplicationController);
            RunQueryButton = new XrmButtonViewModel("Run Query", QuickFind, ApplicationController);
            ChangeQueryType();

            QueryTypeButton.IsVisible = AllowQuery;

            _recordTypes = recordTypes;
            if (_recordTypes.Count() == 1)
            {
                RecordType = _recordTypes.First();
            }
        }
        public ColumnEditDialogViewModel(string recordType, IEnumerable <KeyValuePair <string, double> > currentColumns, IRecordService recordService, Action <IEnumerable <SelectableColumn> > applySelections, Action onCancel, IApplicationController applicationController)
            : base(applicationController)
        {
            RecordService   = recordService;
            RecordType      = recordType;
            ApplySelections = applySelections;
            var columnsCurrenltySelected =
                currentColumns.Select(si => new SelectableColumn(si.Key, RecordService.GetFieldLabel(si.Key, RecordType), si.Value, RemoveCurrentField, AddCurrentField, ApplicationController))
                .ToArray();

            CurrentColumns = new ObservableCollection <SelectableColumn>(columnsCurrenltySelected);
            var selectableFields = RecordService
                                   .GetFields(RecordType)
                                   .Where(f => !CurrentColumns.Any(c => c.FieldName == f))
                                   .Select(f => new SelectableColumn(f, RecordService.GetFieldLabel(f, RecordType), 200, RemoveCurrentField, AddCurrentField, ApplicationController))
                                   .OrderBy(sc => sc.FieldLabel)
                                   .ToArray();

            SelectableColumns = new ObservableCollection <SelectableColumn>(selectableFields);

            ApplyButtonViewModel  = new XrmButtonViewModel("Apply Changes", ApplyChanges, ApplicationController, "Apply The Selection Changes");
            CancelButtonViewModel = new XrmButtonViewModel("Cancel Changes", onCancel, ApplicationController, "Cancel The Selection Changes And Return");

            RefreshIsFirstColumn();
        }
        public ObjectFieldViewModel(string fieldName, string fieldLabel, RecordEntryViewModelBase recordForm,
                                    bool usePicklist)
            : base(fieldName, fieldLabel, recordForm, usePicklist)
        {
            //okay i need to identify that this is getting the lookups from the settings
            SettingsAttribute = GetSettingLookupAttribute();
            if (SettingsAttribute == null)
            {
                //throw new NotImplementedException(
                //    string.Format(
                //        "The {0} Type Has Only Been Implemented For Object Properties With {1} Attribute. You Will Need To Review Instantiating a Different Type Of View Model For The {2} Type Of You Property {3} Or Extending It For Your Needs",
                //        typeof(ObjectFieldViewModel).Name, typeof(SettingsLookup).Name, RecordTypeToLookup, FieldName));
            }
            else
            {
                var settingsObject = GetSettingsObject();

                XrmButton = new XrmButtonViewModel("Search", Search, ApplicationController);
                if (settingsObject != null)
                {
                    _lookupService = new ObjectRecordService(settingsObject, ApplicationController, GetObjectRecordService().ObjectTypeMaps);
                    if (!UsePicklist)
                    {
                        LoadLookupGrid();
                    }
                }

                SetNewAction();
            }
        }
        public ColumnEditDialogViewModel(string recordType, IEnumerable <GridFieldMetadata> currentColumns, IRecordService recordService, Action <IEnumerable <GridFieldMetadata> > applySelections, Action onCancel, IApplicationController applicationController, bool allowLinkedFields = false)
            : base(applicationController)
        {
            RecordService     = recordService;
            RecordType        = recordType;
            ApplySelections   = applySelections;
            AllowLinkedFields = allowLinkedFields;
            var currentColumnsSelectables = new List <SelectableColumn>();

            foreach (GridFieldMetadata column in currentColumns)
            {
                string fieldNameIncludingPrefix = column.AliasedFieldName ?? column.FieldName;
                if (fieldNameIncludingPrefix.Contains("."))
                {
                    //aliased columns are stored within this vm in form
                    //lookup|recordtype.fieldname
                    //but externally in form
                    //lookup_recordtype.fieldname
                    //due to | not being a valid alias value
                    fieldNameIncludingPrefix = fieldNameIncludingPrefix.Replace("_" + column.AltRecordType + ".", "|" + column.AltRecordType + ".");
                }
                currentColumnsSelectables.Add(new SelectableColumn(fieldNameIncludingPrefix, column.OverrideLabel ?? RecordService.GetFieldLabel(column.FieldName, RecordType), column.WidthPart, RemoveCurrentField, AddCurrentField, ApplicationController));
            }
            CurrentColumns = new ObservableCollection <SelectableColumn>(currentColumnsSelectables);

            LinkOptions   = GetLinkOptionsList(RecordType);
            _selectedLink = LinkOptions.First();

            SelectableColumns = new ObservableCollection <SelectableColumn>(GetSelectableColumnsFor(RecordType));

            ApplyButtonViewModel  = new XrmButtonViewModel("Apply Changes", ApplyChanges, ApplicationController, "Apply The Selection Changes");
            CancelButtonViewModel = new XrmButtonViewModel("Cancel Changes", onCancel, ApplicationController, "Cancel The Selection Changes And Return");

            RefreshIsFirstColumn();
        }
 public DynamicGridViewModel(IApplicationController applicationController)
 {
     ApplicationController = applicationController;
     LoadingViewModel      = new LoadingViewModel(applicationController);
     OnDoubleClick         = () => { };
     OnClick            = () => { };
     OnKeyDown          = () => { };
     PreviousPageButton = new XrmButtonViewModel("Prev", () =>
     {
         if (PreviousPageButton.Enabled)
         {
             --CurrentPage;
         }
     }, ApplicationController)
     {
         Enabled = false
     };
     NextPageButton = new XrmButtonViewModel("Next", () =>
     {
         if (NextPageButton.Enabled)
         {
             ++CurrentPage;
         }
     }, ApplicationController)
     {
         Enabled = false
     };
     MaxHeight  = 600;
     LoadDialog = (d) => { ApplicationController.UserMessage(string.Format("Error The {0} Method Has Not Been Set In This Context", nameof(LoadDialog))); };
 }
 public DynamicGridViewModel(IApplicationController applicationController)
 {
     ApplicationController = applicationController;
     LoadingViewModel      = new LoadingViewModel(applicationController);
     //this one a bit of a hack as loading/display controlled in code behind so set the vm as always loading
     SortLoadingViewModel = new LoadingViewModel(applicationController)
     {
         LoadingMessage = "Please Wait While Reloading Sorted Items", IsLoading = true
     };
     OnDoubleClick      = () => { };
     OnClick            = () => { };
     OnKeyDown          = () => { };
     PreviousPageButton = new XrmButtonViewModel("Prev", () =>
     {
         if (PreviousPageButton.Enabled)
         {
             --CurrentPage;
         }
     }, ApplicationController)
     {
         Enabled = false
     };
     NextPageButton = new XrmButtonViewModel("Next", () =>
     {
         if (NextPageButton.Enabled)
         {
             ++CurrentPage;
         }
     }, ApplicationController)
     {
         Enabled = false
     };
     MaxHeight  = 600;
     LoadDialog = (d) => { ApplicationController.UserMessage(string.Format("Error The {0} Method Has Not Been Set In This Context", nameof(LoadDialog))); };
 }
 public void DownloadCsv(string folder)
 {
     ApplicationController.DoOnAsyncThread(() =>
     {
         CsvForExtraction      = false;
         CsvExtracting         = true;
         CsvExtractingProgress = new ProgressControlViewModel(ApplicationController);
         CsvExtractingProgress.UpdateProgress(0, 1, "Extracting To CSV");
         try
         {
             var fileName = string.Format("{0} CSV Download - {1}.csv", ApplicationController.ApplicationName,
                                          DateTime.Now.ToFileTime());
             CsvUtility.CreateCsv(folder, fileName
                                  , Items, new LogController(CsvExtractingProgress));
             CsvExtracting = false;
             CsvExtracted  = true;
             OpenCsvButton = new XrmButtonViewModel("Open CSV", () => OpenFile(folder, fileName),
                                                    ApplicationController);
             OpenCsvFolderButton = new XrmButtonViewModel("Open CSV Folder", () => OpenFolder(folder),
                                                          ApplicationController);
         }
         catch (Exception ex)
         {
             CsvExtracting    = false;
             CsvForExtraction = true;
             ApplicationController.UserMessage("Error Downloading CSV: " + ex.DisplayString());
         }
     });
 }
예제 #8
0
 public GridRowViewModel(IRecord record, DynamicGridViewModel gridViewModel)
     : base(gridViewModel.FormController, gridViewModel.OnlyValidate)
 {
     Record        = record;
     GridViewModel = gridViewModel;
     LoadFields();
     DeleteRowViewModel = new XrmButtonViewModel("Delete", DeleteRow, ApplicationController, description: "Delete");
     EditRowViewModel   = new XrmButtonViewModel("Edit", EditRow, ApplicationController, description: "Open For Editing");
 }
        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;
            }
        }
예제 #10
0
 public MultiSelectDialogViewModel(IEnumerable <T> options, IEnumerable <T> selectedOptions, Action <IEnumerable <T> > onApply, Action onCancel, IApplicationController applicationController)
     : base(applicationController)
 {
     ItemsSource = options == null
         ? new SelectablePicklistOption[0]
         : options
                   .Select(i => new SelectablePicklistOption(i, selectedOptions != null && selectedOptions.Any(s => s.Key == i.Key)))
                   .ToArray();
     ApplyButtonViewModel  = new XrmButtonViewModel("Apply Changes", () => onApply(ItemsSource.Where(i => i.Select).Select(i => i.PicklistItem).ToArray()), ApplicationController, "Apply The Selection Changes");
     CancelButtonViewModel = new XrmButtonViewModel("Cancel Changes", onCancel, ApplicationController, "Cancel The Selection Changes And Return");
 }
        private void LoadViewButtons()
        {
            var views   = RecordService.GetViews(RecordType);
            var buttons = new List <XrmButtonViewModel>();

            foreach (var view in views
                     .Where(v => v.ViewType == ViewType.MainApplicationView && v.Id != null)
                     .OrderBy(v => v.ViewName))
            {
                var button = new XrmButtonViewModel(view.ViewName, () =>
                {
                    LoadingViewModel.IsLoading = true;

                    DoOnAsynchThread(() =>
                    {
                        try
                        {
                            var queryDefinition = RecordService.GetViewAsQueryDefinition(view.Id);
                            if (queryDefinition == null)
                            {
                                throw new NullReferenceException("Error Loading Query. The Result Provided By The Record Service Was Null");
                            }

                            DoOnMainThread(() =>
                            {
                                try
                                {
                                    FilterConditions = CreateFilterCondition();
                                    AppendIntoFilterConditions(queryDefinition.RootFilter, FilterConditions, RecordType);
                                    Joins = CreateJoins();
                                    foreach (var join in queryDefinition.Joins.Where(j => j.JoinType != JoinType.LeftOuter).ToArray())
                                    {
                                        AppendJoinsViewModel(join, Joins);
                                    }
                                }
                                finally
                                {
                                    LoadingViewModel.IsLoading = false;
                                }
                            });
                        }
                        catch (Exception)
                        {
                            LoadingViewModel.IsLoading = false;
                            throw;
                        }
                    });
                }, ApplicationController);
                buttons.Add(button);
            }
            LoadSavedViewButton.ChildButtons = buttons;
        }
        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);
            }
        }
예제 #13
0
 public GridRowViewModel(IRecord record, DynamicGridViewModel gridViewModel, bool isReadOnly = false)
     : base(gridViewModel.FormController, gridViewModel.OnlyValidate)
 {
     IsReadOnly    = isReadOnly;
     Record        = record;
     GridViewModel = gridViewModel;
     LoadFields();
     DeleteRowViewModel        = new XrmButtonViewModel("Remove", DeleteRow, ApplicationController, description: "Remove This Item");
     EditRowViewModel          = new XrmButtonViewModel("Open", EditRow, ApplicationController, description: "Open This Item");
     EditRowNewTabViewModel    = new XrmButtonViewModel("Open In New Tab", EditRowNewTab, ApplicationController, description: "Open This Item In New Tab");
     EditRowNewWindowViewModel = new XrmButtonViewModel("Open In New Window", EditRowNewTab, ApplicationController, description: "Open This Item In New Window");
     OpenWebViewModel          = new XrmButtonViewModel("Open In Browser", OpenWeb, ApplicationController, description: "Open This Item In Browser");
 }
예제 #14
0
 protected RecordEntryFormViewModel(FormController formController, IDictionary <string, IEnumerable <string> > onlyValidate = null)
     : base(formController, onlyValidate)
 {
     SaveButtonViewModel = new XrmButtonViewModel(SaveButtonLabel, DoOnSave, ApplicationController)
     {
         IsVisible = false
     };
     CancelButtonViewModel = new XrmButtonViewModel(CancelButtonLabel, () => OnCancel(), ApplicationController)
     {
         IsVisible = false
     };
     ChangedPersistentFields    = new List <string>();
     LoadingViewModel.IsLoading = true;
 }
예제 #15
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);
                }
            }
        }
        protected RecordEntryViewModel(FormController formController)
            : base(formController.ApplicationController)
        {
            FormController      = formController;
            SaveButtonViewModel = new XrmButtonViewModel(SaveButtonLabel, OnSave, ApplicationController)
            {
                IsVisible = false
            };
            CancelButtonViewModel = new XrmButtonViewModel(CancelButtonLabel, OnCancel, ApplicationController)
            {
                IsVisible = false
            };
            ChangedPersistentFields = new List <string>();

            FormInstance = FormService.CreateFormInstance(RecordType, this, RecordService);
        }
 protected RecordEntryFormViewModel(FormController formController, IDictionary <string, IEnumerable <string> > onlyValidate = null, string saveButtonLabel = null, string cancelButtonLabel = null)
     : base(formController, onlyValidate)
 {
     BackButtonViewModel = new XrmButtonViewModel("Back", () => OnBack(), ApplicationController)
     {
         IsVisible = false
     };
     SaveButtonViewModel = new XrmButtonViewModel(saveButtonLabel ?? "Save", DoOnSave, ApplicationController)
     {
         IsVisible = false
     };
     CancelButtonViewModel = new XrmButtonViewModel(cancelButtonLabel ?? "Cancel", () => OnCancel(), ApplicationController)
     {
         IsVisible = false
     };
     ChangedPersistentFields         = new List <string>();
     LoadingViewModel.IsLoading      = true;
     LoadingViewModel.LoadingMessage = "Please Wait While Loading";
 }
예제 #18
0
        public CompletionScreenViewModel(Action onClose, string heading, IEnumerable <XrmButtonViewModel> options,
                                         object completionObject,
                                         IApplicationController controller)
            : base(controller)
        {
            Heading = new HeadingViewModel(heading, controller);
            CompletionHeadingText = heading;
            CompletionOptions     = options;

            if (completionObject != null)
            {
                var formController = FormController.CreateForObject(completionObject, ApplicationController, null);
                CompletionDetails                  = new ObjectEntryViewModel(null, null, completionObject, formController);
                CompletionDetails.IsReadOnly       = true;
                CompletionDetails.PropertyChanged += CompletionDetails_PropertyChanged;
            }

            //CompletionDetails = new ObjectsGridSectionViewModel("Summary", completionDetails, controller);
            CloseButton = new XrmButtonViewModel("Close", onClose, controller);
        }
 public void LoadLookupGrid()
 {
     LookupGridViewModel = new LookupGridViewModel(this, OnRecordSelected);
     XrmButton           = new XrmButtonViewModel("Search", Search, ApplicationController);
 }