⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 data.cs

📁 ThreeLayer有关详细信息
💻 CS
📖 第 1 页 / 共 3 页
字号:
			if (ht==null)
			{
				string str_Sql=GetPageListCountSqlbyHt(Table,ht_Where,null);
				return (int)ExecuteScalar(connString,CommandType.Text,str_Sql,null);
			}
			else
			{
				string str_Sql=GetPageListCountSqlbyHt(Table,ht_Where,ht);
				SqlParameter[] Parms=new SqlParameter[ht.Count];
				IDictionaryEnumerator et = ht.GetEnumerator();
				int i=0;
				// 作哈希表循环
				while ( et.MoveNext() )
				{
					System.Data.SqlClient.SqlParameter sp=Data.MakeParam("@"+et.Key.ToString(),et.Value.ToString());
					Parms[i]=sp; // 添加SqlParameter对象
					i=i+1;
				}
				return (int)ExecuteScalar(connString,CommandType.Text,str_Sql,Parms);
			}
		}
		/// <summary>
		/// 通过传递条件获得记录条数
		/// </summary>
		/// <param name="connString">数据库连接</param>
		/// <param name="str_Sql">Sql语句</param>
		/// <returns>返回记录条数</returns>
		public static int GetRsCount(string connString,string str_Sql)
		{
			return (int)ExecuteScalar(connString,CommandType.Text,str_Sql,null);
		}
		/// <summary>
		/// 获得单个字段值
		/// </summary>
		/// <param name="connString">数据库连接</param>
		/// <param name="str_Sql">Sql语句,比如Select Name from Table where id=2</param>
		/// <returns></returns>
		public static string GetFiledValue(string connString,string str_Sql)
		{
			return ExecuteScalar(connString,CommandType.Text,str_Sql,null).ToString();
		}

		/// <summary>
		/// 通过运行Sql语句获得IList数据源
		/// </summary>
		/// <param name="conn_Default">数据库连接</param>
		/// <param name="int_PageSize">一页显示记录数</param>
		/// <param name="int_CurrentPageIndex">当前页码</param>
		/// <param name="str_Sql">Sql语句</param>
		/// <param name="class_Name">实体类名</param>
		/// <returns></returns>
		public static IList RunSql(string conn_Default,int int_PageSize,int int_CurrentPageIndex,string str_Sql,string class_Name)
		{
			// ===获得数据库源,返回IList为数据源===
			IList Ilst=new ArrayList();
			// 当没有传递条件参数时作的操作
			using (DataSet ds = ExecuteDataSet(int_PageSize,int_CurrentPageIndex,conn_Default, CommandType.Text, str_Sql, null))
			{
				DataTable dt=ds.Tables[0];
				for (int j=0;j<dt.Rows.Count;j++)
				{
					
					Type myType =Type.GetType(class_Name);// 获得“类”类型
					Object o_Instance=System.Activator.CreateInstance(myType); // 实例化类
					// 获得类的所有属性数组
					PropertyInfo[] myPropertyInfo1 = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
					// 循环属性数组,并给数组属性赋值
					for(int k=0;k<myPropertyInfo1.Length;k++)
					{
						PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo1[k];
						Object filed_Val=dt.Rows[j][myPropInfo.Name];
						switch (myPropInfo.PropertyType.ToString())
						{
							case "System.Int32":
								myPropInfo.SetValue(o_Instance,(int)filed_Val,null);
								break;
							case "System.String":
								myPropInfo.SetValue(o_Instance,filed_Val.ToString(),null);
								break;
							case "System.DateTime":
								myPropInfo.SetValue(o_Instance,Convert.ToDateTime(filed_Val.ToString()),null);
								break;
						}
			
					}
					// 把一行类记录赋值给ILst对象
					Ilst.Add(o_Instance);
					
				}
			}
			return Ilst;
		}

		public static IList RunSql(string conn_Default,int int_PageSize,int int_CurrentPageIndex,string procName,SqlParameter[] prams,string class_Name)
		{
			// ===获得数据库源,返回IList为数据源===
			IList Ilst=new ArrayList();
			// 当没有传递条件参数时作的操作
			using (DataSet ds = ExecuteDataSet(int_PageSize,int_CurrentPageIndex,conn_Default, CommandType.StoredProcedure, procName,prams))
			{
				DataTable dt=ds.Tables[0];
				for (int j=0;j<dt.Rows.Count;j++)
				{
					
					Type myType =Type.GetType(class_Name);// 获得“类”类型
					Object o_Instance=System.Activator.CreateInstance(myType); // 实例化类
					// 获得类的所有属性数组
					PropertyInfo[] myPropertyInfo1 = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
					// 循环属性数组,并给数组属性赋值
					for(int k=0;k<myPropertyInfo1.Length;k++)
					{
						PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo1[k];
						Object filed_Val=dt.Rows[j][myPropInfo.Name];
						switch (myPropInfo.PropertyType.ToString())
						{
							case "System.Int32":
								myPropInfo.SetValue(o_Instance,(int)filed_Val,null);
								break;
							case "System.String":
								myPropInfo.SetValue(o_Instance,filed_Val.ToString(),null);
								break;
							case "System.DateTime":
								myPropInfo.SetValue(o_Instance,Convert.ToDateTime(filed_Val.ToString()),null);
								break;
						}
			
					}
					// 把一行类记录赋值给ILst对象
					Ilst.Add(o_Instance);
					
				}
			}
			return Ilst;
		}

		/// <summary>
		/// 通过页大小,当前页数返回IList数据源
		/// </summary>
		/// <param name="int_PageSize">一页记录数</param>
		/// <param name="int_CurrentPageIndex">当前页数</param>
		/// <param name="Sql_Sel_Code">SQl语句</param>
		/// <param name="ht">传递条件哈希表</param>
		/// <param name="class_Name">实体类名</param>
		/// <returns>表示层传递过来的条件字段参数</returns>
		public static IList GetPageList(string conn_Default,int int_PageSize,int int_CurrentPageIndex,string Table,string ht_Where,string orderby,Hashtable ht,string class_Name)
		{
			// ===获得数据库源,返回IList为数据源===
			IList Ilst=new ArrayList();

			if (ht==null)
			{
				// 当没有传递条件参数时作的操作
				string str_Sql=GetPageListSqlbyHt(Table,ht_Where,orderby,null,class_Name);
				using (DataSet ds = ExecuteDataSet(int_PageSize,int_CurrentPageIndex,conn_Default, CommandType.Text, str_Sql, null))
				{
					DataTable dt=ds.Tables[0];
					for (int j=0;j<dt.Rows.Count;j++)
					{
						
						Type myType =Type.GetType(class_Name);// 获得“类”类型
						Object o_Instance=System.Activator.CreateInstance(myType); // 实例化类
						// 获得类的所有属性数组
						PropertyInfo[] myPropertyInfo1 = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
						// 循环属性数组,并给数组属性赋值
						for(int k=0;k<myPropertyInfo1.Length;k++)
						{
							PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo1[k];
							
							Object filed_Val=dt.Rows[j][myPropInfo.Name];
							switch (myPropInfo.PropertyType.ToString())
							{
								case "System.Int32":
									myPropInfo.SetValue(o_Instance,(int)filed_Val,null);
									break;
								case "System.String":
									myPropInfo.SetValue(o_Instance,filed_Val.ToString(),null);
									break;
								case "System.DateTime":
									myPropInfo.SetValue(o_Instance,Convert.ToDateTime(filed_Val.ToString()),null);
									break;
							}
				
						}
						// 把一行类记录赋值给ILst对象
						Ilst.Add(o_Instance);
					}
				}
			}
			else // 当没有传递条件参数时作的操作
			{

				// 处理传递过来的参数
				SqlParameter[] Parms=new SqlParameter[ht.Count];
				IDictionaryEnumerator et = ht.GetEnumerator();
				int i=0;
				while ( et.MoveNext() )
				{
					System.Data.SqlClient.SqlParameter sp=MakeParam("@"+et.Key.ToString(),et.Value.ToString());
					Parms[i]=sp;
					i=i+1;
				}
				string str_Sql=GetPageListSqlbyHt(Table,ht_Where,orderby,ht,class_Name);
				// 返回ILst
				using (DataSet ds = ExecuteDataSet(int_PageSize,int_CurrentPageIndex,conn_Default, CommandType.Text, str_Sql, Parms))
				{
					DataTable dt=ds.Tables[0];
					for (int j=0;j<dt.Rows.Count;j++)
					{
						
						Type myType =Type.GetType(class_Name);// 获得“类”类型
						Object o_Instance=System.Activator.CreateInstance(myType); // 实例化类
						// 获得类的所有属性数组
						PropertyInfo[] myPropertyInfo1 = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
						// 循环属性数组,并给数组属性赋值
						for(int k=0;k<myPropertyInfo1.Length;k++)
						{
							PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo1[k];
							Object filed_Val=dt.Rows[j][myPropInfo.Name];
							switch (myPropInfo.PropertyType.ToString())
							{
								case "System.Int32":
									myPropInfo.SetValue(o_Instance,(int)filed_Val,null);
									break;
								case "System.String":
									myPropInfo.SetValue(o_Instance,filed_Val.ToString(),null);
									break;
								case "System.DateTime":
									myPropInfo.SetValue(o_Instance,Convert.ToDateTime(filed_Val.ToString()),null);
									break;
							}
				
						}
						// 把一行类记录赋值给ILst对象




						Ilst.Add(o_Instance);
						
					}
				}

			}
			return Ilst;
		}

		
		/// <summary>
		/// ===通过页大小,当前页数返回IList数据源===
		/// </summary>
		/// <param name="int_PageSize">一页记录数</param>
		/// <param name="int_CurrentPageIndex">当前页数</param>
		/// <param name="Sql_Sel_Code">SQl语句</param>
		/// <param name="ht">传递条件哈希表</param>
		/// <param name="class_Name">实体类名</param>
		/// <returns>表示层传递过来的条件字段参数</returns>
		public static Object GetDetail(string conn_Default,string Table,string ht_Where,Hashtable ht,string class_Name)
		{
			// ===获得数据库源,返回IList为数据源===
			IList Ilst=new ArrayList();

			if (ht==null)
			{
				string str_Sql=GetPageListSqlbyHt(Table,ht_Where,null,null,class_Name);
				// 当没有传递条件参数时作的操作
				using (DataSet ds = ExecuteDataSet(conn_Default, CommandType.Text, str_Sql, null))
				{
					DataTable dt=ds.Tables[0];
					for (int j=0;j<dt.Rows.Count;j++)
					{
						
						Type myType =Type.GetType(class_Name);// 获得“类”类型
						Object o_Instance=System.Activator.CreateInstance(myType); // 实例化类
						// 获得类的所有属性数组
						PropertyInfo[] myPropertyInfo1 = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
						// 循环属性数组,并给数组属性赋值
						for(int k=0;k<myPropertyInfo1.Length;k++)
						{
							PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo1[k];
							Object filed_Val=dt.Rows[j][myPropInfo.Name];
							switch (myPropInfo.PropertyType.ToString())
							{
								case "System.Int32":
									myPropInfo.SetValue(o_Instance,(int)filed_Val,null);
									break;
								case "System.String":
									myPropInfo.SetValue(o_Instance,filed_Val.ToString(),null);
									break;
								case "System.DateTime":
									myPropInfo.SetValue(o_Instance,Convert.ToDateTime(filed_Val.ToString()),null);
									break;
							}
				
						}
						// 把一行类记录赋值给ILst对象
						return o_Instance;
					}
				}
			}
			else // 当没有传递条件参数时作的操作
			{

				// 处理传递过来的参数
				SqlParameter[] Parms=new SqlParameter[ht.Count];
				IDictionaryEnumerator et = ht.GetEnumerator();
				int i=0;
				while ( et.MoveNext() )
				{
					System.Data.SqlClient.SqlParameter sp=MakeParam("@"+et.Key.ToString(),et.Value.ToString());
					Parms[i]=sp;
					i=i+1;
				}
				
				string str_Sql=GetPageListSqlbyHt(Table,ht_Where,null,ht,class_Name);
				// 返回ILst
				using (DataSet ds = ExecuteDataSet(conn_Default, CommandType.Text, str_Sql, Parms))
				{
					DataTable dt=ds.Tables[0];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -