*!* PUBLIC go_Form
go_Form = CreateObject ("frmForm")
go_Form.Visible = .T.
go_Form.Show
READ Events
CLOSE ALL
CLEAR ALL
RETURN
*****
DEFINE CLASS frmForm As Form
Width = 600
Height = 360
MinWidth = This.Width
MinHeight = This.Height
AutoCenter = .T.
ShowTips = .T.
Themes = .F.
Add Object grdGames as Grid with;
Top = 66, ;
Left = 18, ;
Height = 360 - 120, ;
Width = 600 - 36, ;
RowHeight = 60, ;
AllowRowSizing = .F., ;
DeleteMark = .F., ;
Visible = .T., ;
Anchor = 15, ;
ReadOnly = .T., ;
ColumnCount = -1, ;
RecordSource = "tblChess"
PROCEDURE grdGames.Init()
WITH This
.Column1.Header1.Caption = "Date"
.Column1.Header1.FontBold = .T.
.Column1.Width = 90
.Column2.Header1.Caption = "City"
.Column2.Header1.FontBold = .T.
.Column2.Width = 90
.Column3.Header1.Caption = "Player White"
.Column3.Header1.FontBold = .T.
.Column3.Width = 126
.Column4.Header1.Caption = "Player Black"
.Column4.Header1.FontBold = .T.
.Column4.Width = 126
ENDWITH
With This.Column5
.Header1.Caption = "Moves"
.Header1.FontBold = .T.
.Width = This.Parent.Width - 432 - 36
.NewObject("edtChessMoves","EditBox")
.CurrentControl = "edtChessMoves"
.edtChessMoves.Visible = .T.
.Sparse = .F.
ENDWITH
ENDPROC
ADD OBJECT lblSearch as LABEL WITH ;
Top = 12, Left = 18, FontBold = .T., FontSize = 10, AutoSize = .T., ;
Caption = "City or Player" + SPACE(6) + "... Moves" + SPACE(45) + " ... up to move"
ADD OBJECT txtCityName as Textbox WITH ;
Top = 36, Left = 18, Width = 96, Format = "!", SpecialEffect = 0
ADD OBJECT txtSearch as Textbox WITH ;
Top = 36, Left = 120, Width = 294, Format = "!", SpecialEffect = 0
ADD OBJECT txtMove as Textbox WITH ;
Top = 36, Left = 420, Width = 36, Format = "9", InputMask = "X9X", SpecialEffect = 0, ToolTipText = "Please enter value as 99."
ADD OBJECT cmdSearch As CommandButton WITH;
Width = 60, Height = 24, Left = 18, Top = 324, Anchor = 6, Caption = "Search", ToolTipText = "Right click to reset filter"
PROCEDURE cmdSearch.RightClick()
WITH ThisForm
.txtCityName.Value = ""
.txtSearch.Value = ""
.txtMove.Value = ""
ENDWITH
SELECT tblChess
WITH ThisForm.grdGames
.ColumnCount = -1
.RecordSource = "tblChess"
.Init()
ENDWITH
ENDPROC
PROCEDURE cmdSearch.Click()
LOCAL lcString2Search, lcMove, lcCityName
lcCityName = ALLTRIM(ThisForm.txtCityName.Value)
lcString2Search = " " + ALLTRIM(ThisForm.txtSearch.Value)
lcMove = ALLTRIM(ThisForm.txtMove.Value)
IF BETWEEN(VAL(SUBSTR(lcMove, 1, 2)), 5 , 75)
lcMove = TRANSFORM(VAL(SUBSTR(lcMove, 1, 2))) + "."
ELSE
ThisForm.txtMove.Value = ""
lcMove = ""
ENDIF
IF EMPTY(lcString2Search)
lcString2Search = " 1."
ENDIF
SELECT dDate, cCity, cWhite, cBlack, SUBSTR(mMoves, ATC(lcString2Search, mMoves, 1), IIF(EMPTY(lcMove), 600, AT(lcMove, mMoves, 1) - ATC(lcString2Search, mMoves, 1))) as cMoves ;
FROM tblChess ;
WHERE ;
IIF(EMPTY(lcCityName) , .T. , ;
(ATC(lcCityName, cCity) != 0 OR ;
ATC(lcCityName, cWhite) != 0 OR ;
ATC(lcCityName, cBlack ) != 0)) ;
AND ATC(lcString2Search, mMoves, 1) # 0 ;
INTO CURSOR csrFGames
WITH ThisForm.grdGames
.ColumnCount = -1
.RecordSource = "csrFGames"
.Init()
ENDWITH
LOCATE
ThisForm.Refresh()
ENDPROC
ADD OBJECT cmdExit As CommandButton WITH;
Width = 60, Height = 24, Left = 522, Top = 324, Anchor = 12, Caption = "Exit", BackColor = RGB(0, 240, 0)
PROCEDURE cmdExit.Click()
CLEAR Events
ThisForm.Release
ENDPROC
ADD OBJECT cmdNew As CommandButton WITH;
Width = 60, Height = 24, Left = 84, Top = 324, Anchor = 6, Caption = "New", BackColor = RGB(0, 240, 240)
PROCEDURE cmdNew.Click()
go_FormAdd = CreateObject ("frmAdd")
go_FormAdd.Visible = .T.
go_FormAdd.Show
ENDPROC
ADD OBJECT cmdEdit as CommandButton WITH ;
Width = 60, Height = 24, Left = 150, Top = 324, Anchor = 6, Caption = "Edit", Name = "cmdEdit"
PROCEDURE cmdEdit.Click()
IF ALIAS() = "TBLCHESS"
IF This.Caption = "Edit"
ThisForm.grdGames.ReadOnly = .F.
This.Caption = "Save"
FOR i = 1 TO ThisForm.ControlCount
IF Thisform.Controls(i).BaseClass = "Commandbutton"
IF ThisForm.Controls(i).Name = "CMDEDIT"
ThisForm.Controls(i).Enabled = .T.
ELSE
ThisForm.Controls(i).Enabled = .F.
ENDIF
ENDIF
ENDFOR
ELSE
ThisForm.grdGames.ReadOnly = .T.
This.Caption = "Edit"
FOR i = 1 TO ThisForm.ControlCount
IF Thisform.Controls(i).BaseClass = "Commandbutton"
ThisForm.Controls(i).Enabled = .T.
ENDIF
ENDFOR
ENDIF
ELSE
= MESSAGEBOX("You have to reset the filter before being able to change data.", 64 , "Changing data", 3000)
ENDIF
ENDPROC
ADD OBJECT cmdLBL as CommandButton WITH ;
Width = 90, Height = 24, Left = 216, Top = 324, Anchor = 6, Caption = "Line By Line"
PROCEDURE cmdLBL.Click()
IF ALIAS() = "CSRFGAMES"
go_FormLBL = CreateObject ("frmLiByLi")
go_FormLBL.Visible = .T.
go_FormLBL.Show
ENDIF
ENDPROC
PROCEDURE Resize()
WITH This.grdGames
.Column5.Width = MAX(.Width - (.Column1.Width + .Column2.Width + .Column3.Width + .Column4.Width) - 36, 210)
ENDWITH
ENDPROC
PROCEDURE Destroy()
CLEAR Events
ThisForm.Release
ENDPROC
PROCEDURE Load()
IF !FILE("tblChess.dbf")
Create Table tblChess (dDate D, cCity C(20), cWhite C(30), cBlack C(30), mMoves M)
INSERT INTO tblChess VALUES ( {^2018/09/03}, "Budapest", "Dame" ,"Turm", " 1.d4 Nf6 2.Nc3 d5 3.f3 e6 4.Bg5 Be7 5.e3 c5 6.Bb5+ Nc6 7.f4 Bd7 8.Nf3 cxd4 9.exd4 h6" + ;
" 10.Bh4 Ne4 11.Bxe7 Qxe7 12.O-O Nxc3 13.bxc3 O-O 14.c4 dxc4 15.Bxc4 Na5 16.Bd3 Rac8" + ;
" 17.Qe1 b6 18.Ne5 Qd6 19.Rd1 Bc6 20.Kh1 f5 21.c4 Ba8 22.Qg3 Nc6 23.c5 bxc5 24.dxc5 Qc7 25.Bc4 Nxe5" + ;
" 26.Bxe6+ Nf7 27.Rd7 Qc6 28.Qg6 Kh8 29.Rxa7 Qxg2+ 30.Qxg2 Bxg2+ 31.Kxg2 Nd8 32.Bxc8")
INSERT INTO tblChess VALUES ( {^2018/06/18}, "Budapest", "Läufer", "Turm", " 1.Nc3 d5 2.d4 Nf6 3.f3 e6 4.Bg5 Be7 5.e3 O-O 6.Nce2 c5 7.c3 b6 8.Ng3 Bb7 9.Bd3 Nbd7" + ;
" 10.f4 h6 11.Bxf6 Nxf6 12.Qf3 cxd4 13.exd4 Qc7 14.Nh3 a5 15.O-O Ba6 16.Bxa6 Rxa6" + ;
" 17.Rae1 b5 18.Re3 Rc6 19.Rfe1 Bd6 20.Ne2 Ne4 21.Nf2 Nd2 22.Qg4 f5 23.Qg6 Bxf4 24.Nxf4 e5 25.Nxd5 Rxg6" + ;
" 26.Nxc7 f4 27.Rd3 e4 28.Rxd2 e3 29.Rde2")
ELSE
USE tblChess
ENDIF
LOCATE
ENDPROC
ENDDEFINE
*****
DEFINE CLASS frmAdd as Form
Width = 480
Height = 240
MinWidth = This.Width
MaxWidth = This.Width
MinHeight = This.Height
MaxHeight = This.Height
WindowType = 1
Caption = "Add Games"
AutoCenter = .T.
Themes = .F.
ADD OBJECT lblDate as Label WITH ;
Top = 24, Left = 12, Caption = "Date"
ADD OBJECT lblCity as Label WITH ;
Top = 24, Left = 102, Caption = "City"
ADD OBJECT lblWPName as Label WITH ;
Top = 24, Left = 228, Caption = "WP Name"
ADD OBJECT lblBPName as Label WITH ;
Top = 24, Left = 354, Caption = "BP Name"
ADD OBJECT lblMoves as Label WITH ;
Top = 84, Left = 12, Caption = "Moves"
ADD OBJECT txtDate as TextBox WITH ;
Top = 48, Left = 12, Width = 78, Value = {}
ADD OBJECT txtCity as TextBox WITH ;
Top = 48, Left = 96, Width = 120, Value = ""
ADD OBJECT txtWPName as TextBox WITH ;
Top = 48, Left = 222, Width = 120, Value = ""
ADD OBJECT txtBPName as TextBox WITH ;
Top = 48, Left = 348, Width = 120, Value = ""
ADD OBJECT edtMoves as EditBox WITH ;
Top = 102, Left = 12, Width = 456, Value = ""
ADD OBJECT cmdSave as CommandButton WITH ;
Top = 204, Left = 12, Height = 24, BackColor = RGB(0, 240, 240), Caption = "Save"
PROCEDURE cmdSave.Click()
LOCAL llSave
llSave = .T.
FOR i = 1 TO ThisForm.ControlCount
IF Thisform.Controls(i).BaseClass = "Textbox" OR ThisForm.Controls(i).BaseClass = "Editbox"
IF EMPTY(ThisForm.Controls(i).Value)
WAIT WINDOW + "Hi - an important field is still empty" TIMEOUT 1
llSave = .F.
ENDIF
ENDIF
ENDFOR
IF llSave
INSERT INTO tblChess VALUES (ThisForm.txtDate.Value, ThisForm.txtCity.Value, ThisForm.txtWPName.Value, ThisForm.txtBPName.Value, ThisForm.edtMoves.Value)
ThisForm.Release()
go_Form.Show()
ENDIF
ENDPROC
ENDDEFINE
*****
[highlight #73D216]DEFINE CLASS frmLiByLi as Form
DIMENSION laMoves[1]
Width = 900
Height = 480
MinWidth = This.Width
MinHeight = This.Height
MinButton = .F.
MaxButton = .F.
WindowType = 1
Caption = "Line By Line"
AutoCenter = .T.
Themes = .F.
ADD OBJECT grdMoves as Grid WITH ;
Top = 12, ;
Left = 12, ;
Height = 480 - 24, ;
Width = 900 - 24, ;
Anchor = 15, ;
ReadOnly = .T., ;
ColumnCount = -1, ;
RecordSource = "csrMoves"
PROCEDURE grdMoves.Init()
LOCAL liFirstMove
liFirstMove = VAL(SUBSTR(csrMoves.cM01, AT(".", csrMoves.cM01, 1) - 2, 2)) - 1
FOR i = 1 TO This.ColumnCount
WITH this
.Columns(i).Header1.Caption = "Move" + ALLTRIM(STR(liFirstMove + i))
.Columns(i).Header1.FontBold = .T.
.Columns(i).Width = 90
ENDWITH
ENDFOR
FOR i = This.ColumnCount TO ALEN(ThisForm.laMoves) STEP -1
This.DeleteColumn(i)
ENDFOR
ENDPROC
PROCEDURE Load()
LOCAL liDots
CREATE CURSOR csrMoves (cM01 C(20), cM02 C(20), cM03 C(20), cM04 C(20), cM05 C(20), ;
cM06 C(20), cM07 C(20), cM08 C(20), cM09 C(20), cM10 C(20), ;
cM11 C(20), cM12 C(20), cM13 C(20), cM14 C(20), cM15 C(20), ;
cM16 C(20), cM17 C(20), cM18 C(20), cM19 C(20), cM20 C(20))
SELECT csrFGames
SCAN
liDots = OCCURS(".", csrFGames.cMoves)
IF liDots > 0
DIMENSION ThisForm.laMoves[liDots]
FOR i = 2 to liDots
ThisForm.laMoves[i - 1] = SUBSTR(csrFGames.cMoves, AT(".", csrFGames.cMoves, i - 1) - 2, AT(".", csrFGames.cMoves, i) - AT(".", csrFGames.cMoves, i - 1))
ENDFOR
APPEND BLANK IN csrMoves
Replace IN csrMoves from ARRAY ThisForm.laMoves
ENDIF
ENDSCAN
SELECT csrMoves
LOCATE
ENDPROC
PROCEDURE Destroy()
USE IN csrMoves
SELECT csrFGames
ThisForm.Release
ENDPROC
ENDDEFINE[/highlight]
*****
Enjoy
MarK