コード例 #1
0
        public static ReportConditionDef AddCondition(this ReportDef def, Guid leftSourceId, Guid leftAttrId, CompareOperation condition, ReportConditionDefType type = ReportConditionDefType.Param, string caption = null)
        {
            Check(def);
            var attrDef = CheckSourceAttribute(def, leftSourceId, leftAttrId);
            var s       = !String.IsNullOrEmpty(caption)
                ? caption
                : attrDef is AttrDef
                    ? ((AttrDef)attrDef).Caption ?? ((AttrDef)attrDef).Name
                    : ((ReportSourceSystemAttributeDef)attrDef).Caption;

            var rightPart = (type == ReportConditionDefType.Param)
                ? (ReportConditionRightPartDef) new ReportConditionRightParamDef {
                Caption = s
            }
                : new ReportConditionRightAttributeDef {
                Attribute = new ReportAttributeDef()
            };

            var conditionDef = new ReportConditionDef
            {
                Id            = Guid.NewGuid(),
                Operation     = ExpressionOperation.And,
                LeftAttribute = new ReportAttributeDef
                {
                    SourceId    = leftSourceId,
                    AttributeId = leftAttrId
                },
                Condition = condition,
                RightPart = rightPart
            };

            def.Conditions.Add(conditionDef);

            return(conditionDef);
        }
コード例 #2
0
        public static ReportConditionDef AddAttributeCondition(this ReportDef def, Guid leftSourceId, Guid leftAttrId,
                                                               CompareOperation condition, Guid rightSourceId, Guid rightAttrId)
        {
            Check(def);
            CheckSourceAttribute(def, leftSourceId, leftAttrId);
            CheckSourceAttribute(def, rightSourceId, rightAttrId);

            var conditionId  = Guid.NewGuid();
            var conditionDef = new ReportConditionDef
            {
                Id            = conditionId,
                Operation     = ExpressionOperation.And,
                LeftAttribute = new ReportAttributeDef {
                    SourceId = leftSourceId, AttributeId = leftAttrId
                },
                Condition = condition,
                RightPart = new ReportConditionRightAttributeDef
                {
                    Attribute = new ReportAttributeDef
                    {
                        SourceId    = rightSourceId,
                        AttributeId = rightAttrId
                    }
                }
            };

            def.Conditions.Add(conditionDef);
            return(conditionDef);
        }
コード例 #3
0
 public static void RemoveColumn(this ReportDef def, Guid sourceId, Guid attrDefId)
 {
     Check(def);
     def.Columns.RemoveAll(
         c =>
         c is ReportAttributeColumnDef && ((ReportAttributeColumnDef)c).Attribute != null &&
         ((ReportAttributeColumnDef)c).Attribute.SourceId == sourceId &&
         ((ReportAttributeColumnDef)c).Attribute.AttributeId == attrDefId);
 }
コード例 #4
0
        public static object GetAttribute(this ReportDef def, ReportAttributeDef attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            return(CheckSourceAttribute(def, attribute.SourceId, attribute.AttributeId));
        }
コード例 #5
0
        public static ReportConditionItemDef GetConditionDef(this ReportDef def, Guid conditionId)
        {
            var condition = FindConditionDef(def, conditionId) as ReportConditionDef;

            if (condition == null)
            {
                throw new ApplicationException("Условие не найдено!");
            }
            return(condition);
        }
コード例 #6
0
        public static ReportSourceDef GetSourceDef(this ReportDef def, Guid sourceId)
        {
            var sourceDef = def.Sources.FirstOrDefault(sd => sd.Id == sourceId);

            if (sourceDef == null)
            {
                throw new ApplicationException("Источник данных не найден!");
            }

            return(sourceDef);
        }
コード例 #7
0
        public static ReportExpConditionDef AddExpConditionDef(this ReportDef def)
        {
            Check(def);
            var conditionId  = Guid.NewGuid();
            var conditionDef = new ReportExpConditionDef
            {
                Id         = conditionId,
                Operation  = ExpressionOperation.And,
                Conditions = new List <ReportConditionItemDef>()
            };

            def.Conditions.Add(conditionDef);
            return(conditionDef);
        }
