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

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

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("taskId", "T_AutomaticCall_Task"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int taskId)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_AutomaticCall_Task");
			strSql.Append(" where taskId=@taskId");
			SqlParameter[] parameters = {
					new SqlParameter("@taskId", SqlDbType.Int,4)
			};
			parameters[0].Value = taskId;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(CallCenterApi.Model.T_AutomaticCall_Task model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_AutomaticCall_Task(");
			strSql.Append("taskName,createTime,createBy,deleteTime,deleteBy,isDelete,question1,path1,question2,path2,question3,path3)");
			strSql.Append(" values (");
			strSql.Append("@taskName,@createTime,@createBy,@deleteTime,@deleteBy,@isDelete,@question1,@path1,@question2,@path2,@question3,@path3)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@taskName", SqlDbType.NVarChar,500),
					new SqlParameter("@createTime", SqlDbType.DateTime),
					new SqlParameter("@createBy", SqlDbType.NVarChar,50),
					new SqlParameter("@deleteTime", SqlDbType.DateTime),
					new SqlParameter("@deleteBy", SqlDbType.NVarChar,50),
					new SqlParameter("@isDelete", SqlDbType.Int,4),
					new SqlParameter("@question1", SqlDbType.NVarChar,500),
					new SqlParameter("@path1", SqlDbType.NVarChar,500),
					new SqlParameter("@question2", SqlDbType.NVarChar,500),
					new SqlParameter("@path2", SqlDbType.NVarChar,500),
					new SqlParameter("@question3", SqlDbType.NVarChar,500),
					new SqlParameter("@path3", SqlDbType.NVarChar,500)};
			parameters[0].Value = model.taskName;
			parameters[1].Value = model.createTime;
			parameters[2].Value = model.createBy;
			parameters[3].Value = model.deleteTime;
			parameters[4].Value = model.deleteBy;
			parameters[5].Value = model.isDelete;
			parameters[6].Value = model.question1;
			parameters[7].Value = model.path1;
			parameters[8].Value = model.question2;
			parameters[9].Value = model.path2;
			parameters[10].Value = model.question3;
			parameters[11].Value = model.path3;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(CallCenterApi.Model.T_AutomaticCall_Task model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_AutomaticCall_Task set ");
			strSql.Append("taskName=@taskName,");
			strSql.Append("createTime=@createTime,");
			strSql.Append("createBy=@createBy,");
			strSql.Append("deleteTime=@deleteTime,");
			strSql.Append("deleteBy=@deleteBy,");
			strSql.Append("isDelete=@isDelete,");
			strSql.Append("question1=@question1,");
			strSql.Append("path1=@path1,");
			strSql.Append("question2=@question2,");
			strSql.Append("path2=@path2,");
			strSql.Append("question3=@question3,");
			strSql.Append("path3=@path3");
			strSql.Append(" where taskId=@taskId");
			SqlParameter[] parameters = {
					new SqlParameter("@taskName", SqlDbType.NVarChar,500),
					new SqlParameter("@createTime", SqlDbType.DateTime),
					new SqlParameter("@createBy", SqlDbType.NVarChar,50),
					new SqlParameter("@deleteTime", SqlDbType.DateTime),
					new SqlParameter("@deleteBy", SqlDbType.NVarChar,50),
					new SqlParameter("@isDelete", SqlDbType.Int,4),
					new SqlParameter("@question1", SqlDbType.NVarChar,500),
					new SqlParameter("@path1", SqlDbType.NVarChar,500),
					new SqlParameter("@question2", SqlDbType.NVarChar,500),
					new SqlParameter("@path2", SqlDbType.NVarChar,500),
					new SqlParameter("@question3", SqlDbType.NVarChar,500),
					new SqlParameter("@path3", SqlDbType.NVarChar,500),
					new SqlParameter("@taskId", SqlDbType.Int,4)};
			parameters[0].Value = model.taskName;
			parameters[1].Value = model.createTime;
			parameters[2].Value = model.createBy;
			parameters[3].Value = model.deleteTime;
			parameters[4].Value = model.deleteBy;
			parameters[5].Value = model.isDelete;
			parameters[6].Value = model.question1;
			parameters[7].Value = model.path1;
			parameters[8].Value = model.question2;
			parameters[9].Value = model.path2;
			parameters[10].Value = model.question3;
			parameters[11].Value = model.path3;
			parameters[12].Value = model.taskId;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public CallCenterApi.Model.T_AutomaticCall_Task GetModel(int taskId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 taskId,taskName,createTime,createBy,deleteTime,deleteBy,isDelete,question1,path1,question2,path2,question3,path3 from T_AutomaticCall_Task ");
			strSql.Append(" where taskId=@taskId");
			SqlParameter[] parameters = {
					new SqlParameter("@taskId", SqlDbType.Int,4)
			};
			parameters[0].Value = taskId;

			CallCenterApi.Model.T_AutomaticCall_Task model=new CallCenterApi.Model.T_AutomaticCall_Task();
			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 CallCenterApi.Model.T_AutomaticCall_Task DataRowToModel(DataRow row)
		{
			CallCenterApi.Model.T_AutomaticCall_Task model=new CallCenterApi.Model.T_AutomaticCall_Task();
			if (row != null)
			{
				if(row["taskId"]!=null && row["taskId"].ToString()!="")
				{
					model.taskId=int.Parse(row["taskId"].ToString());
				}
				if(row["taskName"]!=null)
				{
					model.taskName=row["taskName"].ToString();
				}
				if(row["createTime"]!=null && row["createTime"].ToString()!="")
				{
					model.createTime=DateTime.Parse(row["createTime"].ToString());
				}
				if(row["createBy"]!=null)
				{
					model.createBy=row["createBy"].ToString();
				}
				if(row["deleteTime"]!=null && row["deleteTime"].ToString()!="")
				{
					model.deleteTime=DateTime.Parse(row["deleteTime"].ToString());
				}
				if(row["deleteBy"]!=null)
				{
					model.deleteBy=row["deleteBy"].ToString();
				}
				if(row["isDelete"]!=null && row["isDelete"].ToString()!="")
				{
					model.isDelete=int.Parse(row["isDelete"].ToString());
				}
				if(row["question1"]!=null)
				{
					model.question1=row["question1"].ToString();
				}
				if(row["path1"]!=null)
				{
					model.path1=row["path1"].ToString();
				}
				if(row["question2"]!=null)
				{
					model.question2=row["question2"].ToString();
				}
				if(row["path2"]!=null)
				{
					model.path2=row["path2"].ToString();
				}
				if(row["question3"]!=null)
				{
					model.question3=row["question3"].ToString();
				}
				if(row["path3"]!=null)
				{
					model.path3=row["path3"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select taskId,taskName,createTime,createBy,deleteTime,deleteBy,isDelete,question1,path1,question2,path2,question3,path3 ");
			strSql.Append(" FROM T_AutomaticCall_Task ");
			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(" taskId,taskName,createTime,createBy,deleteTime,deleteBy,isDelete,question1,path1,question2,path2,question3,path3 ");
			strSql.Append(" FROM T_AutomaticCall_Task ");
			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 T_AutomaticCall_Task ");
			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.taskId desc");
			}
			strSql.Append(")AS Row, T.*  from T_AutomaticCall_Task 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("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_AutomaticCall_Task";
			parameters[1].Value = "taskId";
			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
	}
}

