程序代码:
CLEAR ALL
SET PROCEDURE TO "D:\Projects\MyTools\MyTools"
SET SAFETY OFF
CLEAR
Create_SourceDBF()
Create_TargetDBF()
Main()
CLOSE TABLES ALL
CLEAR ALL
RETURN
PROCEDURE Main()
LOCAL loForm
loForm = CREATEOBJECT("C_Form1")
WITH loForm
.Caption = "多條件統計演示程序"
.MinHeight = 400
.MinWidth = 600
.WindowState = 2
.Show
.Button1.SetFocus
ENDWITH
READ EVENTS
ENDPROC
PROCEDURE Create_SourceDBF()
CREATE TABLE dbf1 FREE (訂單號 C(10), 物料編號 C(10), 數量 N(4))
INSERT INTO dbf1 (訂單號, 物料編號, 數量) VALUES ("1", "1", 1)
INSERT INTO dbf1 (訂單號, 物料編號, 數量) VALUES ("2", "2", 2)
INSERT INTO dbf1 (訂單號, 物料編號, 數量) VALUES ("1", "1", 3)
INSERT INTO dbf1 (訂單號, 物料編號, 數量) VALUES ("2", "2", 5)
INSERT INTO dbf1 (訂單號, 物料編號, 數量) VALUES ("3", "1", 7)
INDEX ON 訂單號+物料編號 TO dbf1
GOTO TOP IN dbf1
ENDPROC
PROCEDURE Create_TargetDBF()
CREATE TABLE dbf2 FREE (訂單號 C(10), 物料編號 C(10), 數量 N(4))
INDEX ON 訂單號+物料編號 TO dbf2
ENDPROC
PROCEDURE Collect_Statistics()
IF RECCOUNT("dbf2") > 0
DELETE ALL IN dbf2
ENDIF
SELECT dbf1
SET DELETED ON
SCAN ALL
IF !SEEK(dbf1.訂單號 + dbf1.物料編號, "dbf2", "dbf2")
INSERT INTO dbf2 (訂單號, 物料編號, 數量) VALUES (dbf1.訂單號, dbf1.物料編號, 0)
ENDIF
REPLACE dbf2.數量 WITH dbf2.數量 + dbf1.數量
ENDSCAN
ENDPROC
DEFINE CLASS C_Form1 AS myForm
ADD OBJECT Grid1 AS Grid
ADD OBJECT Grid2 AS Grid
ADD OBJECT Button1 AS CommandButton WITH Caption = "統計", Height = 25, Width = 60
PROCEDURE Arrange
WITH This.Button1
.Top = ThisForm.Height - .Height - 5
.Left = 20
ENDWITH
WITH This.Grid1
.Top = 5
.Left = 5
.Height = ThisForm.Button1.Top - .Top - 5
.Width = (ThisForm.Width / 2) - .Left - 5
ENDWITH
WITH This.Grid2
.Top = This.Grid1.Top
.Left = This.Grid1.Left + This.Grid1.Width + 5
.Height = This.Grid1.Height
.Width = ThisForm.Width - .Left - 5
ENDWITH
ENDPROC
PROCEDURE Grid1.Init
WITH This
.RecordSourceType = 1
.RecordSource = "dbf1"
.ReadOnly = .T.
.HighlightStyle = 2
.DeleteMark = .F.
.SetAll("FontBold", .T., "Header")
ENDWITH
ENDPROC
PROCEDURE Grid2.Init
WITH This
.RecordSourceType = 1
.RecordSource = "dbf2"
.ReadOnly = .T.
.HighlightStyle = 2
.DeleteMark = .F.
.SetAll("FontBold", .T., "Header")
ENDWITH
ENDPROC
PROCEDURE Button1.Click
Collect_Statistics()
ThisForm.Refresh
ENDPROC
ENDDEFINE
如果給了這樣的示範還不知道怎麼修改成任意多條件統計和靈活的表格輸出,那就悲催了。
[
本帖最后由 TonyDeng 于 2013-12-25 15:13 编辑 ]