/// <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>
        /// Constructor for this page
        /// </summary>
        public LookupDialogPage()
        {
            this.InitializeComponent();

            // Register NavigationHelper
            this.navigationHelper            = new NavigationHelper(this);
            this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
            this.navigationHelper.SaveState += this.NavigationHelper_SaveState;

            lookForEntities = new EntityMetadataExCollection();

            // Register Event handler for view change.
            this.CRMGrid.lvList.ItemClick           += lvList_ItemClick;
            this.CRMGrid.cbLookFor.SelectionChanged += cbLookFor_SelectionChanged;
        }
 /// <summary>
 /// This method called when page is loaded to restore state
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     if (e.PageState != null && e.PageState.ContainsKey("formFieldData"))
     {
         formFieldData = e.PageState["formFieldData"] as FormFieldData;
     }
     if (e.PageState != null && e.PageState.ContainsKey("lookForEntities"))
     {
         lookForEntities = e.PageState["lookForEntities"] as EntityMetadataExCollection;
     }
     if (e.PageState != null && e.PageState.ContainsKey("cbLookFor_SelectedIndex"))
     {
         cbLookFor_SelectedIndex = int.Parse(e.PageState["cbLookFor_SelectedIndex"].ToString());
     }
     if (e.PageState != null && e.PageState.ContainsKey("cbLookIn_SelectedIndex"))
     {
         cbLookIn_SelectedIndex = int.Parse(e.PageState["cbLookIn_SelectedIndex"].ToString());
     }
 }
예제 #5
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
        }