ReportViewApp.cs
3.07 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
using Infrastructure;
using MySql.Data.MySqlClient;
using Newtonsoft.Json.Linq;
using System;
using System.Data.SqlClient;
using WebRepository;
namespace WebApp
{
/// <summary>
///
/// </summary>
public class ReportViewApp
{
private IUnitWork _unitWork;
public ReportViewApp(IUnitWork unitWork)
{
_unitWork = unitWork;
}
public TableData QueryData(int ReportId, string Filter)
{
var result = new TableData();
try
{
ReportDesign excelreport = _unitWork.FindSingle<ReportDesign>(u => u.Id == ReportId);
var sql = excelreport.Sql;
var sfilter = excelreport.Params;
if (!string.IsNullOrEmpty(sfilter))
{
if (string.IsNullOrEmpty(Filter))
{
throw new Exception("请填写查询条件!");
}
JObject json = null;
json = JObject.Parse(Filter);
JObject jsondefault = null;
jsondefault = JObject.Parse(sfilter);
foreach (var item in jsondefault)
{
var key = item.Key;
if (!json.ContainsKey(key))
{
throw new Exception("查询条件不正确!");
}
}
foreach (var item in json)
{
sql = sql.Replace(item.Key, item.Value.ToString());
}
}
var config = AppSettingsJson.GetAppSettings();
var ConnString = config.GetSection("ConnectionStrings:BaseDbContext").Value;
try
{
SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(ConnString);
connectionStringBuilder.Password = Encryption.Decrypt(connectionStringBuilder.Password);
ConnString = connectionStringBuilder.ConnectionString;
var ds = new SqlServerHelp(ConnString).SelectGet(sql);
result.data = ds.Tables[0];
result.count = ds.Tables[0].Rows.Count;
}
catch
{
MySqlConnectionStringBuilder connectionStringBuilder = new MySqlConnectionStringBuilder(ConnString);
connectionStringBuilder.Password = Encryption.Decrypt(connectionStringBuilder.Password);
ConnString = connectionStringBuilder.ConnectionString;
var ds = new MySqlHelp(ConnString).SelectGet(sql);
result.data = ds.Tables[0];
result.count = ds.Tables[0].Rows.Count;
}
}
catch (Exception ex)
{
result.code = 500;
result.msg = ExceptionHelp.GetAllMessage(ex);
}
return result;
}
}
}