en GUI, Harbour

DBF Viewer 2020 – Código Fuente II

*------------------------------------------------------*
Procedure SeleArea()
*------------------------------------------------------*
   If !Empty( Alias() )

      DBSelectArea( ( Alias() )->( Select( oWndBase.Tab_1.caption( oWndBase.Tab_1.value ) ) ) )
      cBase := Alias()

      If IsControlDefine(&(Browse_n()),oWndBase)
         oWndBase.&(Browse_n()).SetFocus
      Endif

   Endif

Return

*------------------------------------------------------------------------------*
Procedure CierraBase()
*------------------------------------------------------------------------------*
   If !Empty( Alias() )

      oTab      := GetControlObject("Tab_1","oWndBase")
      nPos      := ( ( Alias() )->( Select( oWndBase.Tab_1.caption( oWndBase.Tab_1.value ) ) ) )

      Set Index To

      If IsControlDefine( &(Browse_n()), oWndBase )
         oWndBase.&(Browse_n()).release
         Close ( oWndBase.Tab_1.caption( oWndBase.Tab_1.value ) )
         oTab:DeletePage ( oTab:value, oTab:caption( oTab:value ) )
         If oWndBase.Tab_1.ItemCount > 0
            DBSelectArea( ( Alias() )->( Select( oWndBase.Tab_1.caption( oWndBase.Tab_1.value ) ) ))
            Titulo()
         Else
            Close data
            oWndBase.Tab_1.release
            aFiles   := {}
            aNewFile := {}
            nRecCopy := {}
            OpenBase("")
         Endif
      Else
         Close data
      Endif

   Endif

return

*------------------------------------------------------------------------------*
Procedure CierraAll()
*------------------------------------------------------------------------------*
   Local nc
   If !Empty( Alias() )
       For nc := 1 to oWndBase.Tab_1.ItemCount
           Close ( oWndBase.Tab_1.caption( nc ) )
       Next
       oWndBase.Tab_1.release
       aFiles   := {}
       aNewFile := {}
       nRecCopy := {}
       OpenBase("")
   Endif

Return

*------------------------------------------------------*
Function Iniciando()     // Cortesía: Fernando Yurisich
*------------------------------------------------------*
   ooWndBase:AcceptFiles := .T.
   ooWndBase:OnDropFiles := { |f| AEval( f, { |c| OpenBase( c ) } ) }
Return Nil

*------------------------------------------------------*
Function AssiCtrlBrw( cTypeField, nlongTot, nLongDec, cFieldName )
*------------------------------------------------------*

   cCtrlBrw := ""
   cComa    := iif( (FieldNum(cFieldName)<=FCount()-1),',','')

   If cTypeField=='L'
      //cCtrlBrw := "{'CHECKBOX','Yes','No'}"+cComa
      cCtrlBrw := "TGridControlLComboBox():New( 'Yes', 'No' )"+cComa
   Elseif cTypeField=='D'
      //cCtrlBrw := "{'DATEPICKER','UPDOWN'}"+cComa
      cCtrlBrw := "TGridControlDatePicker():New( .t., .t. )"+cComa
   Elseif cTypeField=='@' .OR. cTypeField=='T'
      cCtrlBrw := "{'TEXTBOX','DATE',''}"+cComa
      //cCtrlBrw := "{'TIMEPICKER','UPDOWN'}"+cComa
   Elseif cTypeField=='N' .OR. cTypeField=='I' .OR. cTypeField=='W' .OR. cTypeField=='Y' .OR. cTypeField=='B'
      cInpMsk  := iif( nLongDec > 0, REPLICATE( '9', nLongTot - nLongDec -1 ) + '.' + REPLICATE( '9', nLongDec ), REPLICATE( '9', nLongTot - nLongDec ) )
      cCtrlBrw := "{'TEXTBOX','NUMERIC','"+cInpMsk+"'}"+cComa
   Elseif cTypeField=='C'
