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

📄 detailtext.cs

📁 个人信息的源代码
💻 CS
字号:
using System;
using System.Data;

namespace DataAccessLayer
{
	/// <summary>
	/// 详细信息。
	/// </summary>
	public class DetailText
	{
		public int DetailTextID = 0;

		//用于区分是否已更改过,保存之后,由外部对象重置为False
		public bool HasChanged = false;

		private string _text = "";
		public string Text
		{
			get
			{
				return this._text;
			}
			set
			{
				if(this._text != value)
				{
					this._text = value;
					this.HasChanged = true;
				}
			}
		}
		private string _rtf = "";
		public string RTFText
		{
			get
			{
				return this._rtf;
			}
			set
			{
				if(this._rtf != value)
				{
					this._rtf = value;
					this.HasChanged = true;
				}
			}
		}
		//最长的只能为255个字符
		private string _belongto = "";
		public string BelongTo
		{
			get
			{
				return this._belongto;
			}
			set
			{
				if(value.Length > 255)
				{
					value = value.Substring(0, 255);
				}
				if(value == string.Empty)
				{
					throw new Exception("节点的路径不能为空");
				}
				//有可能出错,检查是否路径以"\"结束
				if(value.Substring(value.Length - 1, 1) != "\\")
				{
					value = value + "\\";
				}
				//----------------------------------------
				if(this._belongto != value)
				{
					this._belongto = value;
					this.HasChanged = true;
				}
			}
		}

		public DateTime InputDate = DateTime.Today;

	}
	public class DetailTextAccessObj : BaseAccessObj
	{
		public DetailTextAccessObj(OLEDBAccessObj dbObj) : base(dbObj)
		{
		}

