public static string doQuery()
{
bool hasWhere = false;
StringBuilder sql = new StringBuilder("select * from table");
if (true)
{
hasWhere = appendWhereIfNeed(sql, hasWhere);
sql.AppendLine("FNumber between ' 工号文本框1内容 ' and '工号文本框2内容 '");
}
if (true)
{
hasWhere = appendWhereIfNeed(sql, hasWhere);
sql.AppendLine("FNumber2 between ' 工号文本框1内容 ' and '工号文本框2内容 '");
}
if (true)
{
hasWhere = appendWhereIfNeed(sql, hasWhere);
sql.AppendLine("FNumber3 between ' 工号文本框1内容 ' and '工号文本框2内容 '");
}
return sql.ToString();
}
private static bool appendWhereIfNeed(StringBuilder sql, bool hasWhere)
{
if (hasWhere == false)
{
sql.AppendLine(" where ");
hasWhere = true;
}
else
{
sql.AppendLine(" and ");
}
return hasWhere;
}