您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->IFNuke1.1.0版源码>>Core/Data/DataProvider.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:IFNuke1.1.0版源码
当前文件:文件类型 IFnuke110/Core/Data/DataProvider.cs打开代码结构图
普通视图
		            
1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.Data; 5using System.Data.Common; 6 7using IFNuke; 8 9namespace 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
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:IFNuke1.1.0版源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号