温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:IFNuke1.1.0版源码
当前文件:
IFnuke110/Core/Data/DataProvider.cs,打开代码结构图
IFnuke110/Core/Data/DataProvider.cs,打开代码结构图1using System; 2
using System.Collections.Generic; 3
using System.Text; 4
using System.Data; 5
using System.Data.Common; 6
7
using IFNuke; 8
9
namespace IFNuke.Data 10
{ 11
public abstract class DataProvider 12
{ 13
// Provider constants - eliminates need for reflection later. 14
private const string ProviderType = "data"; // Maps to <sectionGroup> in web.config. 15
private const string ProviderNamespace = "IFNuke.Data"; // Project name space. 16
private const string ProviderAssemblyName = ""; // Project assembly name. 17
18
// Singleton reference to the instantiated object. 19
private static DataProvider _provider = null; 20
private static bool _isCreated = false; 21
protected DataProvider(){} 22
23
public static DataProvider Instance() 24
{ 25
if (!_isCreated) 26
{ 27
_provider = (DataProvider)IFNuke.Reflection.CreateObject(ProviderType); 28
_isCreated = true; 29
} 30
return _provider; 31
} 32
33
protected static string GetTableName<T>() 34
{ 35
T bo = Activator.CreateInstance<T>(); 36
string tableName = bo.GetType().GetField("TableName").GetValue(bo).ToString(); 37
bo = default(T); // suppose to dispose the memory 38
return tableName; 39
} 40
41
protected static string GetIdName<T>() 42
{ 43
T bo = Activator.CreateInstance<T>(); 44
string idName = bo.GetType().GetField("IdName").GetValue(bo).ToString(); 45
bo = default(T); // suppose to dispose the memory 46
return idName; 47
} 48
49
ExecuteNonQuery 69
70
ExecuteDataset 95
96
ExecuteScalar 116
117
ExecuteReader 137
138
public abstract T Select<T>(int id); 139
140
public abstract DataSet Select<T>(string spName, CriteriaCollection parameters, int pageIndex, int pageSize, out int totalRecord); 141
142
public abstract List<T> SelectList<T>(string spName, CriteriaCollection parameters, int pageIndex, int pageSize, out int totalRecord); 143
144
public int Save<T>(T t) 145
{ 146
return Save<T>(t, ""); 147
} 148
149
public abstract int Save<T>(T t, string spName); 150
151
public abstract bool Delete<T>(int id); 152
153
public Dictionary<string, string> GetNameValueList<T>(string idName, string textName) 154
{ 155
string tableName = GetTableName<T>(); 156
string sql = string.Format("select {0}, {1} from {2} order by {3}", idName, textName, tableName, textName); 157
DataTable dt = DataProvider.Instance().ExecuteDataSet(sql).Tables[0]; 158
return DataProvider.ConvertTableToDictionary(dt); 159
} 160
161
public static Dictionary<string, string> ConvertTableToDictionary(DataTable dt) 162
{ 163
Dictionary<string, string> dict = new Dictionary<string, string>(); 164
foreach (DataRow dr in dt.Rows) 165
dict.Add(dr[1].ToString(), dr[0].ToString()); 166
return dict; 167
} 168
} 169
} 170





}
}