Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigTimelineInfoArea"/> class.
        /// </summary>
        /// <param name="definition">
        /// The definition.
        /// </param>
        public ConfigTimelineInfoArea(List <object> definition)
        {
            this.InfoAreaId = definition[0] as string;
            this.LinkId     = Convert.ToInt32(definition[1]);
            this.ConfigName = definition[2] as string;
            var dateFieldIndex = Convert.ToInt32(definition[3]);

            this.ColorString  = definition[4] as string;
            this.Color2String = definition[5] as string;
            this.FilterName   = definition[8] as string;
            this.Text         = definition[9] as string;

            var colorCriteriaDefs = (definition[10] as JArray)?.ToObject <List <object> >();

            if (colorCriteriaDefs != null && colorCriteriaDefs.Any())
            {
                var colorCriteriaArray = new List <ConfigTimelineCriteria>(colorCriteriaDefs.Count);
                foreach (JArray colorCriteriaDef in colorCriteriaDefs)
                {
                    if (colorCriteriaDef == null)
                    {
                        continue;
                    }

                    var criteria = new ConfigTimelineCriteria(colorCriteriaDef.ToObject <List <object> >());
                    colorCriteriaArray.Add(criteria);
                }

                this.ColorCriteria = colorCriteriaArray;
            }

            var configStore   = ConfigurationUnitStore.DefaultStore;
            var searchAndList = configStore.SearchAndListByName(this.ConfigName);
            var fieldControl  = (searchAndList != null
                ? configStore.FieldControlByNameFromGroup("List", searchAndList.FieldGroupName)
                : null) ?? configStore.FieldControlByNameFromGroup("List", this.ConfigName);

            if (fieldControl == null)
            {
                return;
            }

            var fieldsWithName = fieldControl.FunctionNames();

            this.DateField    = fieldsWithName.ValueOrDefault("Date");
            this.TimeField    = fieldsWithName.ValueOrDefault("Time");
            this.EndDateField = fieldsWithName.ValueOrDefault("EndDate");
            this.EndTimeField = fieldsWithName.ValueOrDefault("EndTime");

            if (dateFieldIndex == 0 && this.DateField != null)
            {
                dateFieldIndex = this.DateField.FieldId;
            }
        }
Ejemplo n.º 2
0
        private List <ICalendarItem> CalendarItemsFromResult()
        {
            List <ICalendarItem>    calendarItems = new List <ICalendarItem>();
            IConfigurationUnitStore configStore   = ConfigurationUnitStore.DefaultStore;

            this.resultContexts = new List <UPCoreMappingResultContext>();
            UPMAction goToAction = new UPMAction(StringIdentifier.IdentifierWithStringId("action"));

            goToAction.SetTargetAction(this, this.SwitchToDetail);
            goToAction.LabelText = LocalizedString.TextShowRecord;

            foreach (TimelineSearch timelineSearch in this.searches)
            {
                UPCRMResult result   = timelineSearch.Result;
                int         rowCount = result.RowCount;
                if (rowCount == 0)
                {
                    continue;
                }

                UPConfigTableCaption tableCaption = configStore.TableCaptionByName(timelineSearch.TimelineInfoArea.ConfigName) ??
                                                    configStore.TableCaptionByName(timelineSearch.TimelineInfoArea.InfoAreaId);

                List <UPContainerFieldMetaInfo> tableCaptionResultFieldMap = tableCaption.ResultFieldMapFromMetaInfo(result.MetaInfo);
                if (tableCaptionResultFieldMap == null)
                {
                    continue;
                }

                UPCRMResultCondition resultCondition = null;
                var functionNameFieldMapping         = result.MetaInfo.SourceFieldControl.FunctionNames();
                UPConfigFieldControlField fromField  = functionNameFieldMapping["Date"];
                if (fromField != null)
                {
                    if (this.fromDate != null)
                    {
                        resultCondition = new UPCRMResultFieldCondition(fromField.Field, UPConditionOperator.GreaterEqual,
                                                                        this.fromDate.Value.CrmValueFromDate(), fromField.TabIndependentFieldIndex);
                    }

                    if (this.toDate != null)
                    {
                        UPConfigFieldControlField toField = (functionNameFieldMapping.ContainsKey("EndDate")
                            ? functionNameFieldMapping["EndDate"]
                            : null) ?? fromField;

                        UPCRMResultCondition toCondition = new UPCRMResultFieldCondition(toField.Field, UPConditionOperator.LessEqual,
                                                                                         this.toDate.Value.CrmValueFromDate(), toField.TabIndependentFieldIndex);
                        resultCondition = resultCondition != null?resultCondition.ConditionByAppendingANDCondition(toCondition) : toCondition;
                    }
                }

                UPCoreMappingResultContext resultContext = new UPCoreMappingResultContext(result, result.MetaInfo.SourceFieldControl, timelineSearch.PreparedSearch.ListFieldControl.NumberOfFields);
                resultContext.Context = timelineSearch;
                this.resultContexts.Add(resultContext);

                UPConfigExpand expand = configStore.ExpandByName(timelineSearch.TimelineInfoArea.ConfigName) ??
                                        configStore.ExpandByName(timelineSearch.TimelineInfoArea.InfoAreaId);

                AureaColor defaultColor = null;
                if (!string.IsNullOrEmpty(timelineSearch.TimelineInfoArea.ColorString))
                {
                    defaultColor = AureaColor.ColorWithString(timelineSearch.TimelineInfoArea.ColorString);
                }

                if (defaultColor == null)
                {
                    defaultColor = AureaColor.ColorWithString(expand.ColorKey);
                }

                for (int i = 0; i < rowCount; i++)
                {
                    UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i);
                    if (resultCondition != null && !resultCondition.Check(row))
                    {
                        continue;
                    }

                    ConfigTimelineCriteria matchingCriteria = timelineSearch.MatchingCriteriaForRow(row);
                    AureaColor             color            = null;
                    if (matchingCriteria.Setting1 != null)
                    {
                        color = AureaColor.ColorWithString(matchingCriteria.Setting1);
                    }

                    if (color == null)
                    {
                        color = defaultColor;
                    }

                    ICalendarItem calendarItem = new ResultRowCalendarItem(row, resultContext, new RecordIdentifier(row.RootRecordIdentification), tableCaption, tableCaptionResultFieldMap, null, color);
                    calendarItem.GoToAction = goToAction;
                    calendarItems.Add(calendarItem);
                }
            }

            if (this.fromDate != null && this.toDate != null && this.CalendarPage.IncludeSystemCalendar)
            {
#if PORTING
                ArrayList localCalendarItems = ResultRowCalendarItem.EventsFromLocalCalendarFromToSearchTextCalenderIdentifiers(this.fromDate, this.toDate, null, null);
                if (localCalendarItems.Count)
                {
                    calendarItems.AddRange(localCalendarItems);
                }
#endif
            }

            return(calendarItems);
        }