/// <summary> /// This method is called when user changes Entity /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void cbLookFor_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Firstly remove existing buttons if (abAdd != null) { commandBar.PrimaryCommands.Remove(abAdd); } string schemaName = ""; if (((sender as ComboBox).SelectedItem as EntityMetadataEx).EntityMetadata.IsActivity == true) { schemaName = "Activity"; } else { schemaName = ((sender as ComboBox).SelectedItem as EntityMetadataEx).EntityMetadata.SchemaName; } // Render AppBarButton if (CRMHelper.CheckPrivilege(schemaName, PrivilegeType.Create, PrivilegeDepth.Basic)) { abAdd = new AppBarButton(); abAdd.Icon = new SymbolIcon(Symbol.Add); abAdd.Name = "abAdd"; abAdd.Label = loader.GetString("abAdd\\Label"); abAdd.Click += abAdd_Click; commandBar.PrimaryCommands.Insert(0, abAdd); } }
/// <summary> /// This method is called to initialze page. /// </summary> private async void Initialize() { // First of all, set schemaName to check privilege string schemaName = ""; // i want to add activity selector for activitypointer when adding new if (entityMetadataEx.EntityMetadata.IsActivity == true) { schemaName = "Activity"; } else { schemaName = entityMetadataEx.EntityMetadata.SchemaName; } // Render Add button if (CRMHelper.CheckPrivilege(schemaName, PrivilegeType.Create, PrivilegeDepth.Basic)) { abAdd = new AppBarButton(); abAdd.Icon = new SymbolIcon(Symbol.Add); abAdd.Name = "abAdd"; abAdd.Label = loader.GetString("abAdd\\Label"); abAdd.Click += abAdd_Click; commandBar.PrimaryCommands.Insert(0, abAdd); } // Render Delete button if (CRMHelper.CheckPrivilege(schemaName, PrivilegeType.Delete, PrivilegeDepth.Basic)) { abDelete = new AppBarButton(); abDelete.Icon = new SymbolIcon(Symbol.Delete); abDelete.Name = "abDelete"; abDelete.Label = loader.GetString("abDelete\\Label"); abDelete.Click += abDelete_Click; abDelete.IsEnabled = false; abDelete.Visibility = Visibility.Collapsed; commandBar.PrimaryCommands.Insert(commandBar.PrimaryCommands.IndexOf(abCancel), abDelete); } // Instantiate collection for lookFor combobox EntityMetadataExCollection lookForEntities = new EntityMetadataExCollection(); lookForEntities.Add(entityMetadataEx); // Assign parameters this.CRMGrid.IsGrid = true; this.CRMGrid.LookForEntities = lookForEntities; // Then load data. await this.CRMGrid.LoadData(cbLookIn_SelectedIndex : cbLookIn_SelectedIndex); }
/// <summary> /// This metohd called when Entity Selection changed in Related PivotItem /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void cbLookFor_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Firstly remove existing AppBarButtons. if (abRelatedAdd != null) { commandBar.PrimaryCommands.Remove(abRelatedAdd); } if (abAddExisting != null) { commandBar.PrimaryCommands.Remove(abAddExisting); } if (abRelatedDelete != null) { commandBar.PrimaryCommands.Remove(abRelatedDelete); commandBar.PrimaryCommands.Remove(abSelect); commandBar.PrimaryCommands.Remove(abCancel); } // Set schemaName to check privilege string RelatedRecordSchemaName = ""; if (((sender as ComboBox).SelectedItem as EntityMetadataEx).EntityMetadata.IsActivity == true) { RelatedRecordSchemaName = "Activity"; } else { RelatedRecordSchemaName = ((sender as ComboBox).SelectedItem as EntityMetadataEx).EntityMetadata.SchemaName; } // Render AppBarButton if (CRMHelper.CheckPrivilege(MainRecordSchemaName, PrivilegeType.AppendTo, PrivilegeDepth.Basic) && CRMHelper.CheckPrivilege(RelatedRecordSchemaName, PrivilegeType.Append, PrivilegeDepth.Basic) && CRMHelper.CheckPrivilege(RelatedRecordSchemaName, PrivilegeType.Create, PrivilegeDepth.Basic)) { abRelatedAdd = new AppBarButton(); abRelatedAdd.Icon = new SymbolIcon(Symbol.Add); abRelatedAdd.Name = "abRelatedAdd"; abRelatedAdd.Label = loader.GetString("abRelatedAdd\\Label"); abRelatedAdd.Click += abRelatedAdd_Click; commandBar.PrimaryCommands.Add(abRelatedAdd); } if (CRMHelper.CheckPrivilege(MainRecordSchemaName, PrivilegeType.AppendTo, PrivilegeDepth.Basic) && CRMHelper.CheckPrivilege(RelatedRecordSchemaName, PrivilegeType.Append, PrivilegeDepth.Basic)) { abAddExisting = new AppBarButton(); BitmapIcon bitmapIcon = new BitmapIcon(); bitmapIcon.UriSource = new Uri("ms-appx:///Assets/Data-Add.png"); abAddExisting.Icon = bitmapIcon; abAddExisting.Name = "abAddExisting"; abAddExisting.Label = loader.GetString("abAddExisting\\Label"); abAddExisting.Click += abAddExisting_Click; commandBar.PrimaryCommands.Add(abAddExisting); } if (CRMHelper.CheckPrivilege(MainRecordSchemaName, PrivilegeType.AppendTo, PrivilegeDepth.Basic) && CRMHelper.CheckPrivilege(RelatedRecordSchemaName, PrivilegeType.Append, PrivilegeDepth.Basic)) { abRelatedDelete = new AppBarButton(); abRelatedDelete.Icon = new SymbolIcon(Symbol.Delete); abRelatedDelete.Name = "abRelatedDelete"; abRelatedDelete.Label = loader.GetString("abRelatedDelete\\Label"); abRelatedDelete.Click += abRelatedDelete_Click; commandBar.PrimaryCommands.Add(abRelatedDelete); abSelect = new AppBarButton(); abSelect.Icon = new SymbolIcon(Symbol.List); abSelect.Name = "abSelect"; abSelect.Label = loader.GetString("abSelect\\Label"); abSelect.Click += abSelect_Click; commandBar.PrimaryCommands.Add(abSelect); abCancel = new AppBarButton(); abCancel.Icon = new SymbolIcon(Symbol.Cancel); abCancel.Name = "abCancel"; abCancel.Label = loader.GetString("abCancel\\Label"); abCancel.Click += abCancel_Click; commandBar.PrimaryCommands.Add(abCancel); } // Reset selection mode CRMGrid.lvList.SelectionMode = ListViewSelectionMode.None; // Call ResetRelatedAppBarButtonDisplay when Related view is displayed. if (pvRecord.SelectedItem != null && (pvRecord.SelectedItem as PivotItem).Name == "piRelatedView") { ResetRelatedAppBarButtonDisplay((pvRecord.SelectedItem as PivotItem).Name == "piRelatedView"); } }
/// <summary> /// This method is called to initialze page. /// </summary> private async void Initialize() { #region Initialize AppBarButtons // First of all, set schemaName to check privilege if (entityMetadataEx.EntityMetadata.IsActivity == true) { MainRecordSchemaName = "Activity"; } else { MainRecordSchemaName = entityMetadataEx.EntityMetadata.SchemaName; } // Render AppBarButtons for record. if (CRMHelper.CheckPrivilege(MainRecordSchemaName, PrivilegeType.Create, PrivilegeDepth.Basic)) { abAdd = new AppBarButton(); abAdd.Icon = new SymbolIcon(Symbol.Add); abAdd.Name = "abAdd"; abAdd.Label = loader.GetString("abAdd\\Label"); abAdd.Click += abAdd_Click; commandBar.PrimaryCommands.Add(abAdd); } if (CRMHelper.CheckPrivilege(MainRecordSchemaName, PrivilegeType.Write, PrivilegeDepth.Basic)) { abEdit = new AppBarButton(); abEdit.Icon = new SymbolIcon(Symbol.Edit); abEdit.Name = "abEdit"; abEdit.Label = loader.GetString("abEdit\\Label"); abEdit.Click += abEdit_Click; commandBar.PrimaryCommands.Add(abEdit); } if (CRMHelper.CheckPrivilege(MainRecordSchemaName, PrivilegeType.Delete, PrivilegeDepth.Basic)) { abDelete = new AppBarButton(); abDelete.Icon = new SymbolIcon(Symbol.Delete); abDelete.Name = "abDelete"; abDelete.Label = loader.GetString("abDelete\\Label"); abDelete.Click += abDelete_Click; commandBar.PrimaryCommands.Add(abDelete); } // Check privilege to display Note AppBarButton if (CRMHelper.CheckPrivilege("Note", PrivilegeType.Read, PrivilegeDepth.Basic)) { // If use has read access, then check other privileges too. // AppBarButtons for record. if (CRMHelper.CheckPrivilege("Note", PrivilegeType.Create, PrivilegeDepth.Basic) && CRMHelper.CheckPrivilege(MainRecordSchemaName, PrivilegeType.AppendTo, PrivilegeDepth.Basic)) { abNoteAdd = new AppBarButton(); abNoteAdd.Icon = new SymbolIcon(Symbol.Add); abNoteAdd.Name = "abNoteAdd"; abNoteAdd.Label = loader.GetString("abNoteAdd\\Label"); abNoteAdd.Click += abNoteAdd_Click; commandBar.PrimaryCommands.Add(abNoteAdd); abNoteSave = new AppBarButton(); abNoteSave.Icon = new SymbolIcon(Symbol.Save); abNoteSave.Name = "abNoteSave"; abNoteSave.Label = loader.GetString("abNoteSave\\Label"); abNoteSave.Click += abNoteSave_Click; commandBar.PrimaryCommands.Add(abNoteSave); } if (CRMHelper.CheckPrivilege("Note", PrivilegeType.Delete, PrivilegeDepth.Basic)) { abNoteDelete = new AppBarButton(); abNoteDelete.Icon = new SymbolIcon(Symbol.Delete); abNoteDelete.Name = "abNoteDelete"; abNoteDelete.Label = loader.GetString("abNoteDelete\\Label"); abNoteDelete.Click += abNoteDelete_Click; commandBar.PrimaryCommands.Add(abNoteDelete); abNoteSelect = new AppBarButton(); abNoteSelect.Icon = new SymbolIcon(Symbol.List); abNoteSelect.Name = "abNoteSelect"; abNoteSelect.Label = loader.GetString("abNoteSelect\\Label"); abNoteSelect.Click += abNoteSelect_Click; commandBar.PrimaryCommands.Add(abNoteSelect); abNoteCancel = new AppBarButton(); abNoteCancel.Icon = new SymbolIcon(Symbol.Cancel); abNoteCancel.Name = "abNoteCancel"; abNoteCancel.Label = loader.GetString("abNoteCancel\\Label"); abNoteCancel.Click += abNoteCancel_Click; commandBar.PrimaryCommands.Add(abNoteCancel); } } else { // If no read privilege for note, then hide the pivotitem piNotes.Visibility = Visibility.Collapsed; } #endregion #region Initialize CRMRecordDetail // Assign properties this.CRMRecordDetail.EntityMetadataEx = entityMetadataEx; this.CRMRecordDetail.Id = id; // Assign fields and record if it's cached. If you want to always retrieve latest data, then // do not restore data from cache if (fields != null || record != null) { this.CRMRecordDetail.Record = record; this.CRMRecordDetail.Fields = fields; } // Then road the record await this.CRMRecordDetail.LoadData(); // Get it as reference this.record = CRMRecordDetail.Record; // Get fields as reference this.fields = CRMRecordDetail.Fields; // Put the title this.pvRecord.Title = entityMetadataEx.EntityMetadata.DisplayName.UserLocalizedLabel.Label + ": " + record[entityMetadataEx.EntityMetadata.PrimaryNameAttribute]; #endregion #region Initialize CRMGrid // Now work for related entities pivotitem // Instantiate collection for lookFor combobox EntityMetadataExCollection lookForEntities = new EntityMetadataExCollection(); // Assign all related entities foreach (RelatedData item in entityMetadataEx.RelatedEntities) { EntityMetadataEx em = CRMHelper.EntityMetadataExCollection.Where(x => x.EntityMetadata.ObjectTypeCode == item.ObjectTypeCode).First(); lookForEntities.Add(em); } // Check if there is related entities if (lookForEntities.Count() != 0) { // Assign properties this.CRMGrid.LookForEntities = lookForEntities; CRMGrid.ReferencedEntityLogicalName = entityMetadataEx.EntityMetadata.LogicalName; CRMGrid.ReferencedEntityId = id; // Then load data await this.CRMGrid.LoadData(cbLookFor_SelectedIndex, cbLookIn_SelectedIndex); } #endregion #region Initialize CRMNote // Assign properties this.CRMNotes.Id = id; this.CRMNotes.EntityMetadataEx = entityMetadataEx; // Then load the data await this.CRMNotes.LoadData(); #endregion }