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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ZXDT.CallCenter.Model.T_Wf_WorkFlow model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Wf_WorkFlow(");
			strSql.Append("F_Name,F_CategoryID,F_CategoryName,F_State,F_StartDate,F_CreateDate,F_CreateBy,F_CreateName,F_EditDate,F_EditBy,F_EditName,F_XML,F_EntityId,F_MarkId,F_Useless,F_VerID)");
			strSql.Append(" values (");
			strSql.Append("@F_Name,@F_CategoryID,@F_CategoryName,@F_State,@F_StartDate,@F_CreateDate,@F_CreateBy,@F_CreateName,@F_EditDate,@F_EditBy,@F_EditName,@F_XML,@F_EntityId,@F_MarkId,@F_Useless,@F_VerID)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@F_Name", SqlDbType.VarChar,50),
					new SqlParameter("@F_CategoryID", SqlDbType.Int,4),
					new SqlParameter("@F_CategoryName", SqlDbType.VarChar,50),
					new SqlParameter("@F_State", SqlDbType.Bit,1),
					new SqlParameter("@F_StartDate", SqlDbType.DateTime),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_CreateBy", SqlDbType.Int,4),
					new SqlParameter("@F_CreateName", SqlDbType.VarChar,30),
					new SqlParameter("@F_EditDate", SqlDbType.DateTime),
					new SqlParameter("@F_EditBy", SqlDbType.Int,4),
					new SqlParameter("@F_EditName", SqlDbType.VarChar,30),
					new SqlParameter("@F_XML", SqlDbType.Text),
					new SqlParameter("@F_EntityId", SqlDbType.Int,4),
					new SqlParameter("@F_MarkId", SqlDbType.Int,4),
					new SqlParameter("@F_Useless", SqlDbType.Bit,1),
					new SqlParameter("@F_VerID", SqlDbType.Int,4)};
			parameters[0].Value = model.F_Name;
			parameters[1].Value = model.F_CategoryID;
			parameters[2].Value = model.F_CategoryName;
			parameters[3].Value = model.F_State;
			parameters[4].Value = model.F_StartDate;
			parameters[5].Value = model.F_CreateDate;
			parameters[6].Value = model.F_CreateBy;
			parameters[7].Value = model.F_CreateName;
			parameters[8].Value = model.F_EditDate;
			parameters[9].Value = model.F_EditBy;
			parameters[10].Value = model.F_EditName;
			parameters[11].Value = model.F_XML;
			parameters[12].Value = model.F_EntityId;
			parameters[13].Value = model.F_MarkId;
			parameters[14].Value = model.F_Useless;
			parameters[15].Value = model.F_VerID;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ZXDT.CallCenter.Model.T_Wf_WorkFlow model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Wf_WorkFlow set ");
			strSql.Append("F_Name=@F_Name,");
			strSql.Append("F_CategoryID=@F_CategoryID,");
			strSql.Append("F_CategoryName=@F_CategoryName,");
			strSql.Append("F_State=@F_State,");
			strSql.Append("F_StartDate=@F_StartDate,");
			strSql.Append("F_CreateDate=@F_CreateDate,");
			strSql.Append("F_CreateBy=@F_CreateBy,");
			strSql.Append("F_CreateName=@F_CreateName,");
			strSql.Append("F_EditDate=@F_EditDate,");
			strSql.Append("F_EditBy=@F_EditBy,");
			strSql.Append("F_EditName=@F_EditName,");
			strSql.Append("F_XML=@F_XML,");
			strSql.Append("F_EntityId=@F_EntityId,");
			strSql.Append("F_MarkId=@F_MarkId,");
			strSql.Append("F_Useless=@F_Useless,");
			strSql.Append("F_VerID=@F_VerID");
			strSql.Append(" where F_ID=@F_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@F_Name", SqlDbType.VarChar,50),
					new SqlParameter("@F_CategoryID", SqlDbType.Int,4),
					new SqlParameter("@F_CategoryName", SqlDbType.VarChar,50),
					new SqlParameter("@F_State", SqlDbType.Bit,1),
					new SqlParameter("@F_StartDate", SqlDbType.DateTime),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_CreateBy", SqlDbType.Int,4),
					new SqlParameter("@F_CreateName", SqlDbType.VarChar,30),
					new SqlParameter("@F_EditDate", SqlDbType.DateTime),
					new SqlParameter("@F_EditBy", SqlDbType.Int,4),
					new SqlParameter("@F_EditName", SqlDbType.VarChar,30),
					new SqlParameter("@F_XML", SqlDbType.Text),
					new SqlParameter("@F_EntityId", SqlDbType.Int,4),
					new SqlParameter("@F_MarkId", SqlDbType.Int,4),
					new SqlParameter("@F_Useless", SqlDbType.Bit,1),
					new SqlParameter("@F_VerID", SqlDbType.Int,4),
					new SqlParameter("@F_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.F_Name;
			parameters[1].Value = model.F_CategoryID;
			parameters[2].Value = model.F_CategoryName;
			parameters[3].Value = model.F_State;
			parameters[4].Value = model.F_StartDate;
			parameters[5].Value = model.F_CreateDate;
			parameters[6].Value = model.F_CreateBy;
			parameters[7].Value = model.F_CreateName;
			parameters[8].Value = model.F_EditDate;
			parameters[9].Value = model.F_EditBy;
			parameters[10].Value = model.F_EditName;
			parameters[11].Value = model.F_XML;
			parameters[12].Value = model.F_EntityId;
			parameters[13].Value = model.F_MarkId;
			parameters[14].Value = model.F_Useless;
			parameters[15].Value = model.F_VerID;
			parameters[16].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 T_Wf_WorkFlow ");
			strSql.Append(" where F_ID=@F_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@F_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 T_Wf_WorkFlow ");
			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 ZXDT.CallCenter.Model.T_Wf_WorkFlow GetModel(int F_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 F_ID,F_Name,F_CategoryID,F_CategoryName,F_State,F_StartDate,F_CreateDate,F_CreateBy,F_CreateName,F_EditDate,F_EditBy,F_EditName,F_XML,F_EntityId,F_MarkId,F_Useless,F_VerID from T_Wf_WorkFlow ");
			strSql.Append(" where F_ID=@F_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@F_ID", SqlDbType.Int,4)
};
			parameters[0].Value = F_ID;

			ZXDT.CallCenter.Model.T_Wf_WorkFlow model=new ZXDT.CallCenter.Model.T_Wf_WorkFlow();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["F_ID"]!=null && ds.Tables[0].Rows[0]["F_ID"].ToString()!="")
				{
					model.F_ID=int.Parse(ds.Tables[0].Rows[0]["F_ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Name"]!=null && ds.Tables[0].Rows[0]["F_Name"].ToString()!="")
				{
					model.F_Name=ds.Tables[0].Rows[0]["F_Name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_CategoryID"]!=null && ds.Tables[0].Rows[0]["F_CategoryID"].ToString()!="")
				{
					model.F_CategoryID=int.Parse(ds.Tables[0].Rows[0]["F_CategoryID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_CategoryName"]!=null && ds.Tables[0].Rows[0]["F_CategoryName"].ToString()!="")
				{
					model.F_CategoryName=ds.Tables[0].Rows[0]["F_CategoryName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_State"]!=null && ds.Tables[0].Rows[0]["F_State"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["F_State"].ToString()=="1")||(ds.Tables[0].Rows[0]["F_State"].ToString().ToLower()=="true"))
					{
						model.F_State=true;
					}
					else
					{
						model.F_State=false;
					}
				}
				if(ds.Tables[0].Rows[0]["F_StartDate"]!=null && ds.Tables[0].Rows[0]["F_StartDate"].ToString()!="")
				{
					model.F_StartDate=DateTime.Parse(ds.Tables[0].Rows[0]["F_StartDate"].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_CreateBy"]!=null && ds.Tables[0].Rows[0]["F_CreateBy"].ToString()!="")
				{
					model.F_CreateBy=int.Parse(ds.Tables[0].Rows[0]["F_CreateBy"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_CreateName"]!=null && ds.Tables[0].Rows[0]["F_CreateName"].ToString()!="")
				{
					model.F_CreateName=ds.Tables[0].Rows[0]["F_CreateName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_EditDate"]!=null && ds.Tables[0].Rows[0]["F_EditDate"].ToString()!="")
				{
					model.F_EditDate=DateTime.Parse(ds.Tables[0].Rows[0]["F_EditDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_EditBy"]!=null && ds.Tables[0].Rows[0]["F_EditBy"].ToString()!="")
				{
					model.F_EditBy=int.Parse(ds.Tables[0].Rows[0]["F_EditBy"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_EditName"]!=null && ds.Tables[0].Rows[0]["F_EditName"].ToString()!="")
				{
					model.F_EditName=ds.Tables[0].Rows[0]["F_EditName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_XML"]!=null && ds.Tables[0].Rows[0]["F_XML"].ToString()!="")
				{
					model.F_XML=ds.Tables[0].Rows[0]["F_XML"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_EntityId"]!=null && ds.Tables[0].Rows[0]["F_EntityId"].ToString()!="")
				{
					model.F_EntityId=int.Parse(ds.Tables[0].Rows[0]["F_EntityId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_MarkId"]!=null && ds.Tables[0].Rows[0]["F_MarkId"].ToString()!="")
				{
					model.F_MarkId=int.Parse(ds.Tables[0].Rows[0]["F_MarkId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Useless"]!=null && ds.Tables[0].Rows[0]["F_Useless"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["F_Useless"].ToString()=="1")||(ds.Tables[0].Rows[0]["F_Useless"].ToString().ToLower()=="true"))
					{
						model.F_Useless=true;
					}
					else
					{
						model.F_Useless=false;
					}
				}
				if(ds.Tables[0].Rows[0]["F_VerID"]!=null && ds.Tables[0].Rows[0]["F_VerID"].ToString()!="")
				{
					model.F_VerID=int.Parse(ds.Tables[0].Rows[0]["F_VerID"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select F_ID,F_Name,F_CategoryID,F_CategoryName,F_State,F_StartDate,F_CreateDate,F_CreateBy,F_CreateName,F_EditDate,F_EditBy,F_EditName,F_XML,F_EntityId,F_MarkId,F_Useless,F_VerID ");
			strSql.Append(" FROM T_Wf_WorkFlow ");
			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_Name,F_CategoryID,F_CategoryName,F_State,F_StartDate,F_CreateDate,F_CreateBy,F_CreateName,F_EditDate,F_EditBy,F_EditName,F_XML,F_EntityId,F_MarkId,F_Useless,F_VerID ");
			strSql.Append(" FROM T_Wf_WorkFlow ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			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_Wf_WorkFlow";
			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  Method
	}
}

