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

📄 lda.cs

📁 c#编的CSDN离线助手
💻 CS
字号:
/// <Copyright>
/// This Program Written By Luyan(5drush)
/// 2002/4/23
/// Email:nluyan@163.net
/// QQ:5743345
/// </Copyright>

using System;
using System.Data;
using System.Data.OleDb;

namespace CSDN
{
	/// <summary>
	/// Local Data Access 的摘要说明。
	/// </summary>
	public class LDA
	{
		private OleDbConnection conn;
		public DataSet ds = new DataSet();

		public LDA()
		{
			conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=csdn.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False");
			FillDataSet();
		}

		public void FillDataSet()
		{
			conn.Open();
			string query = "select * from Issue";
			OleDbDataAdapter da = new OleDbDataAdapter(query,conn);
			da.Fill(ds,"Issue");
			query = "select * from Reply";
			da = new OleDbDataAdapter(query,conn);
			da.Fill(ds,"Reply");
			query = "select * from TopicIndex";
			da = new OleDbDataAdapter(query,conn);
			da.Fill(ds,"TopicIndex");
			conn.Close();
		}

		public DataView GetTopicIndexDataView(int RoomId, int Block)
		{
			DataView dvTopicIndex = new DataView(ds.Tables["TopicIndex"],"RoomId = '" + RoomId.ToString() + "' and Block = '" + Block.ToString() + "'", "ReplyDateTime DESC", DataViewRowState.CurrentRows);
			return dvTopicIndex;
		}

		public DataView dvTopicIndex
		{
			get
			{
				return new DataView(ds.Tables["TopicIndex"]);
			}
		}

		public DataView dvIssue
		{
			get
			{
				return new DataView(ds.Tables["Issue"]);
			}
		}

		public DataView dvReply
		{
			get
			{
				return new DataView(ds.Tables["Reply"]);
			}
		}

		public string GetTopicMaxId(int RoomId, int Block)
		{
			DataView dv = new DataView(
				ds.Tables["TopicIndex"],
				"RoomId = '" + RoomId.ToString() + "' and Block = '" + Block.ToString() + "'",
				"TopicId DESC",
				DataViewRowState.CurrentRows
				);
			if(dv.Count == 0)
				return "0";
			else
                return dv[0]["TopicId"].ToString();
		}

		public DateTime GetReplyMaxTime(int RoomId, int Block)
		{
			DataView dv = new DataView(
				ds.Tables["TopicIndex"],
				"RoomId = '" + RoomId.ToString() + "' and Block = '" + Block.ToString() + "'",
				"ReplyDateTime DESC",
				DataViewRowState.CurrentRows
				);
			if(dv.Count == 0)
				return DateTime.Parse("1980/1/1");
			else
                return DateTime.Parse(dv[0]["ReplyDateTime"].ToString());
		}

		public void AddTopicIndex(string TopicId, string TopicName, string PostUserName, int ReplyNum, DateTime ReplyDateTime, int Point, bool endstate, int TopicStatus, string RoomId, string Block)
		{
			
			DataView dv = new DataView(ds.Tables["TopicIndex"]);
			dv.AllowNew = true;
			DataRowView drv = dv.AddNew();
			drv["TopicId"] = TopicId;
			drv["TopicName"] = TopicName;
			drv["PostUserName"] = PostUserName;
			drv["ReplyNum"] = ReplyNum;
			drv["ReplyDateTime"] = ReplyDateTime;
			drv["Point"] = Point;
			drv["endstate"] = endstate;
			drv["TopicStatus"] = TopicStatus;
			drv["RoomId"] = RoomId;
			drv["Block"] = Block;
			drv.EndEdit();
		}

		public void AddTopicIndex(int Room, int Block, TopicItemIndex TopicIndex)
		{
			string TopicMaxId = GetTopicMaxId(Room, Block);
			DataTable tempTable = CreateDataSource();
			DateTime ReplyMaxTime = GetReplyMaxTime(Room,Block);
			DataView dv = new DataView(tempTable);
			for(int i = 0; i < TopicIndex.Length; i++)
			{
				if(Int32.Parse(TopicIndex[i].TopicId) > Int32.Parse(TopicMaxId))
				{
					DataRowView drv = dv.AddNew();
					drv["TopicId"] = TopicIndex[i].TopicId;
					drv["TopicName"] = TopicIndex[i].TopicName;
					drv["PostUserName"] = TopicIndex[i].PostUserName;
					drv["ReplyNum"] = (int)TopicIndex[i].ReplyNum;
					drv["ReplyDateTime"] = TopicIndex[i].ReplyDateTime;
					drv["Point"] = TopicIndex[i].Point;
					drv["endstate"] = TopicIndex[i].EndState;
					drv["TopicStatus"] = 1;
					drv["RoomId"] = Room.ToString();
					drv["Block"] = Block.ToString();
					drv.EndEdit();
				}
				else if(TopicIndex[i].ReplyDateTime > ReplyMaxTime)
				{
					SetTopicIndexStatus(TopicIndex[i].TopicId,2);
				}
				else
				{
					break;
				}
			}
			ds.Merge(tempTable);
			SaveDataSet("TopicIndex");
		}