		/// <summary>
		/// 将自身数据存入数据库中,不用保存文件,因为已经在创建文件时保存了
		/// </summary>
		/// <param name="obj"></param>
		public void SaveMeToDB(DetailText obj)
		{
			if(this.dbObj == null)
				return;
			string strSQL;
			System.Collections.Specialized.ListDictionary pars = new System.Collections.Specialized.ListDictionary();

			if(obj.BelongTo.Substring(obj.BelongTo.Length - 1, 1) != "\\")
			{
				obj.BelongTo = obj.BelongTo + "\\";
			}
			//保存主记录
			strSQL = "AddDetailTextRecord";
			pars.Add("DetailTextIDValue", obj.DetailTextID);
			pars.Add("TextValue", obj.Text);
			pars.Add("BelongToValue", obj.BelongTo);
			pars.Add("InputDateValue", obj.InputDate);
			pars.Add("RTFTextValue", obj.RTFText);

			//System.Windows.Forms.MessageBox.Show(obj.DetailTextID.ToString() + "why");

			try
			{
				this.dbObj.ExecSQLCommand2(strSQL, pars);
			}
			catch(Exception ex)
			{
				throw new Exception("在执行存储过程AddDetailTextRecord时出错,系统给出的信息为:" + ex.Message);
			}
		}
		/// <summary>
		/// 更新对象所对应的数据库记录信息
		/// </summary>
		public void UpdateDBRow(DetailText obj)
		{
			if(obj == null)
				return;

			string strSQL;
			System.Collections.Specialized.ListDictionary pars = new System.Collections.Specialized.ListDictionary();
			strSQL = "UpdateDetailTextRecord";
			if(obj.Text == null)
				obj.Text = "";
			//有可能出错,检查是否路径以"\"结束
			if(obj.BelongTo.Substring(obj.BelongTo.Length - 1, 1) != "\\")
			{
				obj.BelongTo = obj.BelongTo + "\\";
			}

			//更新主记录
			pars.Add("TextValue", obj.Text);
			pars.Add("BelongToValue", obj.BelongTo);
			pars.Add("InputDateValue", obj.InputDate);
			pars.Add("RTFTextValue", obj.RTFText);
			pars.Add("DetailTextIDValue", obj.DetailTextID);
			try
			{
				this.dbObj.ExecSQLCommand2(strSQL, pars);
			}
			catch(Exception ex)
			{
				throw new Exception("在执行存储过程UpdateDetailTextRecord时出错,系统给出的信息为:" + ex.Message);
			}
		}
		/// <summary>
		/// 删除数据库记录
		/// </summary>
		/// <param name="BelongTo"></param>
		public void DeleteDBRow(string BelongTo)
		{
			string strSQL;
			try
			{
				//删除自身记录
				strSQL = "Delete * From DetailText where BelongTo Like '" + BelongTo + "%'";
				this.dbObj.ExecSQLCommand(strSQL);
			}
			catch(Exception ex)
			{
				throw new Exception("在删除DetailText记录时出错,系统给出的信息是:" + ex.Message);
			}
		}
		/// <summary>
		///根据路径名获取对象,没有返回null
		/// </summary>
		/// <param name="strPath"></param>
		/// <returns></returns>
		public DetailText GetObjectByPathStr(string strPath)
		{
			string strSQL = "Select * From DetailText where BelongTo = '" + strPath + "'";
			DataSet ds = this.dbObj.GetSQLDataSet(strSQL, "DetailText");
			DataRow dr;

			if(ds.Tables["DetailText"].Rows.Count > 0)
			{
				dr = ds.Tables["DetailText"].Rows[0];
				return this.LoadFromDataRow(dr);
			}
			return null;
		}
		/// <summary>
		/// 用新路径名刷新老路径名,完成后,所有DetailText表中以OldPathStr开头的记录最后部分用新路径NewPathStr取代
		/// </summary>
		/// <param name="OldPathStr"></param>
		/// <param name="NewPathStr"></param>
		public void RenameNodePath(string OldPathStr, string NewPathStr)
		{
			string strSQL = "RenameDetailTextNode";
			System.Collections.Specialized.ListDictionary pars = new System.Collections.Specialized.ListDictionary();
			//有可能出错,检查是否路径以"\"结束
			if(NewPathStr.Substring(NewPathStr.Length - 1, 1) != "\\")
			{
				NewPathStr = NewPathStr + "\\";
			}
			if(OldPathStr.Substring(OldPathStr.Length - 1, 1) != "\\")
			{
				OldPathStr = OldPathStr + "\\";
			}

			pars.Add("NewText", NewPathStr);
			pars.Add("OldText", OldPathStr);
			pars.Add("FindStr", OldPathStr + "%");

			try
			{
				this.dbObj.ExecSQLCommand2(strSQL, pars);
			}
			catch(Exception ex)
			{
				throw new Exception("在执行存储过程RenameDetailTextNode时出错,系统给出的信息为:" + ex.Message);
			}
		}
		/// <summary>
		/// 当节点移动时,所有DetailText表中以OldPathStr开头的记录完全用新路径NewPathStr取代
		/// </summary>
		/// <param name="OldPathStr"></param>
		/// <param name="NewPathStr"></param>
		public void MoveNodePath(string OldPathStr, string NewPathStr)
		{
			//string strSQL = "MoveDetailTextNode";
			string strSQL = "RenameDetailTextNode";
			System.Collections.Specialized.ListDictionary pars = new System.Collections.Specialized.ListDictionary();
			//有可能出错,检查是否路径以"\"结束
			if(NewPathStr.Substring(NewPathStr.Length - 1, 1) != "\\")
			{
				NewPathStr = NewPathStr + "\\";
			}
			if(OldPathStr.Substring(OldPathStr.Length - 1, 1) != "\\")
			{
				OldPathStr = OldPathStr + "\\";
			}
			pars.Add("NewText", NewPathStr);
			pars.Add("OldText", OldPathStr);
			pars.Add("FindStr", OldPathStr + "%");

			try
			{
				this.dbObj.ExecSQLCommand2(strSQL, pars);
			}
			catch(Exception ex)
			{
				throw new Exception("在执行存储过程RenameDetailTextNode时出错,系统给出的信息为:" + ex.Message);
			}
		}
		/// <summary>
		/// 获取下一个可用的对象ID
		/// </summary>
		/// <returns></returns>
		public int GetNextID()
		{
			//System.Windows.Forms.MessageBox.Show((this.dbObj.GetMaxValueFromTable("DetailText", "DetailTextID") + 1).ToString());
			return this.dbObj.GetMaxValueFromTable("DetailText", "DetailTextID") + 1;
		}
		public void SaveToDataRow(DataRow dr, DetailText obj)
		{
			if(dr == null || obj == null)
			{
				throw new Exception("DetailText.SaveToDataRow need two Argument:dr and obj ,both can not be null");
			}
			dr["DetailTextID"] = obj.DetailTextID;
			dr["BelongTo"] = obj.BelongTo;
			dr["InputDate"] = obj.InputDate;
			dr["Text"] = obj.Text;
			dr["RTFText"] = obj.RTFText;
		}
		public DetailText LoadFromDataRow(DataRow dr)
		{
			if(dr == null)
			{
				throw new Exception("DetailText:LoadFromDataRow need an Argument:dr which can not be null");
			}
			DetailText obj = new DetailText();
			obj.DetailTextID = (int)dr["DetailTextID"];
			obj.BelongTo = dr["BelongTo"].ToString();
			obj.InputDate = (DateTime)dr["InputDate"];
			obj.Text = dr["Text"].ToString();
			if(dr.IsNull("RTFText"))
			{
				obj.RTFText = "";
			}
			else
			{
				obj.RTFText = dr["RTFText"].ToString();
			}
			return obj;
		}
	}
}

⌨️ 快捷键说明

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