*!* good values, missing values and duplicates
PUBLIC goFormSales
goFormSales=NEWOBJECT("clsForm")
goFormSales.Show
Read Events
Close all
Clear All
RETURN
**************************************************
DEFINE CLASS clsForm AS form
AutoCenter = .T.
Caption = "The good, the missing and the dupes"
Width = 660
Height = 420
MinHeight = This.Height
MinWidth = This.Width
MaxWidth = This.Width
ADD OBJECT grdValues AS grid WITH ;
Left = 12, ;
Top = 72, ;
Width = 300, ;
Height = ThisForm.Height - 84, ;
TabIndex = 4, ;
DeleteMark = .F., ;
RecordMark = .F., ;
ColumnCount = -1, ;
RecordSource = "csrValues", ;
Anchor = 15, ;
ReadOnly =.T.
PROCEDURE grdValues.Init
WITH This.Column1
.Header1.Caption = "ID"
ENDWITH
WITH This.Column2
.Header1.Caption = "Description"
ENDWITH
ENDPROC
ADD OBJECT grdMissingValues AS grid WITH ;
Left = 330, ;
Top = 72, ;
Width = 312, ;
Height = ThisForm.Height - 84, ;
TabIndex = 5, ;
DeleteMark = .F., ;
RecordMark = .F., ;
Anchor = 15, ;
ReadOnly =.T., ;
Visible = .F.
ADD OBJECT lblOData as label WITH ;
Left = 12, Top = 42, Caption = "OData", FontSize = 12, FontBold = .T.
ADD OBJECT lblResults as label WITH ;
Left = 330, Top = 42, Caption = "Results", FontSize = 12, FontBold = .T.
ADD OBJECT lblLowerValue as Label WITH ;
Left = 12, Top = 9, Caption = "Lower value :", AutoSize = .T.
ADD OBJECT txtLowerValue as TextBox WITH ;
Left = 96, Top = 6, Width = 48, TabIndex = 1, Value = 1, InputMask = "999"
PROCEDURE txtLowerValue.Valid()
IF This.Value < 1
= MESSAGEBOX("Value must be higher than 0", 16, "Lower value", 3000)
RETURN 0
ENDIF
ENDPROC
ADD OBJECT lblUpperValue as Label WITH ;
Left = 150, Top = 9, Caption = "Upper value :", Autosize = .T.
ADD OBJECT txtUpperValue as TextBox WITH ;
Left = 228, Top = 6, Width = 48, TabIndex = 2, Value = 20, InputMask = "9999"
PROCEDURE txtUpperValue.Valid()
LOCAL liCheckValue
liCheckValue = ThisForm.txtLowerValue.Value
IF This.Value <= liCheckValue
= MESSAGEBOX("Upper value must be higher than lower value", 16, "Upper value", 3000)
RETURN 0
ENDIF
ENDPROC
ADD OBJECT cmdDoit AS CommandButton WITH ;
Left = 330, Top = 6, Height = 24, TabIndex = 3, Autosize = .T., BackColor = RGB(0, 240, 240), Caption = "The good, the missing and the dupes"
PROCEDURE cmdDoit.Click()
LOCAL liUpperValue, liLowerValue
liUpperValue = ThisForm.txtUpperValue.Value
liLowerValue = ThisForm.txtLowerValue.Value
ThisForm.Caption = "The good, the missing and the dupes between " + ALLTRIM(STR(liLowerValue)) + " and " + ALLTRIM(STR(liUpperValue))
CREATE cursor csrAllValues (iValue I)
FOR i = 0 TO liUpperValue - liLowerValue
INSERT INTO csrAllValues VALUES (liLowerValue + i)
ENDFOR
SELECT csrValues.iValue, csrValues.cName, csrDupes.lDupes, .F. as lMissing ;
FROM csrValues ;
JOIN (SELECT iValue, .T. as lDupes FROM csrValues GROUP BY 1 HAVING COUNT(iValue) >= 2) csrDupes ;
ON csrValues.iValue = csrDupes.iValue;
WHERE csrValues.iValue BETWEEN liLowerValue AND liUpperValue ;
UNION ALL ;
SELECT csrValues.iValue, csrValues.cName, csrDupes.lDupes, .F. as lMissing ;
FROM csrValues ;
JOIN (SELECT iValue, .F. as lDupes FROM csrValues GROUP BY 1 HAVING COUNT(iValue) < 2) csrDupes ;
ON csrValues.iValue = csrDupes.iValue ;
WHERE csrValues.iValue BETWEEN liLowerValue AND liUpperValue ;
UNION ALL ;
SELECT csrAllValues.iValue, "*-" as cName, .F. as lDupes, .T. as lMissing ;
FROM csrAllValues ;
WHERE iValue NOT in (Select iValue FROM csrValues) ;
ORDER BY 1 ;
INTO CURSOR csrGoodDupesMissing
WITH ThisForm.grdMissingValues
.Visible = .T.
.ColumnCount = -1
.RecordSource = "csrGoodDupesMissing"
.Column1.Header1.Caption = "ID"
.Column2.Header1.Caption = "Description"
.Column3.Header1.Caption = "Dupes"
.Column3.Width = 54
.Column3.NewObject("chkDupes","CheckBox")
.Column3.CurrentControl = "chkDupes"
.Column3.chkDupes.Caption = ""
.Column3.chkDupes.Visible = .T.
.Column3.Sparse = .F.
.Column3.Alignment = 2
.Column4.Header1.Caption = "Missing"
.Column4.Width = 54
.Column4.NewObject("chkMissing","CheckBox")
.Column4.CurrentControl = "chkMissing"
.Column4.chkMissing.Caption = ""
.Column4.chkMissing.Visible = .T.
.Column4.Sparse = .F.
.Column4.Alignment = 2
.SetAll("DynamicFontItalic", "csrGoodDupesMissing.lDupes", "Column")
.SetAll("DynamicFontBold", "NOT(csrGoodDupesMissing.lDupes or csrGoodDupesMissing.lMissing)", "Column")
.SetAll("DynamicBackColor", "ICASE(csrGoodDupesMissing.lDupes, RGB(225, 225, 0), csrGoodDupesMissing.lMissing, RGB(255, 255, 255), RGB(0, 240, 240))", "Column")
ENDWITH
ENDPROC
PROCEDURE Destroy
Thisform.Release()
CLOSE ALL
Clear Events
ENDPROC
PROCEDURE Load
LOCAL lnI
CREATE CURSOR csrValues (iValue I DEFAULT 1 + INT(RAND() * 29989), cName C(15) DEFAULT "Z" + SYS(2015))
For lnI = 1 To 10000
Append Blank
EndFor
INDEX on iValue TAG xiValue
SET ORDER TO xiValue
LOCATE
ENDPROC
ENDDEFINE
*********************************************