/**  版本信息模板在安装目录下，可自行修改。
* usernotice.cs
*
* 功 能： N/A
* 类 名： usernotice
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2022/2/21 10:07:01   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using YTSoft.DBUtility;

namespace YTSoft.BaseCallCenter.DAL
{
	/// <summary>
	/// 数据访问类:usernotice
	/// </summary>
	public partial class usernotice
	{
		public usernotice()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(YTSoft.BaseCallCenter.Model.usernotice model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into usernotice(");
			strSql.Append("F_noticeid,F_userid,F_state)");
			strSql.Append(" values (");
			strSql.Append("SQL2012F_noticeid,SQL2012F_userid,SQL2012F_state)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("SQL2012F_noticeid", SqlDbType.Int,4),
					new SqlParameter("SQL2012F_userid", SqlDbType.Int,4),
					new SqlParameter("SQL2012F_state", SqlDbType.Int,4)};
			parameters[0].Value = model.F_noticeid;
			parameters[1].Value = model.F_userid;
			parameters[2].Value = model.F_state;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(YTSoft.BaseCallCenter.Model.usernotice model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update usernotice set ");
			strSql.Append("F_noticeid=SQL2012F_noticeid,");
			strSql.Append("F_userid=SQL2012F_userid,");
			strSql.Append("F_state=SQL2012F_state");
			strSql.Append(" where F_id=SQL2012F_id");
			SqlParameter[] parameters = {
					new SqlParameter("SQL2012F_noticeid", SqlDbType.Int,4),
					new SqlParameter("SQL2012F_userid", SqlDbType.Int,4),
					new SqlParameter("SQL2012F_state", SqlDbType.Int,4),
					new SqlParameter("SQL2012F_id", SqlDbType.Int,4)};
			parameters[0].Value = model.F_noticeid;
			parameters[1].Value = model.F_userid;
			parameters[2].Value = model.F_state;
			parameters[3].Value = model.F_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int F_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from usernotice ");
			strSql.Append(" where F_id=SQL2012F_id");
			SqlParameter[] parameters = {
					new SqlParameter("SQL2012F_id", SqlDbType.Int,4)
			};
			parameters[0].Value = F_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string F_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from usernotice ");
			strSql.Append(" where F_id in ("+F_idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public YTSoft.BaseCallCenter.Model.usernotice GetModel(int F_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 F_id,F_noticeid,F_userid,F_state from usernotice ");
			strSql.Append(" where F_id=SQL2012F_id");
			SqlParameter[] parameters = {
					new SqlParameter("SQL2012F_id", SqlDbType.Int,4)
			};
			parameters[0].Value = F_id;

			YTSoft.BaseCallCenter.Model.usernotice model=new YTSoft.BaseCallCenter.Model.usernotice();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public YTSoft.BaseCallCenter.Model.usernotice DataRowToModel(DataRow row)
		{
			YTSoft.BaseCallCenter.Model.usernotice model=new YTSoft.BaseCallCenter.Model.usernotice();
			if (row != null)
			{
				if(row["F_id"]!=null && row["F_id"].ToString()!="")
				{
					model.F_id=int.Parse(row["F_id"].ToString());
				}
				if(row["F_noticeid"]!=null && row["F_noticeid"].ToString()!="")
				{
					model.F_noticeid=int.Parse(row["F_noticeid"].ToString());
				}
				if(row["F_userid"]!=null && row["F_userid"].ToString()!="")
				{
					model.F_userid=int.Parse(row["F_userid"].ToString());
				}
				if(row["F_state"]!=null && row["F_state"].ToString()!="")
				{
					model.F_state=int.Parse(row["F_state"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select F_id,F_noticeid,F_userid,F_state ");
			strSql.Append(" FROM usernotice ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" F_id,F_noticeid,F_userid,F_state ");
			strSql.Append(" FROM usernotice ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM usernotice ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.F_id desc");
			}
			strSql.Append(")AS Row, T.*  from usernotice T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("SQL2012tblName", SqlDbType.VarChar, 255),
					new SqlParameter("SQL2012fldName", SqlDbType.VarChar, 255),
					new SqlParameter("SQL2012PageSize", SqlDbType.Int),
					new SqlParameter("SQL2012PageIndex", SqlDbType.Int),
					new SqlParameter("SQL2012IsReCount", SqlDbType.Bit),
					new SqlParameter("SQL2012OrderType", SqlDbType.Bit),
					new SqlParameter("SQL2012strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "usernotice";
			parameters[1].Value = "F_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

