string sSql = "";
string sValue = txtCarNo.Text.Trim();
// 查询内容未输入
if (sValue.Length == 0)
{
txtCarNo.Focus();
return;
}
sValue = PublicClass.Check.ValueReplace(sValue);//特殊字条串处理
if (comType.SelectedValue.ToString() == "0")
{
// 车牌号码
sSql = "CarNum like '%" + sValue + "%'";
}
DataView dv = new DataView(m_dtCarList, sSql, "AreaCode,CarNum", DataViewRowState.CurrentRows);
#region 特殊字条串替换(DataView过滤)
/// <summary>
/// 特殊字条串替换(DataView过滤)
/// </summary>
/// <param name="sValue">原始字符串</param>
/// <returns>新字符串</returns>
public static string ValueReplace(string sValue)
{
string tempValue = "";
try
{
string[] sList = sValue.Split('[');
int index = sValue.IndexOf('[');
for (int i = 0; i < sList.Length; i++)
{
sList[i] = sList[i].Replace("]", "[]]");
sList[i] = sList[i].Replace("~", "[~]");
sList[i] = sList[i].Replace("@", "[@]");
sList[i] = sList[i].Replace("^", "[^]");
sList[i] = sList[i].Replace("&", "[&]");
sList[i] = sList[i].Replace("*", "[*]");
sList[i] = sList[i].Replace("(", "[(]");
sList[i] = sList[i].Replace(")", "[)]");
sList[i] = sList[i].Replace(">", "[>]");
sList[i] = sList[i].Replace("<", "[<]");
sList[i] = sList[i].Replace("`", "[`]");
sList[i] = sList[i].Replace("-", "[-]");
sList[i] = sList[i].Replace("=", "[=]");
if (index == -1)
{
tempValue += sList[i];
continue;
}
if (i == 0 && index == 0)
{
tempValue += "[[]" + sList[i];
}
else if (index == sValue.Length - 1)
{
if (i == sList.Length - 1)
{
tempValue += sList[i] + "[[]";
}
}
else
{
if (i == sList.Length - 1)
{
tempValue += sList[i];
}
else
{
tempValue += sList[i] + "[[]";
}
}
}
}
catch { }
return tempValue;
}
#endregion