using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace SK.MemberDAL
{
	/// <summary>
	/// CustomText 的摘要说明。
	/// </summary>
	public class CustomText
	{
		/// <summary>
		/// 自定义文件
		/// </summary>
		public CustomText()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		/// <summary>
		/// 添加自定义文本
		/// </summary>
		/// <param name="CustomName">名称</param>
		/// <param name="Content">内容</param>
		/// <returns></returns>
		public object Add(object CustomName,object Content)
		{
			SqlParameter[] oParms =new SqlParameter[2];
			oParms[0] = new SqlParameter("@CustomName",CustomName);
			oParms[1] = new SqlParameter("@Content",Content);

			return SqlHelper.ExecuteScalar(Data.ConnString,CommandType.Text,"insert into CustomText([CustomName],[Content]) values(@CustomName,@Content);select @@IDENTITY",oParms);
		}
		/// <summary>
		/// 更新自定义文本
		/// </summary>
		/// <param name="CustomTextID">编号</param>
		/// <param name="CustomName">名称</param>
		/// <param name="Content">内容</param>
		public void Update(object CustomTextID,object CustomName,object Content)
		{
			SqlParameter[] oParms =new SqlParameter[3];
			oParms[0] = new SqlParameter("@CustomTextID",CustomTextID);
			oParms[1] = new SqlParameter("@CustomName",CustomName);
			oParms[2] = new SqlParameter("@Content",Content);

			SqlHelper.ExecuteNonQuery(Data.ConnString,CommandType.Text,"update CustomText set [CustomName]=@CustomName,[Content]=@Content where CustomTextID=@CustomTextID",oParms);
		}
		/// <summary>
		/// 删除自定义文本
		/// </summary>
		/// <param name="CustomTextID">编号</param>
		public void Delete(object CustomTextID)
		{
			SqlParameter[] oParms =new SqlParameter[1];
			oParms[0] = new SqlParameter("@CustomTextID",CustomTextID);

			SqlHelper.ExecuteNonQuery(Data.ConnString,CommandType.Text,"delete CustomText where CustomTextID=@CustomTextID",oParms);
		}
		/// <summary>
		/// 返回指定的自定义文本
		/// </summary>
		/// <param name="CustomTextID">编号</param>
		/// <returns></returns>
		public DataRow Info(object CustomTextID)
		{
			SqlParameter[] oParms =new SqlParameter[1];
			oParms[0] = new SqlParameter("@CustomTextID",CustomTextID);

			return SqlHelper.ExecuteDataset(Data.ConnString,CommandType.Text,"select * from CustomText where CustomTextID=@CustomTextID",oParms).Tables[0].Rows[0];
		}
		/// <summary>
		/// 返回自定义文本列表
		/// </summary>
		/// <returns></returns>
		public DataSet List()
		{
			return SqlHelper.ExecuteDataset(Data.ConnString,CommandType.Text,"select * from CustomText");
		}
		/// <summary>
		/// 返回指定名称的自定义内容
		/// </summary>
		/// <param name="CustomName">自定义名称</param>
		/// <returns></returns>
		public string GetContent(object CustomName)
		{
			SqlParameter[] oParms =new SqlParameter[1];
			oParms[0] = new SqlParameter("@CustomName",CustomName);

			DataSet ds =  SqlHelper.ExecuteDataset(Data.ConnString,CommandType.Text,"select * from CustomText where CustomName=@CustomName",oParms);
			if(ds.Tables[0].Rows.Count>0)
				return ds.Tables[0].Rows[0]["Content"].ToString();
			else
				return "";
		}
	}
}
