Program.cs
13.4 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
using System;
using System.Collections;
using System.IO;
using DevExpress.DataAccess.Native.Json;
using DevExpress.DataProcessing;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Drawing;
using DevExpress.XtraReports.Security;
using DevExpress.XtraReports.UI;
using Microsoft.Extensions.Configuration;
using PDFExportOpri_CLI.Modules.PdfExport;
using SqlSugar;
namespace PDFExportOpri_CLI
{
class Program
{
static void Main(string[] args)
{
try
{
if (args.Length < 2)
{
Console.WriteLine("Invalid Arguments...");
Environment.Exit(1);
}
ScriptPermissionManager.GlobalInstance = new ScriptPermissionManager(ExecutionMode.Unrestricted);
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
.AddJsonFile(AppDomain.CurrentDomain.BaseDirectory + "./cli-appsettings.json", false)
.Build();
var outputPath = args[0];
var reportId = args[1];
if (Directory.Exists(outputPath))
{
if (File.Exists(outputPath + "export_" + reportId + ".pdf"))
File.Delete(outputPath + "export_" + reportId + ".pdf");
}
else
{
Directory.CreateDirectory(outputPath);
}
using (ReportPrinter rpt = new ReportPrinter())
{
rpt.LoadModel(AppDomain.CurrentDomain.BaseDirectory + "./ModelTemp/IVEH_APP.xml");
SqlSugarClient dbClient = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.MySql,
ConnectionString = "SERVER=" + configuration["Database:Host"] + ";"
+ "DATABASE=" + configuration["Database:Name"] + ";"
+ "UID=" + configuration["Database:Username"] + ";"
+ "PASSWORD=" + configuration["Database:Password"] + ";"
+ "PORT="+configuration["Database:Port"]+";"
});
rpt.LoadData(dbClient, reportId);
//偏载测试图片
int partialloadid = Convert.ToInt32(rpt.ds.Tables["dt1"].Rows[0]["partialloadid"]);
if (partialloadid != -1)
{
string weightNumber = rpt.ds.Tables["dt3"].Rows[0]["weightnumber"].ToString();
XRPictureBox p1 = (XRPictureBox)rpt.FindControl("pb_1", true);
if (p1 != null)
{
p1.ImageUrl = $"./bmp/fm{weightNumber}.jpg";
}
SetPartialItem(rpt);
}
SetImage(rpt);
SetRemark(rpt);
PdfExportOptions opt = rpt.ExportOptions.Pdf;
opt.ConvertImagesToJpeg = false;
opt.Compressed = true;
opt.ImageQuality = PdfJpegImageQuality.High;
rpt.ExportToPdf(outputPath + "export_" + reportId + ".pdf", opt);
}
}
catch (Exception ex)
{
while (ex.InnerException != null)
ex = ex.InnerException;
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
Environment.Exit(-1);
}
Environment.Exit(0);
}
private static void SetPartialItem(ReportPrinter rpt)
{
int loadNumber = Convert.ToInt32(rpt.ds.Tables["dt3"].Rows[0]["loadnumber"]);
int weightNumber = Convert.ToInt32(rpt.ds.Tables["dt3"].Rows[0]["weightnumber"]);
SetPartialRowUnvisiable(rpt, loadNumber);
SetPartialCellUnvisiable(rpt,loadNumber,weightNumber);
SetPartialValue(rpt,loadNumber,weightNumber);
}
private static void SetPartialRowUnvisiable(ReportPrinter rpt, int number)
{
for (int i = 5; i > number; i--)
{
rpt.FindControl($"tr{i}", true).Visible = false;
rpt.FindControl($"tr{i}_0_1", true).Visible = false;
rpt.FindControl($"tr{i}_0_2", true).Visible = false;
rpt.FindControl($"tr{i}_1", true).Visible = false;
rpt.FindControl($"tr{i}_2", true).Visible = false;
rpt.FindControl($"tr{i}_3", true).Visible = false;
rpt.FindControl($"tr{i}_4", true).Visible = false;
rpt.FindControl($"tr{i}_5", true).Visible = false;
rpt.FindControl($"tr{i}_6", true).Visible = false;
}
}
private static void SetPartialCellUnvisiable(ReportPrinter rpt,int loadNumber, int weightNumber)
{
int remainRow = Convert.ToInt32(Math.Ceiling((decimal)weightNumber / 3));
int maxCellNumber = remainRow * 3;
if (maxCellNumber > 16) maxCellNumber = 16;
for (int i = 1; i <= loadNumber; i++)
{
for (int j = 6; j > remainRow; j--)
{
rpt.FindControl($"tr{i}_{j}", true).Visible = false;
}
for (int j = maxCellNumber; j > weightNumber; j--)
{
rpt.FindControl($"tc{i}_{j}", true).Text = "";
rpt.FindControl($"caption_tc{i}_{j}", true).Text = "";
}
}
}
private static void SetPartialValue(ReportPrinter rpt, int loadNumber, int weightNumber)
{
for (int i = 1; i <= loadNumber; i++)
{
Newtonsoft.Json.Linq.JToken item = rpt.jPartial[i - 1];
string testweight = item["testweight"]?.ToString();
string loaderror = item["loaderror"]?.ToString();
string maxerror = item["maxerror"]?.ToString();
if (testweight != "") testweight += " kg";
if (loaderror != "") loaderror += " kg";
if (maxerror != "") maxerror += " kg";
rpt.FindControl($"tc{i}_zh",true).Text = testweight;
rpt.FindControl($"tc{i}_wc", true).Text = loaderror;
rpt.FindControl($"tc{i}_yc", true).Text = maxerror;
rpt.FindControl($"tc{i}_fh", true).Text = item["conformname"]?.ToString();
rpt.FindControl($"tc{i}_mx", true).Text = item["fillname"]?.ToString();
if (item["fillcode"]?.ToString() != "01")
{
for (int j = 1; j <= 6; j++)
{
rpt.FindControl($"tr{i}_{j}", true).Visible = false;
}
}
else
{
Newtonsoft.Json.Linq.JArray deviation = item["deviation"] as Newtonsoft.Json.Linq.JArray;
Newtonsoft.Json.Linq.JToken dItem = null;
for (int j = 1; j <= weightNumber; j++)
{
try
{
dItem = deviation[j - 1];
}
catch
{
dItem = null;
}
if (dItem != null)
{
string devString = dItem["deviation"]?.ToString();
if (devString != "") devString += " kg";
rpt.FindControl($"tc{i}_{j}", true).Text = devString;
}
}
}
}
}
private static void SetImage(ReportPrinter rpt)
{
ArrayList list = new ArrayList();
for (int i = 1; i < 7; i++)
{
string i1 = rpt.ds.Tables["dt1"].Rows[0]["i"+i].ToString().Replace("\"", "").Replace("[", "").Replace("]", "").Trim();
if (i1 != "")
{
string[] items = i1.Split(",");
foreach (string item in items)
{
ImageItemClass imageItem = new ImageItemClass();
switch (i)
{
case 1:
imageItem.groupName = "企业大门";
break;
case 2:
imageItem.groupName = "汽车衡全景";
break;
case 3:
imageItem.groupName = "基础引坡";
break;
case 4:
imageItem.groupName = "仪表近景";
break;
case 5:
imageItem.groupName = "传感器状况";
break;
case 6:
imageItem.groupName = "其他";
break;
}
imageItem.url = "http://image.mtmaster.release.360cbs.com/" + item;
list.Add(imageItem);
}
}
else
{
ImageItemClass imageItem = new ImageItemClass();
switch (i)
{
case 1:
imageItem.groupName = "企业大门";
break;
case 2:
imageItem.groupName = "汽车衡全景";
break;
case 3:
imageItem.groupName = "基础引坡";
break;
case 4:
imageItem.groupName = "仪表近景";
break;
case 5:
imageItem.groupName = "传感器状况";
break;
case 6:
imageItem.groupName = "其他";
break;
}
imageItem.url = $"./bmp/noimage.png";
imageItem.hasImage = false;
list.Add(imageItem);
}
}
int remainGroup = Convert.ToInt32(Math.Ceiling((decimal)list.Count / 6));
int maxRow = remainGroup * 3;
int remainRow = Convert.ToInt32(Math.Ceiling((decimal)list.Count / 2));
for (int i = 3; i > remainGroup; i--)
{
rpt.FindControl($"drp_{i}", true).Visible = false;
}
for (int i = maxRow; i > remainRow; i--)
{
rpt.FindControl($"p_{i}", true).Visible = false;
}
ImageItemClass myItem;
for (int i=1; i <= list.Count; i++)
{
XRPictureBox image = rpt.FindControl($"image_{i}", true) as XRPictureBox;
myItem = (ImageItemClass) list[i - 1];
image.ImageUrl = myItem.url;
if (!myItem.hasImage)
{
PaddingInfo padding = new PaddingInfo(96);
padding.All = 70;
image.Padding = padding;
}
rpt.FindControl($"imagecaption_{i}", true).Text = myItem.groupName;
}
}
private static void SetRemark(ReportPrinter rpt)
{
int completeid = Convert.ToInt32(rpt.ds.Tables["dt1"].Rows[0]["completeid"]);
int partialloadid = Convert.ToInt32(rpt.ds.Tables["dt1"].Rows[0]["partialloadid"]);
int linearid = Convert.ToInt32(rpt.ds.Tables["dt1"].Rows[0]["linearid"]);
int repeatid = Convert.ToInt32(rpt.ds.Tables["dt1"].Rows[0]["repeatid"]);
string remark_idx = "1";
if (completeid == -1)
{
rpt.FindControl("dr_complete", true).Visible = false;
}
else
{
remark_idx = "2";
}
if (partialloadid == -1)
{
rpt.FindControl("dr_partial", true).Visible = false;
}
else
{
remark_idx = "3";
}
if (linearid == -1)
{
rpt.FindControl("dr_linear", true).Visible = false;
}
else
{
remark_idx = "4";
}
if (repeatid == -1)
{
rpt.FindControl("dr_repeat", true).Visible = false;
}
else
{
remark_idx = "5";
}
rpt.FindControl("remark_"+remark_idx, true).Visible = true;
}
}
public class ImageItemClass
{
public string groupName;
public string url;
public bool hasImage = true;
}
}