		public DataTable CreateDataSource()
		{
			DataTable table = new DataTable("TopicIndex");
			table.Columns.Add("TopicId",System.Type.GetType("System.String"));
			table.Columns.Add("TopicName",System.Type.GetType("System.String"));
			table.Columns.Add("PostUserName",System.Type.GetType("System.String"));
			table.Columns.Add("ReplyNum",System.Type.GetType("System.Int32"));
			table.Columns.Add("ReplyDateTime",System.Type.GetType("System.DateTime"));
			table.Columns.Add("Point",System.Type.GetType("System.Int32"));
			table.Columns.Add("endstate",System.Type.GetType("System.Boolean"));
			table.Columns.Add("TopicStatus",System.Type.GetType("System.Int32"));
			table.Columns.Add("RoomId",System.Type.GetType("System.String"));
			table.Columns.Add("Block",System.Type.GetType("System.String"));
			return table;
		}

		public void SetTopicIndexStatus(string TopicId, int Status)
		{
			DataView dv = new DataView(ds.Tables["TopicIndex"],"TopicId = '" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			dv.AllowEdit = true;
			DataRowView drv = dv[0];
			drv["TopicStatus"] = Status;
			drv.EndEdit();
		}

		public void SetTopicIndexReplyNum(string TopicId, int ReplyNum)
		{
			DataView dv = new DataView(ds.Tables["TopicIndex"],"TopicId = '" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			dv.AllowEdit = true;
			DataRowView drv = dv[0];
			drv["ReplyNum"] = ReplyNum;
			drv.EndEdit();
		}

		public void SetTopicIndexReplyDateTime(string TopicId,string ReplyDateTime)
		{
			DataView dv = new DataView(ds.Tables["TopicIndex"],"TopicId='" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			dv.AllowEdit = true;
			DataRowView drv = dv[0];
			drv["ReplyDateTime"] = ReplyDateTime;
			drv.EndEdit();
		}

		public void SetTopicSeen(string TopicId)
		{
			DataView dv = new DataView(ds.Tables["TopicIndex"],"TopicId = '" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			dv.AllowEdit = true;
			DataRowView drv = dv[0];
			drv["HasSeen"] = true;
			drv.EndEdit();
		}

		public int GetTopicIndexStatus(string TopicId)
		{
			DataView dv = new DataView(ds.Tables["TopicIndex"],"TopicId = '" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			return Int32.Parse(dv[0]["TopicStatus"].ToString());
		}

		public int GetTopicIndexReplyNum(string TopicId)
		{
			DataView dv = new DataView(ds.Tables["TopicIndex"],"TopicId = '" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			return Int32.Parse(dv[0]["ReplyNum"].ToString());
		}


		public TopicItemIndex GetTopicItemIndex(int RoomId, int Block)
		{
			TopicItemIndex tii = new TopicItemIndex();
			DataView dv = new DataView(ds.Tables["TopicIndex"],"RoomId = " + RoomId.ToString() + " and Block = " + Block.ToString(),"TopicId",DataViewRowState.CurrentRows);
			for(int i = 0; i < dv.Count; i++)
			{
				tii[i].EndState = Boolean.Parse(dv[i]["EndState"].ToString());
				tii[i].Point = (int)dv[i]["Point"];
				tii[i].PostUserName = dv[i]["PostUserName"].ToString();
				tii[i].ReplyDateTime = DateTime.Parse(dv[i]["ReplyDateTime"].ToString());
				tii[i].ReplyNum = (int)dv[i]["ReplyNum"];
				tii[i].TopicId = dv[i]["TopicId"].ToString();
				tii[i].TopicName = dv[i]["TopicName"].ToString();
			}
			return tii;
		}

		public Topic GetTopic(string TopicId)
		{
			TopicItemIndex tii = new TopicItemIndex();
			DataView dv = new DataView(ds.Tables["Issue"],"TopicId = '" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			Poster poster = new Poster();
			if(dv.Count == 0)
			{
				Exception ex = new Exception("DATAVIEW返回值为零");
				throw ex;
			}
			poster.Credit           = (int)dv[0]["Credit"];
			poster.PostUserId       = dv[0]["PostUserId"].ToString();
			poster.PostUserName     = dv[0]["PostUserName"].ToString();
			poster.PostUserNickName = dv[0]["PostUserNickName"].ToString();
			poster.Rank             = dv[0]["Rank"].ToString();
			poster.RankNum          = dv[0]["RankNum"].ToString();

			ReplyIndex replyIndex = new ReplyIndex();
			DataView dvReply = new DataView(ds.Tables["Reply"],"TopicID = '" + TopicId + "'","PostDateTime",DataViewRowState.CurrentRows);
			for(int i = 0; i < dvReply.Count; i++)
			{
				Poster replyPoster = new Poster();
				replyPoster.Credit = (int)dvReply[i]["Credit"];
				replyPoster.PostUserId = dvReply[i]["PostUserId"].ToString();
				replyPoster.PostUserName = dvReply[i]["PostUserName"].ToString();
				replyPoster.PostUserNickName = dvReply[i]["PostUserNickName"].ToString();
				replyPoster.Rank = dvReply[i]["Rank"].ToString();
				replyPoster.RankNum = dvReply[i]["RankNum"].ToString();

				Reply reply = new Reply(
					replyPoster,
					dvReply[i]["ReplyId"].ToString(),
					dvReply[i]["ReplyId"].ToString(),
					(int)dvReply[i]["Point"],
					DateTime.Parse(dvReply[i]["PostDateTime"].ToString()),
					dvReply[i]["Content"].ToString()
					);
				replyIndex[i] = reply;
			}

			return new Topic(
				poster,
				dv[0]["TopicId"].ToString(),
				dv[0]["TopicName"].ToString(),
				dv[0]["RoomName"].ToString(),
				(int)dv[0]["ReplyNum"],
				DateTime.Parse(dv[0]["PostDateTime"].ToString()),
				(int)dv[0]["Point"],
				(int)dv[0]["ReadNum"],
				dv[0]["RoomId"].ToString(),
				Boolean.Parse(dv[0]["EndState"].ToString()),
				dv[0]["Content"].ToString(),
				replyIndex
				);
		}

		public void SaveDataSet(string Table)
		{
			lock(this)
			{
				OleDbDataAdapter da = new OleDbDataAdapter();
				da.SelectCommand = new OleDbCommand();
				da.SelectCommand.CommandText = "select * from " + Table;
				da.SelectCommand.Connection = conn;
				OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
				conn.Open();
				da.Update(ds,Table);
				conn.Close();
				da.Dispose();
				cb.Dispose();
			}
		}

		public bool HasTopicIndex(string TopicId)
		{
			DataView dv = new DataView(ds.Tables["TopicIndex"],"TopicId = '" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			if(dv.Count != 0) return true;
			else return false;
		}

		public bool HasTopic(string TopicId)
		{
			DataView dv = new DataView(ds.Tables["Issue"],"TopicId = '" + TopicId + "'","TopicId",DataViewRowState.CurrentRows);
			if(dv.Count != 0) return true;
			else return false;
		}

		public void AddIssue(string TopicId, string TopicName, string PostUserId, string PostUserName, string PostUserNickName, string rank, string ranknum, int credit, string RoomName, int ReplyNum, DateTime PostDateTime, int Point, int ReadNum, string RoomId, bool EndState, string Content)
		{
			DataView dv = new DataView(ds.Tables["Issue"]);
			dv.AllowNew = true;
			DataRowView drv  = dv.AddNew();
			drv["TopicId"] = TopicId;
			drv["TopicName"] = TopicName;
			drv["PostUserId"] = PostUserId;
			drv["PostUserName"] = PostUserName;
			drv["PostUserNickName"] = PostUserNickName;
			drv["Rank"] = rank;
			drv["RankNum"] = ranknum;
			drv["Credit"] = credit;
			drv["RoomName"] = RoomName;
			drv["ReplyNum"] = ReplyNum;
			drv["PostDateTime"] = PostDateTime;
			drv["Point"] = Point;
			drv["ReadNum"] = ReadNum;
			drv["RoomId"] = RoomId;
			drv["EndState"] = EndState;
			drv["Content"] = Content;
			drv.EndEdit();
		}

		public void AddReply(string ReplyID, string PostUserId, string PostUserName, string PostUserNickName, string rank, string ranknum, int credit, string TopicID, int Point, DateTime PostDateTime, string Content)
		{
			DataView dv = new DataView(ds.Tables["Reply"]);
			dv.AllowNew = true;
			DataRowView drv = dv.AddNew();
			drv["ReplyId"] = ReplyID;
			drv["PostUserId"] = PostUserId;
			drv["PostUserName"] = PostUserName;
			drv["PostUserNickName"] = PostUserNickName;
			drv["rank"] = rank;
			drv["ranknum"] = ranknum;
			drv["credit"] = credit;
			drv["TopicId"] = TopicID;
			drv["Point"] = Point;
			drv["PostDateTime"] = PostDateTime;
			drv["Content"] = Content;
			drv.EndEdit();
		}

		public DataView GetForumUpdateView(string RoomId, string Block)
		{
			DataView dv = new DataView(ds.Tables["TopicIndex"],"RoomId='" + RoomId + "' and Block = '" + Block + "' and (TopicStatus = '1' or TopicStatus = '2')","ReplyDateTime Desc",DataViewRowState.CurrentRows);
			return dv;
		}
	}
}

⌨️ 快捷键说明

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