0

テキストボックス付きのコントロールがあります。ユーザーが数行のテキストを入力し、それをボタンで送信した後、テキストの行ごとに、ユーザーが値を選択する必要があるグリッド付きの子ウィンドウを表示する必要があります。

ユーザーがクライアントの名前を含む 5 行のテキストを入力するとします (1 行 1 クライアント名)。

[送信] をクリックした後、すべてのユーザーに対して、ChildWindow から営業担当者を選択する必要があります。

もちろん、私のループの効果は、同時に5つのChildWindowsを開いています。

Childwindow grid から要素を選択した後にのみ、ユーザーが次の ChildWindow を取得するにはどうすればよいですか?

4

1 に答える 1

1

おそらく、あなたのコントロールはこのようなクラスを使用することができます.

public class SalesPersonSelector
{
    private Queue<string> _clientNamesToProcess;
    private Dictionary<string, SalesPerson> _selectedSalesPersons;
    private Action<IDictionary<string, SalesPerson>> _onComplete;
    private string _currentClientName;

    public void ProcessNames(IEnumerable<string> clientNames, Action<IDictionary<string, SalesPerson>> onComplete)
    {
        this._clientNamesToProcess = new Queue<string>(clientNames);
        this._selectedSalesPersons = new Dictionary<string, SalesPerson>();
        this._onComplete = onComplete;
        this.SelectSalespersonForNextClient();
    }

    private void SelectSalespersonForNextClient()
    {
        if (this._clientNamesToProcess.Any())
        {
            this._currentClientName = this._clientNamesToProcess.Dequeue();
            ChildWindow childWindow = this.CreateChildWindow(this._currentClientName);
            childWindow.Closed += new EventHandler(childWindow_Closed);
            childWindow.Show();
        }
        else
        {
            this._onComplete(this._selectedSalesPersons);
        }
    }

    private ChildWindow CreateChildWindow(string nextClientName)
    {
        // TODO: Create child window and give it access to the client name somehow.
        throw new NotImplementedException();
    }

    private void childWindow_Closed(object sender, EventArgs e)
    {
        var salesPerson = this.GetSelectedSalesPersonFrom(sender as ChildWindow);
        this._selectedSalesPersons.Add(this._currentClientName, salesPerson);
        this.SelectSalespersonForNextClient();
    }

    private SalesPerson GetSelectedSalesPersonFrom(ChildWindow childWindow)
    {
        // TODO: Get the selected salesperson somehow.
        throw new NotImplementedException();
    }
}

コントロールが既に TextBox の名前を "names" というリストに分割していると仮定すると、次のようにすることができます。

var salesPersonSelector = new SalesPersonSelector();
salesPersonSelector.ProcessNames(names, selections =>
    {
        foreach (var selection in selections)
        {
            var clientName = selection.Key;
            var salesPerson = selection.Value;
            // TODO: Do something with this information.
        }
    });

これはテストしていませんが、Visual Studio で赤い波線が表示されません。

于 2012-05-01T19:54:53.440 に答える