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

        /// <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;
            }
        }

转载于:https://www.cnblogs.com/smthts/archive/2012/07/26/2610378.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值