Exemplo n.º 1
0
        public string Render(object viewModel, string settingType)
        {
            var           setting = UISettings.Current.Items[settingType] as UISetting;
            StringBuilder sb      = new StringBuilder();

            if (setting != null)
            {
                sb.Append(setting.ContentHeader);
            }
            if (!string.IsNullOrEmpty(ContentHeader))
            {
                sb.Append(ContentHeader.ReplaceContextParameters(viewModel, viewModel));
            }
            Render(sb, viewModel);
            if (!string.IsNullOrEmpty(ContentFooter))
            {
                sb.Append(ContentFooter.ReplaceContextParameters(viewModel, viewModel));
            }
            if (setting != null)
            {
                sb.Append(setting.ContentFooter);
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        public override void OnExecute(ICommandContext context, CommandConfig config, CommandResult result)
        {
            var viewResult = result as ExtendedActionResult;

            #region 创建ReportViewer

            ReportViewerSetting reportViewer = new ReportViewerSetting
            {
                DataSources = new List <ReportDataSource>(),
                Parameters  = new List <ReportParameter>()
            };
            reportViewer.ReportPath = ReportPath;

            DataSources.ForEach(p =>
            {
                var pValue = p.GetValue(context);
                if (pValue == null)
                {
                    throw new Exception(string.Format("参数[{0}]不能为空", p.Name));
                }
                reportViewer.DataSources.Add(new ReportDataSource(p.Name, pValue));
            });

            Parameters.ForEach(p =>
            {
                var pValue = p.GetValue(context);
                if (pValue == null)
                {
                    throw new Exception(string.Format("参数[{0}]不能为空", p.Name));
                }
                reportViewer.Parameters.Add(new ReportParameter(p.Name, pValue.ToString()));
            });

            reportViewer.ContentHeader = string.IsNullOrEmpty(ContentHeader) ? "" :
                                         ContentHeader.ReplaceContextParameters(context, context);

            reportViewer.ContentFooter = string.IsNullOrEmpty(ContentFooter) ? "" :
                                         ContentFooter.ReplaceContextParameters(context, context);
            #endregion

            string id = Guid.NewGuid().ToString();
            ReportViewers.Add(id, reportViewer);
            viewResult.ActionResult = ReportViewers.Redirect(id, ReportViewerUrl);

            result.End(NextCommand);
            context.Execute(NextCommand);
        }