原创---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; } }
相关文章推荐
- 如何判断一个C++对象是否在堆上(通过GetProcessHeaps取得所有堆,然后与对象地址比较即可),附许多精彩评论
- js如何判断一个对象是不是Array?
- javascript如何判断一个对象是否是窗口
- JVM如何判断一个Java对象是否可以回收
- java怎么判断两个Set 里的对象的值是否相同【两个set中的值是否相等】、java treeset和hashset如何判断元素是否相同【即对象是否完全相同;利用一个set去除重复元素】
- switch语句中的case后面的分枝值如何指定一个范围
- 如何判断一个C++对象是否在堆栈上(通过VirtualQuery这个API来获取堆栈的起始地址,然后就可以得到答案了),附许多精彩评论
- win10 uwp 如何判断一个对象被移除
- 如何判断一个JS对象是DOM对象
- javascript 如何判断一个对象的类型
- js如何判断一个对象为空
- js如何判断一个对象是不是Array?
- Oracle 如何查询一个对象的完整定义语句 .
- js如何判断一个对象{}是否为空对象,没有任何属性
- js如何判断一个对象是不是Array?
- 【OC学习-15】如何判断两个对象是否属于同一个类?如何判断一个对象是否属于某一个类?
- GC是如何判断一个对象为"垃圾"的?被GC判断为"垃圾"的对象一定会被回收吗?
- Swift:如何判断一个对象是否是某个类(或其子类)的实例
- 如何判断一个C++对象是否在堆上
- .net C# 如何判断一个对象是否具有某个方法