using System;
using System.Data;
using System.Text;
using RMYY_CallCenter_Api.DB;
using System.Collections;
using System.Data.SqlClient;
namespace RMYY_CallCenter_Api.DAL
{
	/// <summary>
	/// 数据访问类:T_Wo_CommonBase
	/// </summary>
	public partial class T_Wo_CommonBase
	{
		public T_Wo_CommonBase()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(RMYY_CallCenter_Api.Model.T_Wo_CommonBase model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Wo_CommonBase(");
			strSql.Append("F_WoCode,F_CreateUser,F_Type,F_SonType,F_Content,F_Proposer,F_ProposerDept,F_DealUser,F_DealDept,F_TimeLimit,F_Status,F_IsDone,F_InternalWorkOrderCode,F_ExternalWorkOrderCode,F_CreateTime,F_UpdateTime,F_Phone)");
			strSql.Append(" values (");
			strSql.Append("@F_WoCode,@F_CreateUser,@F_Type,@F_SonType,@F_Content,@F_Proposer,@F_ProposerDept,@F_DealUser,@F_DealDept,@F_TimeLimit,@F_Status,@F_IsDone,@F_InternalWorkOrderCode,@F_ExternalWorkOrderCode,@F_CreateTime,@F_UpdateTime,@F_Phone)");
			SqlParameter[] parameters = {
					new SqlParameter("@F_WoCode", SqlDbType.VarChar,50),
					new SqlParameter("@F_CreateUser", SqlDbType.Int,4),
					new SqlParameter("@F_Type", SqlDbType.Int,4),
					new SqlParameter("@F_SonType", SqlDbType.Int,4),
					new SqlParameter("@F_Content", SqlDbType.Text),
					new SqlParameter("@F_Proposer", SqlDbType.NVarChar,50),
					new SqlParameter("@F_ProposerDept", SqlDbType.Int,4),
					new SqlParameter("@F_DealUser", SqlDbType.Int,4),
					new SqlParameter("@F_DealDept", SqlDbType.Int,4),
					new SqlParameter("@F_TimeLimit", SqlDbType.DateTime,3),
					new SqlParameter("@F_Status", SqlDbType.Int,4),
					new SqlParameter("@F_IsDone", SqlDbType.Int,4),
					new SqlParameter("@F_InternalWorkOrderCode", SqlDbType.VarChar,500),
					new SqlParameter("@F_ExternalWorkOrderCode", SqlDbType.VarChar,500),
					new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
					new SqlParameter("@F_UpdateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_Phone", SqlDbType.VarChar,50)
            };
			parameters[0].Value = model.F_WoCode;
			parameters[1].Value = model.F_CreateUser;
			parameters[2].Value = model.F_Type;
			parameters[3].Value = model.F_SonType;
			parameters[4].Value = model.F_Content;
			parameters[5].Value = model.F_Proposer;
			parameters[6].Value = model.F_ProposerDept;
			parameters[7].Value = model.F_DealUser;
			parameters[8].Value = model.F_DealDept;
			parameters[9].Value = model.F_TimeLimit;
			parameters[10].Value = model.F_Status;
			parameters[11].Value = model.F_IsDone;
			parameters[12].Value = model.F_InternalWorkOrderCode;
			parameters[13].Value = model.F_ExternalWorkOrderCode;
			parameters[14].Value = model.F_CreateTime;
			parameters[15].Value = model.F_UpdateTime;
            parameters[16].Value = model.F_Phone;
            

            return DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
		}
	
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(RMYY_CallCenter_Api.Model.T_Wo_CommonBase model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Wo_CommonBase set ");
		//	strSql.Append("F_WoCode=@F_WoCode,");
			strSql.Append("F_CreateUser=@F_CreateUser,");
			strSql.Append("F_Type=@F_Type,");
			strSql.Append("F_SonType=@F_SonType,");
			strSql.Append("F_Content=@F_Content,");
			strSql.Append("F_Proposer=@F_Proposer,");
			strSql.Append("F_ProposerDept=@F_ProposerDept,");
			strSql.Append("F_DealUser=@F_DealUser,");
			strSql.Append("F_DealDept=@F_DealDept,");
			strSql.Append("F_TimeLimit=@F_TimeLimit,");
			strSql.Append("F_Status=@F_Status,");
			strSql.Append("F_IsDelete=@F_IsDelete,");
			strSql.Append("F_IsDone=@F_IsDone,");
			strSql.Append("F_InternalWorkOrderCode=@F_InternalWorkOrderCode,");
			strSql.Append("F_ExternalWorkOrderCode=@F_ExternalWorkOrderCode,");
			strSql.Append("F_CreateTime=@F_CreateTime,");
			strSql.Append("F_UpdateTime=@F_UpdateTime,");
            strSql.Append("F_Phone=@F_Phone,");
            strSql.Append("F_UrgeCount=@F_UrgeCount");
            

            strSql.Append(" where F_WoCode=@F_WoCode");
			SqlParameter[] parameters = {
					new SqlParameter("@F_WoCode", SqlDbType.VarChar,50),
					new SqlParameter("@F_CreateUser", SqlDbType.Int,4),
					new SqlParameter("@F_Type", SqlDbType.Int,4),
					new SqlParameter("@F_SonType", SqlDbType.Int,4),
					new SqlParameter("@F_Content", SqlDbType.Text),
					new SqlParameter("@F_Proposer", SqlDbType.NVarChar,50),
					new SqlParameter("@F_ProposerDept", SqlDbType.Int,4),
					new SqlParameter("@F_DealUser", SqlDbType.NVarChar,50),
					new SqlParameter("@F_DealDept", SqlDbType.Int,4),
					new SqlParameter("@F_TimeLimit", SqlDbType.DateTime,3),
					new SqlParameter("@F_Status", SqlDbType.Int,4),
					new SqlParameter("@F_IsDelete", SqlDbType.Int,4),
					new SqlParameter("@F_IsDone", SqlDbType.Int,4),
					new SqlParameter("@F_InternalWorkOrderCode", SqlDbType.VarChar,500),
					new SqlParameter("@F_ExternalWorkOrderCode", SqlDbType.VarChar,500),
					new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
					new SqlParameter("@F_UpdateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_Phone", SqlDbType.VarChar,50),
                                  new SqlParameter("@F_UrgeCount", SqlDbType.Int,4)
            };
			parameters[0].Value = model.F_WoCode;
			parameters[1].Value = model.F_CreateUser;
			parameters[2].Value = model.F_Type;
			parameters[3].Value = model.F_SonType;
			parameters[4].Value = model.F_Content;
			parameters[5].Value = model.F_Proposer;
			parameters[6].Value = model.F_ProposerDept;
			parameters[7].Value = model.F_DealUser;
			parameters[8].Value = model.F_DealDept;
			parameters[9].Value = model.F_TimeLimit;
			parameters[10].Value = model.F_Status;

            parameters[11].Value = model.F_IsDelete;
            parameters[12].Value = model.F_IsDone;
			parameters[13].Value = model.F_InternalWorkOrderCode;
			parameters[14].Value = model.F_ExternalWorkOrderCode;
			parameters[15].Value = model.F_CreateTime;
			parameters[16].Value = model.F_UpdateTime;
            parameters[17].Value = model.F_Phone;
            parameters[18].Value = model.F_UrgeCount;
            int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_Wo_CommonBase ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
};

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public RMYY_CallCenter_Api.Model.T_Wo_CommonBase GetModel(string F_WoCode)
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 * from T_Wo_CommonBase ");
			strSql.Append(" where F_WoCode=@F_WoCode");
 
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WoCode", SqlDbType.VarChar)
            };
            parameters[0].Value = F_WoCode;
            RMYY_CallCenter_Api.Model.T_Wo_CommonBase model=new RMYY_CallCenter_Api.Model.T_Wo_CommonBase();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return ConvertToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select F_WoCode,F_CreateUser,F_Type,F_Phone,F_SonType,F_Content,F_Proposer,F_ProposerDept,F_DealUser,F_DealDept,F_TimeLimit,F_Status,F_IsDelete,F_IsDone,F_InternalWorkOrderCode,F_ExternalWorkOrderCode,F_CreateTime,F_UpdateTime ");
			strSql.Append(" FROM T_Wo_CommonBase ");
			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_WoCode,F_CreateUser,F_Type,F_SonType,F_Phone,F_Content,F_Proposer,F_ProposerDept,F_DealUser,F_DealDept,F_TimeLimit,F_Status,F_IsDelete,F_IsDone,F_InternalWorkOrderCode,F_ExternalWorkOrderCode,F_CreateTime,F_UpdateTime ");
			strSql.Append(" FROM T_Wo_CommonBase ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}


		/// <summary>
		/// 获取指定字段数据
		/// </summary>
		public DataTable GetFieldList(string field,string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			string select = "*";
			if(field.Trim()!="")
			{
				select = field;
			}
			strSql.Append("select "+select);
			strSql.Append(" FROM T_Wo_CommonBase ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString()).Tables[0];
		}


		/// <summary>
		/// 装换成实体类
		/// </summary>
		public RMYY_CallCenter_Api.Model.T_Wo_CommonBase ConvertToModel(DataRow dr)
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			if (dr != null)
			{
				RMYY_CallCenter_Api.Model.T_Wo_CommonBase model=new RMYY_CallCenter_Api.Model.T_Wo_CommonBase();
				model.F_WoCode=dr["F_WoCode"].ToString();
				if(dr["F_CreateUser"].ToString()!="")
				{
					model.F_CreateUser=int.Parse(dr["F_CreateUser"].ToString());
				}
				if(dr["F_Type"].ToString()!="")
				{
					model.F_Type=int.Parse(dr["F_Type"].ToString());
				}
				if(dr["F_SonType"].ToString()!="")
				{
					model.F_SonType=int.Parse(dr["F_SonType"].ToString());
				}
				model.F_Content=dr["F_Content"].ToString();
				if(dr["F_Proposer"].ToString()!="")
				{
					model.F_Proposer= dr["F_Proposer"].ToString();
				}
				if(dr["F_ProposerDept"].ToString()!="")
				{
					model.F_ProposerDept=int.Parse(dr["F_ProposerDept"].ToString());
				}
				if(dr["F_DealUser"].ToString()!="")
				{
					model.F_DealUser = dr["F_DealUser"].ToString();
                }
				if(dr["F_DealDept"].ToString()!="")
				{
					model.F_DealDept=int.Parse(dr["F_DealDept"].ToString());
				}
				if(dr["F_TimeLimit"].ToString()!="")
				{
					model.F_TimeLimit=DateTime.Parse(dr["F_TimeLimit"].ToString());
				}


                if (dr["F_Status"].ToString()!="")
				{
					model.F_Status=int.Parse(dr["F_Status"].ToString());
				}
				if (dr["F_IsDelete"].ToString() != "")
				{
					model.F_IsDelete = int.Parse(dr["F_IsDelete"].ToString());
				}
				if (dr["F_IsDone"].ToString() != "")
				{
					model.F_IsDone = int.Parse(dr["F_IsDone"].ToString());
				}
				if (dr["F_InternalWorkOrderCode"].ToString() != "")
				{
					model.F_InternalWorkOrderCode = dr["F_InternalWorkOrderCode"].ToString();
				}
				if (dr["F_ExternalWorkOrderCode"].ToString() != "")
				{
					model.F_ExternalWorkOrderCode = dr["F_ExternalWorkOrderCode"].ToString();
				}
				if (dr["F_CreateTime"].ToString()!="")
				{
					model.F_CreateTime=DateTime.Parse(dr["F_CreateTime"].ToString());
				}
				if(dr["F_UpdateTime"].ToString()!="")
				{
					model.F_UpdateTime=DateTime.Parse(dr["F_UpdateTime"].ToString());
				}
                if (dr["F_Phone"].ToString() != "")
                {
                    model.F_Phone = dr["F_Phone"].ToString();
                }
                if (dr["F_ReplayCount"] != null && dr["F_ReplayCount"].ToString() != "")
                {
                    model.F_ReplayCount = int.Parse(dr["F_ReplayCount"].ToString());
                }
                if (dr["F_UrgeCount"] != null && dr["F_UrgeCount"].ToString() != "")
                {
                    model.F_UrgeCount = int.Parse(dr["F_UrgeCount"].ToString());
                }
                return model;
			}
			else
			{
				return null;
			}
		}

		#endregion  Method
	}
}

