多字段动态查询

private bool GetCondition(MerchantTravelXSJL tb, string key, string searchCity, string phoneNumber, DateTime? buyStartDate, DateTime? buyEndDate, int? checkStatus)
{
bool boolResult = true;

if (!String.IsNullOrEmpty(key))
{
boolResult &= tb.MERCHANTNAME == key;
}
if (!String.IsNullOrEmpty(searchCity))
{
boolResult &= tb.CITYCODE == searchCity;
}
if (!String.IsNullOrEmpty(phoneNumber))
{
boolResult &= tb.CELLPHONENUMBER == phoneNumber;

}
if (buyStartDate.HasValue)
{
boolResult &= (tb.CREATEDTIME >= buyStartDate.Value);
}
if (buyEndDate.HasValue)
{
boolResult &= tb.CREATEDTIME < buyEndDate.Value;
}
if (checkStatus.HasValue)
{
boolResult &= tb.STATUS == checkStatus;
}
return boolResult;
}

posted @ 2017-05-06 16:20  筱老邪  阅读(153)  评论(0)    收藏  举报