在数据窗口中如何验证用户是否输入了数据

mahaixing 2002-07-18 11:40:58
我希望在提交数据库的之前验证数据窗口中用户是否输入了相应列数据,如果没有输入数据,就显示提示信息要求用户输入并且取消数据库提交过程!请问我应该如何做??
...全文
107 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
人生如梦 2002-07-18
  • 打赏
  • 举报
回复
关注~~
hzhxxx 2002-07-18
  • 打赏
  • 举报
回复
///////////////////////////////////////////////////////////////
//
// 名称: f_dw_findrequired
//
// 功能: 判断记录的主域值是否为空,如果有主域值为空,将数据窗口
// 焦点移到相应的行列,并返回错误信息
//
// 日期:
//
// 范围: 公共
//
// 自变量: datawindow dw----数据窗口名称
//
// 返回值: string----错误消息,用于用户显示
//
// 日志:
//
////////////////////////////////////////////////////////////////////////

string colname,coltype
int col,colcount
long currow,rowcount


SetPointer(HourGlass!)
rowcount=dw.RowCount()
currow=dw.GetRow()
dw.AcceptText()
colcount=Integer(dw.Describe("datawindow.column.count"))
for currow=1 to rowcount
if dw.getitemstatus(currow,0,Primary! )=notmodified! then continue//
for col=1 to colcount
if dw.Describe("#"+string(col)+".key")="yes" then
coltype = dw.Describe("#"+string(col)+".ColType")
if left(coltype,4)="char" or left(coltype,4)="varc"then
if IsNull(dw.GetItemString(currow,col)) then
dw.ScrollToRow(currow)
dw.SetColumn(col)
dw.SetFocus()
colname=dw.Describe("#"+string(col)+".name")
//save_sign=FALSE
return "第"+string(currow)+"个记录 "+dw.Describe(colname+"_t.text") + " 没有数据!~r~n"
end if
end if //for string type
if left(coltype,7)="decimal" then
if IsNull(dw.GetItemDecimal(currow,col)) then
dw.ScrollToRow(currow)
dw.SetColumn(col)
dw.SetFocus()
colname=dw.Describe("#"+string(col)+".name")
//save_sign=FALSE
return "第"+string(currow)+"个记录 "+dw.Describe(colname+"_t.text") + " 没有数据!~r~n"
end if
end if //for decimal type
if coltype="date" then
if IsNull(dw.GetItemDate(currow,col)) then
dw.ScrollToRow(currow)
dw.SetColumn(col)
dw.SetFocus()
colname=dw.Describe("#"+string(col)+".name")
//save_sign=FALSE
return "第"+string(currow)+"个记录 "+dw.Describe(colname+"_t.text") + " 没有数据!~r~n"
end if
end if //for date type
if coltype="datetime" then
if IsNull(dw.GetItemDateTime(currow,col)) then
dw.ScrollToRow(currow)
dw.SetColumn(col)
dw.SetFocus()
colname=dw.Describe("#"+string(col)+".name")
//save_sign=FALSE
return "第"+string(currow)+"个记录 "+dw.Describe(colname+"_t.text") + " 没有数据!~r~n"
end if
end if //for datetime type
if coltype="number" then
if IsNull(dw.GetItemNumber(currow,col)) then
dw.ScrollToRow(currow)
dw.SetColumn(col)
dw.SetFocus()
colname=dw.Describe("#"+string(col)+".name")
//save_sign=FALSE
return "第"+string(currow)+"个记录 "+dw.Describe(colname+"_t.text") + " 没有数据!~r~n"
end if
end if //for number type
if coltype="time" then
if IsNull(dw.GetItemTime(currow,col)) then
dw.ScrollToRow(currow)
dw.SetColumn(col)
dw.SetFocus()
colname=dw.Describe("#"+string(col)+".name")
//save_sign=FALSE
return "第"+string(currow)+"个记录 "+dw.Describe(colname+"_t.text") + " 没有数据!~r~n"
end if
end if //for time type
if coltype="timestamp" then
if IsNull(dw.GetItemTime(currow,col)) then
dw.ScrollToRow(currow)
dw.SetColumn(col)
dw.SetFocus()
colname=dw.Describe("#"+string(col)+".name")
//save_sign=FALSE
return "第"+string(currow)+"个记录 "+dw.Describe(colname+"_t.text") + " 没有数据!~r~n"
end if
end if //for timestamp type
if coltype="int" or coltype="long" then
if IsNull(dw.GetItemnumber(currow,col)) then
dw.ScrollToRow(currow)
dw.SetColumn(col)
dw.SetFocus()
colname=dw.Describe("#"+string(col)+".name")
//save_sign=FALSE
return "第"+string(currow)+"个记录 "+dw.Describe(colname+"_t.text") + " 没有数据!~r~n"
end if
end if //for int
end if
next // for col
next // for row
return "ok"
hyxdtj 2002-07-18
  • 打赏
  • 举报
