发现这个问题解释了一种在层之间进行通信的方式。然而还有一方面。
假设我使用接口将消息从 BLL 发送到 UI,如下例所示:
public interface IUiCallbacks
{
void SendMessage(string message);
void SendException(string message, Exception ex);
}
public class WinFormsUiCallbacks : IUiCallbacks
{
public void SendMessage(string message)
{
MessageBox.Show(message);
}
public void SendException(string message, Exception ex)
{
MessageBox.Show(string.Format("Unfortunately, the following errror has occurred:{0}{1}", Environment.NewLine, ex.Message));
}
}
public class OrderService
{
private IUiCallbacks _iUiCallbacks;
...
public OrderService() { ... }
public OrderService(IUiCallbacks iUiCallbacks)
{
_iUiCallbacks = iUiCallbacks;
}
...
public void AddOrder(Order order)
{
...
if(OrderAlreadyExists(order))
{
if(_iUiCallbacks != null)
_iUiCallbacks.SendMessage("The order can not be added, because it is already accepted.");
return;
}
...
}
...
}
我想要一个确认框来确认覆盖现有订单,而不是信息消息。
在这种情况下如何处理确认框的结果?
谢谢,亚历克斯