.repx模板参数填充

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<br>引用dll<br>DevExpress.Printing.v17.1.Core.dll<br>DevExpress.XtraReports.v17.1.dll<br><br><br>public void Print(PaperKind PagerKind, ReportModel rm, string fileName)
{
    XtraReport r = new XtraReport();
    string ls_temp = DirFileHelper.GetAbsolutePath(rm.templateName) ;//模板路径
    if (!File.Exists(ls_temp))
    {
        //MessageBox.Show("未找到模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }
    r.LoadLayout(ls_temp);
    r.DataAdapter = null;
    r.DataMember = null;
    r.PrintingSystem.ShowMarginsWarning = false;
    r.PrintingSystem.ShowPrintStatusDialog = false;
    r.ExportOptions.Xls.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text;
    r.ExportOptions.Xlsx.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text;
    r.DataSource = rm.List_Data;//明细数据
    r.PrintingSystem.PageSettings.PaperKind = PagerKind;
    r.PaperKind = PagerKind;//纸张大小
    #region 绑定参数<br>            if (rm.BaseParamter_DT != null && rm.BaseParamter_DT.Rows.Count > 0)//主表数据
    {
        for (int i = 0; i < rm.BaseParamter_DT.Columns.Count; i++)
        {
            if (r.Parameters[rm.BaseParamter_DT.Columns[i].ColumnName] == null)
            {
                continue;
            }
            try
            {
                r.Parameters[rm.BaseParamter_DT.Columns[i].ColumnName].Value
                    = rm.BaseParamter_DT.Rows[0][i] == null ? "" : rm.BaseParamter_DT.Rows[0][i];
            }
            catch (Exception ex)
            {
                // MessageBox.Show(ex.Message);
            }
        }
    }
    foreach (KeyValuePair<string, object> item_Ext in rm.BaseParamter_Ext)
    {
        if (r.Parameters[item_Ext.Key] == null)
            continue;
        r.Parameters[item_Ext.Key].Value = item_Ext.Value;
    }
    r.CreateDocument();
    #endregion
 
    #region 根据控件名绑定数据
    if (!rm.BandDataByControlName.IsNullOrEmpty())
    {
        foreach (var item_control in rm.BandDataByControlName)
        {
            var ctl = r.FindControl(item_control.Key, true);
            if (ctl != null)
            {
                if (ctl is DevExpress.XtraReports.UI.XRCheckBox)
                {
                    ((ctl as DevExpress.XtraReports.UI.XRCheckBox).Checked) = item_control.Value.IsTrue();
                }
                else
                {
                    ctl.Text = item_control.Value.Cast<string>();
                }
            }
        }
    }
    #endregion
 
    #region 绑定复选框
    if (rm.BandDataForCheckBox != null && rm.BandDataForCheckBox.Length > 0)
    {
        var val = rm.BandDataForCheckBox.Split('|');
        string[] val_key = null;
        foreach (var item_control in val)
        {
            val_key = item_control.Split(':');
            dynamic ctl = r.FindControl(val_key[0], true);
            if (ctl != null)
            {
                if (ctl is DevExpress.XtraReports.UI.XRCheckBox)
                {
                    var param = new DevExpress.XtraReports.Parameters.Parameter();
                    param.Type = typeof(bool);
                    param.Value = val_key[1].IsTrue();
                    param.Name = val_key[0];
                    param.Visible = false;
                    r.Parameters.Add(param);
                    var bind = new XRBinding(param, "Checked", null);
                    ctl.DataBindings.Add(bind);
                }
            }
        }
    }
    #endregion
    string virtualPath = $"{DateTime.Now.Year.ToString()}/{DateTime.Now.Month.ToString()}/{DateTime.Now.ToString("yyyyMMddHHmmss")}_{fileName}";
    string fullFileName = $"{Config.GetValue("AnnexesFile")}/{virtualPath}";//保存路径
    r.ExportToImage(fullFileName);//保存为图片
}

posted on   zhusk  阅读(396)  评论(0编辑  收藏  举报

编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· 程序员常用高效实用工具推荐,办公效率提升利器!
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 【译】WinForms:分析一下(我用 Visual Basic 写的)
点击右上角即可分享
微信分享提示