//      cCtrlBrw := "{'TEXTBOX','CHARACTER','@A'}"+cComa
      cCtrlBrw := "{'TEXTBOX','CHARACTER',}"+cComa
   Elseif cTypeField=='M' .OR. cTypeField=='G' .OR. cTypeField=='P'
      cCtrlBrw := "{}"+cComa
      //cCtrlBrw := "TGridControlMemo():New('Edit Memo Field')"+cComa
   Else
      cCtrlBrw := "{}"+cComa
   Endif

Return( cCtrlBrw )

*------------------------------------------------------------------------------*
Function VerHeadIcon( aTip )
*------------------------------------------------------------------------------*
   Local nv
   aFtype    := aClone( aTip )
   aHeadIcon := {"hdel"}

   For nv := 1 to FCount()
       Do Case
          Case aFType[nv]=='L'
               aadd(aHeadIcon,"hlogic")
          Case aFType[nv]=='D'
               aadd(aHeadIcon,"hfech")
          Case aFType[nv]=='@'
               aadd(aHeadIcon,"hfech")
          Case aFType[nv]=='N'
               aadd(aHeadIcon,"hnum")
          Case aFType[nv]=='B'
               aadd(aHeadIcon,"hnum")
          Case aFType[nv]=='I'
               aadd(aHeadIcon,"hnum")
          Case aFType[nv]=='C'
               aadd(aHeadIcon,"hchar")
          Case aFType[nv]=='M'
               aadd(aHeadIcon,"hmemo")
          Case aFType[nv]=='G'
               aadd(aHeadIcon,"hmemo")
          Case aFType[nv]=='T'
               aadd(aHeadIcon,"hfech")
          Case aFType[nv]=='P'
               aadd(aHeadIcon,"hmemo")
          Case aFType[nv]=='W'
               aadd(aHeadIcon,"hnum")
          Case aFType[nv]=='Y'
               aadd(aHeadIcon,"hnum")
          Otherwise
               aadd(aHeadIcon,"hchar")
       Endcase
   Next

Return( aHeadIcon )

*------------------------------------------------------------------------------*
Function SetHeaderImages()
*------------------------------------------------------------------------------*
   Local nc

   If !Empty( Alias() )

      For nc := 1 to oWndBase.Tab_1.ItemCount
          cAreaPos  := AllTrim( Str(nc) )
          cBrowse_n := "Browse_"+cAreaPos

          If IsControlDefined(&cBrowse_n,oWndBase)
             oWndBase.&(cBrowse_n).Fontname  := cFont
             oWndBase.&(cBrowse_n).Fontsize  := nSize
             oWndBase.&(cBrowse_n).fontcolor := aFntClr
             oWndBase.&(cBrowse_n).Backcolor := aBackClr
          Endif
      Next
   Endif

Return Nil

*------------------------------------------------------------------------------*
Function GetIndexInfo()
*------------------------------------------------------------------------------*
   LOCAL aInd:= {}, ig, cKey

   If !Empty( Alias() )
      FOR ig := 1 to 50
         IF ( cKey := ( Alias() )->( IndexKey( ig ) ) ) == ''
            EXIT
         ENDIF
         Aadd( aInd, "TAG "+( Alias() )->( OrdName( ig ) ) + ' : ' + "KEY " + cKey )
      NEXT
   Endif

RETURN aInd

*------------------------------------------------------------------------------*
Procedure SeleOrder()
*------------------------------------------------------------------------------*
   If !Empty( Alias() )
      ( Alias() )->(OrdSetFocus(0))
   Endif
Return

*------------------------------------------------------------------------------*
Procedure IndexItems()
*------------------------------------------------------------------------------*
   Local ni
   If !Empty( Alias() )
      nTags := ( Alias() )->( OrdCount() )
      for ni = 1 to nTags
         if ! Empty( OrdName( ni ) )
            if ! Empty( OrdName( 1 ) )
               DbSetOrder( OrdName( 1 ) )
               DbGoTop()
            endif
            ITEM OrdName( ni ) ACTION  ( Alias() )->( DbSetOrder( OrdName(ni) ) )
         endif
      next
   Endif
