Procedure Load
Public aMyCurrentRow(1)
Create Cursor T1 (名称 C(10),数量 I,单价 I,金额 I)
Select T1
For m.lnI=1 To 9
Append Blank
Endfor
Insert Into T1 Values (" 合 计",0,0,0)
Locate
Endproc
Procedure Init
Thisform.AddProperty("MyGridAddModi",0)
Thisform.Grid1.SetAll("DynamicForeColor","Iif(Empty(名称),Thisform.Grid1.BackColor,Thisform.Grid1.ForeColor)","Column")
m.lnGridColumns=Thisform.Grid1.ColumnCount
For m.lnI=2 To m.lnGridColumns
Thisform.Grid1.Columns(m.lnI).Format="Z"
Endfor
Endproc
Procedure grid1.AfterRowColChange
Lparameters nColIndex,nRecno
If Thisform.MyGridAddModi>0
Update T1 Set 金额=数量*单价 Where Strtran(名称,Space(1),"")<>"合计" And !Empty("名称")
Select Sum(数量) As 数量S,Avg(单价) As 单价A,Sum(金额) As 金额S Into Cursor T2 From T1 Where Strtran(名称,Space(1),"")<>"合计" And !Empty("名称")
If !Isnull(T2.数量S)
Update T1 Set 数量=T2.数量S,单价=T2.单价A,金额=T2.金额S Where Strtran(名称,Space(1),"")=="合计"
Else
Update T1 Set 数量=0,单价=0,金额=0 Where Strtran(名称,Space(1),"")=="合计"
Endif
This.Refresh
Endif
If Type("nRecno")="N"
Select T1
Go (nRecno)
Endif
Endproc
Procedure grid1.BeforeRowColChange
Lparameters nColIndex
If (This.RowColChange=1 Or This.RowColChange=3) And Thisform.MyGridAddModi>0
Nodefault
Endif
Endproc
Procedure cmd_add.Click
Select T1
Scan
If Empty(名称)
Exit
Endif
Endscan
If !Eof()
Store .F. To Thisform.CMD_ADD.Enabled,Thisform.CMD_DEL.Enabled,Thisform.CMD_MODIFY.Enabled
Store .T. To Thisform.Grid1.AllowCellSelection,Thisform.CMD_SAVE.Enabled,Thisform.CMD_CANCEL.Enabled
Thisform.MyGridAddModi=1
Thisform.Grid1.ActivateCell(Recno("T1"),1)
Thisform.Grid1.SetFocus()
Else
Messagebox("此单据已填写满!"+Space(3),48,"信息提示")
Endif
Endproc
Procedure cmd_save.Click
Thisform.Grid1.AfterRowColChange(,Recno())
Store .T. To Thisform.CMD_ADD.Enabled,Thisform.CMD_DEL.Enabled,Thisform.CMD_MODIFY.Enabled
Store .F. To Thisform.Grid1.AllowCellSelection,Thisform.CMD_SAVE.Enabled,Thisform.CMD_CANCEL.Enabled
Thisform.MyGridAddModi=0
Endproc
Procedure cmd_modify.Click
Select T1
If Strtran(名称,Space(1),"")=="合计" Or Empty(名称)
Return
Endif
Scatter To aMyCurrentRow
Store .F. To Thisform.CMD_ADD.Enabled,Thisform.CMD_DEL.Enabled,Thisform.CMD_MODIFY.Enabled
Store .T. To Thisform.Grid1.AllowCellSelection,Thisform.CMD_SAVE.Enabled,Thisform.CMD_CANCEL.Enabled
Thisform.MyGridAddModi=2
Thisform.Grid1.ActivateCell(Recno("T1"),1)
Thisform.Grid1.SetFocus()
Endproc
Procedure cmd_del.Click
Select T1
If Strtran(名称,Space(1),"")=="合计" Or Empty(名称)
Return
Endif
Blank
m.lnRecno=Recno()
Thisform.MyGridAddModi=1
Thisform.Grid1.AfterRowColChange(,Recno())
Thisform.MyGridAddModi=0
Go (m.lnRecno)
Thisform.Grid1.Refresh
Endproc
Procedure cmd_cancel.Click
Select T1
If Thisform.MyGridAddModi=1
Blank
Else
Gather From aMyCurrentRow
Endif
Thisform.Grid1.AfterRowColChange(,Recno())
Store .T. To Thisform.CMD_ADD.Enabled,Thisform.CMD_DEL.Enabled,Thisform.CMD_MODIFY.Enabled
Store .F. To Thisform.Grid1.AllowCellSelection,Thisform.CMD_SAVE.Enabled,Thisform.CMD_CANCEL.Enabled
Thisform.MyGridAddModi=0
Thisform.Grid1.Refresh
Endproc
Enddefine