当前位置: 代码迷 >> VFP >> 哪位大侠有VFP的Grid控件的深入应用,就是跟财务软件的格式类似解决方案
  详细解决方案

哪位大侠有VFP的Grid控件的深入应用,就是跟财务软件的格式类似解决方案

热度:7208   发布时间:2013-02-26 00:00:00.0
哪位大侠有VFP的Grid控件的深入应用,就是跟财务软件的格式类似
我在做金额录入的表单,想模拟金蝶等财务软件的那个输入系统,:如下图

我想VFP的Grid能做到这样,不知道哪个高手有没有这样现成的例子给我一个,提前谢谢了

------解决方案--------------------------------------------------------
VFP9.0

SQL code
Public oform1oform1=Newobject("form1")oform1.ShowReturnDefine Class form1 As Form    Top = 0    Left = 0    Height = 273    Width = 452    DoCreate = .T.    Caption = "Form1"    Name = "Form1"    AutoCenter = .T.    Add Object grid1 As Grid With ;        DeleteMark = .F., ;        Height = 218, ;        Left = 24, ;        TabIndex = 1, ;        Top = 47, ;        Visible = .T., ;        Width = 396, ;        AllowCellSelection = .F., ;        Name = "Grid1"    Add Object cmd_add As CommandButton With ;        Top = 13, ;        Left = 68, ;        Height = 25, ;        Width = 60, ;        Caption = "增加", ;        TabIndex = 2, ;        Name = "CMD_ADD"    Add Object cmd_save As CommandButton With ;        Top = 13, ;        Left = 248, ;        Height = 25, ;        Width = 60, ;        Caption = "保存", ;        Enabled = .F., ;        TabIndex = 5, ;        Name = "CMD_SAVE"    Add Object cmd_modify As CommandButton With ;        Top = 13, ;        Left = 128, ;        Height = 25, ;        Width = 60, ;        Caption = "修改", ;        TabIndex = 3, ;        Name = "CMD_MODIFY"    Add Object cmd_del As CommandButton With ;        Top = 13, ;        Left = 188, ;        Height = 25, ;        Width = 60, ;        Caption = "删除", ;        TabIndex = 4, ;        Name = "CMD_DEL"    Add Object cmd_cancel As CommandButton With ;        Top = 13, ;        Left = 308, ;        Height = 25, ;        Width = 60, ;        Caption = "取消", ;        Enabled = .F., ;        TabIndex = 6, ;        Name = "CMD_CANCEL"    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    EndprocEnddefine
  相关解决方案