Exemplo n.º 1
0
        /// <summary>
        /// 初始化报表模板
        /// </summary>
        /// <returns></returns>
        internal async Task <bool> InitTemplate()
        {
            try
            {
                // 报表设计时始终不缓存模板!
                string define = await ReadTemplate();

                Root = await AtRpt.DeserializeTemplate(define);

                AttachRootEvent();
                return(true);
            }
            catch { }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 导入报表模板
        /// </summary>
        /// <param name="p_define"></param>
        /// <returns></returns>
        internal async Task ImportTemplate(string p_define)
        {
            var old = Root;

            if (old != null)
            {
                DetachRootEvent();
            }

            Root = await AtRpt.DeserializeTemplate(p_define);

            AttachRootEvent();
            TemplateChanged?.Invoke(this, new TemplateChangedArgs {
                NewRoot = Root, OldRoot = old
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// 初始化模板、脚本、参数默认值
        /// </summary>
        /// <returns></returns>
        internal async Task <bool> Init()
        {
            if (_inited)
            {
                return(Root != null);
            }

            // 加载模板
            _inited = true;
            if (Root == null)
            {
                if (string.IsNullOrEmpty(Name))
                {
                    Kit.Warn("未提供报表模板名称!");
                }
                else if (CacheTemplate && _tempCache.TryGetValue(Name, out var temp))
                {
                    // 允许缓存先查找缓存
                    // 通过名称加载模板,代码中写名称可读性比ID高!!!
                    Root = temp;
                }
                else
                {
                    try
                    {
                        string define = await ReadTemplate();

                        Root = await AtRpt.DeserializeTemplate(define);

                        if (CacheTemplate)
                        {
                            // 允许缓存,名称作为键
                            _tempCache[Name] = Root;
                        }
                    }
                    catch (Exception ex)
                    {
                        Kit.Warn("加载报表模板时异常!\r\n" + ex.Message);
                    }
                }

                if (Root == null)
                {
                    return(false);
                }
            }

            // 脚本对象
            if (!string.IsNullOrEmpty(Root.ViewSetting.Script))
            {
                Type type = Type.GetType(Root.ViewSetting.Script);
                if (type == null)
                {
                    Kit.Warn($"缺少脚本类型【{Root.ViewSetting.Script}】");
                }
                else
                {
                    ScriptObj = (RptScript)Activator.CreateInstance(type);
                    if (ScriptObj == null)
                    {
                        Kit.Warn($"脚本类型【{Root.ViewSetting.Script}】需继承RptScript");
                    }
                }
            }

            // 根据参数默认值创建初始查询参数(自动查询时用)
            if (Root.ViewSetting.AutoQuery &&
                Params == null &&
                Root.Params.Data.Count > 0)
            {
                Params = Root.Params.BuildInitDict();
            }
            return(true);
        }