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

📄 forum_busobj.cs

📁 ASP.net网站开发四“酷”全书:新闻、论坛、电子商城、博客_源码
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace BusObjectForum
{
	//登录的类
	public class LoginC
	{
		public LoginC()
		{
		}
		//论坛验证登陆
		public bool checkLogin(string LoginName,string PWD,string strConn)
		{
			string sql = "select count(*) as fintLoginCount from T_Operator where fchrLoginName = '" + LoginName +
				"' and fchrPassWord = '" + PWD + "'";
			OleDbConnection oConn = new OleDbConnection(strConn);
			oConn.Open();
			OleDbCommand oCommand = new OleDbCommand(sql,oConn);
			OleDbDataReader oReader = oCommand.ExecuteReader();
			while (oReader.Read())
			{
				if(oReader.GetInt32(0)==0)
				{
					return false;
				}
			}
			oReader.Close();
			oConn.Close();
			return true;
		}
		//管理端验证登陆
		public bool checkLoginAdmin(string LoginName,string PWD,string strConn)
		{
			string sql = "select count(*) as fintLoginCount from T_Operator where fbitIsAdmin = 1 and fchrLoginName = '" + LoginName +
				"' and fchrPassWord = '" + PWD + "'";
			OleDbConnection oConn = new OleDbConnection(strConn);
			oConn.Open();
			OleDbCommand oCommand = new OleDbCommand(sql,oConn);
			OleDbDataReader oReader = oCommand.ExecuteReader();
			while (oReader.Read())
			{
				if(oReader.GetInt32(0)==0)
				{
					return false;
				}
			}
			oReader.Close();
			oConn.Close();
			return true;
		}
		//取用户信息
		public DataSet getUserInfo(string LoginName,string PWD,string strConn,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			InnerFunction oFunction = new InnerFunction();
			string strSelect = "select * from T_Operator where fchrLoginName = '" + LoginName +
				"' and fchrPassWord = '" + PWD + "'";
			ErrDesc = "";
			oDataSet =oFunction.getDataSetBySQL(strConn,strSelect,out ErrDesc);
			if(ErrDesc=="")
				return oDataSet;
			else
				return null;
		}
		//通过UserID取当前用户注册信息
		public DataSet getUserInfoByID(string UID,string strConn,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			InnerFunction oFunction = new InnerFunction();
			string strSelect = "select * from T_Operator where fbitNoUsed=0 and fchrOperatorID = '"  + UID + "'";
			ErrDesc = "";
			oDataSet =oFunction.getDataSetBySQL(strConn,strSelect,out ErrDesc);
			if(ErrDesc=="")
				return oDataSet;
			else
				return null;
		}
		//当前登录的用户数
		public int getUserCount(string strConn)
		{
			string sql = "select count(*) as fintLoginCount from T_Operator where fchrAction='1'";
			OleDbConnection oConn = new OleDbConnection(strConn);
			oConn.Open();
			OleDbCommand oCommand = new OleDbCommand(sql,oConn);
			OleDbDataReader oReader = oCommand.ExecuteReader();
			int intLoginCount = 0;
			while (oReader.Read())
			{
				intLoginCount = (int)oReader["fintLoginCount"];
			}
			oReader.Close();
			oConn.Close();
			return intLoginCount;
		}
		//改变用户登录状态
		public void changeActionState(string strConn,string state)
		{
			
		}
	}
	//系统功能权限
	public class SysRightC
	{
		public SysRightC()
		{
		
		}
		public bool CheckUserFunction(string strConn,string strCurFunctionID,string strUID,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			InnerFunction oFunction = new InnerFunction();
			bool blnCheck = false;
			string sql = "select Count(*) from T_OperatorFunction where fchrOperatorID = '" + strUID + 
					"' and fchrFunctionID = '" + strCurFunctionID + "'";
			oDataSet =oFunction.getDataSetBySQL(strConn,sql,out ErrDesc);
			string strCount = oDataSet.Tables[0].Rows[0].ItemArray[0].ToString();
			if(strCount=="0")
			{
				blnCheck = false;
			}
			else
			{
				blnCheck = true;
			}
			return blnCheck;
 		}
	}
	//Forum功能
	public class ForumC
	{
		//构造
		public ForumC()
		{
			
		}
		//得到Function列表
		public DataSet getForumList(string strConn,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			InnerFunction oFunction = new InnerFunction();
			string strSelect = "select FUN.*,OP.fchrOperatorName as fchrRePersonName from T_Function FUN left outer join T_Operator OP " +
				" on FUN.fchrOperatorID = OP.fchrOperatorID";
			ErrDesc = "";
			oDataSet =oFunction.getDataSetBySQL(strConn,strSelect,out ErrDesc);
			if(ErrDesc=="")
				return oDataSet;
			else
				return null;
		}
		//返回操作员功能权限列表
		public DataSet getFunctionByOperatorID(string strConn,string strOperatorID,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			InnerFunction oFunction = new InnerFunction();
			string strSelect = "select * from T_OperatorFunction where fchrOperatorID ='"+strOperatorID + "'";
			ErrDesc = "";
			oDataSet =oFunction.getDataSetBySQL(strConn,strSelect,out ErrDesc);
			if(ErrDesc=="")
				return oDataSet;
			else
				return null;
		}
		//得到当前Function的主题列表
		public DataSet getTopicByFunction(string strConn,string strFunctionID,bool blnIncNoUsed,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			InnerFunction oFunction = new InnerFunction();
			string strSelect = "select TP.* ,OP.fchrOperatorName,Fun.fchrFunctionName," + 
				"(case TP.fbitIsGood  when 1 then '是' else  '否' end) as fchrIsGood,  " +
				"(case TP.fbitIsTop  when 1 then '是' else  '否' end) as fchrIsTop," +
				"(case TP.fbitNoUsed  when 1 then '是' else  '否' end) as fchrNoUsed  " +
				"from T_Topic TP left outer Join T_Operator OP on TP.fchrOperatorID = OP.fchrOperatorID " +
				"left outer join T_Function Fun on TP.fchrFunctionID=Fun.fchrFunctionID ";
			//是否包含已删除项
			if(blnIncNoUsed)
					strSelect +=" where TP.fchrFunctionID = '" + strFunctionID + "' Order by TP.fbitIsTop";
			else
				strSelect +=" where TP.fbitNoUsed='0' and TP.fchrFunctionID = '" + strFunctionID + "' Order by TP.fbitIsTop Desc";
			
			ErrDesc = "";
			oDataSet =oFunction.getDataSetBySQL(strConn,strSelect,out ErrDesc);
			if(ErrDesc=="")
				return oDataSet;
			else
				return null;
		}
		//得到当前主题回复
		public DataSet getForumByTopic(string strConn,string strTopicID,bool blnIncNoUsed,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			InnerFunction oFunction = new InnerFunction();
			string strSelect = "select isnull(OP.fchrOperatorName,'') as fchrOperatorName,"+
				"(case FR.fbitNoUsed when 1 then '是' else '否' end) as fchrNoUsed,"+
				"TP.fchrTopicCaption,FR.* " +
				"from t_Forum FR left outer join T_Topic TP on FR.fchrFatherID = TP.fchrTopicID " + 
				"left outer join T_Operator OP on FR.fchrOperatorID = OP.fchrOperatorID " ;
			if(blnIncNoUsed)
				strSelect += "where fchrFatherID='" + strTopicID + "' order by FR.fdtmDate desc";
			else
				strSelect += "where FR.fbitNoUsed = '0' and fchrFatherID='" + strTopicID + "' order by FR.fdtmDate desc";
			ErrDesc = "";
			oDataSet =oFunction.getDataSetBySQL(strConn,strSelect,out ErrDesc);
			if(ErrDesc=="")
				return oDataSet;
			else
				return null;
		}
		//更新Forum状态
		public bool SetForumState(string strConn,string strForumID,string strIsNoUsed,out string ErrDesc)
		{
			ErrDesc="";
			string sql = "Update T_Forum set fbitNoUsed = @fbitNoUsed where fchrForumID = '" + strForumID + "'";
			SqlConnection oConn = new SqlConnection(strConn);
			SqlCommand oCommand = new SqlCommand(sql,oConn);
			oCommand.Parameters.Add(new SqlParameter("@fbitNoUsed",SqlDbType.VarChar,10));
			oCommand.Parameters["@fbitNoUsed"].Value= strIsNoUsed;
			oConn.Open();
			try
			{
				oCommand.ExecuteNonQuery();
			}
			catch(Exception exp)
			{
				ErrDesc = exp.Message;
				return false;
			}
			return true;
		}
		//增加新讨论
		public void addNewTopic(string InXML,string outXML,out string ErrDesc)
		{
			ErrDesc="";
		}
	}
	//administrator功能
	public class AdminC
	{
		public AdminC()
		{
			
		}
		public DataSet getOperatorList(string strConn,out string ErrDesc)
		{
			ErrDesc = "";
			DataSet oDataSet = new DataSet();
			string sql="select OP.*,(case OP.fbitIsAdmin when 1 then '是' else '否' end) as fchrIsAdmin,"+
				"(case OP.fbitIsPower when 1 then '是' else '否' end) as fchrIsPower, "+
				"(case OP.fbitNoUsed when 1 then '是' else '否' end) as fchrNoUsed "+
				"  from T_Operator OP";
			InnerFunction oFunction = new InnerFunction();
			oDataSet = oFunction.getDataSetBySQL(strConn,sql,out ErrDesc);
			if(ErrDesc=="")
			{
				return oDataSet;
			}
			else
			{
				return null;
			}
		}
		public DataSet getUserParaList(string strConn,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			ErrDesc="";
			string sql="select * from T_UserPara";
			InnerFunction oFunction = new InnerFunction();
			oDataSet = oFunction.getDataSetBySQL(strConn,sql,out ErrDesc);
			if(ErrDesc=="")
			{
				return oDataSet;
			}
			else
			{
				return null;
			}
		}
		//通过ID更新系统参数
		public bool UpdateParaByID(string strConn,string strValue,string strParaID,out string ErrDesc)
		{
			ErrDesc="";
			string sql = "Update T_UserPara set fchrValue=@fchrValue where fchrUserParaID='" + strParaID + "'";

			SqlConnection oConn = new SqlConnection(strConn);
			
			SqlCommand oCommand = new SqlCommand(sql,oConn);
			oCommand.Parameters.Add(new SqlParameter("@fchrValue",SqlDbType.VarChar,50));
			oCommand.Parameters["@fchrValue"].Value= strValue;
			oConn.Open();
			try
			{
				oCommand.ExecuteNonQuery();
			}
			catch(Exception exp)
			{
				ErrDesc = exp.Message;
				return false;
			}
			oConn.Close();
			return true;
		}
		//通过ID更新操作员
		public bool UpdateOperatorAdminState(string strConn,string strIsPower,string strIsAdmin,string strIsNoUsed,string strOperatorID,string[] arrSelFunction,out string ErrDesc)
		{
			ErrDesc="";
			string sql = "Update T_Operator set fbitIsPower=@fbitIsPower,"+
						"fbitIsAdmin=@fbitIsAdmin,fbitNoUsed=@fbitNoUsed"+
						" where fchrOperatorID='" + strOperatorID + "'";
			SqlConnection oConn = new SqlConnection(strConn);
			SqlCommand oCommand = new SqlCommand(sql,oConn);
			oCommand.Parameters.Add(new SqlParameter("@fbitIsPower",SqlDbType.VarChar,10));
			oCommand.Parameters["@fbitIsPower"].Value= strIsPower;
			oCommand.Parameters.Add(new SqlParameter("@fbitIsAdmin",SqlDbType.VarChar,10));
			oCommand.Parameters["@fbitIsAdmin"].Value= strIsAdmin;
			oCommand.Parameters.Add(new SqlParameter("@fbitNoUsed",SqlDbType.VarChar,10));
			oCommand.Parameters["@fbitNoUsed"].Value= strIsNoUsed;
			oConn.Open();
			try
			{
				oCommand.ExecuteNonQuery();
			}
			catch(Exception exp)
			{
				ErrDesc = exp.Message;
				return false;
			}
			oConn.Close();
			UpdateOperatorFunction(strConn,strOperatorID,arrSelFunction,out ErrDesc);
			if(ErrDesc!="")
			{
				return false;
			}
			return true;
		}
		public void UpdateOperatorFunction(string strConn,string strOperatorID,string[] arrSelFunction,out string ErrDesc)
		{
			//删除原始的功能权限
			ErrDesc="";
			string sql = "delete from T_OperatorFunction where fchrOperatorID='"+ strOperatorID +"'";
			SqlConnection oConn = new SqlConnection(strConn);
			SqlCommand oCommand = new SqlCommand(sql,oConn);
			oConn.Open();
			try
			{
				oCommand.ExecuteNonQuery();
			}
			catch(Exception exp)
			{
				ErrDesc = exp.Message;
			}
			//添加新的功能权限
			string sqlInsert = "Insert into T_OperatorFunction (fchrRightID,fchrOperatorID,fchrFunctionID)"+
							"Values(@fchrRightID,@fchrOperatorID,@fchrFunctionID)";
			SqlCommand oCommandIns = new SqlCommand();
			oCommandIns.CommandText = sqlInsert;
			oCommandIns.Connection = oConn;
			InnerFunction oFunction = new BusObjectForum.InnerFunction();
			oCommandIns.Parameters.Add(new SqlParameter("@fchrRightID",SqlDbType.UniqueIdentifier ,16));
			oCommandIns.Parameters.Add(new SqlParameter("@fchrOperatorID",SqlDbType.VarChar,50));
			oCommandIns.Parameters.Add(new SqlParameter("@fchrFunctionID",SqlDbType.VarChar,50));
			for(int i=0;i<=arrSelFunction.Length-1;i++)
			{
				oCommandIns.Parameters["@fchrRightID"].Value= oFunction.getNewID();
				oCommandIns.Parameters["@fchrOperatorID"].Value= "{" + strOperatorID + "}";
				oCommandIns.Parameters["@fchrFunctionID"].Value = "{" + arrSelFunction[i] + "}";
				try
				{
					oCommandIns.ExecuteNonQuery();
				}
				catch(Exception exp)
				{
					ErrDesc = exp.Message;
					oConn.Close();
				}
			}
			oConn.Close();
		}
		//通过ID更新主题置顶,精华等状态
		public bool UpdateTopicState(string strConn,string strIsGood,string strIsTop,string strFuncID,string strIsNoUsed,string strTopicID,out string ErrDesc)
		{
			ErrDesc="";
			string sql = "Update T_Topic set fbitIsGood=@fbitIsGood,"+
				"fbitIsTop=@fbitIsTop,fbitNoUsed=@fbitNoUsed,"+
				"fchrFunctionID=@fchrFunctionID"+
				" where fchrTopicID='" + strTopicID + "'";
			SqlConnection oConn = new SqlConnection(strConn);
			SqlCommand oCommand = new SqlCommand(sql,oConn);
			oCommand.Parameters.Add(new SqlParameter("@fbitIsGood",SqlDbType.VarChar,10));
			oCommand.Parameters["@fbitIsGood"].Value= strIsGood;
			oCommand.Parameters.Add(new SqlParameter("@fbitIsTop",SqlDbType.VarChar,10));
			oCommand.Parameters["@fbitIsTop"].Value= strIsTop;
			oCommand.Parameters.Add(new SqlParameter("@fbitNoUsed",SqlDbType.VarChar,10));
			oCommand.Parameters["@fbitNoUsed"].Value= strIsNoUsed;
			oCommand.Parameters.Add(new SqlParameter("@fchrFunctionID",SqlDbType.VarChar,50));
			oCommand.Parameters["@fchrFunctionID"].Value= strFuncID;
			oConn.Open();
			try
			{
				oCommand.ExecuteNonQuery();
			}
			catch(Exception exp)
			{
				ErrDesc = exp.Message;
				return false;
			}
			oConn.Close();
			return true;
		}

	}
	public class InnerFunction
	{
		public InnerFunction()
		{
		}
		public DataSet getDataSetBySQL(string strConn,string sql,out string ErrDesc)
		{
			ErrDesc = "";
			DataSet oDataSet = new DataSet();
			string strSelect = sql;
			try
			{
				OleDbConnection oConn = new OleDbConnection(strConn);
				OleDbDataAdapter oAdapter = new OleDbDataAdapter(strSelect,oConn); 
				oAdapter.Fill(oDataSet,"T_Function");
				return oDataSet;
			}
			catch(Exception exp1)
			{
				ErrDesc = exp1.Message;
				return null;
			}
		}
		public Guid getNewID()
		{
			Guid oGid = Guid.NewGuid();
			return oGid;
		}
		public string getUserParaByName(string strConn,string strParaName,out string ErrDesc)
		{
			DataSet oDataSet = new DataSet();
			string sql = "select fchrValue from T_UserPara where fchrParaName='"+ strParaName +"'";
			oDataSet =this.getDataSetBySQL(strConn,sql,out ErrDesc);
			string strValue = oDataSet.Tables[0].Rows[0].ItemArray[0].ToString();
			return strValue;
		}
	}

}

⌨️ 快捷键说明

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