PUBLIC odataupdate
SET CLASSLIB TO ab\aw\samples\fic\classe\ficsample.vcx ADDITIVE
odataupdate=NEWOBJECT("dataupdate")
odataupdate.Show
RETURN
**************************************************
#INCLUDE "ab\ab.h"
DEFINE CLASS dataupdate AS ficfrm
Height = 450
Width = 811
DoCreate = .T.
Caption = "Data Update"
MaxWidth = 1000
MinWidth = 780
BackColor = RGB(240,240,240)
_memberdata = [<VFPData><memberdata name="sourcetype" display="sourceType"/><memberdata name="grctxtvalid" display="grcTxtValid"/><memberdata name="cursorrefresh" display="cursorRefresh"/><memberdata name="fetchiscomplete" display="FetchIsComplete"/><memberdata name="grdrecordsourceset" display="grdRecordSourceSet"/></VFPData>]
wbswidth = 2
Name = "DataUpdate"
cntOK.opgStyle.optClassic.Value = 1
cntOK.opgStyle.optClassic.Left = 0
cntOK.opgStyle.optClassic.Top = 0
cntOK.opgStyle.optClassic.Name = "optClassic"
cntOK.opgStyle.optBS.Left = 0
cntOK.opgStyle.optBS.Top = 30
cntOK.opgStyle.optBS.Name = "optBS"
cntOK.opgStyle.Left = 10
cntOK.opgStyle.Top = 10
cntOK.opgStyle.ZOrderSet = 0
cntOK.opgStyle.Name = "opgStyle"
cntOK.cmdOK.Top = 6
cntOK.cmdOK.Left = 141
cntOK.cmdOK.ZOrderSet = 2
cntOK.cmdOK.Name = "cmdOK"
cntOK.imgSrce.Left = 105
cntOK.imgSrce.Top = 45
cntOK.imgSrce.ZOrderSet = 1
cntOK.imgSrce.Name = "imgSrce"
cntOK.imgHelp.Left = 152
cntOK.imgHelp.Top = 49
cntOK.imgHelp.ZOrderSet = 3
cntOK.imgHelp.Name = "imgHelp"
cntOK.Anchor = 9
cntOK.Top = 5
cntOK.Left = 615
cntOK.Width = 185
cntOK.Height = 85
cntOK.ZOrderSet = 3
cntOK.Name = "cntOK"
waitpic.ZOrderSet = 5
waitpic.Name = "waitpic"
lblFiC.Left = 15
lblFiC.Top = 430
lblFiC.ZOrderSet = 4
lblFiC.Name = "lblFiC"
lblTime.Height = 15
lblTime.Left = 375
lblTime.Top = 430
lblTime.Width = 423
lblTime.ZOrderSet = 15
lblTime.Name = "lblTime"
ADD OBJECT lblresult AS ficlbl WITH ;
FontBold = .T., ;
FontName = "Consolas", ;
Anchor = 11, ;
WordWrap = .T., ;
Caption = "Data update result", ;
Height = 30, ;
Left = 473, ;
Top = 105, ;
Width = 322, ;
ZOrderSet = 0, ;
wcpropsave = "Caption,ToolTipText, ForeColor, Visible", ;
wbsllinked = .NULL., ;
wbsctag = "h4", ;
wcssclassadd = "text-info", ;
Name = "lblResult"
ADD OBJECT opgbuffering AS ficopg WITH ;
ButtonCount = 3, ;
Anchor = 41, ;
BorderStyle = 0, ;
Height = 34, ;
Left = 325, ;
Top = 22, ;
Width = 259, ;
ZOrderSet = 1, ;
ToolTipText = ['CursorGetProp("Buffering", thisForm.Grid.RecordSource)'], ;
Name = "opgBuffering", ;
Ficopt1.FontName = "Consolas", ;
Ficopt1.FontSize = 11, ;
Ficopt1.Anchor = 130, ;
Ficopt1.Caption = "1-None", ;
Ficopt1.Value = 1, ;
Ficopt1.Height = 30, ;
Ficopt1.Left = 0, ;
Ficopt1.Style = 1, ;
Ficopt1.Top = 0, ;
Ficopt1.Width = 83, ;
Ficopt1.Name = "optNone", ;
Ficopt2.FontName = "Consolas", ;
Ficopt2.FontSize = 11, ;
Ficopt2.Anchor = 160, ;
Ficopt2.Caption = "3-Row", ;
Ficopt2.Height = 30, ;
Ficopt2.Left = 82, ;
Ficopt2.Style = 1, ;
Ficopt2.Top = 0, ;
Ficopt2.Width = 86, ;
Ficopt2.Name = "optRow", ;
Ficopt3.FontName = "Consolas", ;
Ficopt3.FontSize = 11, ;
Ficopt3.Anchor = 40, ;
Ficopt3.Caption = "5-Table", ;
Ficopt3.Value = 0, ;
Ficopt3.Height = 30, ;
Ficopt3.Left = 170, ;
Ficopt3.Style = 1, ;
Ficopt3.Top = 0, ;
Ficopt3.Width = 88, ;
Ficopt3.Name = "optTable"
ADD OBJECT lblcsp_bf AS ficlbl WITH ;
FontSize = 8, ;
Anchor = 41, ;
Caption = "grid.RecordSource Buffering", ;
Height = 12, ;
Left = 325, ;
Top = 7, ;
Width = 252, ;
ForeColor = RGB(64,128,128), ;
ZOrderSet = 2, ;
wbsctag = "p", ;
Name = "lblCSP_BF"
ADD OBJECT tutoinfoboxfic AS ficebxsrcecode WITH ;
Anchor = 15, ;
Height = 247, ;
Left = 470, ;
Top = 175, ;
Width = 327, ;
ZOrderSet = 6, ;
Name = "tutoInfoBoxFIC"
ADD OBJECT grd AS ficgrd WITH ;
FontName = "Consolas", ;
FontSize = 9, ;
Anchor = 7, ;
AllowRowSizing = .F., ;
DeleteMark = .F., ;
Height = 328, ;
Left = 10, ;
RowHeight = 20, ;
Top = 95, ;
Width = 446, ;
ZOrderSet = 7, ;
wlcontentdynamic = .T., ;
Name = "grd"
ADD OBJECT opgsourcetype AS ficopg WITH ;
ButtonCount = 4, ;
Anchor = 131, ;
BorderStyle = 0, ;
Height = 34, ;
Left = 7, ;
Top = 22, ;
Width = 287, ;
ZOrderSet = 8, ;
ToolTipText = "thisForm.Grid.RecordSource", ;
wbsclbllinked = "lblCSP_ST", ;
Name = "opgSourceType", ;
Ficopt1.FontName = "Consolas", ;
Ficopt1.FontSize = 11, ;
Ficopt1.Anchor = 130, ;
Ficopt1.Caption = "Table", ;
Ficopt1.Value = 1, ;
Ficopt1.Height = 30, ;
Ficopt1.Left = 1, ;
Ficopt1.Style = 1, ;
Ficopt1.ToolTipText = "Local VFP Table: tastrade!customers", ;
Ficopt1.Top = 0, ;
Ficopt1.Width = 67, ;
Ficopt1.Name = "optTable", ;
Ficopt2.FontName = "Consolas", ;
Ficopt2.FontSize = 11, ;
Ficopt2.Anchor = 160, ;
Ficopt2.Caption = "L View", ;
Ficopt2.Value = 0, ;
Ficopt2.Height = 30, ;
Ficopt2.Left = 69, ;
Ficopt2.Style = 1, ;
Ficopt2.ToolTipText = "Local View tastrade!v_customers", ;
Ficopt2.Top = 0, ;
Ficopt2.Width = 73, ;
Ficopt2.Name = "optLView", ;
Ficopt3.FontName = "Consolas", ;
Ficopt3.FontSize = 11, ;
Ficopt3.Anchor = 160, ;
Ficopt3.Caption = "L CAD", ;
Ficopt3.Value = 0, ;
Ficopt3.Height = 30, ;
Ficopt3.Left = 143, ;
Ficopt3.Style = 1, ;
Ficopt3.ToolTipText = "Local cursorAdapter on tastrade!customers", ;
Ficopt3.Top = 0, ;
Ficopt3.Width = 67, ;
Ficopt3.Name = "optLCAD", ;
Ficopt4.FontName = "Consolas", ;
Ficopt4.FontSize = 11, ;
Ficopt4.Anchor = 40, ;
Ficopt4.Caption = "R View", ;
Ficopt4.Value = 0, ;
Ficopt4.Height = 30, ;
Ficopt4.Left = 211, ;
Ficopt4.Style = 1, ;
Ficopt4.ToolTipText = "Remote View on SQLserver Northwind!customers", ;
Ficopt4.Top = 0, ;
Ficopt4.Width = 71, ;
Ficopt4.Name = "optRView"
ADD OBJECT cmdsave AS ficcmd WITH ;
Top = 140, ;
Left = 722, ;
Height = 30, ;
Width = 76, ;
FontName = "Consolas", ;
FontSize = 11, ;
Anchor = 40, ;
Caption = "Save", ;
ZOrderSet = 9, ;
Name = "cmdSave"
ADD OBJECT cmddelete AS ficcmd WITH ;
Top = 140, ;
Left = 540, ;
Height = 30, ;
Width = 77, ;
FontName = "Consolas", ;
FontSize = 11, ;
Anchor = 160, ;
Caption = "Delete", ;
ZOrderSet = 10, ;
Name = "cmdDelete"
ADD OBJECT cmdcancel AS ficcmd WITH ;
Top = 140, ;
Left = 645, ;
Height = 30, ;
Width = 76, ;
FontName = "Consolas", ;
FontSize = 11, ;
Anchor = 160, ;
Caption = "Cancel", ;
ZOrderSet = 11, ;
Name = "cmdCancel"
ADD OBJECT cmdnew AS ficcmd WITH ;
Top = 140, ;
Left = 470, ;
Height = 30, ;
Width = 70, ;
FontName = "Consolas", ;
FontSize = 11, ;
Anchor = 130, ;
Caption = "New", ;
ZOrderSet = 12, ;
Name = "cmdNew"
ADD OBJECT lblrs AS ficlbl WITH ;
FontBold = .T., ;
FontName = "Consolas", ;
Anchor = 3, ;
Alignment = 2, ;
Caption = "grid.RecordSource = ...", ;
Height = 23, ;
Left = 10, ;
Top = 65, ;
Width = 441, ;
ForeColor = RGB(83,83,255), ;
ZOrderSet = 13, ;
wcssclassadd = "text-info", ;
wbsctag = "", ;
wbsllinked = .NULL., ;
Name = "lblRS"
ADD OBJECT lblcsp_st AS ficlbl WITH ;
FontSize = 8, ;
Anchor = 131, ;
Caption = "grid.RecordSource SourceType", ;
Height = 12, ;
Left = 10, ;
Top = 8, ;
Width = 277, ;
ForeColor = RGB(64,128,128), ;
ZOrderSet = 14, ;
wbsctag = "p", ;
Name = "lblCSP_ST"
ADD OBJECT cmdcboenable AS ficcmd WITH ;
Top = 385, ;
Left = 355, ;
Height = 30, ;
Width = 85, ;
FontName = "Consolas", ;
FontSize = 10, ;
Anchor = 6, ;
Caption = "Disable", ;
ZOrderSet = 16, ;
wcpropsave = "Enabled,Caption", ;
Name = "cmdCboEnable"
*-- CursorGetProp("SourceType", thisForm.grd.RecordSource) as clear text
PROCEDURE sourcetype
local sourceType
sourceType = Iif(Used(thisForm.grd.RecordSource);
, CursorGetProp("SourceType", thisForm.grd.RecordSource);
, .null.;
)
return ICase(;
IsNull(m.sourceType),;
'?',;
m.sourceType > 100,;
'LCursorAdapter',;
m.sourceType % 100 = 1,;
'LView',;
m.sourceType % 100 = 2,;
'RView',;
m.sourceType % 100 = 3,;
'Table',;
'?';
)
ENDPROC
*-- thisForm.grd.grc*.txt*.Valid() - delegate method
PROCEDURE grctxtvalid
return AddProperty(;
m.thisForm;
,'nBufferDirty';
, nBufferDirty(m.thisForm.grd.recordSource);
)
ENDPROC
*-- refreshes View or CursorAdapter contents
PROCEDURE cursorrefresh
LOCAL success as Boolean;
, sourceType as String;
, oCAD as ficCAD of ficSample;
, aa[1];
sourceType = Lower(thisForm.SourceType())
do case
case m.sourceType == Lower('LView')
success = 1 = thisForm.wViewParmSet(;
thisForm.grd.RecordSource;
, 'cCusID';
, '';
, .T.;
) or Empty(AError(aa))
case m.sourceType == Lower('LCursorAdapter')
oCAD = GetCursorAdapter(thisForm.grd.RecordSource)
success = oCAD.CursorRefresh() or Empty(AError(aa))
otherwise
success = .T.
endcase
if !m.success
AddProperty(m.thisForm, 'cDataOpe', 'cursor refresh')
AddProperty(m.thisForm, 'cDataError', m.aa[2])
endif
return m.success
ENDPROC
*-- grid.RecordSource is not a remote cursor or FetchIsComplete
PROCEDURE fetchiscomplete
return !thisForm.sourceType() == 'RView' or CursorGetProp("FetchIsComplete", thisForm.grd.RecordSource)
ENDPROC
*-- Set grid.recordSource based on opgSourceType.Value
PROCEDURE grdrecordsourceset
lparameters formRefreshNot as Boolean
LOCAL success as Boolean;
, iValue as Integer;
, cAlias_ as String;
, cAlias as String;
, lAlias as Boolean;
, customer_ID as String;
, lTable as Boolean;
store thisForm.grd.RecordSource to cAlias, cAlias_
lAlias = Used(m.cAlias)
customer_ID = Iif(m.lAlias, Evaluate(m.cAlias + '.customer_ID'), '')
lTable = Upper(m.cAlias) == Upper('Customer_Table') or !m.lAlias
iValue = thisForm.opgSourceType.Value
* set new grid.RecordSource
do case
case m.iValue = 1
cAlias = 'Customer_Table'
lTable = Iif(m.lTable, .null., .T.)
case m.iValue = 2
cAlias = 'Customer_LView'
lTable = Iif(m.lTable, .F., .null.)
case m.iValue = 3
cAlias = 'Customer_LCAD'
lTable = Iif(m.lTable, .F., .null.)
case m.iValue = 4
cAlias = 'Customer_RView'
lTable = Iif(m.lTable, .F., .null.)
endcase
#IFNDEF PREVIOUS_FIC_VERSION
do case
case Used(m.cAlias)
case m.cAlias = 'Customer_Table'
use tastrade!customer in 0 again alias Customer_Table
case m.cAlias = 'Customer_LView'
cCusID = ''
use tastrade!v_customer in 0 again alias Customer_LView
select Customer_LView
index on customer_ID tag cust_id candidate
set order to
case m.cAlias = 'Customer_LCAD'
thisForm.dataEnvironment.cursor6.cursorFill
select Customer_LCAD
index on customer_ID tag cust_id candidate
set order to
case m.cAlias = 'Customer_RView'
cCusID = ''
use tastrade!Customer_RView in 0 again alias Customer_RView
endcase
#ENDIF
with thisForm.grd as awgrd of aw.vcx
.RecordSource = m.cAlias
for iGrc = 1 to .ColumnCount
with .Columns(m.iGrc) as ficGrc of tutoSets.prg
.ControlSource = m.cAlias + '.' + ICase(;
m.iGrc = 1,;
'customer_id',;
m.iGrc = 2,;
'company_name',;
m.iGrc = 3,;
'region_id',;
m.iGrc = 4,;
'active',;
m.iGrc = 5,;
'contact_title',;
m.iGrc = 6,;
'contact_name',;
'';
)
assert !Empty(.ControlSource)
.Alignment = .Alignment
.DynamicBackColor = Iif(.ReadOnly;
, '';
, Textmerge('';
+ [Iif(];
+ [CursorGetProp('Buffering', '<<m.cAlias>>') = 1];
+ [ or ];
+ [<<.ControlSource>> == Oldval('<<JustField(.ControlSource)>>', '<<m.cAlias>>')];
+ [, <<.BackColor>>];
+ [, <<Rgb(255,128,128)>>];
+ [)]);
)
endwith
endfor
endwith
* refresh cursor if applicable
success = thisForm.cursorRefresh()
* if new grid.RecordSource is not the table, clear buffering on table
do case
case !m.success or IsNull(m.lTable)
case m.lTable
CursorSetProp("Buffering", m.thisForm.customerTableBuffering, 'Customer_Table')
otherwise
thisForm.customerTableBuffering = CursorGetProp("Buffering", 'Customer_Table')
CursorSetProp("Buffering", 1, 'Customer_Table')
endcase
* restore Recno(grid.RecordSource)
select (m.cAlias)
if m.lAlias
locate for customer_ID = m.customer_ID
lAlias = Found()
endif
if !m.lAlias
go top
endif
#IF .F.
if Upper(m.cAlias) # Upper(m.cAlias_) and Used(m.cAlias_)
if CursorGetProp("Buffering", m.cAlias_) > 1
TableRevert(.T., m.cAlias_)
endif
use in (m.cAlias_)
endif
#ENDIF
if !lTrue(m.formRefreshNot)
thisForm.Refresh
endif
ENDPROC
PROCEDURE Init
lparameters tiRS, tiBuf
DoDefault()
if m.this.wlInitFirst
local aa[1], oCmd as Commandbutton
if aoClassCont(@m.aa, this, 'Commandbutton') > 0
for each oCmd in m.aa
m.oCmd.ResetToDefault('fontSize')
endfor
endif
if thisForm.wBSlHTMLgen
thisForm.lblCSP_ST.Left = thisForm.opgSourceType.Left
thisForm.lblCSP_ST.Width = thisForm.opgSourceType.Width
thisForm.lblCSP_BF.Left = thisForm.opgBuffering.Left
thisForm.lblCSP_BF.Width = thisForm.opgBuffering.Width
endif
this.grdRecordSourceSet()
return
endif
this.opgSourceType.Value = Evl(m.tiRS, 3)
this.opgSourceType.Valid
this.opgBuffering.Value = Evl(m.tiBuf, 3)
this.opgBuffering.Valid
this.grdRecordSourceSet(.T.)
ENDPROC
PROCEDURE Load
local result
result = DoDefault()
set ansi off
set deleted on
select Customer_LCAD
index on customer_ID tag cust_id candidate
set order to
select Customer_LView
index on customer_ID tag cust_id candidate
set order to
this.AddProperty('nSQLhandle', SQLconnect('NorthWind'))
wcPropSaveNotEdit(m.this, 'nSQLhandle')
if m.this.nSQLhandle > -1
select 0
use tastrade!customer_RView connstring m.this.nSQLhandle nodata
*!* index on customer_ID tag cust_id candidate
*!* set order to
Requery()
endif
AddProperty(m.thisForm, 'cDataOpe', '')
AddProperty(m.thisForm, 'nDataRec', 0)
AddProperty(m.thisForm, 'cDataError', '')
AddProperty(m.thisForm, 'nBufferDirty', 0)
thisForm.AddProperty('customerTableBuffering', CursorGetProp("Buffering", 'customer_table'))
select 0
return m.result
ENDPROC
PROCEDURE wreadme
lparameters cLangUser
cLangUser = Evl(Evl(m.cLangUser, m.this.wcLangUser), cLangUser())
local result as String
* remove '.F. && ' whenever a translation is available
do case
case m.cLangUser = 'fr'
text to result noshow flags 1
Cet écran illustre les multiples possibilités de mise à jour des données avec FoxInCloud:
- tous les types de sources de données
- tous les types de tampons (buffering)
- saisie des données dans une grille
Chaque fois que vous changez d'option de données, la grille est rechargée avec les nouvelles données.
Pour simuler plusieurs utilisateurs simultanée, affichez ce formulaire dans plusieurs navigateurs simultanément (par ex. firefox et chrome) ; vous verrez comment les modifications de données par un utilisateur sont visibles par le ou les autre(s) utilisateur().
L'option 'R View' (vue distante) illustre le support du chargement progressif des données avec CursorGetProp("FetchAsNeeded") ; initialement la grille est chargée avec CursorGetProp("FetchSize") enregistrements ; chaque fois que vous déplacez le curseur vers la dernière ligne de la grille, un autre jeu de CursorGetProp("FetchSize") enregistrements se charge jusqu'à CursorGetProp("FetchIsComplete").
Notez que, le curseur ne pouvant être modifié qu'une fois tous les enregistrements chargés (CursorGetProp("FetchIsComplete")), la grille reste en lecture seule jusque là.
endtext
case .F.
text to result noshow flags 1
endtext
case .F.
text to result noshow flags 1
endtext
case .F.
text to result noshow flags 1
endtext
case .F.
text to result noshow flags 1
endtext
otherwise
text to result noshow flags 1
This screen shows the various possibilities of updating data with FoxInCloud:
- All types of data sources
- All types of buffering methods
- Updating data in a grid
Every time you select another data option, the grid gets reloaded with new data.
To simulate multiple simultaneous users, display this form simultaneously in multiple browsers (eg Firefox and Chrome); you will see how a user data changes are visible to other user(s).
The 'R View' option (remote view) demonstrates progressive fetching using CursorGetProp("FetchAsNeeded"): initially CursorGetProp("FetchSize") records are loaded, whenever you move to the last visible row in the grid, another set of CursorGetProp("FetchSize") records loads in until CursorGetProp("FetchIsComplete").
Please note that, as the cursor can be modified only when all records are fetched (CursorGetProp("FetchIsComplete")), grid remains read-only until then.
endtext
endcase
return m.result
ENDPROC
PROCEDURE lblresult.refresh_
DoDefault()
this.Visible = CursorGetProp("Buffering", m.thisForm.grd.RecordSource) > 1
if !m.this.Visible
return
endif
this.ToolTipText = ICase(;
thisForm.wcLangUser == 'fr', [Résultat de la dernière opération sur les données],;
[Result of the last data-related operation];
)
local nBufferDirty as Integer
nBufferDirty = nBufferDirty(m.thisForm.grd.RecordSource)
DO CASE
case !thisForm.FetchIsComplete()
this.Caption = '';
+ cL(m.thisForm.grd.RecordSource);
+ ' ' + ICase(;
thisForm.wcLangUser == 'fr', [est en lecture seule car son chargement est incomplet],;
[is read-only because fetch is incomplete];
);
+ '.'
this.ForeColor = RGB(64,128,128)
case m.thisForm.nDataRec > 0
* setStepOn(lView(m.thisForm.grd.RecordSource))
store '';
+ cL(m.thisForm.grd.RecordSource);
+ [, ] + m.thisForm.cDataOpe;
+ [ ] + Transform(m.thisForm.nDataRec) + [ rec] + Iif(m.thisForm.nDataRec > 1, 's', '') + [.];
+ [: ] + Iif(Empty(m.thisForm.cDataError), 'success', 'error: ' + m.thisForm.cDataError);
to this.Caption, this.ToolTipText
this.ForeColor = Iif(Empty(m.thisForm.cDataError);
, Rgb(0, 200, 0);
, Rgb(255, 0, 0);
)
AddProperty(m.thisForm, 'cDataOpe', '')
AddProperty(m.thisForm, 'nDataRec', 0)
AddProperty(m.thisForm, 'cDataError', '')
case m.nBufferDirty > 0
this.Caption = '';
+ cL(m.thisForm.grd.RecordSource);
+ ' ' + ICase(;
thisForm.wcLangUser == 'fr', [a],;
[has];
);
+ ' ' + Transform(m.nBufferDirty);
+ ' ' + ICase(;
thisForm.wcLangUser == 'fr', [enr. tamponné],;
[buff. record];
) + Iif(m.nBufferDirty > 1, 's', '');
+ ' ' + ICase(;
thisForm.wcLangUser == 'fr', [modifié] + Iif(m.nBufferDirty > 1, 's', ''),;
[modified];
);
+ [.];
this.ForeColor = Rgb(255, 64, 64)
otherwise
this.Caption = '';
+ cL(m.thisForm.grd.RecordSource);
+ ' ' + ICase(;
thisForm.wcLangUser == 'fr', [n'a aucun enr. modifié],;
[has no record modified];
);
+ [.];
this.ForeColor = Rgb(0,128,255)
endcase
ENDPROC
PROCEDURE opgbuffering.refresh_
local iBuffering
this.Enabled = thisForm.FetchIsComplete() and !lBufferDirty(thisForm.grd.RecordSource)
this.SetAll('Enabled', this.Enabled)
iBuffering = Iif(Used(thisForm.grd.RecordSource);
, CursorGetProp("Buffering", thisForm.grd.RecordSource);
, .null.;
)
this.Value = ICase(;
IsNull(m.iBuffering),;
'?',;
m.iBuffering = 1,;
1,;
m.iBuffering = 3,;
2,;
m.iBuffering = 5,;
3,;
0;
)
ENDPROC
PROCEDURE opgbuffering.Valid
if m.thisForm.wlHTMLgen
return .T.
endif
local success as Boolean;
, oException as Exception;
try
success = CursorSetProp(;
"Buffering";
, ICase(;
m.this.Value = 1,;
1,;
m.this.Value = 2,;
3,;
m.this.Value = 3,;
5,;
0;
);
, m.thisForm.grd.RecordSource;
)
catch to oException
thisForm.wMessageBox(cException(m.oException))
endtry
thisForm.Refresh
return m.success
ENDPROC
PROCEDURE opgbuffering.optNone.refresh_
this.Enabled = Lower(thisForm.SourceType()) == Lower('Table')
ENDPROC
PROCEDURE grd.refresh_
this.ReadOnly = !thisForm.FetchIsComplete()
this.columns(1).ReadOnly = .T.
store this.ReadOnly or thisForm.cmdCboEnable.lReadOnly to;
this.columns(3).ReadOnly;
, this.columns(3).ficTxt.ReadOnly;
, thisForm.cmdCboEnable.lReadOnly
ENDPROC
PROCEDURE grd.waftercolchange
LPARAMETERS nColIndex
do case
case m.thisForm.wlHTMLgen
return .T.
case !DoDefault(@m.nColIndex)
return .F.
endcase
thisForm.Refresh
ENDPROC
PROCEDURE grd.wafterrowchange
LPARAMETERS tuRow
do case
case m.thisForm.wlHTMLgen
return .T.
case !DoDefault(@m.tuRow)
return .F.
endcase
if m.thisForm.nBufferDirty > 0 and Empty(nBufferDirty(m.this.recordSource))
AddProperty(m.thisForm, 'cDataOpe', 'auto save')
AddProperty(m.thisForm, 'nDataRec', m.thisForm.nBufferDirty)
AddProperty(m.thisForm, 'cDataError', '')
thisForm.nBufferDirty = 0
endif
thisForm.Refresh
ENDPROC
PROCEDURE grd.Init
local iGrc as Integer, cGrc as String, cField as String
with m.this as ficGrd of ficSample
.ColumnCount = 6
FOR iGrc = 1 TO .ColumnCount
with .Columns(m.iGrc) as Column
#define column_region 3
#define column_active 4
#define column_readOnly 6
cField = 'customer.' + ICase(;
m.iGrc = 1,;
'customer_ID',;
m.iGrc = 2,;
'Company_name',;
m.iGrc = 3,;
'Region_ID',;
m.iGrc = 4,;
'active',;
m.iGrc = 5,;
'Contact_Title',;
m.iGrc = 6,;
'Contact_name',;
'';
)
cGrc = ICase(;
m.iGrc = 1,;
'ID',;
m.iGrc = 2,;
'Company',;
m.iGrc = 3,;
'Region',;
m.iGrc = 4,;
'active?',;
m.iGrc = 5,;
'Title',;
m.iGrc = 6,;
'Contact',;
'';
)
.Width = ICase(;
m.iGrc = 1,;
060,;
m.iGrc = 2,;
220,;
m.iGrc = 3,;
100,;
m.iGrc = 4,;
50,;
m.iGrc = 5,;
180,;
m.iGrc = 6,;
150,;
0;
)
* Replace native members by instances of adapted classes
.Name = 'grc' + cVFPName(m.cGrc)
.RemoveObject('Text1')
.AddObject('ficTxt', ICase(;
m.iGrc = column_region,;
'ficCbo',;
m.iGrc = column_readOnly,;
'ficTxtGrc',;
m.iGrc = column_active,;
'ficChk',;
'ficTxt';
))
.Sparse = !InList(m.iGrc, column_region, column_active)
.Alignment = Iif(m.iGrc = column_active, 2, 3)
if m.iGrc = column_region
with .ficTxt as combobox
select region, Cast(region_id as C(5)) from region into array .waRowSource
for i = 1 to _Tally*2
.waRowSource[m.i] = Alltrim(.waRowSource[m.i])
endfor
.Margin = 1
.Style = 2
.DisplayCount = 10
.BoundColumn = 2
.BoundTo = .T.
.RowSourceType = 5
.RowSource = 'this.waRowSource'
store rgb(216, 091, 220);
to .BackColor, .Parent.BackColor, .ItemBackColor
store rgb(255, 255, 255);
to .ForeColor, .ItemForeColor
endwith
endif
.CurrentControl = 'ficTxt'
.wlContentDynamic = .T.
.ReadOnly = InList(m.iGrc, 1, column_region)
.BackColor = ICase(;
.ReadOnly,;
Rgb(200, 200, 200),;
m.iGrc = 2,;
Rgb(255, 255, 128),;
.BackColor;
)
BindEvent(.ficTxt, 'Valid', m.thisForm, 'grcTxtValid')
.SetAll('FontName', .FontName)
.SetAll('FontSize', .FontSize)
.SetAll('Visible', .T.)
.SetAll('FontBold', .T., .HeaderClass)
.SetAll('Caption', Evl(DBGetProp(m.cField, 'Field', 'Caption'), m.cGrc), .HeaderClass)
store Evl(DBGetProp(m.cField, 'Field', 'Comment'), m.cField);
+ CRLF + ICase(;
m.iGrc = column_region,;
'Fixed now in Web mode! see dataUpdate.js :-)',;
m.iGrc = column_readOnly,;
'read-only if .RecordSource is a table (just for fun and test)',;
.ReadOnly,;
'read-only',;
'editable';
);
to .ToolTipText, .ficTxt.ToolTipText
endwith
endfor
endwith
ENDPROC
PROCEDURE opgsourcetype.refresh_
this.Enabled = !lBufferDirty(thisForm.grd.RecordSource)
ENDPROC
PROCEDURE opgsourcetype.Valid
if m.thisForm.wlHTMLgen
return .T.
endif
thisForm.grdRecordSourceSet
ENDPROC
PROCEDURE opgsourcetype.Init
this.Value = 1
return DoDefault()
ENDPROC
PROCEDURE opgsourcetype.optRView.refresh_
this.Enabled = m.thisForm.nSQLhandle > -1
ENDPROC
PROCEDURE cmdsave.refresh_
this.Enabled = lBufferDirty(thisForm.grd.RecordSource)
return DoDefault()
ENDPROC
PROCEDURE cmdsave.Click
if m.thisForm.wlHTMLgen
return .T.
endif
LOCAL success as Boolean;
, cAlias as String;
, customer_ID as String;
, nBufferDirty as Integer;
, aa[1];
cAlias = thisForm.grd.RecordSource
customer_ID = Evaluate(m.cAlias + '.customer_ID')
nBufferDirty = nBufferDirty(m.cAlias)
* ======================================
success = TableUpdate(2, .T., m.cAlias, aa)
* ======================================
if !m.success and luEqual(m.aa, -1)
AError(aa)
endif
AddProperty(m.thisForm, 'cDataOpe', 'man. save')
AddProperty(m.thisForm, 'nDataRec', m.nBufferDirty)
AddProperty(m.thisForm, 'cDataError', Iif(m.success, '', m.aa[2]))
if m.success
success = thisForm.cursorRefresh()
endif
if m.success
select (m.cAlias)
locate for customer_ID = m.customer_ID
if !Found()
go top
endif
endif
thisForm.Refresh
return m.success
ENDPROC
PROCEDURE cmddelete.Click
if m.thisForm.wlHTMLgen
return .T.
endif
local customer, customer_ID
customer = Trim(Evaluate(thisForm.grd.RecordSource + '.company_name'))
customer_ID = Trim(Evaluate(thisForm.grd.RecordSource + '.customer_ID'))
thisForm.wMessageBox(;
'wFormCallBack';
, Textmerge([Delete customer '<<m.customer>>'? (ID <<m.customer_ID>>)]);
, 4+32;
, 'Attention';
)
ENDPROC
PROCEDURE cmddelete.wformcallback
LPARAMETERS tuUserChoice
if m.tuUserChoice = IDYES
* =====================================
delete in (m.thisForm.grd.RecordSource)
* =====================================
if thisForm.cmdSave.Enabled;
and InList(CursorGetProp("Buffering", m.thisForm.grd.RecordSource), 2, 3)
thisForm.cmdSave.Click
go top in (m.thisForm.grd.RecordSource)
else
go top in (m.thisForm.grd.RecordSource)
thisForm.Refresh
endif
endif
ENDPROC
PROCEDURE cmddelete.refresh_
this.Enabled = thisForm.FetchIsComplete()
return DoDefault()
ENDPROC
PROCEDURE cmdcancel.refresh_
this.Enabled = lBufferDirty(thisForm.grd.RecordSource)
return DoDefault()
ENDPROC
PROCEDURE cmdcancel.Click
if m.thisForm.wlHTMLgen
return .T.
endif
LOCAL success as Boolean;
, cAlias as String;
, customer_ID as String;
, sourceType as String;
, nBufferDirty as Integer;
, aa[1];
cAlias = thisForm.grd.RecordSource
customer_ID = Evaluate(m.cAlias + '.customer_ID')
sourceType = thisForm.SourceType()
* ======================================
nBufferDirty = TableRevert(.T., m.cAlias)
success = m.nBufferDirty > 0
* ======================================
if !m.success
AError(aa)
endif
AddProperty(m.thisForm, 'cDataOpe', 'cancel')
AddProperty(m.thisForm, 'nDataRec', m.nBufferDirty)
AddProperty(m.thisForm, 'cDataError', Iif(m.success, '', m.aa[2]))
if m.success
success = thisForm.cursorRefresh()
endif
select (m.cAlias)
locate for customer_ID = m.customer_ID
if !Found()
go top
endif
thisForm.Refresh
ENDPROC
PROCEDURE cmdnew.refresh_
this.Enabled = !(.T.;
and m.thisForm.SourceType() == 'Table';
and CursorGetProp("Buffering", m.thisForm.grd.RecordSource) = 1;
) and thisForm.FetchIsComplete()
return DoDefault()
ENDPROC
PROCEDURE cmdnew.Click
if m.thisForm.wlHTMLgen
return .T.
endif
append blank in (thisForm.grd.RecordSource)
replace in (thisForm.grd.RecordSource);
customer_ID with Right(Sys(2015), 5);
company_Name with ICase(;
thisForm.wcLangUser == 'fr', [z Société],;
[z Company];
);
thisform.Refresh
ENDPROC
PROCEDURE lblrs.refresh_
DoDefault()
local iBuffering
iBuffering = Iif(Used(thisForm.grd.RecordSource);
, CursorGetProp("Buffering", thisForm.grd.RecordSource);
, .null.;
)
this.Caption = '';
+ [grid.RecordSource = '];
+ thisForm.grd.RecordSource;
+ [': ];
+ Ltrim(Str(RecCount_(thisForm.grd.RecordSource)));
+ [ ] + ICase(;
thisForm.wcLangUser == 'fr', [enrs],;
[recs];
);
+ [, ] + Iif(thisForm.FetchIsComplete();
, ICase(;
IsNull(m.iBuffering),;
'?',;
m.iBuffering >=4,;
'table',;
m.iBuffering >= 2,;
'row',;
'no';
);
+ ' buffering';
, ICase(;
thisForm.wcLangUser == 'fr', [lecture seule],;
[read-only];
);
);
+ []
ENDPROC
PROCEDURE cmdcboenable.refresh_
this.Enabled = !this.Parent.grd.ReadOnly
this.Caption = 'Read ' + Proper(Iif(thisForm.grd.Columns(3).ReadOnly, 'only', 'write'))
return DoDefault()
ENDPROC
PROCEDURE cmdcboenable.Click
if thisForm.wlHTMLgen
return
endif
with thisForm.grd.Columns(3) as Column
store !.ReadOnly to .ReadOnly, .ficTxt.ReadOnly, this.lReadOnly
endwith
this.Refresh
ENDPROC
PROCEDURE cmdcboenable.Init
this.Visible = !thisForm.wBSlHTMLgen and .F.
AddProperty(this, 'lReadOnly', .T.)
return DoDefault()
ENDPROC
ENDDEFINE