コード例 #8
0
        public static ReportConditionDef AssignConditionRightVariable(this ReportDef def, Guid conditionId, string systemName)
        {
            Check(def);
            var condition = FindConditionDef(def, conditionId) as ReportConditionDef;

            if (condition == null)
            {
                throw new ApplicationException("Условие не найдено!");
            }

            condition.RightPart = new ReportConditionRightVariableDef
            {
                //Caption = caption,
                SystemValue = systemName
            };

            return(condition);
        }
コード例 #9
0
        public static void RemoveSource(this ReportDef def, Guid sourceId)
        {
            Check(def);
            if (def.SourceId == sourceId)
            {
                throw new ApplicationException("Не могу удалить базовый источник из отчета!");
            }

            def.Columns.RemoveAll(
                c =>
                c is ReportAttributeColumnDef && ((ReportAttributeColumnDef)c).Attribute != null &&
                ((ReportAttributeColumnDef)c).Attribute.SourceId == sourceId);

            def.Conditions.RemoveAll(c => ConditionHasSource(c, sourceId));

            def.Joins.RemoveAll(j => j.MasterId == sourceId || j.SourceId == sourceId);
            def.Sources.RemoveAll(s => s.Id == sourceId);
        }
コード例 #10
0
        public static ReportConditionDef AssignConditionRightParam(this ReportDef def, Guid conditionId, string caption, object value)
        {
            Check(def);
            var condition = FindConditionDef(def, conditionId) as ReportConditionDef;

            if (condition == null)
            {
                throw new ApplicationException("Условие не найдено!");
            }

            condition.RightPart = new ReportConditionRightParamDef
            {
                Caption = caption,
                Value   = value
            };

            return(condition);
        }
コード例 #11
0
        public static ReportConditionDef AssignConditionRightAttribute(this ReportDef def, Guid conditionId, Guid sourceId, Guid attrDefId)
        {
            Check(def);
            var condition = FindConditionDef(def, conditionId) as ReportConditionDef;

            if (condition == null)
            {
                throw new ApplicationException("Условие не найдено!");
            }
            CheckSourceAttribute(def, sourceId, attrDefId);

            condition.RightPart = new ReportConditionRightAttributeDef
            {
                Attribute = new ReportAttributeDef
                {
                    SourceId    = sourceId,
                    AttributeId = attrDefId
                }
            };

            return(condition);
        }
コード例 #12
0
        public static object CheckSourceAttribute(this ReportDef def, Guid sourceId, Guid attrDefId)
        {
            var sourceDef = GetSourceDef(def, sourceId);

            if (sourceDef.DocDef == null || sourceDef.DocDef.Attributes == null)
            {
                throw new ApplicationException("Ошибка в источнике данных!");
            }

            object attr = sourceDef.DocDef.Attributes.FirstOrDefault(a => a.Id == attrDefId);

            if (attr == null && sourceDef.Attributes != null)
            {
                attr = sourceDef.Attributes.FirstOrDefault(a => a.Id == attrDefId);
            }

            if (attr == null)
            {
                throw new ApplicationException(String.Format("Атрибут \"{0}\" не найден в источнике данных!", attrDefId));
            }

            return(attr);
        }
コード例 #13
0
 public static void Check(this ReportDef def)
 {
     if (def == null)
     {
         throw new ApplicationException("Отчет не определен!");
     }
     if (def.Sources == null)
     {
         def.Sources = new List <ReportSourceDef>();
     }
     if (def.Columns == null)
     {
         def.Columns = new List <ReportColumnDef>();
     }
     if (def.Joins == null)
     {
         def.Joins = new List <ReportSourceJoinDef>();
     }
     if (def.Conditions == null)
     {
         def.Conditions = new List <ReportConditionItemDef>();
     }
 }
コード例 #14
0
        public static ReportAttributeColumnDef AddColumn(this ReportDef def, Guid sourceId, Guid attrDefId, string caption = null)
        {
            Check(def);
            var attr = CheckSourceAttribute(def, sourceId, attrDefId);

            var attrDef = new ReportAttributeDef {
                SourceId = sourceId, AttributeId = attrDefId
            };
            var s = !String.IsNullOrEmpty(caption)
                ? caption
                : attr is AttrDef
                    ? ((AttrDef)attr).Caption ?? ((AttrDef)attr).Name
                    : ((ReportSourceSystemAttributeDef)attr).Caption;
            var columnDef = new ReportAttributeColumnDef
            {
                Attribute = attrDef,
                Caption   = s,
                Visible   = true,
                Id        = Guid.NewGuid()
            };

            def.Columns.Add(columnDef);
            return(columnDef);
        }
