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_WorkOrderState
	/// </summary>
	public partial class T_Wo_WorkOrderState
	{
		public T_Wo_WorkOrderState()
		{}
		#region  Method

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ZXDT.CallCenter.Model.T_Wo_WorkOrderState model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Wo_WorkOrderState(");
			strSql.Append("F_Name,F_Code,F_Des,F_Sort,F_Stateimage,F_Deleteflag)");
			strSql.Append(" values (");
			strSql.Append("@F_Name,@F_Code,@F_Des,@F_Sort,@F_Stateimage,@F_Deleteflag)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@F_Name", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Code", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Des", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Sort", SqlDbType.Int,4),
					new SqlParameter("@F_Stateimage", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Deleteflag", SqlDbType.Int,4)};
			parameters[0].Value = model.F_Name;
			parameters[1].Value = model.F_Code;
			parameters[2].Value = model.F_Des;
			parameters[3].Value = model.F_Sort;
			parameters[4].Value = model.F_Stateimage;
			parameters[5].Value = model.F_Deleteflag;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ZXDT.CallCenter.Model.T_Wo_WorkOrderState model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Wo_WorkOrderState set ");
			strSql.Append("F_Name=@F_Name,");
			strSql.Append("F_Code=@F_Code,");
			strSql.Append("F_Des=@F_Des,");
			strSql.Append("F_Sort=@F_Sort,");
			strSql.Append("F_Stateimage=@F_Stateimage,");
			strSql.Append("F_Deleteflag=@F_Deleteflag");
			strSql.Append(" where F_WorkOrderStateId=@F_WorkOrderStateId");
			SqlParameter[] parameters = {
					new SqlParameter("@F_Name", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Code", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Des", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Sort", SqlDbType.Int,4),
					new SqlParameter("@F_Stateimage", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Deleteflag", SqlDbType.Int,4),
					new SqlParameter("@F_WorkOrderStateId", SqlDbType.Int,4)};
			parameters[0].Value = model.F_Name;
			parameters[1].Value = model.F_Code;
			parameters[2].Value = model.F_Des;
			parameters[3].Value = model.F_Sort;
			parameters[4].Value = model.F_Stateimage;
			parameters[5].Value = model.F_Deleteflag;
			parameters[6].Value = model.F_WorkOrderStateId;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZXDT.CallCenter.Model.T_Wo_WorkOrderState GetModel(int F_WorkOrderStateId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 F_WorkOrderStateId,F_Name,F_Code,F_Des,F_Sort,F_Stateimage,F_Deleteflag from T_Wo_WorkOrderState ");
			strSql.Append(" where F_WorkOrderStateId=@F_WorkOrderStateId");
			SqlParameter[] parameters = {
					new SqlParameter("@F_WorkOrderStateId", SqlDbType.Int,4)
};
			parameters[0].Value = F_WorkOrderStateId;

			ZXDT.CallCenter.Model.T_Wo_WorkOrderState model=new ZXDT.CallCenter.Model.T_Wo_WorkOrderState();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				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_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_Code"]!=null && ds.Tables[0].Rows[0]["F_Code"].ToString()!="")
				{
					model.F_Code=ds.Tables[0].Rows[0]["F_Code"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_Des"]!=null && ds.Tables[0].Rows[0]["F_Des"].ToString()!="")
				{
					model.F_Des=ds.Tables[0].Rows[0]["F_Des"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_Sort"]!=null && ds.Tables[0].Rows[0]["F_Sort"].ToString()!="")
				{
					model.F_Sort=int.Parse(ds.Tables[0].Rows[0]["F_Sort"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Stateimage"]!=null && ds.Tables[0].Rows[0]["F_Stateimage"].ToString()!="")
				{
					model.F_Stateimage=ds.Tables[0].Rows[0]["F_Stateimage"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_Deleteflag"]!=null && ds.Tables[0].Rows[0]["F_Deleteflag"].ToString()!="")
				{
					model.F_Deleteflag=int.Parse(ds.Tables[0].Rows[0]["F_Deleteflag"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select F_WorkOrderStateId,F_Name,F_Code,F_Des,F_Sort,F_Stateimage,F_Deleteflag ");
			strSql.Append(" FROM T_Wo_WorkOrderState ");
			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_WorkOrderStateId,F_Name,F_Code,F_Des,F_Sort,F_Stateimage,F_Deleteflag ");
			strSql.Append(" FROM T_Wo_WorkOrderState ");
			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_Wo_WorkOrderState";
			parameters[1].Value = "F_WorkOrderStateId";
			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
	}
}

