Example #1
0
        private void BuildGroupWithConfigurationItemsUpdateableItems(UPObjectivesConfiguration groupConfiguration, List <UPCRMResultRow> items, Dictionary <string, UPCRMResultRow> updateableItems)
        {
            // search for group and create if not found
            string                   groupKey            = groupConfiguration.SectionName;
            UPObjectivesGroup        group               = this.GroupDictionary.ValueOrDefault(groupKey);
            UPCRMFilterBasedDecision filterBasedDecision = groupConfiguration.FilterBasedDecision;

            if (group == null)
            {
                group = new UPObjectivesGroup(groupKey, this, groupConfiguration);
                this.Groups.Add(group);
                this.GroupDictionary.SetObjectForKey(group, groupKey);
            }

            int count = items?.Count ?? 0;

            if (count == 0)
            {
                this.LoadNextGroup();
                return;
            }

            for (int i = 0; i < count; i++)
            {
                UPCRMResultRow row  = items[i];
                DateTime?      date = row.RawValueAtIndex(groupConfiguration
                                                          .FieldForFunction(Constants.FieldCompletedOnFunction)
                                                          .TabIndependentFieldIndex)
                                      .DateFromCrmValue();

                bool canBeDeleted = false;
                if (updateableItems != null)
                {
                    canBeDeleted = updateableItems.ValueOrDefault(row.RootRecordIdentification) != null;
                }

                // create item
                UPObjectivesItem item = new UPObjectivesItem(row.RootRecordIdentification, date ?? DateTime.MinValue, group, canBeDeleted, this);
                if (filterBasedDecision != null)
                {
                    List <UPConfigButton> actionButtons = filterBasedDecision.ButtonsForResultRow(row);
                    foreach (UPConfigButton button in actionButtons)
                    {
                        item.AddButtonAction(button);
                    }
                }

                item.SetFromResultRow(row);
                item.LoadDocumentsWithMaxResults(this.MaxDocuments);
                group.AddItem(item);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UPObjectivesItem"/> class.
        /// </summary>
        /// <param name="keyValue">The key value.</param>
        /// <param name="date">The date.</param>
        /// <param name="group">The group.</param>
        /// <param name="canBeDeleted">if set to <c>true</c> [can be deleted].</param>
        /// <param name="documentDelegate">The document delegate.</param>
        public UPObjectivesItem(string keyValue, DateTime date, UPObjectivesGroup group, bool canBeDeleted, UPObjectivesDocumentDelegate documentDelegate)
        {
            this.KeyValue         = keyValue;
            this.Date             = date;
            this.DocumentDelegate = documentDelegate;
            this.Group            = group;
            int count = this.AdditionalFields?.Count ?? 0;

            if (count > 0)
            {
                this.values = new List <string>(this.AdditionalFields.Count);
                for (int i = 0; i < count; i++)
                {
                    this.values.Add(string.Empty);
                }
            }

            this.Deleted      = false;
            this.Changed      = false;
            this.Created      = false;
            this.CanBeDeleted = canBeDeleted;
        }