代码不显示Sumary属性 [英] Code Not Displaying Sumary Property

查看:80
本文介绍了代码不显示Sumary属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里发布这个是因为我从根本上认为问题存在于我的代码中而不是屏幕设计或数据设计中。我正在按照Andy Kung过去的教程创建一个列表框移动器屏幕,用于组合表的多对多关系。
原始文章已经消失,但它的存档可以在归档机器的archive.org上找到2011年12月11日的条目https://web.archive.org/web/20111211024506/http://blogs .msdn.com / b / lightswitch / archive / 2010/12/16 / how-to-create-a-many-to-many-relationship-andy-kung.aspx

I'm posting this here because I think fundamentally the problem(s) lay in my code not in screen design or data design. I'm following a tutorial I have in past from Andy Kung to create a list box mover screen for a many to many relationship combining table. The original article is gone but the archive of it can be found at archive.org in the wayback machine The Dec 11 2011 entry here https://web.archive.org/web/20111211024506/http://blogs.msdn.com/b/lightswitch/archive/2010/12/16/how-to-create-a-many-to-many-relationship-andy-kung.aspx .

所有的拳头都有两个部分需要一些代码,第一部分是根据文章的建议定义一个汇总属性,Beth Massi在另一篇文章中有所介绍

充分利用LightSwitch摘要属性
。用VB编写的两篇文章作为平台Lightswitch都是为VB和C#文章设计的,所以我必须将代码转换为C#,见下文。



Andy Kung的文章simple在应用程序端定义了摘要属性代码,就像Lightswitch使用计算字段在该方面运行一样。他们使用的计算字段代码看起来像这样,我已尽力在C#
中定义代码,如下面两个版本,因为第二个版本是在添加或删除条目时尝试处理空值。



Fist of all there are two parts that require a little code the first part is defining a summary property as recommended by the article which is covered in a separate article by Beth Massi Getting the Most out of LightSwitch Summary Properties. Both Articles at written in VB as the platform Lightswitch was designed for both VB and C# articles so I have to convert the code to C# see below.

The Andy Kung article simple defines the summary property code on the application side the way Lightswitch does with a calculated field the runs on that side. The calculated field code they use looked like this and I've done my best to define the code in C# as follows below two versions because the second version was to try and handle nulls when adding or removing entries.

Private Sub Summary_Compute(ByRef result As String)
    result = Genre.Name
End Sub


partial void PanelParts_Compute(ref string result)
        {
                result = LabPart.LabPartFullName;
        }


partial void PanelParts_Compute(ref string result)
        {
            if (LabPart == null)
            {
                result = LabPart.LabPartFullName ?? "None Listed";
            }
            if (LabPart.LabPartFullName  != null)
                result = LabPart.LabPartFullName;
        }


这里的问题是,在屏幕上显示其余的说明,在父实体中选定条目的详细信息下面设置两列以显示列出对父实体设置的关联子属性的控制,
以及当前可用的所有可能实验部件的第二个列表。可用的实验室部件显示在列表中,但当我使用编码的按钮将实验室部件添加到其他列表中未显示的面板时,盲目地在空行上删除
 抛出null异常表示没有要删除的内容。在这种情况下,我正在从实验室部件组装实验室面板,屏幕如下所示,中间有第三列用于添加删除按钮。我将
显示原始VB代码和C#sharp代码以及定义按钮操作方法。



没有显示任何内容此处选择实验室面板或使用代码中定义的按钮将实验室部件添加到该实验室面板时。甚至没有排序标题显示此列表控件,就像它对于此列表旁边的可用实验室部件列表一样。

The problem here is that on the screen while it appears the rest of the instructions to setup two columns below the details of a selected entry in the parent entity to show a list control of both the associated children properties set to the parent entity, and a second list of all of the possible Lab Parts currently available. The Available Lab Parts show up in the list but when I use the buttons coded to add Lab Parts to a panel they do not show up in the other list and blindly hitting delete on the empty rows throws the null exception to indicate there is nothing to remove. In this case I'm assembling Lab Panels from their Lab Parts the screen looks like the following with a third column in the middle for the add remove buttons. I will show the original VB code and the C# sharp code I'm have as well to define the buttons methods of action.

Nothing shows up in here when a Lab Panel is selected or a Lab Part is added to that Lab Panel with the buttons defined in code. Not even a sort header shows up for this list control like it does for the available Lab Parts list next to this one.

这是用于电影类型的多对多屏幕按钮的VB代码示例 以及代码  I'已修改为适用于C# 屏幕,用于将实验室面板与实验室部件组装在一起。

