/// <summary>
        /// This method is called to initialze page.
        /// </summary>
        private async void Initialize()
        {
            // Set properties
            EntityMetadataExCollection lookForEntities = new EntityMetadataExCollection();

            lookForEntities.Add(entityMetadataEx);
            this.CRMGrid.LookForEntities = lookForEntities;
            // Then load data
            await this.CRMGrid.LoadData();
        }
        /// <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 method called when user navigated to this page.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            progressRing.IsActive = true;

            // If UserInfo is null, then initialize the helper
            if (CRMHelper.UserInfo == null)
            {
                await CRMHelper.Initialize();
            }

            // Check if there is any temporaryData. if restored, then temporary data does not exist
            object[] parameters = CRMHelper.temporaryData as object[];
            if (parameters != null)
            {
                // if this if first navigation, then no formFieldData, otherwise its restored or back from new record
                if (formFieldData == null)
                {
                    this.formFieldData = parameters[0] as FormFieldData;
                }
                else // assume back after created new record or back just by clicking cancel button.
                {
                    Entity record = parameters[0] as Entity;
                    // If record is created, then filter result down to the created record.
                    if (record != null)
                    {
                        searchCriteria = record[lookForEntities.
                                                Where(x => x.EntityMetadata.LogicalName == record.LogicalName).First().EntityMetadata.PrimaryNameAttribute].ToString();
                    }
                }
            }

            //if restored, then temporary data does not exist
            if (lookForEntities == null || lookForEntities.Count() == 0)
            {
                List <EntityMetadataEx> targetList = new List <EntityMetadataEx>();
                targetList.AddRange(CRMHelper.EntityMetadataExCollection.Where(x => (parameters[1] as string[]).Contains(x.EntityMetadata.LogicalName)));
                foreach (var target in targetList)
                {
                    lookForEntities.Add(target);
                }
            }

            Initialize();

            progressRing.IsActive = false;
        }
Esempio n. 4
0
        /// <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
        }