0

我有一个带有文本框的控件。在用户输入几行文本并通过按钮提交之后,对于每一行文本,我需要显示一个带有网格的子窗口,用户必须在其中选择一些值。

假设用户输入了 5 行带有客户名称的文本(一行一个客户名称)。

对于他们每个人在单击提交后,他必须从 ChildWindow 中选择 Salesperson。

当然现在我的循环效果是同时打开 5 个 ChildWindows。

仅在从 Childwindow 网格中选择一个元素后,如何让用户获取下一个 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 中的名称拆分为一个名为“名称”的列表,那么您可以这样做:

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 回答