与问题相关:成功保存记录后显示消息

huangapple go评论66阅读模式
英文:

related to question: show message after a successful record saving

问题

我想要显示一个消息,只有在保存了一个新对象之后才会显示,并在其他记录保存情况下隐藏它,如何做到这一点?

英文:

I have been read the answer for the question written in the following link: https://stackoverflow.com/questions/69046380/show-message-after-a-successful-record-saving/69055284#69055284

The solution was very useful, but my question is: If I want to show a message only after a new object is saved, and hide it in other record saving cases, How to do that?

答案1

得分: 0

你可以像下面这样做。如果事件不是你要查找的事件类型,你就不设置消息。如果消息为null或为空,就不显示它。

void ObjectSpace_Committed(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(message))
    {
        MessageOptions options = new();
        options.Duration = 2000;
        options.Message = message;
        options.Type = InformationType.Success;
        options.Web.Position = InformationPosition.Right;
        options.Win.Caption = "Success";
        options.Win.Type = WinMessageType.Toast;
        Application.ShowViewStrategy.ShowMessage(options);
        message = string.Empty;
    }
}

void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e)
{
    if (ObjectSpace.IsNewObject(e.Object))
    {
        message = string.Format("Record Saved Successfully");
    }
}
英文:

You could do something like the below. If the event is not the event type you are looking for, you just don't set the message. And if the message is null or empty, you don't show it.

void ObjectSpace_Committed(object sender, EventArgs e)
{
    if (!string.IsNullOrEMpty(message))
    {
        MessageOptions options = new();
        options.Duration = 2000;
        options.Message = message;
        options.Type = InformationType.Success;
        options.Web.Position = InformationPosition.Right;
        options.Win.Caption = "Success";
        options.Win.Type = WinMessageType.Toast;
        Application.ShowViewStrategy.ShowMessage(options);
        message = string.Empty;
    }
}

void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e)
{
    if (ObjectSpace.IsNewObject(e.Object))
    {
        message=string.Format("Record Saved Successfully");
    }
}

huangapple
  • 本文由 发表于 2023年5月24日 17:53:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322230.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定