要求:我有一个用C#编写的windows应用程序,目前只会搜索一个.corp文件(按公司搜索:160)我希望它搜索多个由逗号分隔的公司值(例如:按公司搜索:160,220,310,550,610)。C# - 查询多个逗号分隔值查询参数w /字符串分隔符
问题:如何搜索由逗号分隔的多个corp值? (例如:由Corp搜索:160,220,310,550,610)。 当有x个逗号(例如:Corp1,Corp2等)时,必须用逗号值分割字符串,并将每个字符串的值设置为x + 1个变量(例如:Corp1,Corp2,Corp3) Corp3具有2个逗号所以3个变量将必须被定义),然后循环搜索X + 1次对每个CORP的值
以下是在MainForm.cs代码相关的代码,其中CORP值被定义:
private SearchCriteria GetSearchCriteria()
{
// Initialize Search Parameters object
SearchCriteria sc = new SearchCriteria(textBoxCorp.Text,
textBoxOrderNumber.Text,
textBoxCampaign.Text,
textBoxCity.Text,
comboBoxState.Text,
textBoxZip.Text,
folderBrowserDialog1.SelectedPath,
folderBrowserDialog2.SelectedPath,
radioButtonAny.Checked,
radioButtonAll.Checked);
return sc;
}
private void textBoxCorp_TextChanged(object sender, EventArgs e) { }
这里是SearchProcess.cs其中CORP值带来和检查,看它是否阻铁相匹配的相关代码ch:
// Function runs in worker thread and emulates long process.
public void Run()
{
m_sc = (SearchCriteria)m_form.Invoke(m_form.m_DelegateGetSearchCriteria);
// Display parameters
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Corp: " + m_sc.get_Corp() });
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on OrderNumber: " + m_sc.get_OrderNumber() });
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Campaign: " + m_sc.get_Campaign() });
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on City: " + m_sc.get_City() });
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on State: " + m_sc.get_State() });
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Zip: " + m_sc.get_Zip() });
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Source Path: " + m_sc.get_SourcePath() });
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Target Path: " + m_sc.get_TargetPath() });
if (m_sc.get_SearchAND()==true)
{
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search for All" });
}
else
{
m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search for Any" });
}
// Found should be true if ANY of the criteria are met.
// This is an OR logic gate
// If any of the given fields do match then it is a true
if (m_sc.get_SearchOR().Equals(true))
{
// Check for the Corp type match
if (m_sc.get_Corp() != "" && String.Compare(AgentID, m_sc.get_Corp()) == 0)
{
found = true;
}
}
// Copy the file if ANY of the search criteria have been met
if (found)
{
m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"FOUND: Order_No: " + Order_No +
" barcode: " + barcode +
" MailerCode: " + MailerCode +
" AgentID: " + AgentID +
" City: " + City +
" State: " + State +
" ZIP: " + ZIP});
//passes values to TransferFile
TransferFile(directory, barcode, AgentID, ZIP);
}
} // end for that finds each matching record
任何帮助将不胜感激!谢谢!!!
谁能回答这个问题? – 2011-04-07 20:07:34