コード例 #1
0
        /// <summary>
        /// This methods LoadData to control
        /// </summary>
        public void LoadData()
        {
            progressRing.IsActive = true;

            // Check if Create or Update
            // If there is no Record data, or data without id information, then it's for new Record
            if (Record == null || Record.Id == Guid.Empty)
            {
                isUpdate = false;
                // however, if Record is not null, then it is new operation for regarding item
                if (Record != null)
                {
                    isRegarding = true;
                }
            }
            foreach (var field in Fields)
            {
                if ((isUpdate && !(bool)field.FieldMetadata.IsValidForUpdate) || (!isUpdate && !(bool)field.FieldMetadata.IsValidForCreate))
                {
                    continue;
                }
                // do not show from field
                if (field.FieldMetadata.LogicalName == "from")
                {
                    continue;
                }
                if ((isUpdate || isRegarding) && field.FieldData == null)
                {
                    field.FieldData = (Record.Attributes.Contains(field.FieldMetadata.LogicalName)) ? Record.Attributes[field.FieldMetadata.LogicalName] : null;
                }
                if (field.FieldMetadata.LogicalName == "ownerid" && field.FieldData == null)
                {
                    EntityReference owner = new EntityReference(SystemUser.EntityLogicalName, (Guid)CRMHelper.UserInfo.SystemUserId);
                    owner.Name      = CRMHelper.UserInfo.FullName;
                    field.FieldData = owner;
                }
                // Put description field to txtDescription in second grid row.
                if (field.FieldMetadata.LogicalName == "description")
                {
                    var w = Window.Current.Bounds.Width;
                    txtDescription.Width       = w - 36;
                    txtDescription.DataContext = field;
                    Binding binding = new Binding();
                    binding.Path = new PropertyPath("FieldData");
                    binding.Mode = BindingMode.TwoWay;
                    txtDescription.SetBinding(TextBox.TextProperty, binding);
                    continue;
                }

                Grid grid = CRMHelper.GenerateField(field, isUpdate);

                if (grid.Children[1].GetType().Equals(typeof(LookupControl)))
                {
                    (grid.Children[1] as LookupControl).LookupControlButton_Click += LookupButton_Click;
                }
                if (grid.Children[1].GetType().Equals(typeof(ActivityPartyLookupControl)))
                {
                    (grid.Children[1] as ActivityPartyLookupControl).ActivityPartyDeleteButton_Click += ActivityPartyDelteButton_Click;
                    (grid.Children[1] as ActivityPartyLookupControl).ActivityPartyAddButton_Click    += ActivityPartyAddButton_Click;
                }
                if (grid == null)
                {
                    continue;
                }

                this.lvFields.Items.Add(grid);
            }

            progressRing.IsActive = false;
        }
コード例 #2
0
        /// <summary>
        /// Loading data
        /// </summary>
        public void LoadData()
        {
            // Show ProgressRing
            progressRing.IsActive = true;

            // Check if this is Create or Update
            // If there is no Record data then it is Create, or data without Id information, then it's for new Record
            if (Record == null)
            {
                isUpdate = false;
            }
            // If record is not null but Id is empty, then this is regarding (as if it comes from regarding record data is filled depending on mapping)
            else if (Record.Id == Guid.Empty)
            {
                isUpdate    = false;
                isRegarding = true;
            }

            // Iterate through each Field and display on the form
            foreach (var field in Fields)
            {
                // If this is update form yet the field is not valid for update, then go next field.
                // If this is create form yet the field is not valid for create, then go next field.
                if ((isUpdate && !(bool)field.FieldMetadata.IsValidForUpdate) || (!isUpdate && !(bool)field.FieldMetadata.IsValidForCreate))
                {
                    continue;
                }

                // If this is create or new as regarding yet no data exist, then fill it.
                if ((isUpdate || isRegarding) && field.FieldData == null)
                {
                    field.FieldData = (Record.Attributes.Contains(field.FieldMetadata.LogicalName)) ?
                                      Record.Attributes[field.FieldMetadata.LogicalName] : null;
                }

                // If the field is owner but no data filled, assign current user as owner.
                if (field.FieldMetadata.LogicalName == "ownerid" && field.FieldData == null)
                {
                    EntityReference owner = new EntityReference(SystemUser.EntityLogicalName, (Guid)CRMHelper.UserInfo.SystemUserId);
                    owner.Name      = CRMHelper.UserInfo.FullName;
                    field.FieldData = owner;
                }

                // Create field
                Grid grid = CRMHelper.GenerateField(field, isUpdate);

                // If nothing returned, then go to next field.
                if (grid == null)
                {
                    continue;
                }

                // If the field has LookupControl in it (means this is owner, lookup, customer), then assing click event.
                if (grid.Children[1].GetType().Equals(typeof(LookupControl)))
                {
                    (grid.Children[1] as LookupControl).LookupControlButton_Click += LookupButton_Click;
                }

                // If the field has ActivityPartyLookupControl, then assign Add/Delete method.
                if (grid.Children[1].GetType().Equals(typeof(ActivityPartyLookupControl)))
                {
                    (grid.Children[1] as ActivityPartyLookupControl).ActivityPartyAddButton_Click    += ActivityPartyAddButton_Click;
                    (grid.Children[1] as ActivityPartyLookupControl).ActivityPartyDeleteButton_Click += ActivityPartyDelteButton_Click;
                }

                // If the field has EntityImageControl, then place it on the top of the form.
                if (grid.Children[1].GetType().Equals(typeof(EntityImageControl)))
                {
                    this.lvFields.Items.Insert(0, grid);
                }
                // Anything else, just add to the form.
                else
                {
                    this.lvFields.Items.Add(grid);
                }
            }

            // Supress ProgressRing
            progressRing.IsActive = false;
        }