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

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

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int F_Id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_Wo_StateAlarmDate");
			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_Wo_StateAlarmDate model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Wo_StateAlarmDate(");
			strSql.Append("F_DeptId,F_DeptCode,F_WorkOrderTypeId,F_WorkOrderStateId,F_Gcount,F_Gunit,F_Ccount,F_Cunit,F_IsMain,F_DeleteFlag,F_Createby,F_CreateDate,F_ModifyBy,F_ModifyDate)");
			strSql.Append(" values (");
			strSql.Append("@F_DeptId,@F_DeptCode,@F_WorkOrderTypeId,@F_WorkOrderStateId,@F_Gcount,@F_Gunit,@F_Ccount,@F_Cunit,@F_IsMain,@F_DeleteFlag,@F_Createby,@F_CreateDate,@F_ModifyBy,@F_ModifyDate)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@F_DeptId", SqlDbType.Int,4),
					new SqlParameter("@F_DeptCode", SqlDbType.NVarChar,50),
					new SqlParameter("@F_WorkOrderTypeId", SqlDbType.Int,4),
					new SqlParameter("@F_WorkOrderStateId", SqlDbType.Int,4),
					new SqlParameter("@F_Gcount", SqlDbType.Int,4),
					new SqlParameter("@F_Gunit", SqlDbType.Int,4),
					new SqlParameter("@F_Ccount", SqlDbType.Int,4),
					new SqlParameter("@F_Cunit", SqlDbType.Int,4),
					new SqlParameter("@F_IsMain", SqlDbType.Int,4),
					new SqlParameter("@F_DeleteFlag", SqlDbType.Int,4),
					new SqlParameter("@F_Createby", SqlDbType.Int,4),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_ModifyBy", SqlDbType.Int,4),
					new SqlParameter("@F_ModifyDate", SqlDbType.DateTime)};
			parameters[0].Value = model.F_DeptId;
			parameters[1].Value = model.F_DeptCode;
			parameters[2].Value = model.F_WorkOrderTypeId;
			parameters[3].Value = model.F_WorkOrderStateId;
			parameters[4].Value = model.F_Gcount;
			parameters[5].Value = model.F_Gunit;
			parameters[6].Value = model.F_Ccount;
			parameters[7].Value = model.F_Cunit;
			parameters[8].Value = model.F_IsMain;
			parameters[9].Value = model.F_DeleteFlag;
			parameters[10].Value = model.F_Createby;
			parameters[11].Value = model.F_CreateDate;
			parameters[12].Value = model.F_ModifyBy;
			parameters[13].Value = model.F_ModifyDate;

			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_StateAlarmDate model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Wo_StateAlarmDate set ");
			strSql.Append("F_DeptId=@F_DeptId,");
			strSql.Append("F_DeptCode=@F_DeptCode,");
			strSql.Append("F_WorkOrderTypeId=@F_WorkOrderTypeId,");
			strSql.Append("F_WorkOrderStateId=@F_WorkOrderStateId,");
			strSql.Append("F_Gcount=@F_Gcount,");
			strSql.Append("F_Gunit=@F_Gunit,");
			strSql.Append("F_Ccount=@F_Ccount,");
			strSql.Append("F_Cunit=@F_Cunit,");
			strSql.Append("F_IsMain=@F_IsMain,");
			strSql.Append("F_DeleteFlag=@F_DeleteFlag,");
			strSql.Append("F_Createby=@F_Createby,");
			strSql.Append("F_CreateDate=@F_CreateDate,");
			strSql.Append("F_ModifyBy=@F_ModifyBy,");
			strSql.Append("F_ModifyDate=@F_ModifyDate");
			strSql.Append(" where F_Id=@F_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@F_DeptId", SqlDbType.Int,4),
					new SqlParameter("@F_DeptCode", SqlDbType.NVarChar,50),
					new SqlParameter("@F_WorkOrderTypeId", SqlDbType.Int,4),
					new SqlParameter("@F_WorkOrderStateId", SqlDbType.Int,4),
					new SqlParameter("@F_Gcount", SqlDbType.Int,4),
					new SqlParameter("@F_Gunit", SqlDbType.Int,4),
					new SqlParameter("@F_Ccount", SqlDbType.Int,4),
					new SqlParameter("@F_Cunit", SqlDbType.Int,4),
					new SqlParameter("@F_IsMain", SqlDbType.Int,4),
					new SqlParameter("@F_DeleteFlag", SqlDbType.Int,4),
					new SqlParameter("@F_Createby", SqlDbType.Int,4),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_ModifyBy", SqlDbType.Int,4),
					new SqlParameter("@F_ModifyDate", SqlDbType.DateTime),
					new SqlParameter("@F_Id", SqlDbType.Int,4)};
			parameters[0].Value = model.F_DeptId;
			parameters[1].Value = model.F_DeptCode;
			parameters[2].Value = model.F_WorkOrderTypeId;
			parameters[3].Value = model.F_WorkOrderStateId;
			parameters[4].Value = model.F_Gcount;
			parameters[5].Value = model.F_Gunit;
			parameters[6].Value = model.F_Ccount;
			parameters[7].Value = model.F_Cunit;
			parameters[8].Value = model.F_IsMain;
			parameters[9].Value = model.F_DeleteFlag;
			parameters[10].Value = model.F_Createby;
			parameters[11].Value = model.F_CreateDate;
			parameters[12].Value = model.F_ModifyBy;
			parameters[13].Value = model.F_ModifyDate;
			parameters[14].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_Wo_StateAlarmDate ");
			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_Wo_StateAlarmDate ");
			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_Wo_StateAlarmDate GetModel(int F_Id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 F_Id,F_DeptId,F_DeptCode,F_WorkOrderTypeId,F_WorkOrderStateId,F_Gcount,F_Gunit,F_Ccount,F_Cunit,F_IsMain,F_DeleteFlag,F_Createby,F_CreateDate,F_ModifyBy,F_ModifyDate from T_Wo_StateAlarmDate ");
			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_Wo_StateAlarmDate model=new ZXDT.CallCenter.Model.T_Wo_StateAlarmDate();
			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_DeptId"]!=null && ds.Tables[0].Rows[0]["F_DeptId"].ToString()!="")
				{
					model.F_DeptId=int.Parse(ds.Tables[0].Rows[0]["F_DeptId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_DeptCode"]!=null && ds.Tables[0].Rows[0]["F_DeptCode"].ToString()!="")
				{
					model.F_DeptCode=ds.Tables[0].Rows[0]["F_DeptCode"].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_Gcount"]!=null && ds.Tables[0].Rows[0]["F_Gcount"].ToString()!="")
				{
					model.F_Gcount=int.Parse(ds.Tables[0].Rows[0]["F_Gcount"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Gunit"]!=null && ds.Tables[0].Rows[0]["F_Gunit"].ToString()!="")
				{
					model.F_Gunit=int.Parse(ds.Tables[0].Rows[0]["F_Gunit"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Ccount"]!=null && ds.Tables[0].Rows[0]["F_Ccount"].ToString()!="")
				{
					model.F_Ccount=int.Parse(ds.Tables[0].Rows[0]["F_Ccount"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Cunit"]!=null && ds.Tables[0].Rows[0]["F_Cunit"].ToString()!="")
				{
					model.F_Cunit=int.Parse(ds.Tables[0].Rows[0]["F_Cunit"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_IsMain"]!=null && ds.Tables[0].Rows[0]["F_IsMain"].ToString()!="")
				{
					model.F_IsMain=int.Parse(ds.Tables[0].Rows[0]["F_IsMain"].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());
				}
				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_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_ModifyBy"]!=null && ds.Tables[0].Rows[0]["F_ModifyBy"].ToString()!="")
				{
					model.F_ModifyBy=int.Parse(ds.Tables[0].Rows[0]["F_ModifyBy"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_ModifyDate"]!=null && ds.Tables[0].Rows[0]["F_ModifyDate"].ToString()!="")
				{
					model.F_ModifyDate=DateTime.Parse(ds.Tables[0].Rows[0]["F_ModifyDate"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select F_Id,F_DeptId,F_DeptCode,F_WorkOrderTypeId,F_WorkOrderStateId,F_Gcount,F_Gunit,F_Ccount,F_Cunit,F_IsMain,F_DeleteFlag,F_Createby,F_CreateDate,F_ModifyBy,F_ModifyDate ");
			strSql.Append(" FROM T_Wo_StateAlarmDate ");
			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_DeptId,F_DeptCode,F_WorkOrderTypeId,F_WorkOrderStateId,F_Gcount,F_Gunit,F_Ccount,F_Cunit,F_IsMain,F_DeleteFlag,F_Createby,F_CreateDate,F_ModifyBy,F_ModifyDate ");
			strSql.Append(" FROM T_Wo_StateAlarmDate ");
			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_StateAlarmDate";
			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
	}
}

