【问题标题】:Lightswitch custom addandeditnew screen灯开关自定义添加和编辑新屏幕
【发布时间】:2014-02-21 22:23:24
【问题描述】:

我有一个客户实体的列表和详细信息应用程序,当用户单击addnewandedit 按钮时,我想打开一个包含有限数量字段的自定义模式屏幕。

在指南中它说创建一个新的“详细信息”屏幕并将其设置为默认值应该这样做,但它不使用自定义屏幕,仍然使用自动生成的屏幕。

我尝试用application.showcustomAddClient() 覆盖按钮,但这会将其作为选项卡打开,而不是像自动生成的那样作为模式窗口打开。

然后我尝试将customaddclient 设置为模态窗口,但现在当我单击addandeditnew 时,我得到一个必须单击的按钮,然后将屏幕作为模态窗口打开,我无法工作为什么它不会直接打开模态窗口?

我尝试调用application.showscreen(customaddclient,Enumerable.Empty<object>()),但出现语法错误。

任何有关如何指定用于自定义addandeditnew 的模态屏幕的帮助都会非常有帮助。

【问题讨论】:

标签: screen visual-studio-lightswitch


【解决方案1】:

对于我的自定义模态窗口,我喜欢使用@YannDuran 的Modal Windows Helper Class。创建它时,您将要添加的表或查询传递给它,您的自定义模态窗口的名称,以及(可选)放置在模态窗口顶部的标题。该类几乎负责其余的工作,包括正确处理 X 按钮。

您的代码将是这样的:

'Declare a Modal Window Helper for use in this screen
Private AddClientHelper As ModalWindowHelper

Private Sub ScreenName_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
    'Create Helpers
    Me.AddClientHelper = New ModalWindowHelper(Me.qClientTable, "mwAddClient", "Add Client")
End Sub

Private Sub ScreenName_Created()
    'Initialize Helpers
    Me.AddClientHelper.Initialise()
End Sub

Private Sub qClientTableAddAndEditNew_CanExecute(ByRef result As Boolean)
    'Check to see if user is allowed to add an Entity
    result = Me.AddClientHelper.CanAdd()
End Sub

Private Sub qClientTableAddAndEditNew_Execute()
    'Add a new Entity to the Collection
    Me.AddClientHelper.AddEntity()
End Sub

Private Sub qClientTableEditSelected_CanExecute(ByRef result As Boolean)
    'Check to see if user is allowed to view an Entity
    result = Me.AddClientHelper.CanView()
End Sub

Private Sub qClientTableEditSelected_Execute()
    'Open selected Entity for viewing/editing
    Me.AddClientHelper.ViewEntity()
End Sub

'Save button on custom Modal Window
Private Sub btnSaveClient_Execute()
    'Check for validation errors
    If (Me.Details.ValidationResults.HasErrors = False) Then
        'Close the modal window
        Me.AddClientHelper.DialogOk()

        'Save the new Client to the database
        Me.Save()
    Else
        'If validation errors exist,
        Dim res As String = ""
        'Add each one to a string,
        For Each msg In Me.Details.ValidationResults
            res = res & msg.Property.DisplayName & ": " & msg.Message & vbCrLf
        Next msg

        'And display them in a message box
        Me.ShowMessageBox(res, "Validation error", MessageBoxOption.Ok)
    End If
End Sub

'Cancel button on custom Modal Window
Private Sub btnCancelClient_Execute()
    'Cancel the entry, discarding the changes
    Me.AddClientHelper.DialogCancel()
End Sub

【讨论】:

  • 这也能处理多对多关系吗?
  • @HiTech 原样?不,但它可以。我可能会一次将实体添加到表 A 中。并且在您的自定义模式窗口上,可以向表 B 添加多个关系。如果表 B 上的实体数量是静态的并且知道,您可能会这样做哪个复选框。否则,在保存表 A 实体之前,您将需要一个 AutoCompleteBox 和一个添加按钮来一次将一个关系添加到表 A 中的实体。这一切都取决于您的自定义模式窗口的设计。
  • 我采取了不同的路线然后建议但我得到了它的工作。感谢您抽出宝贵时间回复@embedded.kyle
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多