public void InsertRecord(IRecord record, int index) { DoOnAsynchThread(() => { RecordForm.LoadingViewModel.IsLoading = true; try { //this part may take a while to load/create (e.g. get record types for record type field) //so create on asynch thread while loading so doesn't freeze ui //then add to observable collection on main thread var rowItem = new GridRowViewModel(record, DynamicGridViewModel); DoOnMainThread(() => { try { DynamicGridViewModel.GridRecords.Insert(index, rowItem); rowItem.OnLoad(); rowItem.RunOnChanges(); DynamicGridViewModel.RefreshGridButtons(); } finally { RecordForm.LoadingViewModel.IsLoading = false; } }); } catch (Exception) { RecordForm.LoadingViewModel.IsLoading = false; throw; } }); }
public void AddSelectedItems(DynamicGridViewModel grid, RecordEntryViewModelBase recordForm, string subGridReference) { var mainFormInContext = recordForm; if (recordForm is GridRowViewModel) { mainFormInContext = recordForm.ParentForm; } mainFormInContext.ApplicationController.DoOnAsyncThread(() => { mainFormInContext.LoadingViewModel.IsLoading = true; try { Thread.Sleep(100); foreach (var selectedRow in grid.SelectedRows) { AddSelectedItem(selectedRow, recordForm, subGridReference); } mainFormInContext.ClearChildForm(); } catch (Exception ex) { mainFormInContext.ApplicationController.ThrowException(ex); } finally { mainFormInContext.LoadingViewModel.IsLoading = false; } }); }
public static GetGridRecordsResponse GetGridRecordPage(this DynamicGridViewModel gridViewModel, QueryDefinition query) { query.Top = gridViewModel.CurrentPageCeiling + 1; var sortExpression = gridViewModel.GetLastSortExpression(); if (sortExpression != null) { if (!sortExpression.FieldName.Contains(".")) { query.Sorts.Insert(0, gridViewModel.GetLastSortExpression()); } else { //if we have a sort on a field in a linked field //we need to add the sort to the appropriate join in the query var splitName = sortExpression.FieldName.Split('.'); var matchingJoins = query.Joins.Where(j => j.Alias != null && j.Alias == splitName[0]); if (matchingJoins.Any()) { matchingJoins.First().Sorts.Add(new SortExpression(splitName[1], sortExpression.SortType)); } } } var records = gridViewModel.RecordService.RetreiveAll(query); records.PopulateEmptyLookups(gridViewModel.RecordService, null); var hasMoreRows = records.Count() > gridViewModel.CurrentPageCeiling; records = records.Skip(gridViewModel.CurrentPageFloor).Take(gridViewModel.PageSize).ToArray(); return(new GetGridRecordsResponse(records, hasMoreRows)); }
public SortSpawn(int currentCount, DynamicGridViewModel grid, System.Windows.Controls.Grid sortingMainGrid, System.Windows.Controls.Grid sortingLoadGrid) { CurrentCount = currentCount; Grid = grid; SortingMainGrid = sortingMainGrid; SortingLoadGrid = sortingLoadGrid; }
protected void columnHeader_Click(object sender, RoutedEventArgs e) { var columnHeader = sender as DataGridColumnHeader; if (columnHeader != null && !(columnHeader.Column is DeleteRowColumn) && !(columnHeader.Column is EditRowColumn)) { var sortMember = columnHeader.Column.SortMemberPath; if (sortMember != null) { if (DynamicGridViewModel.GridRecords.Any()) { //due to the heavy xaml structure for the view model views //they sometimes take an eternity to sort //especially if lookup, and multiselect fields and heap of rows //so do this hack to display loading while it sorts //the row load event in the view will decrease the sort count until loaded //could not use bindings for this as they were not processing into the ui thread in correct sequence //so have just hacked this way in code behind which seems to take immediate effect SortingLoadGrid.Visibility = Visibility.Visible; SortingMainGrid.Visibility = Visibility.Hidden; DynamicGridViewModel.SortIt(sortMember.Trim(new[] { '[', ']' })); } } } }
public static GetGridRecordsResponse GetGridRecordPage(this DynamicGridViewModel gridViewModel, QueryDefinition query, IEnumerable <string> notInList = null) { if (gridViewModel.LoadingViewModel != null) { gridViewModel.LoadingViewModel.LoadingMessage = "Running Query"; } notInList = notInList ?? new string[0]; var sortExpression = gridViewModel.GetLastSortExpression(); if (sortExpression != null) { if (!sortExpression.FieldName.Contains(".")) { query.Sorts.Insert(0, gridViewModel.GetLastSortExpression()); } else { //if we have a sort on a field in a linked field //we need to add the sort to the appropriate join in the query var splitName = sortExpression.FieldName.Split('.'); var matchingJoins = query.Joins.Where(j => j.Alias != null && j.Alias == splitName[0]); if (matchingJoins.Any()) { matchingJoins.First().Sorts.Add(new SortExpression(splitName[1], sortExpression.SortType)); } } } IEnumerable <IRecord> records = null; if (!notInList.Any()) { query.Top = gridViewModel.CurrentPageCeiling + 1; records = gridViewModel.RecordService.RetreiveAll(query); } else { var recordList = new List <IRecord>(); gridViewModel.RecordService.ProcessResults(query, (r) => { recordList.AddRange(r.Where(t => !notInList.Contains(t.Id))); return(!(recordList.Count() > gridViewModel.CurrentPageCeiling)); }); records = recordList; } records.PopulateEmptyLookups(gridViewModel.RecordService, null); var hasMoreRows = records.Count() > gridViewModel.CurrentPageCeiling; records = records.Skip(gridViewModel.CurrentPageFloor).Take(gridViewModel.PageSize).ToArray(); if (gridViewModel.LoadingViewModel != null) { gridViewModel.LoadingViewModel.LoadingMessage = "Please Wait While Loading"; } return(new GetGridRecordsResponse(records, hasMoreRows)); }
private void GenerateBat(DynamicGridViewModel grid) { var selectedRows = grid.SelectedRows; if (selectedRows.Count() != 1) { ApplicationController.UserMessage("Only 1 Row May Be Selected For The Generate Bat Option"); } else { var selectedRow = selectedRows.First(); var name = selectedRow.GetStringFieldFieldViewModel(nameof(IAllowSaveAndLoad.Name)).Value; var codeBase = Assembly.GetExecutingAssembly().Location; var uri = new UriBuilder(codeBase); string executableConsoleApp = Uri.UnescapeDataString(uri.Path); var arguments = new Dictionary <string, string> { { "SettingsFolderName", ApplicationController.ApplicationName }, { "Request", name }, { "LogPath", "Log" }, }; //get the module implementing the request type var moduleController = ApplicationController.ResolveType(typeof(ModuleController)) as ModuleController; if (moduleController == null) { throw new NullReferenceException(typeof(ModuleController).Name); } var matchingModules = moduleController .GetLoadedModules() .Where(module => module is ICommandLineExecutable && ((ICommandLineExecutable)module).RequestType.AssemblyQualifiedName == grid.RecordType) .Cast <ICommandLineExecutable>() .ToArray(); if (!matchingModules.Any()) { throw new NullReferenceException(string.Format("Could Not Find {0} Implementing {1} With {2} {3}", typeof(ModuleBase).Name, typeof(ICommandLineExecutable).Name, nameof(ICommandLineExecutable.RequestType), grid.RecordType)); } if (matchingModules.Count() > 1) { throw new NullReferenceException(string.Format("Error Multiple {0} Found Implementing {1} With {2} {3}", typeof(ModuleBase).Name, typeof(ICommandLineExecutable).Name, nameof(ICommandLineExecutable.RequestType), grid.RecordType)); } var executableModule = matchingModules.First(); var commandLine = string.Format("\"{0}\" \"{1}\" {2}", executableConsoleApp, executableModule.CommandName, string.Join(" ", arguments.Select(kv => string.Format("-\"{0}\" \"{1}\"", kv.Key, kv.Value)))); var newFileName = ApplicationController.GetSaveFileName(string.Format("{0} {1}.bat", executableModule.CommandName, name), "bat"); if (newFileName != null) { var folder = Path.GetDirectoryName(newFileName); var fileName = Path.GetFileName(newFileName); FileUtility.WriteToFile(folder, fileName, commandLine); } } }
private static void GenerateMappings(DynamicGridViewModel g) { g.ApplicationController.DoOnAsyncThread(() => { try { var r = g.ParentForm; if (r == null) { throw new NullReferenceException("Could Not Load The Form. The ParentForm Is Null"); } r.LoadingViewModel.LoadingMessage = "Please Wait While Generating Mappings"; r.LoadingViewModel.IsLoading = true; try { var mappingsGrid = r.GetEnumerableFieldViewModel(nameof(ImportSqlRequest.SqlImportTableMapping.Mappings)); var sourceType = r.GetRecord().GetOptionKey(nameof(ImportSqlRequest.SqlImportTableMapping.SourceTable)); if (string.IsNullOrWhiteSpace(sourceType)) { throw new NullReferenceException($"{nameof(ImportSqlRequest.SqlImportTableMapping.SourceTable)} Is Required For This Function"); } var targetType = r.GetRecord().GetOptionKey(nameof(ImportSqlRequest.SqlImportTableMapping.TargetType)); if (string.IsNullOrWhiteSpace(targetType)) { throw new NullReferenceException($"{nameof(ImportSqlRequest.SqlImportTableMapping.TargetType)} Is Required For This Function"); } //alright this one is going to create a mapping for each excel tab //if the name matches with a target type then we will auto populate the target var sourceService = r.RecordService.GetLookupService(nameof(ImportSqlRequest.SqlImportTableMapping.SourceTable), typeof(ImportSqlRequest.SqlImportTableMapping).AssemblyQualifiedName, nameof(ImportSqlRequest.Mappings), r.GetRecord()); var targetLookupService = r.RecordService.GetLookupService(nameof(ImportSqlRequest.SqlImportTableMapping.TargetType), nameof(ImportSqlRequest.SqlImportTableMapping), nameof(ImportSqlRequest.Mappings), r.GetRecord()); foreach (var sourceColumn in sourceService.GetFields(sourceType)) { var fieldLabel = sourceService.GetFieldLabel(sourceColumn, sourceType); var fieldMapping = new ImportSqlRequest.SqlImportTableMapping.SqlImportFieldMapping(); fieldMapping.SourceColumn = new RecordField(sourceColumn, fieldLabel); if (targetType != null) { var targetFieldResponse = GetTargetField(targetLookupService, fieldLabel, targetType); if (targetFieldResponse.IsMatch) { fieldMapping.TargetField = new RecordField(targetFieldResponse.LogicalName, targetLookupService.GetFieldLabel(targetFieldResponse.LogicalName, targetType)); } } mappingsGrid.InsertRecord(new ObjectRecord(fieldMapping), 0); } } finally { r.LoadingViewModel.IsLoading = false; } } catch (Exception ex) { g.ApplicationController.ThrowException(ex); } }); }
/// <summary> /// Load the selected grid row's object into the parent parent form /// </summary> public void LoadSelected(DynamicGridViewModel g) { try { if (!(g.SelectedRows.Count() == 1)) { g.ApplicationController.UserMessage("You Must Select 1 Row To Load"); return; } var parentForm = g.ParentForm as ObjectEntryViewModel; if (parentForm == null) { throw new NullReferenceException(string.Format("Error parent form is not of type {0}", typeof(ObjectEntryViewModel))); } //get the selected object var selectionSubGrid = parentForm.GetEnumerableFieldViewModel(nameof(SavedSettings.SavedRequests)); var selectedObjectRecord = selectionSubGrid.DynamicGridViewModel.SelectedRows.Count() == 1 ? selectionSubGrid.DynamicGridViewModel.SelectedRows.First().GetRecord() as ObjectRecord : null; var selectedObject = selectedObjectRecord == null ? null : selectedObjectRecord.Instance; if (selectedObject != null) { //map the selected object into the parent parent forms object var parentParentForm = parentForm.ParentForm as ObjectEntryViewModel; if (parentParentForm == null) { throw new NullReferenceException(string.Format("Error parent parent form is not of type {0}", typeof(ObjectEntryViewModel))); } var parentFormObject = parentParentForm.GetObject(); var mapper = new ClassSelfMapper(); mapper.Map(selectedObject, parentFormObject); if (parentFormObject is ServiceRequestBase) { ((ServiceRequestBase)parentFormObject).DisplaySavedSettingFields = false; } parentParentForm.LoadingViewModel.IsLoading = true; //allow loading to display Thread.Sleep(1000); //reload the parent parent form fo4r the updated object parentParentForm.Reload(); foreach (var grid in parentParentForm.SubGrids) { grid.DynamicGridViewModel.ReloadGrid(); } } parentForm.LoadSubgridsToObject(); parentForm.OnSave(); } catch (Exception ex) { ApplicationController.ThrowException(ex); } }
public void QuickFind() { var anyNotValid = ValidateCurrentSearch(); if (anyNotValid) { return; } DynamicGridViewModel.ReloadGrid(); }
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; } }
public void QuickFind() { var isValid = ValidateCurrentSearch(); if (!isValid) { return; } DynamicGridViewModel.ReloadGrid(); QueryRun = true; }
public static GetGridRecordsResponse GetGridRecordPage(this DynamicGridViewModel gridViewModel, QueryDefinition query) { query.Top = gridViewModel.CurrentPageCeiling + 1; if (gridViewModel.GetLastSortExpression() != null) { query.Sorts.Insert(0, gridViewModel.GetLastSortExpression()); } var records = gridViewModel.RecordService.RetreiveAll(query); var hasMoreRows = records.Count() > gridViewModel.CurrentPageCeiling; records = records.Skip(gridViewModel.CurrentPageFloor).Take(gridViewModel.PageSize).ToArray(); return(new GetGridRecordsResponse(records, hasMoreRows)); }
public MainWindow() { InitializeComponent(); var dynamicGridViewModel = new DynamicGridViewModel { GridWidth = 25, GridHeight = 15, BorderColor = Colors.Blue, StartColor = Colors.Azure, FinishColor = Colors.CornflowerBlue, }; DataContext = dynamicGridViewModel; }
public GetGridRecordsResponse GetGridRecords(bool ignorePages) { if (DynamicGridViewModel.HasPaging && !ignorePages) { var conditions = new[] { new Condition(LinkedRecordLookup, ConditionType.Equal, RecordForm.RecordId) }; return(DynamicGridViewModel.GetGridRecordPage(conditions, null)); } else { return(new GetGridRecordsResponse(GetRecordService().GetLinkedRecords(LinkedRecordType, RecordForm.RecordType, LinkedRecordLookup, RecordForm.RecordId))); } }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { var sequence = ""; GetInput(ref sequence); if (!string.IsNullOrEmpty(sequence)) { GetReferenceCoordinates(out var x_ref, out var y_ref, out var x, out var y); GetCoordinates(ref x, ref y, ref sequence); int totalRow = 0, totalCol = 0; GetRowColCount(ref totalRow, ref totalCol); bool isXinBounds = isValidX(x, totalCol); bool isYinBounds = isValidY(y, totalRow); string outputStr = GetOutput(x, y, x_ref, y_ref, isXinBounds, isYinBounds, totalCol, totalRow); int cols = CheckCount(int.Parse(txtColCount.Text), 12); int row = CheckCount(int.Parse(txtColCount.Text), 12); if (isXinBounds && isYinBounds) { dynamicGridViewModel = new DynamicGridViewModel() { GridWidth = cols, GridHeight = row, BorderColor = Colors.Blue, StartColor = Colors.Azure, FinishColor = Colors.CornflowerBlue, posX = x, posY = y, }; dynamicGridViewModel.SelectCell(x, y, Colors.Gray); DataContext = dynamicGridViewModel; } RefreshText(ref outputStr); } else { sequence = ""; MessageBox.Show("Input cant be empty"); } }
public GetGridRecordsResponse GetGridRecords(bool ignorePages, IEnumerable <string> fields = null) { var isValid = ValidateCurrentSearch(); if (!isValid) { return(new GetGridRecordsResponse(new IRecord[0])); } var query = GenerateQuery(); query.Fields = fields; var notInList = new HashSet <string>(); if (IncludeNotIn) { DateTime notInThreshold; notInList = GetNotInIds(out notInThreshold); AdjustQueryForCreatedThreshold(query, notInThreshold); } if (!DynamicGridViewModel.HasPaging || ignorePages) { var loadingVm = DynamicGridViewModel.LoadingViewModel; var records = new List <IRecord>(); DynamicGridViewModel.RecordService.ProcessResults(query, (r) => { records.AddRange(r.Where(t => !notInList.Contains(t.Id))); if (loadingVm != null) { loadingVm.LoadingMessage = "Running Main Query - " + records.Count; } }); if (loadingVm != null) { loadingVm.LoadingMessage = "Populating Empty Lookups"; } records.PopulateEmptyLookups(RecordService, null); if (loadingVm != null) { loadingVm.LoadingMessage = "Please Wait While Loading"; } return(new GetGridRecordsResponse(records)); } else { return(DynamicGridViewModel.GetGridRecordPage(query, notInList)); } }
protected void columnHeader_Click(object sender, RoutedEventArgs e) { var columnHeader = sender as DataGridColumnHeader; if (columnHeader != null && !(columnHeader.Column is DeleteRowColumn) && !(columnHeader.Column is EditRowColumn)) { var sortMember = columnHeader.Column.SortMemberPath; if (sortMember != null) { DynamicGridViewModel.SortIt(sortMember.Trim(new[] { '[', ']' })); } } }
public LookupGridViewModel(IReferenceFieldViewModel referenceField, Action <IRecord> onRecordSelected) : base(referenceField.RecordEntryViewModel.ApplicationController) { OnRecordSelected = onRecordSelected; DynamicGridViewModel = new DynamicGridViewModel(ApplicationController) { OnDoubleClick = OnDoubleClick, ViewType = ViewType.LookupView, RecordService = referenceField.LookupService, FormController = new FormController(referenceField.LookupService, null, referenceField.RecordEntryViewModel.ApplicationController), RecordType = referenceField.RecordTypeToLookup, IsReadOnly = true, }; }
public static GetGridRecordsResponse GetGridRecordPage(this DynamicGridViewModel gridViewModel, IEnumerable <Condition> conditions, IEnumerable <SortExpression> sorts) { var sortList = sorts == null ? new List <SortExpression>() : sorts.ToList(); if (gridViewModel.GetLastSortExpression() != null) { sortList.Insert(0, gridViewModel.GetLastSortExpression()); } var records = gridViewModel.RecordService.GetFirstX(gridViewModel.RecordType, gridViewModel.CurrentPageCeiling + 1, null, conditions, sortList); var hasMoreRows = records.Count() > gridViewModel.CurrentPageCeiling; records = records.Skip(gridViewModel.CurrentPageFloor).Take(gridViewModel.PageSize).ToArray(); return(new GetGridRecordsResponse(records, hasMoreRows)); }
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 MainWindow() { InitializeComponent(); dynamicGridViewModel = new DynamicGridViewModel { GridWidth = 12, GridHeight = 12, BorderColor = Colors.Blue, StartColor = Colors.Azure, FinishColor = Colors.CornflowerBlue, posX = 11, posY = 11, }; _y = dynamicGridViewModel.GridHeight; _x = dynamicGridViewModel.GridWidth; dynamicGridViewModel.SelectCell(0, 11, Colors.Gray); DataContext = dynamicGridViewModel; }
private InstanceComparerResponse GetResponse(DynamicGridViewModel g) { var record = g.ParentForm.GetRecord(); var objectRecord = record as ObjectRecord; if (objectRecord == null) { throw new NullReferenceException($"Error expected response record of type {typeof(ObjectRecord).Name}. Actual type is {record.GetType().Name}"); } var instance = objectRecord.Instance; var response = objectRecord.Instance as InstanceComparerResponse; if (response == null) { throw new NullReferenceException($"Error expected response object of type {typeof(InstanceComparerResponse).Name}. Actual type is {instance.GetType().Name}"); } return(response); }
public GetGridRecordsResponse GetGridRecords(bool ignorePages) { var anyNotValid = ValidateCurrentSearch(); if (anyNotValid) { return(new GetGridRecordsResponse(new IRecord[0])); } var query = GenerateQuery(); if (!DynamicGridViewModel.HasPaging || ignorePages) { var records = DynamicGridViewModel.RecordService.RetreiveAll(query); return(new GetGridRecordsResponse(records)); } else { return(DynamicGridViewModel.GetGridRecordPage(query)); } }
public LookupGridViewModel(IReferenceFieldViewModel referenceField, Action <IRecord> onRecordSelected) : base(referenceField.RecordEntryViewModel.ApplicationController) { OnRecordSelected = onRecordSelected; Func <bool, GetGridRecordsResponse> getGridRecords = (ignorePages) => { var query = new QueryDefinition(referenceField.RecordTypeToLookup); query.IsQuickFind = true; query.QuickFindText = referenceField.EnteredText; if (!string.IsNullOrWhiteSpace(referenceField.EnteredText)) { var quickFindFields = DynamicGridViewModel.RecordService.GetStringQuickfindFields(referenceField.RecordTypeToLookup); query.RootFilter.ConditionOperator = FilterOperator.Or; query.RootFilter.Conditions.AddRange(quickFindFields.Select(f => new Condition(f, ConditionType.BeginsWith, referenceField.EnteredText))); } if (!DynamicGridViewModel.HasPaging || ignorePages) { var records = DynamicGridViewModel.RecordService.RetreiveAll(query); return(new GetGridRecordsResponse(records)); } else { return(DynamicGridViewModel.GetGridRecordPage(query)); } }; DynamicGridViewModel = new DynamicGridViewModel(ApplicationController) { PageSize = MaxRecordsForLookup, GetGridRecords = getGridRecords, OnDoubleClick = OnDoubleClick, ViewType = ViewType.LookupView, RecordService = referenceField.LookupService, FormController = new FormController(referenceField.LookupService, null, referenceField.RecordEntryViewModel.ApplicationController), RecordType = referenceField.RecordTypeToLookup, IsReadOnly = true, }; }
/// <summary> /// Load the selected grid row's object into the parent parent form /// </summary> public void LoadSelected(DynamicGridViewModel g) { try { if (!(g.SelectedRows.Count() == 1)) { g.ApplicationController.UserMessage("You Must Select 1 Row To Load"); return; } var parentForm = g.ParentForm as ObjectEntryViewModel; if (parentForm == null) { throw new NullReferenceException(string.Format("Error parent form is not of type {0}", typeof(ObjectEntryViewModel))); } //get the selected object var selectionSubGrid = parentForm.GetEnumerableFieldViewModel(nameof(SavedSettings.SavedRequests)); var selectedObjectRecord = selectionSubGrid.DynamicGridViewModel.SelectedRows.Count() == 1 ? selectionSubGrid.DynamicGridViewModel.SelectedRows.First().GetRecord() as ObjectRecord : null; var selectedObject = selectedObjectRecord == null ? null : selectedObjectRecord.Instance; if (selectedObject != null) { //map the selected object into the parent parent forms object var parentParentForm = parentForm.ParentForm as ObjectEntryViewModel; if (parentParentForm == null) { throw new NullReferenceException(string.Format("Error parent parent form is not of type {0}", typeof(ObjectEntryViewModel))); } var loadIntoForm = parentParentForm; LoadSavedObject(selectedObject, loadIntoForm); } parentForm.LoadSubgridsToObject(); parentForm.OnSave(); } catch (Exception ex) { ApplicationController.ThrowException(ex); } }
public GetGridRecordsResponse GetGridRecords(bool ignorePages) { if (DynamicGridViewModel.HasPaging && !ignorePages) { var conditions = new[] { new Condition(LinkedRecordLookup, ConditionType.Equal, RecordForm.RecordId) }; return(DynamicGridViewModel.GetGridRecordPage(conditions, null)); } else { var lastSortExpression = DynamicGridViewModel.GetLastSortExpression(); var records = GetRecordService().GetLinkedRecords(LinkedRecordType, RecordForm.RecordType, LinkedRecordLookup, RecordForm.RecordId).ToList(); if (lastSortExpression != null) { RecordComparer.SortList(records, lastSortExpression); } return(new GetGridRecordsResponse(records)); } }
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; } } }); }
internal void SetItemsSource(IEnumerable <T> items) { ItemsSource = items == null ? new SelectablePicklistOption[0] : items.Select(i => new SelectablePicklistOption(i, RefreshSelectedItemsIntoValue, Value != null && Value.Any(v => v == i))).ToArray(); var optionsObject = new SelectablePicklistOptions() { Options = ItemsSource }; var recordService = new ObjectRecordService(optionsObject, ApplicationController); Func <IEnumerable <IRecord> > getRecordsFunc = () => recordService.RetreiveAll(new QueryDefinition(typeof(SelectablePicklistOption).AssemblyQualifiedName)); DynamicGridViewModel = new DynamicGridViewModel(ApplicationController) { ViewType = ViewType.LookupView, FormController = new FormController(recordService, null, ApplicationController), RecordType = typeof(SelectablePicklistOption).AssemblyQualifiedName, RecordService = recordService, GetGridRecords = (b) => new GetGridRecordsResponse(getRecordsFunc()), IsReadOnly = true }; Action onClick = () => { var selectedItem = DynamicGridViewModel.SelectedRow; if (selectedItem != null) { var isSelectedField = selectedItem.GetBooleanFieldFieldViewModel(nameof(SelectablePicklistOption.Select)); isSelectedField.Value = !isSelectedField.Value; DynamicGridViewModel.SelectedRow = null; } }; DynamicGridViewModel.OnClick = onClick; DoOnAsynchThread(() => { DynamicGridViewModel.GridRecords = GridRowViewModel.LoadRows(getRecordsFunc(), DynamicGridViewModel); OnPropertyChanged(nameof(DynamicGridViewModel)); OnPropertyChanged(nameof(StringDisplay)); }); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); IUnityContainer container = new UnityContainer(); container.RegisterType <ILogger, EmptyLogger>(); var dynamicGridViewModel = new DynamicGridViewModel(container.Resolve <ILogger>()) { CellWidth = 25, CellHeight = 25, BorderColor = Colors.Blue, StartColor = Colors.Azure, FinishColor = Colors.CornflowerBlue }; container.RegisterInstance(typeof(IDynamicGridViewModel), dynamicGridViewModel, new ContainerControlledLifetimeManager()); var mainWindow = container.Resolve <MainWindow>(); Application.Current.MainWindow = mainWindow; Application.Current.MainWindow.Show(); }