-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDataHelper.cs
More file actions
113 lines (97 loc) · 4.33 KB
/
DataHelper.cs
File metadata and controls
113 lines (97 loc) · 4.33 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
using ExpressBase.Common.Objects;
using ExpressBase.Common.Objects.Attributes;
using ExpressBase.Common.Structures;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Runtime.Serialization;
using System.Text;
namespace ExpressBase.Common.Data
{
public class DataHelper
{
// public DbDataReader GetDataReader()
// {
//var myDataSourceservice = base.ResolveService<DataSourceService>();
//if (Report.DataSourceRefId != string.Empty)
//{
// cresp = this.Redis.Get<DataSourceColumnsResponse>(string.Format("{0}_columns", Report.DataSourceRefId));
// if (cresp.IsNull)
// cresp = myDataSourceservice.Any(new DataSourceColumnsRequest { RefId = Report.DataSourceRefId });
// Report.DataColumns = (cresp.Columns.Count > 1) ? cresp.Columns[1] : cresp.Columns[0];
// dresp = myDataSourceservice.Any(new DataSourceDataRequest { RefId = Report.DataSourceRefId, Draw = 1, Start = 0, Length = 100 });
// Report.DataRow = dresp.Data;
//}
// }
public static IEnumerable<DbParameter> GetParams(IDatabase db, bool isPaged, List<Param> reqParams, int iLimit, int iOffset)
{
if (isPaged)
{
if (reqParams == null)
reqParams = new List<Param>();
var _dicLimit = new Param { Name = "limit", Type = ((int)EbDbTypes.Int32).ToString(), Value = ((iLimit != -1) ? iLimit.ToString() : 0.ToString()) };
var _dicOffset = new Param { Name = "offset", Type = ((int)EbDbTypes.Int32).ToString(), Value = iOffset.ToString() };
reqParams.RemoveAll(e => e.Name == "limit");
reqParams.RemoveAll(e => e.Name == "offset");
reqParams.AddRange(new Param[] { _dicLimit, _dicOffset });
}
if (reqParams != null && reqParams.Count > 0)
{
foreach (Param param in reqParams)
{
if (param.ValueTo != null)
{
if (db.Vendor == DatabaseVendors.PGSQL)
yield return db.GetNewParameter(string.Format(":{0}", param.Name), (EbDbTypes)Convert.ToInt32(param.Type), param.ValueTo);
else
yield return db.GetNewParameter(string.Format("{0}", param.Name), (EbDbTypes)Convert.ToInt32(param.Type), param.ValueTo);
}
}
}
}
}
public class Param
{
public Param() { }
[DataMember(Order = 1)]
public string Name { get; set; }
[DataMember(Order = 2)]
public string Type { get; set; }
[DataMember(Order = 3)]
public string Value { get; set; }
[DataMember(Order = 4)]
public dynamic ValueTo
{
get
{
if (Type == ((int)EbDbTypes.Decimal).ToString())
return Convert.ToDecimal(Value);
else if (Type == ((int)EbDbTypes.Int16).ToString())
return Convert.ToInt16(Value);
else if (Type == ((int)EbDbTypes.Int32).ToString())
return Convert.ToInt32(Value);
else if (Type == ((int)EbDbTypes.Int64).ToString())
return Convert.ToInt64(Value);
else if (Type == ((int)EbDbTypes.Date).ToString())
return Convert.ToDateTime(Value);
else if (Type == ((int)EbDbTypes.DateTime).ToString())
return Convert.ToDateTime(Value);
else if (Type == ((int)EbDbTypes.Boolean).ToString())
return Convert.ToBoolean(Value);
else if (Type == ((int)EbDbTypes.String).ToString())
return (Value == null) ? string.Empty : Value;
else if (Type == ((int)EbDbTypes.Time).ToString())
return TimeSpan.Parse(Value ?? "0");
else
return Value;
}
}
[DataMember(Order = 5)]
public bool Required { set; get; } = true;
[DataMember(Order = 6)]
public string NameF { set; get; } //formatted name
[DataMember(Order = 7)]
public string ValueF { set; get; } //formatted value
}
}