0

要件:現在、.CSV ファイルを 1 つの Corp 値 (例: Search by Corp: 160) でのみ検索する C# で記述された Windows アプリケーションがあり、コンマで区切られた複数の Corp 値 (例: Search by Corp) を検索する必要があります。 : 160、220、310、550、610)。

問題:コンマで区切られた複数の corp 値を検索するにはどうすればよいですか?? (例: Corp で検索: 160、220、310、550、610)。文字列はカンマ値で分割する必要があり、各文字列の値は変数の x+1 に設定する必要があります (例: Corp1、Corp2、Corp3)。には 2 つのコンマがあるため、3 つの変数を定義する必要があります)、各 corp 値に対して検索を x+1 回ループします

corp 値が定義されているMainForm.csコード内の関連コードを次に示します。

    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) { }

corp 値が取り込まれ、検索と一致するかどうかがチェックされるSearchProcess.csの関連コードを次に示します。

    // 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 

どんな助けでも大歓迎です!ありがとう!!!

4

1 に答える 1

1

あなたが何をしているのか完全にはわかりません.検索を行うデータソースはどこにあるので、推測してください:

string sCorpFilter = m_sc.get_Corp();
IEnumerable<string> corps = null;

if (! string.IsNullOrEmpty(sCorpFilter))
{
  corps = sCorpFilter.Split(",".ToCharArray(),
   StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim());
}
[...]
if (corps != null && corps.Contains(AgentID))
{
  found = true;
}
于 2011-02-25T16:12:59.597 に答える