This is the VB code example for the many to many screen buttons for movie genres and the code I've modified to work for a C# screen for assembling Lab Panels with Lab Parts.

        Private Sub AddGenre_Execute()
            If (Genres.SelectedItem IsNot Nothing) Then
                Dim mg As MovieGenre = MovieGenres.AddNew()
                mg.Movie = Me.MovieProperty
                mg.Genre = Genres.SelectedItem
            End If
        End Sub
 
        Private Sub RemoveGenre_Execute()
            MovieGenres.DeleteSelected()
        End Sub





 partial void AddLabPart_Execute()
        {
        if (LabPanelAssembledParts.SelectedItem != null)
            {
                bool LabPartExists = false;
                foreach (LabPanelAssembledPart mgSearch in this.LabPanelAssembledParts)
                    {
                        if (mgSearch.LabPart.LabPartFullName == this.LabPart.SelectedItem.LabPartFullName)
                        {
                            LabPartExists = true;
                        }
                }

                if (LabPartExists == true)
                {
                    ScreenExtensions.ShowMessageBox(this, "'Lab Panel Part' already exists");
                }
                else
                {
                    LabPanelAssembledPart lpap = LabPanelAssembledParts.AddNew();
                    lpap.LabPanel = this.LabPanelProperty;
                    lpap.LabPart = LabPart.SelectedItem;
                }
            }
        }

        partial void RemoveLabPart_Execute()
        {
            LabPanelAssembledParts.DeleteSelected();
        }




我很确定问题再次与代码没有建立屏幕有关,因为这个例子的所有说明都是如此否则是直截了当的。


I'm pretty sure the problem again is somehow related to the code not building the screens as all of the instructions for this example are straight forward otherwise.

推荐答案

要清楚,不再支持Lightswitch。如果你离开LS那么你很好。如果你想让LS工作,那么你需要转换为其他东西。

To be clear Lightswitch is no longer supported. If you're moving away from LS then you're good. If you're trying to get LS to work then you need to convert to something else instead.

如果LabPart不为null并且等效于,那么Compute方法的第一个版本将起作用VB代码。第二个版本没有正确处理空值,如果LabPart为null,则会崩溃。第一个if语句正在检查LabPart是否为null
,如果它是IS然后取消引用它并导致崩溃。第二个if语句没问题,但是如果你使用的是更新版本的C#,那么你可以大大简化代码。

The first version of your Compute method would work if LabPart is not null and is equivalent to the VB code. The second version isn't handling nulls properly and will crash if LabPart is null. The first if statement is checking to see if LabPart is null and if it IS then dereferencing it and causing a crash. The second if statement is fine but if you're using a newer version of C# then you can simplify the code dramatically.

private void PanelParts_Compute ( ref string result )
{
   result = LabPart?.LabPartFullName ?? "None Listed";
}

请注意,您根本不应该使用partial。你应该真的返回字符串,而不是设置ref参数。参考参数几乎总是错误的解决方案。 

Note that you shouldn't be using partial at all. Also you should really return the string, not set a ref parameter. Ref parameters are almost always the wrong solution. 

在你的第二组代码中,我很难理解你为什么要做你正在做的事情。第一个if语句查看是否有所选项。如果有,那么你有(我假设LabPart)。然后使用foreach搜索所有
部分,将它们与一个名为LabPart.SelectedItem的新对象进行比较。你确定这是正确的逻辑吗? if语句中的SelectedItem与foreach循环有什么关系?其余的逻辑看起来类似于VB中的
,但请注意,不再支持LS。您需要远离它,因为它将来不适用于较新的系统。

In your second set of code I'm having a hard time understanding why you're doing what you're doing. The first if statement looks to see if there is a selected item. If there is then you have the (I assume LabPart). You then use a foreach to search all the parts comparing them to some new object called LabPart.SelectedItem. Are you really sure this is the correct logic? What does the SelectedItem in the if statement have to do with the foreach loop at all? The rest of the logic looks similar to what you had in VB but note, again, LS is no longer supported. You need to move away from it as it won't work on newer systems in the future.

最后请注意,在VB(可能还有LS)中,有一种惯例是,与控件/事件名称匹配的方法会自动连接到事件(或者至少设计师以这种方式生成它)。因此,在幕后,控件具有设置为创建的方法的事件
。如果您手动编写此代码,则必须自己连接事件,否则将无法调用它们。由于LS不再受支持,我无法验证它是如何工作的。

Finally note that in VB (and probably LS) there was the convention that a method that matched the control/event name would automatically be hooked up to the event (or at least the designer generated it this way). So behind the scenes the control(s) had events that were set to the method that was created. If you're writing this code manually then you'll have to hook up the events yourself otherwise they won't be called. Since LS isn't supported anymore I have no way of verifying how it worked.


这篇关于代码不显示Sumary属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