ReportPrinter.cs
12.2 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using System.Drawing.Printing;
using System.IO;
using DevExpress.XtraPrinting;
using Newtonsoft.Json.Linq;
using SqlSugar;
namespace PDFExportOpri_CLI.Modules.PdfExport
{
public partial class ReportPrinter : DevExpress.XtraReports.UI.XtraReport
{
public DataSet ds = new DataSet();
public JArray jPartial = null;
public void LoadModel(string file)
{
this.LoadLayout(file);
this.Landscape = false;
this.PaperKind = PaperKind.A4;
}
public void LoadData(SqlSugarClient client,string id)
{
DataTable dt1 = client.Ado.GetDataTable(@$"SELECT
FROM_UNIXTIME( m.firstinspectiontime, '%Y年%m月%d日' ) years,
p1.NAME pf1name, p2.NAME pf2name, p3.NAME pf3name, p4.NAME pf4name, p5.NAME pf5name, p6.NAME pf6name, p7.NAME pf7name,
c1.NAME cf1name, c2.NAME cf2name, c3.NAME cf3name, o1.NAME ot1name, o2.NAME ot2name, o3.NAME ot3name, o4.NAME ot4name,
n.NAME axlename, o.NAME antiexplosionname, b.email reportusername, c.`name` categoryname, d.`name` classname, e.NAME testname,
g.NAME areaname, h.NAME provincename, i.`name` cityname, j.NAME countyname, k.NAME enterprisetypename, l.`name` issapname,
a.* , f.*, m.*
FROM
( SELECT * FROM opri_inspection WHERE id = {id} ) a
LEFT JOIN mt_user b ON ( a.reportuserid = b.id )
LEFT JOIN opri_dmb c ON ( a.categorycode = c.`code` AND c.type = 'categorytype' )
LEFT JOIN opri_dmb d ON ( a.classcode = d.`code` AND d.type = 'classtype' )
LEFT JOIN opri_dmb e ON ( a.testcode = e.`code` AND e.type = 'testtype' )
LEFT JOIN opri_client f ON ( a.clientid = f.id )
LEFT JOIN opri_dmb g ON ( f.areacode = g.`code` AND g.type = 'areatype' )
LEFT JOIN sys_xtqyb h ON ( f.provincecode = h.`code` )
LEFT JOIN sys_xtqyb i ON ( f.citycode = i.`code` )
LEFT JOIN sys_xtqyb j ON ( f.countycode = j.`code` )
LEFT JOIN opri_dmb k ON ( f.enterprisetypecode = k.`code` AND k.type = 'enterprisetype' )
LEFT JOIN opri_dmb l ON ( f.issapcode = l.`code` AND l.type = 'issaptype' )
LEFT JOIN opri_product m ON ( a.productid = m.id )
LEFT JOIN opri_dmb n ON ( m.axlecode = n.`code` AND n.type = 'axletype' )
LEFT JOIN opri_dmb o ON ( m.antiexplosioncode = o.`code` AND o.type = 'antiexplosiontype' )
LEFT JOIN opri_dmb p1 ON ( a.pf1code = p1.`code` AND p1.type = 'pf1type' )
LEFT JOIN opri_dmb p2 ON ( a.pf2code = p2.`code` AND p2.type = 'pf2type' )
LEFT JOIN opri_dmb p3 ON ( a.pf3code = p3.`code` AND p3.type = 'pf3type' )
LEFT JOIN opri_dmb p4 ON ( a.pf4code = p4.`code` AND p4.type = 'pf4type' )
LEFT JOIN opri_dmb p5 ON ( a.pf5code = p5.`code` AND p5.type = 'pf5type' )
LEFT JOIN opri_dmb p6 ON ( a.pf6code = p6.`code` AND p6.type = 'pf6type' )
LEFT JOIN opri_dmb p7 ON ( a.pf7code = p7.`code` AND p7.type = 'pf7type' )
LEFT JOIN opri_dmb c1 ON ( a.cf1code = c1.`code` AND c1.type = 'cf1type' )
LEFT JOIN opri_dmb c2 ON ( a.cf2code = c2.`code` AND c2.type = 'cf2type' )
LEFT JOIN opri_dmb c3 ON ( a.cf3code = c3.`code` AND c3.type = 'cf3type' )
LEFT JOIN opri_dmb o1 ON ( a.ot1code = o1.`code` AND o1.type = 'ot1type' )
LEFT JOIN opri_dmb o2 ON ( a.ot2code = o2.`code` AND o2.type = 'ot2type' )
LEFT JOIN opri_dmb o3 ON ( a.ot3code = o3.`code` AND o3.type = 'ot3type' )
LEFT JOIN opri_dmb o4 ON ( a.ot4code = o4.`code` AND o4.type = 'ot4type' )");
DataTable dt_new = dt1.Clone();
foreach (DataRow rowInsert in dt1.Rows)
{
dt_new.Rows.Add(rowInsert.ItemArray);
}
dt_new.TableName = "dt1";
ds.Tables.Add(dt_new);
DataTable dt2 = client.Ado.GetDataTable(@$"select a.inspectionid,a.proposal,b.name sensorname,c.name sensorcablename,
d.name sensorconnectorname,e.name elec1name,f.name elec2name,g.name elec3name,
h.name elec4name,i.name elec5name,j.name elec6name
from (select * from opri_inspection_complete where inspectionid = {id}) a
left join opri_dmb b on (a.sensorcode = b.code and b.type = 'sensortype')
left join opri_dmb c on (a.sensorcablecode = c.code and c.type = 'sensorcabletype')
left join opri_dmb d on (a.sensorconnectorcode = d.code and d.type = 'sensorconnectortype')
left join opri_dmb e on (a.elec1code = e.code and e.type = 'elec1type')
left join opri_dmb f on (a.elec2code = f.code and f.type = 'elec2type')
left join opri_dmb g on (a.elec3code = g.code and g.type = 'elec3type')
left join opri_dmb h on (a.elec4code = h.code and h.type = 'elec4type')
left join opri_dmb i on (a.elec5code = i.code and i.type = 'elec5type')
left join opri_dmb j on (a.elec6code = j.code and j.type = 'elec6type')");
DataTable dt_new2 = dt2.Clone();
foreach (DataRow rowInsert in dt2.Rows)
{
dt_new2.Rows.Add(rowInsert.ItemArray);
}
dt_new2.TableName = "dt2";
ds.Tables.Add(dt_new2);
DataTable dt3 = client.Ado.GetDataTable(@$"select a.id id,a.remark,a.`group` group_tmp,b.name weightnumber,c.name loadnumber
from (select id,weightnumbercode,loadnumbercode,remark,`group` from opri_inspection_partialload where inspectionid = {id}) a
left join opri_dmb b on (a.weightnumbercode = b.code and b.type = 'weightnumbertype')
left join opri_dmb c on (a.loadnumbercode = c.code and c.type = 'loadnumbertype')");
if (dt3.Rows.Count > 0)
{
jPartial = JArray.Parse(dt3.Rows[0]["group_tmp"].ToString());
}
DataTable dt_new3 = dt3.Clone();
foreach (DataRow rowInsert in dt3.Rows)
{
dt_new3.Rows.Add(rowInsert.ItemArray);
}
dt_new3.TableName = "dt3";
ds.Tables.Add(dt_new3);
DataTable dt4 = client.Ado.GetDataTable(@$"select id, remark,`group` group_tmp from opri_inspection_linear where inspectionid = {id}");
DataTable dt4_1 = new DataTable();
dt4_1.Columns.Add("no", typeof(string));
dt4_1.Columns.Add("mainid", typeof(int));
dt4_1.Columns.Add("testpoint", typeof(string));
dt4_1.Columns.Add("nominalvalue", typeof(string));
dt4_1.Columns.Add("showvalue", typeof(string));
dt4_1.Columns.Add("showerror", typeof(string));
dt4_1.Columns.Add("maxerror", typeof(string));
dt4_1.Columns.Add("conformcode", typeof(string));
dt4_1.Columns.Add("conformname", typeof(string));
if (dt4.Rows.Count > 0)
{
JArray jTmp = JArray.Parse(dt4.Rows[0]["group_tmp"].ToString());
int idx = 0;
foreach (JToken item in jTmp)
{
idx++;
DataRow newRow = dt4_1.NewRow();
newRow["mainid"] = Convert.ToInt32(dt4.Rows[0]["id"]);
newRow["no"] = idx.ToString();
newRow["testpoint"] = item["testpoint"].ToString();
newRow["nominalvalue"] = item["nominalvalue"].ToString();
newRow["showvalue"] = item["showvalue"].ToString();
newRow["showerror"] = item["showerror"].ToString();
newRow["maxerror"] = item["maxerror"].ToString();
newRow["conformcode"] = item["conformcode"].ToString();
newRow["conformname"] = item["conformname"].ToString();
dt4_1.Rows.Add(newRow);
}
}
DataTable dt_new4 = dt4.Clone();
foreach (DataRow rowInsert in dt4.Rows)
{
dt_new4.Rows.Add(rowInsert.ItemArray);
}
DataTable dt_new4_1 = dt4_1.Clone();
foreach (DataRow rowInsert in dt4_1.Rows)
{
dt_new4_1.Rows.Add(rowInsert.ItemArray);
}
dt_new4.TableName = "dt4";
dt_new4_1.TableName = "dt4_1";
ds.Tables.Add(dt_new4_1);
ds.Tables.Add(dt_new4);
ds.Relations.Add(new DataRelation("group2", ds.Tables["dt4"].Columns["id"], ds.Tables["dt4_1"].Columns["mainid"]));
DataTable dt5 = client.Ado.GetDataTable(@$"select id, remark,`data` data_tmp from opri_inspection_repeat where inspectionid = {id}");
DataTable dt5_1 = new DataTable();
dt5_1.Columns.Add("no", typeof(string));
dt5_1.Columns.Add("mainid", typeof(int));
dt5_1.Columns.Add("timescode", typeof(string));
dt5_1.Columns.Add("timesname", typeof(string));
dt5_1.Columns.Add("repeatloadcode", typeof(string));
dt5_1.Columns.Add("repeatloadname", typeof(string));
dt5_1.Columns.Add("fillcode", typeof(string));
dt5_1.Columns.Add("fillname", typeof(string));
dt5_1.Columns.Add("weight", typeof(string));
dt5_1.Columns.Add("repeaterror", typeof(string));
dt5_1.Columns.Add("maxerror", typeof(string));
dt5_1.Columns.Add("conformcode", typeof(string));
dt5_1.Columns.Add("conformname", typeof(string));
DataTable dt5_1_1 = new DataTable();
dt5_1_1.Columns.Add("no", typeof(string));
dt5_1_1.Columns.Add("mainid", typeof(string));
dt5_1_1.Columns.Add("testreading", typeof(string));
if (dt5.Rows.Count > 0)
{
JArray jTmp = JArray.Parse(dt5.Rows[0]["data_tmp"].ToString());
int idx = 0;
foreach (JToken item in jTmp)
{
idx++;
DataRow newRow = dt5_1.NewRow();
newRow["mainid"] = Convert.ToInt32(dt5.Rows[0]["id"]);
newRow["no"] = "重复性测试组"+idx.ToString();
newRow["timescode"] = item["timescode"]?.ToString();
newRow["timesname"] = item["timesname"]?.ToString();
newRow["repeatloadcode"] = item["repeatloadcode"]?.ToString();
newRow["repeatloadname"] = item["repeatloadname"]?.ToString();
newRow["fillcode"] = item["fillcode"]?.ToString();
newRow["fillname"] = item["fillname"]?.ToString();
newRow["weight"] = item["weight"]?.ToString();
newRow["repeaterror"] = item["repeaterror"]?.ToString();
newRow["maxerror"] = item["maxerror"]?.ToString();
newRow["conformcode"] = item["conformcode"]?.ToString();
newRow["conformname"] = item["conformname"]?.ToString();
dt5_1.Rows.Add(newRow);
JArray groupArray = (JArray) item["group"];
int idx2 = 0;
foreach (JToken groupItem in groupArray)
{
idx2++;
newRow = dt5_1_1.NewRow();
newRow["mainid"] = "重复性测试组" + idx.ToString();
newRow["no"] = $"第{idx2}次";
newRow["testreading"] = groupItem["testreading"];
dt5_1_1.Rows.Add(newRow);
}
}
}
DataTable dt_new5 = dt5.Clone();
foreach (DataRow rowInsert in dt5.Rows)
{
dt_new5.Rows.Add(rowInsert.ItemArray);
}
DataTable dt_new5_1 = dt5_1.Clone();
foreach (DataRow rowInsert in dt5_1.Rows)
{
dt_new5_1.Rows.Add(rowInsert.ItemArray);
}
DataTable dt_new5_1_1 = dt5_1_1.Clone();
foreach (DataRow rowInsert in dt5_1_1.Rows)
{
dt_new5_1_1.Rows.Add(rowInsert.ItemArray);
}
dt_new5.TableName = "dt5";
dt_new5_1.TableName = "dt5_1";
dt_new5_1_1.TableName = "dt5_1_1";
ds.Tables.Add(dt_new5);
ds.Tables.Add(dt_new5_1);
ds.Tables.Add(dt_new5_1_1);
ds.Relations.Add(new DataRelation("data", ds.Tables["dt5"].Columns["id"], ds.Tables["dt5_1"].Columns["mainid"]));
ds.Relations.Add(new DataRelation("group", ds.Tables["dt5_1"].Columns["no"], ds.Tables["dt5_1_1"].Columns["mainid"]));
this.DataSource = ds;
}
}
}