/// <summary> /// 获取行数据 /// </summary> /// <param name="model">查询对象</param> public DataRow GetRow(Adctab model) { string strwhere = " 1=1 "; Command db = new Command(); DbCommand cmd = db.CreateCommand(); #region -- 主键区 -- if(model.Aid > 0) { strwhere += " and aid = @Aid"; cmd.Parameters.Add(db.CreateParameter("@Aid", model.Aid,DbType.Int32)); } #endregion #region -- 数字区 -- if(model.AdcAge > 0) { strwhere += " and adcAge = @AdcAge"; cmd.Parameters.Add(db.CreateParameter("@AdcAge", model.AdcAge,DbType.Int32)); } if(model.AdcStatus > 0) { strwhere += " and adcStatus = @AdcStatus"; cmd.Parameters.Add(db.CreateParameter("@AdcStatus", model.AdcStatus,DbType.Int32)); } #endregion #region -- 字符区 -- if(!string.IsNullOrEmpty(model.AdcName)) { strwhere += " and adcName = @AdcName"; cmd.Parameters.Add(db.CreateParameter("@AdcName", model.AdcName,DbType.AnsiString)); } if(!string.IsNullOrEmpty(model.AdcSex)) { strwhere += " and adcSex = @AdcSex"; cmd.Parameters.Add(db.CreateParameter("@AdcSex", model.AdcSex,DbType.AnsiStringFixedLength)); } #endregion string sql = String.Format("SELECT {0} FROM adctab where {1} {2}", SelectedFields,strwhere, OrderBy); cmd.CommandText = sql; return db.GetRow(cmd); }
/// <summary> /// 获取分页数据 /// </summary> /// <param name="pageindex">当前页</param> /// <param name="pagesize">分页大小</param> /// <param name="rowCount">输出总行数</param> /// <param name="model">查询对象</param> public DataTable GetPageList(int pageindex, int pagesize, out int rowCount, Adctab model) { string strwhere = " 1=1 "; Command db = new Command(); DbCommand cmd = db.CreateCommand(); #region -- 主键区 -- if(model.Aid > 0) { strwhere += " and aid = @Aid"; cmd.Parameters.Add(db.CreateParameter("@Aid", model.Aid,DbType.Int32)); } #endregion #region -- 数字区 -- if(model.AdcAge > 0) { strwhere += " and adcAge = @AdcAge"; cmd.Parameters.Add(db.CreateParameter("@AdcAge", model.AdcAge,DbType.Int32)); } if(model.AdcStatus > 0) { strwhere += " and adcStatus = @AdcStatus"; cmd.Parameters.Add(db.CreateParameter("@AdcStatus", model.AdcStatus,DbType.Int32)); } #endregion #region -- 字符区 -- if(!string.IsNullOrEmpty(model.AdcName)) { strwhere += " and adcName like @AdcName+'%'"; cmd.Parameters.Add(db.CreateParameter("@AdcName", model.AdcName,DbType.AnsiString)); } if(!string.IsNullOrEmpty(model.AdcSex)) { strwhere += " and adcSex = @AdcSex"; cmd.Parameters.Add(db.CreateParameter("@AdcSex", model.AdcSex,DbType.AnsiStringFixedLength)); } #endregion string sql = String.Format("SELECT {0} FROM adctab where {1} {2}", SelectedFields,strwhere, OrderBy); string countSql = "SELECT COUNT(*) FROM adctab where " + strwhere; cmd.CommandText = countSql; rowCount = Convert.ToInt32(db.GetVar(cmd)); ISqlText sqlPage = SqlFactory.CreateSqlDialect(); string sqlPageText = sqlPage.GetPageSqlText(sql, pagesize, pageindex, "aid"); cmd.CommandText = sqlPageText; return db.Select(cmd); }