回复
检查4个缓冲区的状态
lianga123 2002-07-18
  • 打赏
  • 举报
回复
给一个函数很好用的,不过要在pb的datawindow的Validation Expression写入表达式

例如 name这一个列是个字符型的。你就在Validation Expression中写

Not (IsNull(GetText()) Or Len(Trim(GetText())) = 0)

然后在 Validation Message写 "姓名不能为空"


其它的如果你还要的也可以这样加就行了


If ue_check_valid(dw_1) = false Then
这样写就了,你可以试试,很好用的


/*——————————————————————————————-
函数名称:ue_check_valid
参数: datawindow
返回值: false true
描 述:数据是否合法
——————————————————————————————-*/
If RowCount() = 0 Then Return True
SetRedraw(False)
Integer li_row, li_columns, li_count,li_tab
Boolean lb_retval = True
String ls_valid, ls_retval, ls_mess

li_row = GetRow()
li_columns = Integer(Object.DataWindow.Column.Count)
For li_count = 1 To li_columns
This.Modify("#" + String(li_count) + ".Protect = 0")
li_tab = Integer(Describe("#" + String(li_count) + ".tabsequence"))
If li_tab = 0 Then
This.Modify("#" + String(li_count) + ".tabsequence = 1")
End If

ls_valid = Describe("#" + String(li_count) + ".Validation")
If Not (ls_valid = "" Or IsNull(ls_valid)) AND ls_valid <> "?" Then
SetColumn(li_count)
ls_retval = Describe("Evaluate('If(" + ls_valid + ",0, 1)'," + String(li_row) + ")")
If ls_retval = "1" Then
ls_mess = Describe("#" + String(li_count) + ".ValidationMsg")
ls_mess = mid(ls_mess, 4, Len(ls_mess) - 3)
f_cm_message("E"+ ls_mess)
lb_retval = False
If li_tab = 0 Then
This.Modify("#" + String(li_count) + ".tabsequence = 1")
End If
SetFocus()
SetColumn(li_count)
Exit
End If
End If
Next
SetRedraw(True)
Return lb_retval






xirumin 2002-07-18
  • 打赏
  • 举报
回复
在提交之前判断
if dw.object.f_xxx[ ...] = '' or isnull( ... ) then
messagebox()
else
dw.update( true )
end if
kaiwen_lv 2002-07-18
  • 打赏
  • 举报
回复
用accepttext()函数来判断就可以了。
kaiwen_lv 2002-07-18
  • 打赏
  • 举报
回复
用accepttext()函数来判断,如果没有输入就提示就可以了。
yzip 2002-07-18
  • 打赏
  • 举报
回复
1.可以在数据窗口的updatestart事件或者在按钮事件,数据库保存前对每一列数据进行检查,看看数据列是否为空 (=""),如果为空则出现错误提示,并将光标定位.
2.如果使用了字段较多,可以使用findrequired()函数进行判断.然后处理
3.可以在数据输入过程中,每个itemchanged事件来检查数据是否正确.

可以查看PB帮助和PB例程
xjbs 2002-07-18
  • 打赏
  • 举报
回复
for ...
if geitem(row,col)='' then message...
next
xjbs 2002-07-18
  • 打赏
  • 举报
回复
for ...
if geitem(row,col)='' then message...
next
cosco 2002-07-18
  • 打赏
  • 举报
回复
写个函数吧
f_checkrequiredfields()
参数d_atawindow
类型datawindow
返回值类型 boolean
***在数据窗口dw_1的必输项的列edit属性中将(Required)选中
代码如下:
integer nColumn = 1
long lRow = 1
string szColumn

if d_atawindow.Accepttext() = -1 then
d_atawindow.setfocus()
return False
end if

if d_atawindow.findrequired(primary!,lrow,ncolumn,szcolumn,true) < 0 then
return false
end if
if lrow <> 0 then
szcolumn = d_atawindow.describe(szcolumn + "_t.Text")

messagebox("提示信息",szcolumn + "值不能为空!",stopsign!,ok!)

//b_doublemessagebox = true

d_atawindow.setredraw(false)
d_atawindow.setcolumn(nColumn)
d_atawindow.scrolltorow(lrow)
d_atawindow.setredraw(true)
d_atawindow.setfocus()
return false
end if

return true
blackcorbie 2002-07-18
  • 打赏
  • 举报
回复
下面是进行判断是否对数据列进行了修改
if dw_1.deletedcount( ) = 0 and dw_1.modifiedcount( ) = 0 then
messagebox("对不起!","没有进行任何修改!")
return
end if

还有:
if dw_1.object.name[row] = "" or isnull(dw_1.object.name[row]) then
messagebox("","")
return
end if
771218 2002-07-18
  • 打赏
  • 举报
回复
上面都说了

1,079

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