
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ZXDT.DBUtility;

namespace ZXDT.CallCenter.DAL
{
	/// <summary>
	/// 数据访问类:T_Good_TransGroup
	/// </summary>
	public partial class T_Good_TransGroup
	{
		public T_Good_TransGroup()
		{}
		#region  BasicMethod

		
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(ZXDT.CallCenter.Model.T_Good_TransGroup model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Good_TransGroup(");
			strSql.Append("F_GroupStatusId,F_GroupStatusName,F_RecivedDepId,F_RecivedDepName,F_RecivedUserID,F_RecivedUserName,F_CreateDepid,F_CreateDepName,F_CreateUserID,F_CreateUserName,F_CreateDate,F_UpdateDate)");
			strSql.Append(" values (");
			strSql.Append("@F_GroupStatusId,@F_GroupStatusName,@F_RecivedDepId,@F_RecivedDepName,@F_RecivedUserID,@F_RecivedUserName,@F_CreateDepid,@F_CreateDepName,@F_CreateUserID,@F_CreateUserName,@F_CreateDate,@F_UpdateDate)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@F_GroupStatusId", SqlDbType.Int,4),
					new SqlParameter("@F_GroupStatusName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_RecivedDepId", SqlDbType.Int,4),
					new SqlParameter("@F_RecivedDepName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_RecivedUserID", SqlDbType.Int,4),
					new SqlParameter("@F_RecivedUserName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_CreateDepid", SqlDbType.NChar,10),
					new SqlParameter("@F_CreateDepName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_CreateUserID", SqlDbType.Int,4),
					new SqlParameter("@F_CreateUserName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_UpdateDate", SqlDbType.DateTime)};
			parameters[0].Value = model.F_GroupStatusId;
			parameters[1].Value = model.F_GroupStatusName;
			parameters[2].Value = model.F_RecivedDepId;
			parameters[3].Value = model.F_RecivedDepName;
			parameters[4].Value = model.F_RecivedUserID;
			parameters[5].Value = model.F_RecivedUserName;
			parameters[6].Value = model.F_CreateDepid;
			parameters[7].Value = model.F_CreateDepName;
			parameters[8].Value = model.F_CreateUserID;
			parameters[9].Value = model.F_CreateUserName;
			parameters[10].Value = model.F_CreateDate;
			parameters[11].Value = model.F_UpdateDate;

			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_Good_TransGroup model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Good_TransGroup set ");
			strSql.Append("F_GroupStatusId=@F_GroupStatusId,");
			strSql.Append("F_GroupStatusName=@F_GroupStatusName,");
			strSql.Append("F_RecivedDepId=@F_RecivedDepId,");
			strSql.Append("F_RecivedDepName=@F_RecivedDepName,");
			strSql.Append("F_RecivedUserID=@F_RecivedUserID,");
			strSql.Append("F_RecivedUserName=@F_RecivedUserName,");
			strSql.Append("F_CreateDepid=@F_CreateDepid,");
			strSql.Append("F_CreateDepName=@F_CreateDepName,");
			strSql.Append("F_CreateUserID=@F_CreateUserID,");
			strSql.Append("F_CreateUserName=@F_CreateUserName,");
			strSql.Append("F_CreateDate=@F_CreateDate,");
			strSql.Append("F_UpdateDate=@F_UpdateDate");
            strSql.Append(" where F_Id=@F_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@F_GroupStatusId", SqlDbType.Int,4),
					new SqlParameter("@F_GroupStatusName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_RecivedDepId", SqlDbType.Int,4),
					new SqlParameter("@F_RecivedDepName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_RecivedUserID", SqlDbType.Int,4),
					new SqlParameter("@F_RecivedUserName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_CreateDepid", SqlDbType.NChar,10),
					new SqlParameter("@F_CreateDepName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_CreateUserID", SqlDbType.Int,4),
					new SqlParameter("@F_CreateUserName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_UpdateDate", SqlDbType.DateTime),
					new SqlParameter("@F_Id", SqlDbType.Int,4)};
			parameters[0].Value = model.F_GroupStatusId;
			parameters[1].Value = model.F_GroupStatusName;
			parameters[2].Value = model.F_RecivedDepId;
			parameters[3].Value = model.F_RecivedDepName;
			parameters[4].Value = model.F_RecivedUserID;
			parameters[5].Value = model.F_RecivedUserName;
			parameters[6].Value = model.F_CreateDepid;
			parameters[7].Value = model.F_CreateDepName;
			parameters[8].Value = model.F_CreateUserID;
			parameters[9].Value = model.F_CreateUserName;
			parameters[10].Value = model.F_CreateDate;
			parameters[11].Value = model.F_UpdateDate;
            parameters[12].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 id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_Good_TransGroup ");
            strSql.Append(" where F_Id=@F_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@F_Id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZXDT.CallCenter.Model.T_Good_TransGroup GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 F_Id,F_GroupStatusId,F_GroupStatusName,F_RecivedDepId,F_RecivedDepName,F_RecivedUserID,F_RecivedUserName,F_CreateDepid,F_CreateDepName,F_CreateUserID,F_CreateUserName,F_CreateDate,F_UpdateDate from T_Good_TransGroup ");
            strSql.Append(" where id=@F_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@F_Id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

			ZXDT.CallCenter.Model.T_Good_TransGroup model=new ZXDT.CallCenter.Model.T_Good_TransGroup();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZXDT.CallCenter.Model.T_Good_TransGroup DataRowToModel(DataRow row)
		{
			ZXDT.CallCenter.Model.T_Good_TransGroup model=new ZXDT.CallCenter.Model.T_Good_TransGroup();
			if (row != null)
			{
                if (row["F_Id"] != null && row["F_Id"].ToString() != "")
				{
                    model.F_Id = int.Parse(row["F_Id"].ToString());
				}
				if(row["F_GroupStatusId"]!=null && row["F_GroupStatusId"].ToString()!="")
				{
					model.F_GroupStatusId=int.Parse(row["F_GroupStatusId"].ToString());
				}
				if(row["F_GroupStatusName"]!=null)
				{
					model.F_GroupStatusName=row["F_GroupStatusName"].ToString();
				}
				if(row["F_RecivedDepId"]!=null && row["F_RecivedDepId"].ToString()!="")
				{
					model.F_RecivedDepId=int.Parse(row["F_RecivedDepId"].ToString());
				}
				if(row["F_RecivedDepName"]!=null)
				{
					model.F_RecivedDepName=row["F_RecivedDepName"].ToString();
				}
				if(row["F_RecivedUserID"]!=null && row["F_RecivedUserID"].ToString()!="")
				{
					model.F_RecivedUserID=int.Parse(row["F_RecivedUserID"].ToString());
				}
				if(row["F_RecivedUserName"]!=null)
				{
					model.F_RecivedUserName=row["F_RecivedUserName"].ToString();
				}
				if(row["F_CreateDepid"]!=null)
				{
					model.F_CreateDepid=row["F_CreateDepid"].ToString();
				}
				if(row["F_CreateDepName"]!=null)
				{
					model.F_CreateDepName=row["F_CreateDepName"].ToString();
				}
				if(row["F_CreateUserID"]!=null && row["F_CreateUserID"].ToString()!="")
				{
					model.F_CreateUserID=int.Parse(row["F_CreateUserID"].ToString());
				}
				if(row["F_CreateUserName"]!=null)
				{
					model.F_CreateUserName=row["F_CreateUserName"].ToString();
				}
				if(row["F_CreateDate"]!=null && row["F_CreateDate"].ToString()!="")
				{
					model.F_CreateDate=DateTime.Parse(row["F_CreateDate"].ToString());
				}
				if(row["F_UpdateDate"]!=null && row["F_UpdateDate"].ToString()!="")
				{
					model.F_UpdateDate=DateTime.Parse(row["F_UpdateDate"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select F_Id,F_GroupStatusId,F_GroupStatusName,F_RecivedDepId,F_RecivedDepName,F_RecivedUserID,F_RecivedUserName,F_CreateDepid,F_CreateDepName,F_CreateUserID,F_CreateUserName,F_CreateDate,F_UpdateDate ");
			strSql.Append(" FROM T_Good_TransGroup ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

	
		#endregion  BasicMethod
		
	}
}

