powerbuilder:如何确保数据窗口中的文本字段不为空?

发布于 2024-09-06 17:18:25 字数 56 浏览 2 评论 0原文

我有一个正在使用 pfc 服务的用户对象。现在,在更新过程中,如何确保数据窗口中的文本字段不为空?

I have a user object which is using pfc services. Now, during update, how can I make sure that a text field in datawindow is not empty?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一场春暖 2024-09-13 17:18:25

PFC 有一个 DataWindow 必需列服务,该服务可以更改列的必需属性的行为以在保存时进行评估。如果您的要求涉及编辑掩码列,则这将不起作用,但可能是实现此目的的简单方法。

为了使用它,我将以下代码放入构造函数中(警告:我已经有一段时间没有使用它了):

of_SetReqColumn(TRUE)
inv_reqcolumn.of_RegisterSkipColumn ("col_a")

祝你好运,

Terry。

PFC has a DataWindow Required Column service, that changes the behaviour of columns' Required attribute to evaluate at save time. If your requirement involves editmask columns, this won't work, but may be an easy way to achieve this otherwise.

To use this, I'd put the following code in the Constructor (warning: it's been a while since I've used it):

of_SetReqColumn(TRUE)
inv_reqcolumn.of_RegisterSkipColumn ("col_a")

Good luck,

Terry.

八巷 2024-09-13 17:18:25

我将尝试解释我使用的方法,以确保用户不会将指定字段留空。以下是我放入 u_dw(祖先)的 pfc_updateprep 事件中的代码。然后,对于我希望在任何情况下都给出值的每一列,我在文本字段的 tag 属性中放置一个 M 。描述该列的strong>。 HTH。

integer         li_size,i,l,li_zero
string           ls_textname,ls_tag,ls_objects[]
string           ls_col,ls_type,ls_text,ls_key,ls_any
any             la_null,la_any
dec             ld_zero
real               lr_zero
long               ll_zero
boolean         lb_zero

dwItemStatus    l_status,l_key_status

This.Modify("DataWindow.Table.UpdateKeyinPlace=Yes")

li_size = This.inv_base.of_Getobjects(ls_objects[ ],"column","*",TRUE)

FOR l=1 TO This.Rowcount()
    l_status=This.GetItemStatus(l, 0,Primary!)
    IF l_status=NewModified! OR l_status=Datamodified! THEN
        FOR i = 1 to li_size
            ls_col=ls_objects[i]

            ls_key = Upper(This.Describe(ls_col+".Key"))
            ls_type=This.Describe ( ls_col + ".ColType")

            ls_textname=ls_col+"_t" // because the textnames that I use are the same as the column names followed by a "_t"
            ls_tag=This.Describe(ls_textname+".Tag")
            ls_text=This.Describe(ls_textname+".Text")


            IF ls_tag='M' THEN
                lb_zero = FALSE
                IF This.Rowcount()>0 THEN
                    la_null=This.inv_base.of_GetItemany(l,ls_col)

                    choose case Upper(MidA(ls_type,1,3))
                        case 'DEC' 
                            ld_zero=Dec(la_null)
                            IF ld_zero = 0 THEN lb_zero=TRUE
                        case 'INT' 
                            li_zero=Integer(la_null)
                            IF li_zero = 0 THEN lb_zero=TRUE
                        case 'REA' 
                            lr_zero=Real(la_null)
                            IF lr_zero = 0 THEN lb_zero=TRUE
                        case 'LON' 
                            ll_zero=Long(la_null)
                            IF ll_zero = 0 THEN lb_zero=TRUE
                    end choose

                    IF Isnull(la_null) OR lb_zero THEN
                        Messagebox(gnv_app.of_Getframe().Getactivesheet().Title,&
                                    "You must provide a value for the following field ~r("+&
                                    ls_text+") !!!")
                        Return FAILURE
                    END IF
                END IF
            END IF
        NEXT
    END IF
NEXT

