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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(ZXDT.CallCenter.Model.T_Good_TransInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Good_TransInfo(");
			strSql.Append("F_GroupKey,F_TStatus,F_TStatusName,F_RecivedDepId,F_RecivedDepName,F_RecivedUserID,F_RecivedUserName,F_RecivedDate,F_CreateDate,F_Remark,F_OtherDeptName,F_GoodInfoId)");
			strSql.Append(" values (");
			strSql.Append("@F_GroupKey,@F_TStatus,@F_TStatusName,@F_RecivedDepId,@F_RecivedDepName,@F_RecivedUserID,@F_RecivedUserName,@F_RecivedDate,@F_CreateDate,@F_Remark,@F_OtherDeptName,@F_GoodInfoId)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@F_GroupKey", SqlDbType.NVarChar,50),
					new SqlParameter("@F_TStatus", SqlDbType.Int,4),
					new SqlParameter("@F_TStatusName", 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_RecivedDate", SqlDbType.DateTime),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_Remark", SqlDbType.NVarChar,4000),
					new SqlParameter("@F_OtherDeptName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_GoodInfoId", SqlDbType.Int,4)};
			parameters[0].Value = model.F_GroupKey;
			parameters[1].Value = model.F_TStatus;
			parameters[2].Value = model.F_TStatusName;
			parameters[3].Value = model.F_RecivedDepId;
			parameters[4].Value = model.F_RecivedDepName;
			parameters[5].Value = model.F_RecivedUserID;
			parameters[6].Value = model.F_RecivedUserName;
			parameters[7].Value = model.F_RecivedDate;
			parameters[8].Value = model.F_CreateDate;
			parameters[9].Value = model.F_Remark;
			parameters[10].Value = model.F_OtherDeptName;
			parameters[11].Value = model.F_GoodInfoId;

			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_TransInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Good_TransInfo set ");
			strSql.Append("F_GroupKey=@F_GroupKey,");
			strSql.Append("F_TStatus=@F_TStatus,");
			strSql.Append("F_TStatusName=@F_TStatusName,");
			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_RecivedDate=@F_RecivedDate,");
			strSql.Append("F_CreateDate=@F_CreateDate,");
			strSql.Append("F_Remark=@F_Remark,");
			strSql.Append("F_OtherDeptName=@F_OtherDeptName,");
			strSql.Append("F_GoodInfoId=@F_GoodInfoId");
            strSql.Append(" where F_Id=@F_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@F_GroupKey", SqlDbType.NVarChar,50),
					new SqlParameter("@F_TStatus", SqlDbType.Int,4),
					new SqlParameter("@F_TStatusName", 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_RecivedDate", SqlDbType.DateTime),
					new SqlParameter("@F_CreateDate", SqlDbType.DateTime),
					new SqlParameter("@F_Remark", SqlDbType.NVarChar,4000),
					new SqlParameter("@F_OtherDeptName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_GoodInfoId", SqlDbType.Int,4),
					new SqlParameter("@F_Id", SqlDbType.Int,4)};
			parameters[0].Value = model.F_GroupKey;
			parameters[1].Value = model.F_TStatus;
			parameters[2].Value = model.F_TStatusName;
			parameters[3].Value = model.F_RecivedDepId;
			parameters[4].Value = model.F_RecivedDepName;
			parameters[5].Value = model.F_RecivedUserID;
			parameters[6].Value = model.F_RecivedUserName;
			parameters[7].Value = model.F_RecivedDate;
			parameters[8].Value = model.F_CreateDate;
			parameters[9].Value = model.F_Remark;
			parameters[10].Value = model.F_OtherDeptName;
			parameters[11].Value = model.F_GoodInfoId;
            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_TransInfo ");
            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_TransInfo ");
            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_TransInfo GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,F_GroupKey,F_TStatus,F_TStatusName,F_RecivedDepId,F_RecivedDepName,F_RecivedUserID,F_RecivedUserName,F_RecivedDate,F_CreateDate,F_Remark,F_OtherDeptName,F_GoodInfoId from T_Good_TransInfo ");
            strSql.Append(" where F_Id=@F_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@F_Id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

			ZXDT.CallCenter.Model.T_Good_TransInfo model=new ZXDT.CallCenter.Model.T_Good_TransInfo();
			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_TransInfo DataRowToModel(DataRow row)
		{
			ZXDT.CallCenter.Model.T_Good_TransInfo model=new ZXDT.CallCenter.Model.T_Good_TransInfo();
			if (row != null)
			{
                if (row["F_Id"] != null && row["F_Id"].ToString() != "")
				{
                    model.F_Id = int.Parse(row["F_Id"].ToString());
				}
				if(row["F_GroupKey"]!=null)
				{
					model.F_GroupKey=row["F_GroupKey"].ToString();
				}
				if(row["F_TStatus"]!=null && row["F_TStatus"].ToString()!="")
				{
					model.F_TStatus=int.Parse(row["F_TStatus"].ToString());
				}
				if(row["F_TStatusName"]!=null)
				{
					model.F_TStatusName=row["F_TStatusName"].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_RecivedDate"]!=null && row["F_RecivedDate"].ToString()!="")
				{
					model.F_RecivedDate=DateTime.Parse(row["F_RecivedDate"].ToString());
				}
				if(row["F_CreateDate"]!=null && row["F_CreateDate"].ToString()!="")
				{
					model.F_CreateDate=DateTime.Parse(row["F_CreateDate"].ToString());
				}
				if(row["F_Remark"]!=null)
				{
					model.F_Remark=row["F_Remark"].ToString();
				}
				if(row["F_OtherDeptName"]!=null)
				{
					model.F_OtherDeptName=row["F_OtherDeptName"].ToString();
				}
				if(row["F_GoodInfoId"]!=null && row["F_GoodInfoId"].ToString()!="")
				{
					model.F_GoodInfoId=int.Parse(row["F_GoodInfoId"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select F_Id,F_GroupKey,F_TStatus,F_TStatusName,F_RecivedDepId,F_RecivedDepName,F_RecivedUserID,F_RecivedUserName,F_RecivedDate,F_CreateDate,F_Remark,F_OtherDeptName,F_GoodInfoId ");
			strSql.Append(" FROM T_Good_TransInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}

            strSql.Append(" order by F_Id ");
			return DbHelperSQL.Query(strSql.ToString());
		}

		
		#endregion  BasicMethod
		
	}
}

