ExcelreportApp.cs
2.02 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
using Newtonsoft.Json.Linq;
using System;
using WebRepository;
namespace WebApp
{
/// <summary>
///
/// </summary>
public class ExcelReportApp
{
private ISqlWork _sqlWork;
private IUnitWork _unitWork;
public ExcelReportApp(ISqlWork sqlWork, IUnitWork unitWork)
{
_sqlWork = sqlWork;
_unitWork = unitWork;
}
public TableData QueryData(int ReportId, string Filter)
{
var result = new TableData();
try
{
Excelreport excelreport = _unitWork.FindSingle<Excelreport>(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 ds = _sqlWork.SelectGet(sql);
result.data = ds.Tables[0];
result.count = ds.Tables[0].Rows.Count;
result.code = 200;
}
catch (Exception ex)
{
result.code = 500;
result.msg = ex.Message;
}
return result;
}
}
}