Return  SUCCESS

I will try to explain the method that I use in order to make sure that a user will not leave a specified field empty. The following is the code that I have put in the pfc_updateprep event of u_dw (the ancestor). Then, for each one of the columns that I want a value to be given in any case, I put an M in the tag property of the textfield that describes the column. HTH.

integer         li_size,i,l,li_zero
string           ls_textname,ls_tag,ls_objects[]
string           ls_col,ls_type,ls_text,ls_key,ls_any
any             la_null,la_any
dec             ld_zero
real               lr_zero
long               ll_zero
boolean         lb_zero

dwItemStatus    l_status,l_key_status

This.Modify("DataWindow.Table.UpdateKeyinPlace=Yes")

li_size = This.inv_base.of_Getobjects(ls_objects[ ],"column","*",TRUE)

FOR l=1 TO This.Rowcount()
    l_status=This.GetItemStatus(l, 0,Primary!)
    IF l_status=NewModified! OR l_status=Datamodified! THEN
        FOR i = 1 to li_size
            ls_col=ls_objects[i]

            ls_key = Upper(This.Describe(ls_col+".Key"))
            ls_type=This.Describe ( ls_col + ".ColType")

            ls_textname=ls_col+"_t" // because the textnames that I use are the same as the column names followed by a "_t"
            ls_tag=This.Describe(ls_textname+".Tag")
            ls_text=This.Describe(ls_textname+".Text")


            IF ls_tag='M' THEN
                lb_zero = FALSE
                IF This.Rowcount()>0 THEN
                    la_null=This.inv_base.of_GetItemany(l,ls_col)

                    choose case Upper(MidA(ls_type,1,3))
                        case 'DEC' 
                            ld_zero=Dec(la_null)
                            IF ld_zero = 0 THEN lb_zero=TRUE
                        case 'INT' 
                            li_zero=Integer(la_null)
                            IF li_zero = 0 THEN lb_zero=TRUE
                        case 'REA' 
                            lr_zero=Real(la_null)
                            IF lr_zero = 0 THEN lb_zero=TRUE
                        case 'LON' 
                            ll_zero=Long(la_null)
                            IF ll_zero = 0 THEN lb_zero=TRUE
                    end choose

                    IF Isnull(la_null) OR lb_zero THEN
                        Messagebox(gnv_app.of_Getframe().Getactivesheet().Title,&
                                    "You must provide a value for the following field ~r("+&
                                    ls_text+") !!!")
                        Return FAILURE
                    END IF
                END IF
            END IF
        NEXT
    END IF
NEXT

Return  SUCCESS
靖瑶 2024-09-13 17:18:25

我在 PB 中所做的是将以下数据窗口列属性设置为 TRUE 或选中:

  • 空字符串为 NULL
  • 必需

如果执行此操作,数据窗口应自动为您验证该字段并防止用户将该字段留空。

[编辑 - Terry 总是好的建议后的澄清]

我的帖子的第一部分应该适用于数据输入时的文本字段,我相信将强制用户在允许焦点更改之前在 dw 中输入有效值,除非您修改该行为,例如,在 itemchanged 事件中。

可以打开 PFC 所需列服务并向其注册列以提供节省时间的验证。这使得用户在导航字段时在字段中移动变得不那么麻烦,并且只会在用户尝试保存时困扰他们。

What I've done in PB is to set the following datawindow column properties to TRUE or checked:

  • Empty string is NULL
  • Required

If you do this, the datawindow should automatically validate the field for you and prevent the user from leaving the field blank.

[EDIT - Clarification after Terry's always good advice]

The first part of my post should work for text fields at data entry time and I believe will force the user to enter a valid value in the dw before allowing focus to change unless you modify that behavior, for example, in the itemchanged event.

The PFC Required Column service can be turned on and the column registered with it to provide save-time validation. This makes it less cumbersome for a user to move through the fields while navigating the fields, and only pesters the user when they try to save.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文