Return

*------------------------------------------------------------------------------*
Procedure CopyRec(nOp)  // Copiar
*------------------------------------------------------------------------------*
   If !Empty( Alias() )

       If nOp = 1   // Selecciona registro
          RecReply()
          MuestraRec()
       Else         // Limpia Selección de registro
          nRecCopy := {}
          nRecSel := 0
          oWndBase.StatusBar.Item(2) := 'Selected Record: '
          Actualizar()
       Endif
   Endif
return

*------------------------------------------------------------------------------*
Function RecToMost()
*------------------------------------------------------------------------------*
   Local nr
   If Empty(nRecCopy)
      nRet := 0
   Else
      For nr := 1 to Len(nRecCopy)
          nRet := nRecCopy[ iif(AScan( nRecCopy[nr], nArea )>0, AScan( nRecCopy[nr], nArea ),1), 2 ]
      Next
   Endif
Return(nRet)

*------------------------------------------------------------------------------*
Function RecReply()
*------------------------------------------------------------------------------*

   aRec := oWndBase.&( Browse_n() ).Value

   If Empty(nRecCopy)
      Aadd( nRecCopy, { ( Alias() )->( Select( oWndBase.Tab_1.caption( oWndBase.Tab_1.value ) ) ), aRec[1] } )
   Endif

Return Nil

*------------------------------------------------------------------------------*
procedure PasteRec() // Pegar
*------------------------------------------------------------------------------*
   local nPos   := 0, i := 1
   local aDatos := {}

   If !Empty( Alias() )
      If Empty(nRecCopy)
         Msginfo('No Selected Record',PROGRAM)
      Else
        If ( Alias() )->( Select() ) = nRecCopy[ 1, 1 ]
           If MsgYesNo("This action will replace the current record"+Hb_OsNewLine()+"with the data of the selected record"+Hb_OsNewLine()+"Are you sure?",PROGRAM)
              nPos := oWndBase.&( Browse_n() ).Value
              ( Alias() )->( DBGoTo( nRecCopy[ 1, 2 ] ) )
              For i = 1 to ( Alias() )->( FCount() )
                  Aadd( aDatos, ( Alias() )->( Fieldget(i) ) )
              Next
              ( Alias() )->( DbGoTo( nPos[1]) )
              ( Alias() )->( flock() )
              For i = 1 to ( Alias() )->( Fcount() )
                  ( Alias() )->( Fieldput( i, adatos[i] ) )
              Next
              ( Alias() )->( DbUnLock() )
              nRecSel  := 0
              nRecCopy := {}
              oWndBase.StatusBar.Item(2) := 'Selected Record: '
           Endif
        Endif
      EndIf
      Actualizar()
   Endif

Return

*------------------------------------------------------------------------------*
Function DBF_Idx()   // Indices de la base de datos
*------------------------------------------------------------------------------*
   Local ix
   lSalida := .t. ; k := 1 ; nVeces := 1
   aIndice       := {}
   aIndiceCampo  := {}

   Do while lSalida
      If ( (Alias() )->( OrdName( k ) ) == "" )
         lSalida := .f.
      Else
         cIndice := ( Alias() )->( OrdName( k ) )
         aAdd( aIndice, cIndice )
         cClave := Upper( (Alias() )->( OrdKey( k ) ) )
         For ix := 1 to FCount()
             If nVeces <= 1
                nInicio := At( FieldName(ix), cClave )
                If  nInicio != 0
                    aAdd( aIndiceCampo, ix )
                    nVeces++
                Endif
             Endif
         Next
      Endif
      k++
      nVeces := 1
   Enddo

   // Numero de indice
   If ( (Alias())->( ordSetFocus() ) == "" )
      nIndiceActivo := 1
   Else
      nIndiceActivo := AScan( aIndice, (Alias())->( OrdSetFocus() ) )
   Endif

   AutoMsgInfo( aIndice, "aIndice" )

Return(aIndiceCampo)