One of my team mates made the function check all the mandatory columns in one datawindow.
His idea is to utilize the TAG property in every columns. Just fill the TAG property value with Column's full name, if you think that column is mandatory.
To use the function, just call with the datawindow name as parameter / argument.
Here's the function
Function Name: f_cek_required
Return: integer (1-Success, -1 mandatory column required to be filled)
Argument type: datawindow
Argument name: dw
1: string sTemp
2: long lRowCount, lColCount, i, j
3:
4: SetPointer(HourGlass!)
5:
6: lRowCount = dw.RowCount()
7: lColCount = long(dw.Describe("DataWindow.Column.Count"))
8:
9: IF dw.AcceptText() = -1 THEN RETURN -1
10:
11: DO
12: i = dw.GetNextModified(i, Primary!)
13: IF i > 0 THEN
14: FOR j = 1 TO lColCount
15: IF Left(dw.Describe("#" + String(j) + ".colType"),7) = "decimal" THEN
16: IF isNull(dw.GetItemNumber(i, j)) OR dw.GetItemNumber(i, j) = 0 THEN
17: sTemp = ""
18: END IF
19: ELSE
20: sTemp = Trim(String(dw.object.data[i,j]))
21: END IF
22:
23: IF isNull(sTemp) THEN sTemp = ""
24:
25: IF sTemp <> "" THEN CONTINUE
26:
27: sTemp = dw.Describe("#" + String(j) + ".tag")
28: IF sTemp <> "?" THEN
29: MessageBox("Value Required", "You have to fill "+sTemp)
30: sTemp = dw.Describe("#" + String(j) + ".name")
31: dw.SetFocus()
32: dw.ScrollToRow(i)
33: dw.SetColumn(sTemp)
34: RETURN -1
35: END IF
36: NEXT
37: END IF
38: LOOP WHILE i > 0
39:
40: RETURN 1
To use the function
1: If f_cek_required(dw_1) = -1 then return
Why Can't you use FindRequired Datawindow function to check for the required column, there is a property called required for every column in the datawindow you need to check it and use FindRequired function.
ReplyDeleteIt's because we created this function when Powerbuilder 5 was launch, and no FindRequired or Required property before :)
ReplyDelete