图片附件: 游客没有浏览图片的权限,请
登录 或
注册
程序代码:
Main()
RETURN
PROCEDURE Main()
LOCAL loForm
loForm = NEWOBJECT("Class_Main")
loForm.Show
READ EVENTS
ENDPROC
DEFINE CLASS Class_Main AS Form
Caption = "ksbbzhr"
Width = 800
Height = 600
BorderStyle = 1
ShowTips = .T.
ADD OBJECT Grid1 AS Class_Grid
PROCEDURE Load
SET DELETED ON
IF !USED("Table1")
USE Table1 EXCLUSIVE IN 0
ENDIF
ENDPROC
PROCEDURE Unload
USE IN Table1
ENDPROC
PROCEDURE Init
ThisForm.Arrange
ENDPROC
PROCEDURE Destroy
CLEAR EVENTS
ENDPROC
PROCEDURE Arrange
WITH ThisForm.Grid1
.Top = 5
.Left = 5
.Width = ThisForm.Width - .Left - 5
.Height = ThisForm.Height - .Top - 5
.Arrange
ENDWITH
ENDPROC
PROCEDURE Grid1.Init
WITH This._Grid
.HighlightStyle = 2
.RecordSourceType = 1
.RecordSource = "Table1"
ENDWITH
ENDPROC
PROCEDURE Show
This.Grid1.SetFocus
ENDPROC
ENDDEFINE
DEFINE CLASS Class_Grid AS Container
BorderWidth = 0
HIDDEN _Record[1]
ADD OBJECT _Buttons AS CommandGroup WITH BorderStyle = 0
ADD OBJECT _Info AS EditBox
ADD OBJECT _Grid AS Grid WITH DeleteMark = .F.
ADD OBJECT _EditCmd AS CommandGroup WITH BorderStyle = 0
PROCEDURE Arrange
WITH This._Buttons
.Top = 0
.Left = 0
ENDWITH
WITH This._Info
.Top = This._Buttons.Top + This._Buttons.Height + 5
.Left = This._Buttons.Left
.Height = This.Height - .Top
.Width = This._Buttons.Width - .Left
ENDWITH
WITH This._EditCmd
.Top = This.Height - .Height
.Left = This.Width - .Width
ENDWITH
WITH This._Grid
.Top = 0
.Left = This._Buttons.Left + This._Buttons.Width + 5
.Height = This._EditCmd.Top - .Top - 5
.Width = This.Width - .Left
ENDWITH
ENDPROC
PROCEDURE GotFocus
This._Grid.SetFocus
ENDPROC
PROCEDURE _Buttons.Init
LOCAL laCaption[6,2], lnIndex, lnRow, lnCol, lnWidth, lnHeight, lnPos
laCaption[1,1] = "_SPQCP"
laCaption[1,2] = RGB(0,128,0)
laCaption[2,1] = "_ÁªÏµµ¥"
laCaption[2,2] = RGB(0,0,255)
laCaption[3,1] = "_ºÏͬÎı¾"
laCaption[3,2] = RGB(213,0,0)
laCaption[4,1] = "NCR"
laCaption[5,1] = "¶¯Æ½ºâ"
laCaption[6,1] = "³ö³§¼Ç¼"
lnWidth = 60
lnHeight = 19
WITH This
.ButtonCount = ALEN(laCaption, 1)
lnRow = 1
lnCol = 1
FOR lnIndex = 1 TO ALEN(laCaption, 1)
WITH .Buttons[lnIndex]
lnPos = ATC("_", laCaption[lnIndex,1])
.Caption = SUBSTRC(laCaption[lnIndex,1], lnPos + 1)
IF (lnPos > 0)
.FontUnderline = .T.
ENDIF
.FontBold = .T.
IF !EMPTY(laCaption[lnIndex,2])
.ForeColor = laCaption[lnIndex,2]
ENDIF
.Width = lnWidth
.Height = lnHeight
.Top = 2 + (lnRow - 1) * (lnHeight + 2)
.Left = 3 + (lnCol - 1) * (lnWidth + 2)
IF MOD(lnIndex, 3) == 0
lnRow = lnRow + 1
lnCol = 1
ELSE
lnCol = lnCol + 1
ENDIF
ENDWITH
NEXT
.Width = 3 + 3 * (lnWidth + 2) + 3
.Height = 2 + 2 * (lnHeight + 2) + 2
ENDWITH
ENDPROC
PROCEDURE _Buttons.Click
MESSAGEBOX("µ±Ç°¼Ç¼: " + TRANSFORM(RECNO("Table1")) + " °´Å¥: " + This.Buttons[This.Value].Caption)
This.Parent._Grid.SetFocus
ENDPROC
PROCEDURE _Grid.AfterRowColChange(tnColumn)
This.Parent.Show_Data()
ENDPROC
PROCEDURE Show_Data
LOCAL lcString, lnIndex
lcString = ""
FOR lnIndex = 1 TO FCOUNT("Table1")
lcString = lcString + FIELD(lnIndex, "Table1", 1) + ": " + TRANSFORM(EVALUATE("Table1." + FIELD(lnIndex, "Table1"))) + CHR(13) + CHR(10)
NEXT
This._Info.Value = lcString
ENDPROC
PROCEDURE _EditCmd.Init
LOCAL laButtons[4,2], lnIndex, lnWidth, lnHeight
laButtons[1,1] = "Ôö¼Ó[\<A]"
laButtons[1,2] = "Ôö¼ÓÒ»ÌõеļǼ"
laButtons[2,1] = "ɾ³ý[\<D]"
laButtons[2,2] = "ɾ³ýµ±Ç°¼Ç¼"
laButtons[3,1] = "¸´ÖÆ[\<C]"
laButtons[3,2] = "½«µ±Ç°¼Ç¼¸´ÖƵ½ÄÚ´æ¼ôÌù°å"
laButtons[4,1] = "ð¤Ìù[\<V]"
laButtons[4,2] = "½«ÄÚ´æÖеļǼð¤Ìùµ½µ±Ç°¼Ç¼²¢È¡´úÖ®"
lnWidth = 60
lnHeight = 25
WITH This
.ButtonCount = ALEN(laButtons, 1)
FOR lnIndex = 1 TO .ButtonCount
WITH .Buttons[lnIndex]
.Caption = laButtons[lnIndex,1]
.ToolTipText = laButtons[lnIndex,2]
.Width = lnWidth
.Height = lnHeight
.Top = 0
.Left = (lnIndex - 1) * lnWidth
ENDWITH
NEXT
.Buttons[4].Enabled = .F.
.Width = .ButtonCount * lnWidth
.Height = lnHeight
ENDWITH
ENDPROC
PROCEDURE _EditCmd.Click
DO CASE
CASE This.Value == 1
This.Parent.Append_Record
CASE This.Value == 2
This.Parent.Delete_Record
CASE This.Value == 3
This.Parent.Copy_Record
CASE This.Value == 4
This.Parent.Paste_Record
ENDCASE
This.Parent._Grid.SetFocus
ENDPROC
PROCEDURE Append_Record
SELECT Table1
APPEND BLANK
ENDPROC
PROCEDURE Delete_Record
IF MESSAGEBOX("ÄúÈ·ÈÏɾ³ýµ±Ç°¼Ç¼Âð£¿", 32 + 4 + 256, ThisForm.Caption) == 6
SELECT Table1
DELETE
SKIP -1
ENDIF
ENDPROC
PROCEDURE Copy_Record
LOCAL lcAlias, lnFields, lnIndex, lcField
WITH This
lcAlias = ._Grid.RecordSource
lnFields = FCOUNT(lcAlias)
DIMENSION ._Record[lnFields]
FOR lnIndex = 1 TO lnFields
lcField = lcAlias + "." + FIELD(lnIndex, lcAlias)
._Record[lnIndex] = EVALUATE(lcField)
NEXT
._EditCmd.Buttons[4].Enabled = .T.
ENDWITH
ENDPROC
PROCEDURE Paste_Record
LOCAL lcAlias, lnFields, lnIndex, lcField
WITH This
lcAlias = ._Grid.RecordSource
lnFields = FCOUNT(lcAlias)
SELECT (lcAlias)
FOR lnIndex = 1 TO lnFields
lcField = lcAlias + "." + FIELD(lnIndex, lcAlias)
REPLACE &lcField WITH ._Record[lnIndex]
NEXT
._EditCmd.Buttons[4].Enabled = .F.
ENDWITH
ENDPROC
ENDDEFINE
[
本帖最后由 TonyDeng 于 2012-12-12 03:23 编辑 ]