图片附件: 游客没有浏览图片的权限,请
登录 或
注册
** test.prg
CREATE CURSOR 表1 (学号 C(10))
INSERT INTO 表1 VALUES ("2056001")
INSERT INTO 表1 VALUES ("3078002")
CREATE CURSOR 表2 (代码 C(2), 专业名 C(10))
INSERT INTO 表2 VALUES ("78","物理专业")
INSERT INTO 表2 VALUES ("56","化学专业")
INDEX on 代码 TAG 代码
SELECT 表1
SET RELATION TO SUBSTR(学号,3,2) INTO 表2
GO TOP
of = CREATEOBJECT("myForm")
of.show
READ EVENTS
SET RELATION TO
RETURN
DEFINE CLASS myForm as Form
ADD OBJECT label1 as label WITH top=14,left=10,caption="学号"
ADD OBJECT text1 as textbox WITH top=10,left=40
ADD OBJECT label2 as label WITH top=14,left=160,caption="专业名"
ADD OBJECT combo1 as combobox WITH top=10,left=200,style=2,rowsourcetype=3,;
rowsource="SELECT 专业名,代码 FROM 表2 INTO CURSOR 专业名列表"
ADD OBJECT cmd1 as commandbutton WITH top=2,left=320,width=40,height=22,caption="添加"
ADD OBJECT cmd2 as commandbutton WITH top=26,left=320,width=40,height=22,caption="修改"
ADD OBJECT grid1 as myGrid WITH top=50
PROCEDURE unload
CLEAR EVENTS
ENDPROC
PROCEDURE init
this.grid1.setfocus
this.grid1.click
ENDPROC
PROCEDURE grid1.click
thisform.text1.value = 表1.学号
= 表2.专业名
ENDPROC
PROCEDURE grid1.AfterRowColChange(nColIndex)
this.click
ENDPROC
PROCEDURE combo1.InteractiveChange
thisform.text1.value = LEFT(thisform.text1.value,2)+专业名列表.代码+SUBSTR(thisform.text1.value,5)
ENDPROC
PROCEDURE cmd1.click
IF SEEK(SUBSTR(thisform.text1.value,3,2), "表2")
INSERT INTO 表1 VALUES (thisform.text1.value)
thisform.grid1.setfocus
ELSE
MESSAGEBOX("学号中专业代码无效")
ENDIF
ENDPROC
PROCEDURE cmd2.click
IF SEEK(SUBSTR(thisform.text1.value,3,2), "表2")
REPLACE 表1.学号 WITH thisform.text1.value IN "表1"
thisform.grid1.setfocus
ELSE
MESSAGEBOX("学号中专业代码无效")
ENDIF
ENDPROC
ENDDEFINE
DEFINE CLASS myGrid as grid
RecordSource="表1"
AllowCellSelection=.F.
ColumnCount=2
PROCEDURE init
this.Column1.ControlSource="表1.学号"
this.Column2.ControlSource="表2.专业名"
ENDPROC
ENDDEFINE