您的位置:首页 > 其它

原创---switch(T obj)选择语句如何判断是某一个对象

2012-07-26 17:07 423 查看
/// <summary>
/// 判断警单是否存在
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="ajbh">案件编号</param>
/// <param name="obj">对象实例(T1,T2,T3)</param>
/// <returns>true为存在,false为不存在</returns>
public bool GetCase<T>( string ajbh, T obj )
{
if (string.IsNullOrEmpty( ajbh ))
{
return true;
}
if (obj is Nullable)
{
return true;
}
int count = 0;
string sql = string.Empty;
switch (obj.GetType().Name.ToLower())
{
case "t1":
sql = string.Format( "select count(*) from t_case_1 t where t.bh='{0}'", ajbh );
break;
case "t2":
sql = string.Format( "select count(*) from t_case_2 t where t.bh='{0}'", ajbh );
break;
case "t3":
sql = string.Format( "select count(*) from t_case_3 t where t.bh='{0}'", ajbh );
break;
}

if (string.IsNullOrEmpty( sql ))
{
return true;
}
using (DbCommand cmd = database.GetSqlStringCommand( sql ))
{
count = Convert.ToInt32( database.ExecuteScalar( cmd ) );
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