XBROWSE fiirst steps
Posted:
Sun Apr 14, 2013 1:50 pm
by MarcoBoschi
Hi,
I'm creating a very simple program
I use xBrowse class
- Code: Select all Expand view
REDEFINE XBROWSE oBrw ID 101 OF oDlg ALIAS "k2" CELL LINES FONT oFont FASTEDIT
oBrw:lFastEdit = .T.
Each column is define like this
- Code: Select all Expand view
oCol = oBrw:AddCol()
oCol:bStrData := { || field->cod_comp }
oCol:cHeader := "CODICE COMPONENTE"
oCol:nEditType := EDIT_GET
oCol:cEditPicture := "@!"
oCol:bOnPostEdit := { | oCol, xVal, nKey | makerep( "field->cod_comp", nkey, oBrw, xVal ) }
oCol:nWidth := 200
oCol:nDataStrAlign := AL_LEFT
In the dialog There are also some buttons: Insert button and Delete button that are working
The question is
In the action of edit button which instruction I have to write in if I want the same behaviour of VK_RETURN pressed?
Best regards
Marco
Re: XBROWSE fiirst steps
Posted:
Sun Apr 14, 2013 3:15 pm
by nageswaragunupudi
Because you said "first steps", I would advise you adopt the right way of coding xbrowse.
The above code is better written as :
- Code: Select all Expand view
REDEFINE XBROWSE oBrw ID 101 OF oDlg DATASOURCE "k2" ;
COLUMNS "cod_comp" ;
HEADERS "CODICE_COMPONENTE" ;
PICTURES "@!" ;
COLSIZES 200 ;
CELL LINES FASTEDIT
WITH OBJECT oBrw
:aCols[ 1 ]:nEditType := EDIT_GET
END
ACTIVATE DIALOG oDlg
I recommend using COLUMNS clause to create columns than using oBrw:AddCol() and assigning various datas to each column object.
COLUMNS clause for creating of columns is extremely powerful. XBrowse checks the column name with the field names of the DBF and also open indexes and determines automatically datatype, picture clause required, alignment of data (right alignment for numbers and dates and left alignment for other types), index orders to use for sorting, calculations for totalling, etc., incremental seeks, filters, etc. and also prepares a well tested codeblock for bOnPostEdit.
Please note that the codeblocks automatically generated by XBrowse for example bOnPostEdit, bSeek etc are well tested and much better than what you may write and even other wise there is no point in writing them for each column of each browse in your application when xbrowse does it automatically for you and that too bug-free.
You may even omit specifying column size and alignment because XBrowse automatically determines the best-fit.
Please note that you can enter complex expressions also inside the COLUMNS claiuse like "salary * 1.20", "Trim( First ) + ' ' + Trim( Last )", etc.
I assure you that you will get far better results by using COLUMNS clause for creating columns than oBrw:AddCol() and other methods of the column and all attendant disadvantages of this approach.
You liked to know how to use EDIT_BUTTON. This is used when you want a separate interface like a separate dialog to capture the new value.
Syntax:
- Code: Select all Expand view
WITH OBJECT oBrw:aCols[ 1 ]
:nEditType := EDIT_BUTTON
:bEditBlock := { | nRow, nCol, oCol, nKey | MyBtnAction( nRow, nCol, oCol, nKey ) }
Your function should accept the new value and return the new value. If you decide not to modify the value, you should retun NIL.
You need to do all validations and use picture clauses, etc inside your function.
This is a simple sample:
- Code: Select all Expand view
static function MyBtnAction( r, c, oCol, nKey )
local cVal := oCol:Value
if MsgGet( 'enter new value', 'code', @cVal )
return cVal
endif
return nil
Re: XBROWSE fiirst steps
Posted:
Sun Apr 14, 2013 4:06 pm
by MarcoBoschi
Many thanks Nage,
I'm sorry but I meant this:
- Code: Select all Expand view
REDEFINE BUTTON oButIns ID 202 OF oDlg ACTION ins_tab( oBrw , .T. )
REDEFINE BUTTON oButMod ID 203 OF oDlg ACTION MsgInfo( "MOD_TAB") // mod_tab( )
REDEFINE BUTTON oButDel ID 204 OF oDlg ACTION del_tab( oBrw , .T. )
I want that user may click on oButIns rather then pressing INS key
or oButDel rather then DEL key
and If user press oButMod simulate the VK_RETURN pressing that is user want to edit the cell
Re: XBROWSE fiirst steps
Posted:
Sun Apr 14, 2013 4:35 pm
by Antonio Linares
Marco,
To edit the browse you can do:
oBrowse:Edit( VK_RETURN )
Re: XBROWSE fiirst steps
Posted:
Sun Apr 14, 2013 4:58 pm
by devtuxtla
Hello Nages ...
Do you Have a manual to describe the power of xBrowse?
I am not referring to the source code ...
regards
Re: XBROWSE fiirst steps
Posted:
Thu Apr 18, 2013 5:38 am
by ShumingWang
obrow := TXBrowse():New( odlg )
obrow:SetMySQL(@odb2)
obrow:bKeyDown := {|nKey|sto0120(nkey,odlg,otabs),if(ledit,if(nKey==VK_DELETE .and. LEN(ALLTRIM(odb1:stockid))>0, (if(msgyesno("删除这行吗?","请选择"),(sto0103(odb2:qty,0),odb2:DELETE(),obrow:Refresh()),)),if(nKey==VK_INSERT .and. LEN(ALLTRIM(odb1:stockid))>0,(obrow:gobottom(),obrow:godown()),)),) }
oCol := obrow1:AddCol()
oCol:cHeader := "dblclick"
oCol:AddResource("checkoff")
oCol:bBmpData := { ||1}
ocol:nwidth:=40
oCol := obrow:AddCol()
oCol:bStrData := { ||odb2:itemid}
oCol:cHeader := "物料编码"
ocol:beditvalue:={||odb2:itemid}
oCol:nedittype:= {||if(ledit .and. LEN(ALLTRIM(odb1:stockid))>0.and.odb2:qty==0,EDIT_GET_BUTTON,0)}
oCol:bEditBlock:={||goods2brw(odb2:itemid,,,odb2)}
oCol:cEditPicture:="@!"
oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:itemid,;
(if(!odb2:EOF(),;
(v:=goods2brw(v,.t.,@unitid2,odb2),odb2:unitpri:=sto0109(odb1:DATE,v,odb1:vendorid),odb2:itemid:=v,odb2:unitid:=unitid2,odb2:SAVE()),;
(v:=goods2brw(v,.t.,@unitid2,odb2),odb2:unitpri:=sto0109(odb1:DATE,v,odb1:vendorid),odb2:itemid:=v,odb2:invono:=invono1,odb2:unitid:=unitid2,odb2:APPEND());
);
), ;
) }
oCol := obrow:AddCol()
oCol:bStrData := { ||oServer:QueryData("select descrip from goods2 where itemid='"+odb2:itemid+"'")}
oCol:cHeader := "名称规格"
if llots
oCol := obrow:AddCol()
oCol:bStrData := {||odb2:lotsid}
oCol:cHeader := clots
oCol:bEditBlock:={||lotsstockqtybrw(odb2:itemid,odb1:stockid)}
oCol:nEditType := {||if(ledit.and.!odb2:EOF().and.odb2:qty==0,EDIT_GET_BUTTON,0)}
oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:lotsid,(sto0510(odb2:lotsid,v),odb2:lotsid:=v,odb2:save()) , ) }
end
oCol := obrow:AddCol()
oCol:bStrData := { ||odb2:unitid}
oCol:cHeader := "单位码"
ocol:beditvalue:={||odb2:unitid}
ocol:nedittype:= {||if(ledit.and.!odb2:EOF().and.odb2:qty==0,EDIT_GET_BUTTON,0)}
oCol:bEditBlock := {||unitbrw(odb2:itemid,odb2:unitid)}
oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:unitid,(v:=unitbrw(odb2:itemid,v,.t.),odb2:unitid:=v,odb2:SAVE()) , ) }
oCol := obrow:AddCol()
oCol:bStrData := { ||oServer:QueryData("select unit from unit where itemid='"+odb2:itemid+"' and unitid='"+odb2:unitid+"'")}
oCol:cHeader := "单位"
oCol := obrow:AddCol()
oCol:bStrData := { ||odb2:pono}
oCol:cHeader := "采购单号"
ocol:beditvalue:={||odb2:pono}
ocol:nedittype:= {||if(ledit .and. !odb2:EOF(),EDIT_GET_BUTTON,0)}
oCol:bEditBlock := {||sto0123(odb2:itemid,odb1:vendorid,odb2:mid)}
oCol:cEditPicture:="@!"
oCol:bOnPostEdit := {|o, v, n| if(n != VK_ESCAPE .and. v != odb2:pono,sto0108(v),) }
oCol := obrow:AddCol()
oCol:bStrData := { ||odb2:ordno}
oCol:cHeader := "生产单号"
ocol:beditvalue:={||odb2:ordno}
ocol:nedittype:= {||if(ledit .and. !odb2:EOF(),1,0)}
oCol:cEditPicture:="@!"
oCol:bOnPostEdit := {|o, v, n| if(n != VK_ESCAPE .and. v != odb2:ordno,(odb2:ordno:=v,odb2:save()),) }
oCol := obrow:AddCol()
oCol:bStrData := { ||odb2:qty}
oCol:cHeader := "Qty"
ocol:beditvalue:={||odb2:qty}
ocol:nedittype:={||if(ledit.and.!odb2:EOF(),1,0)}
oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:qty,sto0103(odb2:qty,v),)}
oCol:nDataStrAlign := AL_RIGHT
oCol:cFooter :=" "
oCol:nFootStrAlign:= AL_RIGHT
oCol:nWidth := 65
oCol := obrow:AddCol()
oCol:bStrData := {||odb2:COLOR}
oCol:cHeader := ALLTRIM(::array1[4])
ocol:nwidth:=150
oCol := obrow:AddCol()
oCol:bStrData := { ||if(odb2:ldamage,"Y","")}
oCol:cHeader := "报废Y/N"
oCol:bEditValue := {||odb2:ldamage}
oCol:nEditType := {||if(::ledit .and. !odb2:EOF(),1,0)}
oCol:ceditpicture := "Y"
oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:ldamage,(oserver:query("update subptin2 set ldamage="+if(v,"1","0")+if(v,",lback=0,unitpri=0","")+" where mid="+cvaltochar(odb2:mid)),odb2:refresh()) , ) }
ocol:setcheck()
oCol := obrow:AddCol()
oCol:bStrData := { ||odb2:lfinish}
oCol:cHeader := "结案"
oCol:nEditType := {||if(::ledit .and. !odb2:EOF().and.::aright2[6]=="Y",4,0)}
ocol:aEditListTxt:={" ","Y"}
ocol:aEditListBound:={" ","Y"}
oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:lfinish,(oserver:query("update subptou2 set lfinish='"+V+"' where mid="+cvaltochar(odb2:ID)),odb2:refresh()) , ) }
oCol:nWidth :=30
oCol := obrow:AddCol()
oCol:bStrData := { ||::cpath1+"\sub\"+cvaltochar(odb2:imgid)+".jpg"}
oCol:cHeader := "jpg"
ocol:cdatatype:="F"
Re: XBROWSE fiirst steps
Posted:
Thu Apr 18, 2013 6:05 am
by Otto
Hello
I would suggest you AutoCode.
Best regards,
Otto