public string GetQuerySql(ITSPAreaQueryModel model, object state = null)
{
var sqlBuilder = new StringBuilder();
sqlBuilder.AppendFormat(@"{0}
/*---Script For Select Top N Rows---*/
SELECT SQL_CALC_FOUND_ROWS
a.Id,
a.AreaName ,
a.Location ,
a.AreaHead ,
a.Remark ,
a.RowState,
a.CreateOn,
a.CreateBy,
a.UpdateOn,
a.UpdateBy
FROM ITSPArea as a", _SqlComment);
if (model.RowState == null)
{
sqlBuilder.AppendFormat("{0}WHERE a.RowState IN ( 0,1 )", Environment.NewLine);
}
else
{
sqlBuilder.AppendFormat("{0}WHERE a.RowState={1}", Environment.NewLine, model.RowState);
}
if (!string.IsNullOrEmpty(model.AreaName))
{
sqlBuilder.AppendFormat("{0}and a.AreaName=@AreaName", Environment.NewLine);
}
if (!string.IsNullOrEmpty(model.AreaHead))
{
sqlBuilder.AppendFormat("{0}and a.AreaHead=@AreaHead", Environment.NewLine);
}
sqlBuilder.AppendFormat("{0}order by a.CreateOn desc", Environment.NewLine);
sqlBuilder.AppendFormat("{0}LIMIT {1},{2};", Environment.NewLine, (model.PageIndex - ) * model.PageSize, model.PageSize);
sqlBuilder.AppendFormat("{0}SELECT FOUND_ROWS()", Environment.NewLine);
return sqlBuilder.ToString();
}