XBROWSE fiirst steps

XBROWSE fiirst steps

Postby MarcoBoschi » Sun Apr 14, 2013 1:50 pm

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
User avatar
MarcoBoschi
 
Posts: 1025
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: XBROWSE fiirst steps

Postby nageswaragunupudi » Sun Apr 14, 2013 3:15 pm

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
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10308
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: XBROWSE fiirst steps

Postby MarcoBoschi » Sun Apr 14, 2013 4:06 pm

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
User avatar
MarcoBoschi
 
Posts: 1025
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: XBROWSE fiirst steps

Postby Antonio Linares » Sun Apr 14, 2013 4:35 pm

Marco,

To edit the browse you can do:

oBrowse:Edit( VK_RETURN )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41401
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XBROWSE fiirst steps

Postby devtuxtla » Sun Apr 14, 2013 4:58 pm

Hello Nages ...

Do you Have a manual to describe the power of xBrowse?

I am not referring to the source code ...

regards
Visite Chiapas, el paraiso de México.
devtuxtla
 
Posts: 392
Joined: Tue Jul 29, 2008 1:55 pm

Re: XBROWSE fiirst steps

Postby ShumingWang » Thu Apr 18, 2013 5:38 am

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"
http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
ShumingWang
 
Posts: 460
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Re: XBROWSE fiirst steps

Postby Otto » Thu Apr 18, 2013 6:05 am

Hello
I would suggest you AutoCode.
Best regards,
Otto
Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6064
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 35 guests