コード例 #15
0
        public static ReportConditionDef AddParamCondition(this ReportDef def, Guid sourceId, Guid attrDefId, CompareOperation condition, object value, string paramCaption)
        {
            Check(def);
            GetSourceDef(def, sourceId);

            var conditionId  = Guid.NewGuid();
            var conditionDef = new ReportConditionDef
            {
                Id            = conditionId,
                Operation     = ExpressionOperation.And,
                LeftAttribute = new ReportAttributeDef {
                    SourceId = sourceId, AttributeId = attrDefId
                },
                Condition = condition,
                RightPart = new ReportConditionRightParamDef
                {
                    Caption = paramCaption,
                    Value   = value
                }
            };

            def.Conditions.Add(conditionDef);
            return(conditionDef);
        }
コード例 #16
0
        public static bool HasCrossGrouping(this ReportDef def)
        {
            Check(def);

            return(def.Columns.OfType <ReportAttributeColumnDef>().Any(c => c.Grouping == ReportColumnGroupingType.CrossGroup));
        }
コード例 #17
0
        public static ReportSourceJoinDef JoinDocDefSource(this ReportDef def, Guid masterSourceId, DocDef docDef,
                                                           Guid attrDefId)
        {
            Check(def);
            var masterSourceDef = GetSourceDef(def, masterSourceId);
            var docDefCount     = def.Sources.Count(s => s.DocDef.Id == docDef.Id);

            var jointSourceId  = Guid.NewGuid();
            var jointSourceDef = new ReportSourceDef
            {
                Id         = jointSourceId,
                DocDef     = docDef,
                Caption    = docDef.Caption + (docDefCount > 0 ? (docDefCount + 1).ToString() : String.Empty),
                Attributes = new List <ReportSourceSystemAttributeDef>()
            };

            jointSourceDef.Attributes.Add(new ReportSourceSystemAttributeDef
            {
                Id      = Guid.NewGuid(),
                Ident   = SystemIdent.Created,
                Caption = "Дата создания документа"
            });
            jointSourceDef.Attributes.Add(new ReportSourceSystemAttributeDef
            {
                Id      = Guid.NewGuid(),
                Ident   = SystemIdent.Modified,
                Caption = "Дата изменения документа"
            });
            jointSourceDef.Attributes.Add(new ReportSourceSystemAttributeDef
            {
                Id      = Guid.NewGuid(),
                Ident   = SystemIdent.State,
                Caption = "Статус документа"
            });
            jointSourceDef.Attributes.Add(new ReportSourceSystemAttributeDef
            {
                Id      = Guid.NewGuid(),
                Ident   = SystemIdent.StateDate,
                Caption = "Дата установки статуса документа"
            });

            def.Sources.Add(jointSourceDef);

            var jointAttrId  = Guid.NewGuid();
            var attr         = masterSourceDef.DocDef.Attributes.FirstOrDefault(a => a.Id == attrDefId);
            var jointAttrDef = attr != null
                ? new ReportAttributeDef {
                Id = jointAttrId, SourceId = masterSourceId, AttributeId = attrDefId
            }
                : new ReportAttributeDef {
                Id = jointAttrId, SourceId = jointSourceId, AttributeId = attrDefId
            };

            var joinDef =
                new ReportSourceJoinDef
            {
                Id            = Guid.NewGuid(),
                JoinAttribute = jointAttrDef,
                JoinType      = SqlSourceJoinType.Inner,
                MasterId      = masterSourceId,
                SourceId      = jointSourceId
            };

            def.Joins.Add(joinDef);

            return(joinDef);
        }
コード例 #18
0
 public static ReportConditionItemDef FindConditionDef(this ReportDef def, Guid conditionId)
 {
     Check(def);
     return(def.Conditions.Select(c => FindConditionById(c, conditionId)).FirstOrDefault(c => c != null));
 }
コード例 #19
0
 public static void RemoveColumn(this ReportDef def, Guid columnId)
 {
     Check(def);
     def.Columns.RemoveAll(c => c.Id == columnId);
 }
コード例 #20
0
 public static void RemoveCondition(this ReportDef def, Guid conditionId)
 {
     Check(def);
     RemoveConditionIn(def.Conditions, conditionId);
 }