using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ZXDT.DBUtility;//Please add references
namespace ZXDT.CallCenter.DAL
{
	/// <summary>
	/// 数据访问类:T_Wo_WorkOrderTask
	/// </summary>
	public partial class T_Wo_WorkOrderTask
	{
		public T_Wo_WorkOrderTask()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(ZXDT.CallCenter.Model.T_Wo_WorkOrderTask model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Wo_WorkOrderTask(");
			strSql.Append("F_WORKORDERTYPEID,F_WORKORDERSTATEID,F_OWNERID,F_CREATEDATE,F_OPTUSERID,F_OPTDATE,F_EXFLAG,F_LOSEDATE,F_FORMID,F_OPTBTN,F_PLANFINISHTIME,F_REMINDTIME,F_TIMES,F_ASSIGNPARTICIPATOR,F_INSTANCEID,F_TASKFLAG,F_LOSEFLAG)");
			strSql.Append(" values (");
			strSql.Append("@F_WORKORDERTYPEID,@F_WORKORDERSTATEID,@F_OWNERID,@F_CREATEDATE,@F_OPTUSERID,@F_OPTDATE,@F_EXFLAG,@F_LOSEDATE,@F_FORMID,@F_OPTBTN,@F_PLANFINISHTIME,@F_REMINDTIME,@F_TIMES,@F_ASSIGNPARTICIPATOR,@F_INSTANCEID,@F_TASKFLAG,@F_LOSEFLAG)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@F_WORKORDERTYPEID", SqlDbType.Int,4),
					new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
					new SqlParameter("@F_OWNERID", SqlDbType.Int,4),
					new SqlParameter("@F_CREATEDATE", SqlDbType.DateTime),
					new SqlParameter("@F_OPTUSERID", SqlDbType.Int,4),
					new SqlParameter("@F_OPTDATE", SqlDbType.DateTime),
					new SqlParameter("@F_EXFLAG", SqlDbType.Int,4),
					new SqlParameter("@F_LOSEDATE", SqlDbType.DateTime),
					new SqlParameter("@F_FORMID", SqlDbType.DateTime),
					new SqlParameter("@F_OPTBTN", SqlDbType.VarChar,100),
					new SqlParameter("@F_PLANFINISHTIME", SqlDbType.DateTime),
					new SqlParameter("@F_REMINDTIME", SqlDbType.DateTime),
					new SqlParameter("@F_TIMES", SqlDbType.Int,4),
					new SqlParameter("@F_ASSIGNPARTICIPATOR", SqlDbType.Text),
					new SqlParameter("@F_INSTANCEID", SqlDbType.Int,4),
					new SqlParameter("@F_TASKFLAG", SqlDbType.Int,4),
					new SqlParameter("@F_LOSEFLAG", SqlDbType.Int,4)};
			parameters[0].Value = model.F_WORKORDERTYPEID;
			parameters[1].Value = model.F_WORKORDERSTATEID;
			parameters[2].Value = model.F_OWNERID;
			parameters[3].Value = model.F_CREATEDATE;
			parameters[4].Value = model.F_OPTUSERID;
			parameters[5].Value = model.F_OPTDATE;
			parameters[6].Value = model.F_EXFLAG;
			parameters[7].Value = model.F_LOSEDATE;
			parameters[8].Value = model.F_FORMID;
			parameters[9].Value = model.F_OPTBTN;
			parameters[10].Value = model.F_PLANFINISHTIME;
			parameters[11].Value = model.F_REMINDTIME;
			parameters[12].Value = model.F_TIMES;
			parameters[13].Value = model.F_ASSIGNPARTICIPATOR;
			parameters[14].Value = model.F_INSTANCEID;
			parameters[15].Value = model.F_TASKFLAG;
			parameters[16].Value = model.F_LOSEFLAG;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ZXDT.CallCenter.Model.T_Wo_WorkOrderTask model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Wo_WorkOrderTask set ");
			strSql.Append("F_WORKORDERTYPEID=@F_WORKORDERTYPEID,");
			strSql.Append("F_WORKORDERSTATEID=@F_WORKORDERSTATEID,");
			strSql.Append("F_OWNERID=@F_OWNERID,");
			strSql.Append("F_CREATEDATE=@F_CREATEDATE,");
			strSql.Append("F_OPTUSERID=@F_OPTUSERID,");
			strSql.Append("F_OPTDATE=@F_OPTDATE,");
			strSql.Append("F_EXFLAG=@F_EXFLAG,");
			strSql.Append("F_LOSEDATE=@F_LOSEDATE,");
			strSql.Append("F_FORMID=@F_FORMID,");
			strSql.Append("F_OPTBTN=@F_OPTBTN,");
			strSql.Append("F_PLANFINISHTIME=@F_PLANFINISHTIME,");
			strSql.Append("F_REMINDTIME=@F_REMINDTIME,");
			strSql.Append("F_TIMES=@F_TIMES,");
			strSql.Append("F_ASSIGNPARTICIPATOR=@F_ASSIGNPARTICIPATOR,");
			strSql.Append("F_INSTANCEID=@F_INSTANCEID,");
			strSql.Append("F_TASKFLAG=@F_TASKFLAG,");
			strSql.Append("F_LOSEFLAG=@F_LOSEFLAG");
			strSql.Append(" where F_TASKID=@F_TASKID");
			SqlParameter[] parameters = {
					new SqlParameter("@F_WORKORDERTYPEID", SqlDbType.Int,4),
					new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
					new SqlParameter("@F_OWNERID", SqlDbType.Int,4),
					new SqlParameter("@F_CREATEDATE", SqlDbType.DateTime),
					new SqlParameter("@F_OPTUSERID", SqlDbType.Int,4),
					new SqlParameter("@F_OPTDATE", SqlDbType.DateTime),
					new SqlParameter("@F_EXFLAG", SqlDbType.Int,4),
					new SqlParameter("@F_LOSEDATE", SqlDbType.DateTime),
					new SqlParameter("@F_FORMID", SqlDbType.DateTime),
					new SqlParameter("@F_OPTBTN", SqlDbType.VarChar,100),
					new SqlParameter("@F_PLANFINISHTIME", SqlDbType.DateTime),
					new SqlParameter("@F_REMINDTIME", SqlDbType.DateTime),
					new SqlParameter("@F_TIMES", SqlDbType.Int,4),
					new SqlParameter("@F_ASSIGNPARTICIPATOR", SqlDbType.Text),
					new SqlParameter("@F_INSTANCEID", SqlDbType.Int,4),
					new SqlParameter("@F_TASKFLAG", SqlDbType.Int,4),
					new SqlParameter("@F_LOSEFLAG", SqlDbType.Int,4),
					new SqlParameter("@F_TASKID", SqlDbType.Int,4)};
			parameters[0].Value = model.F_WORKORDERTYPEID;
			parameters[1].Value = model.F_WORKORDERSTATEID;
			parameters[2].Value = model.F_OWNERID;
			parameters[3].Value = model.F_CREATEDATE;
			parameters[4].Value = model.F_OPTUSERID;
			parameters[5].Value = model.F_OPTDATE;
			parameters[6].Value = model.F_EXFLAG;
			parameters[7].Value = model.F_LOSEDATE;
			parameters[8].Value = model.F_FORMID;
			parameters[9].Value = model.F_OPTBTN;
			parameters[10].Value = model.F_PLANFINISHTIME;
			parameters[11].Value = model.F_REMINDTIME;
			parameters[12].Value = model.F_TIMES;
			parameters[13].Value = model.F_ASSIGNPARTICIPATOR;
			parameters[14].Value = model.F_INSTANCEID;
			parameters[15].Value = model.F_TASKFLAG;
			parameters[16].Value = model.F_LOSEFLAG;
			parameters[17].Value = model.F_TASKID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZXDT.CallCenter.Model.T_Wo_WorkOrderTask GetModel(int F_TASKID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 F_TASKID,F_WORKORDERTYPEID,F_WORKORDERSTATEID,F_OWNERID,F_CREATEDATE,F_OPTUSERID,F_OPTDATE,F_EXFLAG,F_LOSEDATE,F_FORMID,F_OPTBTN,F_PLANFINISHTIME,F_REMINDTIME,F_TIMES,F_ASSIGNPARTICIPATOR,F_INSTANCEID,F_TASKFLAG,F_LOSEFLAG from T_Wo_WorkOrderTask ");
			strSql.Append(" where F_TASKID=@F_TASKID");
			SqlParameter[] parameters = {
					new SqlParameter("@F_TASKID", SqlDbType.Int,4)
};
			parameters[0].Value = F_TASKID;

			ZXDT.CallCenter.Model.T_Wo_WorkOrderTask model=new ZXDT.CallCenter.Model.T_Wo_WorkOrderTask();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["F_TASKID"]!=null && ds.Tables[0].Rows[0]["F_TASKID"].ToString()!="")
				{
					model.F_TASKID=int.Parse(ds.Tables[0].Rows[0]["F_TASKID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_WORKORDERTYPEID"]!=null && ds.Tables[0].Rows[0]["F_WORKORDERTYPEID"].ToString()!="")
				{
					model.F_WORKORDERTYPEID=int.Parse(ds.Tables[0].Rows[0]["F_WORKORDERTYPEID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_WORKORDERSTATEID"]!=null && ds.Tables[0].Rows[0]["F_WORKORDERSTATEID"].ToString()!="")
				{
					model.F_WORKORDERSTATEID=int.Parse(ds.Tables[0].Rows[0]["F_WORKORDERSTATEID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_OWNERID"]!=null && ds.Tables[0].Rows[0]["F_OWNERID"].ToString()!="")
				{
					model.F_OWNERID=int.Parse(ds.Tables[0].Rows[0]["F_OWNERID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_CREATEDATE"]!=null && ds.Tables[0].Rows[0]["F_CREATEDATE"].ToString()!="")
				{
					model.F_CREATEDATE=DateTime.Parse(ds.Tables[0].Rows[0]["F_CREATEDATE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_OPTUSERID"]!=null && ds.Tables[0].Rows[0]["F_OPTUSERID"].ToString()!="")
				{
					model.F_OPTUSERID=int.Parse(ds.Tables[0].Rows[0]["F_OPTUSERID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_OPTDATE"]!=null && ds.Tables[0].Rows[0]["F_OPTDATE"].ToString()!="")
				{
					model.F_OPTDATE=DateTime.Parse(ds.Tables[0].Rows[0]["F_OPTDATE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_EXFLAG"]!=null && ds.Tables[0].Rows[0]["F_EXFLAG"].ToString()!="")
				{
					model.F_EXFLAG=int.Parse(ds.Tables[0].Rows[0]["F_EXFLAG"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_LOSEDATE"]!=null && ds.Tables[0].Rows[0]["F_LOSEDATE"].ToString()!="")
				{
					model.F_LOSEDATE=DateTime.Parse(ds.Tables[0].Rows[0]["F_LOSEDATE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_FORMID"]!=null && ds.Tables[0].Rows[0]["F_FORMID"].ToString()!="")
				{
					model.F_FORMID=DateTime.Parse(ds.Tables[0].Rows[0]["F_FORMID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_OPTBTN"]!=null && ds.Tables[0].Rows[0]["F_OPTBTN"].ToString()!="")
				{
					model.F_OPTBTN=ds.Tables[0].Rows[0]["F_OPTBTN"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_PLANFINISHTIME"]!=null && ds.Tables[0].Rows[0]["F_PLANFINISHTIME"].ToString()!="")
				{
					model.F_PLANFINISHTIME=DateTime.Parse(ds.Tables[0].Rows[0]["F_PLANFINISHTIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_REMINDTIME"]!=null && ds.Tables[0].Rows[0]["F_REMINDTIME"].ToString()!="")
				{
					model.F_REMINDTIME=DateTime.Parse(ds.Tables[0].Rows[0]["F_REMINDTIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_TIMES"]!=null && ds.Tables[0].Rows[0]["F_TIMES"].ToString()!="")
				{
					model.F_TIMES=int.Parse(ds.Tables[0].Rows[0]["F_TIMES"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_ASSIGNPARTICIPATOR"]!=null && ds.Tables[0].Rows[0]["F_ASSIGNPARTICIPATOR"].ToString()!="")
				{
					model.F_ASSIGNPARTICIPATOR=ds.Tables[0].Rows[0]["F_ASSIGNPARTICIPATOR"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_INSTANCEID"]!=null && ds.Tables[0].Rows[0]["F_INSTANCEID"].ToString()!="")
				{
					model.F_INSTANCEID=int.Parse(ds.Tables[0].Rows[0]["F_INSTANCEID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_TASKFLAG"]!=null && ds.Tables[0].Rows[0]["F_TASKFLAG"].ToString()!="")
				{
					model.F_TASKFLAG=int.Parse(ds.Tables[0].Rows[0]["F_TASKFLAG"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_LOSEFLAG"]!=null && ds.Tables[0].Rows[0]["F_LOSEFLAG"].ToString()!="")
				{
					model.F_LOSEFLAG=int.Parse(ds.Tables[0].Rows[0]["F_LOSEFLAG"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select F_TASKID,F_WORKORDERTYPEID,F_WORKORDERSTATEID,F_OWNERID,F_CREATEDATE,F_OPTUSERID,F_OPTDATE,F_EXFLAG,F_LOSEDATE,F_FORMID,F_OPTBTN,F_PLANFINISHTIME,F_REMINDTIME,F_TIMES,F_ASSIGNPARTICIPATOR,F_INSTANCEID,F_TASKFLAG,F_LOSEFLAG ");
			strSql.Append(" FROM T_Wo_WorkOrderTask ");
			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_TASKID,F_WORKORDERTYPEID,F_WORKORDERSTATEID,F_OWNERID,F_CREATEDATE,F_OPTUSERID,F_OPTDATE,F_EXFLAG,F_LOSEDATE,F_FORMID,F_OPTBTN,F_PLANFINISHTIME,F_REMINDTIME,F_TIMES,F_ASSIGNPARTICIPATOR,F_INSTANCEID,F_TASKFLAG,F_LOSEFLAG ");
			strSql.Append(" FROM T_Wo_WorkOrderTask ");
			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_Wo_WorkOrderTask ");
			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_TASKID desc");
			}
			strSql.Append(")AS Row, T.*  from T_Wo_WorkOrderTask 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_Wo_WorkOrderTask";
			parameters[1].Value = "F_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  Method
	}
}

