从自定义控件运行查找查询 [英] Running a lookup query from custom control

查看:68
本文介绍了从自定义控件运行查找查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义控件中包含以下代码,该代码允许用户在文本框中输入值,然后按Enter键打开LightSwitch屏幕.在textBox_KeyDown事件上,我有这个:

I have the following code inside a custom control that allows the user to enter a value in a textbox and presses Enter to open a LightSwitch screen. On the textBox_KeyDown event I have this:

            if (e.Key == Key.Enter)
            {
 
                // Get a reference to the LightSwitch DataContext 
                var objDataContext = (IContentItem)this.DataContext;
 
                // Get a reference to the LightSwitch Screen. In this case, it's the Home screen.
                var Screen = (Microsoft.LightSwitch.Client.IScreenObject)objDataContext.Screen;
 
                Screen.Details.Properties["BarCodeTextbox"].Value = Convert.ToInt64(this.txt.Text);
 
                // Now call the Method on the LightSwitch screen
                Screen.Details.Dispatcher.BeginInvoke(() =>
                {
                    Screen.Details.Methods["OpenTransactionList"].CreateInvocation(null).Execute();
                });
            }

在此,用户输入条形码,然后按Enter.但是我的问题是,当用户输入不存在的条形码时,Lightswitch仍会打开TransactionList屏幕(带有空白字段).如何设置它,以便可以检查是否 该特定条形码存在的记录.如果是,那么我将调用屏幕,否则,我将在标签中显示一条消息,指出该记录不存在.

Here, the user enters the BarCode and presses enter. But the problem I have is that when the user enters a bar code that does not exist, Lightswitch still opens the TransactionList screen (with blank fields). How can I set it up so that I can check if the record with that particular bar code exists. If yes, then I'll call the screen, otherwise I'll display a message in a label saying the record does not exist.

谢谢!

推荐答案

您可以进行查找.您已经有了屏幕参考,因此可以访问其DataWorkspace.使用FirstOrDefault,然后测试是否为空.如果结果为空,则条形码不会退出,因此请显示您的消息框;如果结果不为空,则条形码 确实存在,因此请显示屏幕.
You can do a lookup. You already have the screen reference, therefore, you have access to its DataWorkspace. Use FirstOrDefault, then test for null. If the result is null, the barcode didn't exit, so show your messagebox, if it's not null the barcaode did exist, so show the screen.


这篇关于从自定义控件运行查找查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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