Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Starting with cursorAdapter
Message
 
To
12/05/2005 07:17:05
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01013277
Message ID:
01013311
Views:
13
OK, I'll try to explain (my English is not capable to do that full).
Besides of that I hate View Designer :o))) CAs are more flexible then RVs, In Init event you can pass as many parameters as you want and then you can construct your SelectCmd (and not only) in different ways. With one CA class you can Select very different Fileds and Record Sets. Let me show, this is my real class I use in my application to receive a Data from a two different SQL server DBs and prepare my Cursor with the SAME fields I need so I didn't need to change anything in my programs/forms etc.
DEFINE CLASS MyInOut AS CursorAdapter
is_timechange = 0

PROCEDURE Init(what_sys, d_src, timechange)
local llReturn
do case
    case not pemstatus(This, '__VFPSetup', 5)
        This.AddProperty('__VFPSetup', 0)
    case This.__VFPSetup = 2
        This.__VFPSetup = 0
        return
ENDCASE
this.is_timechange = IIF(TYPE("timechange") # "N", 0, timechange)
this.Alias         = "MyInOut"
llReturn           = dodefault()
*** Select connection code: DO NOT REMOVE
set multilocks on
***<DataSource>
this.DataSourceType = "ODBC"
This.DataSource     = d_src  && sqlstringconnect(conn_str)
*this.Tag            = conn_str
***</DataSource>
*** End of Select connection code: DO NOT REMOVE
*** Setup code: DO NOT REMOVE
***<SelectCmd>
DO CASE
   CASE what_sys == 1 && Old DataBase of Masters
        this.Tables    = "InOut, Zavod, Common"
        this.WhereType = 1
        This.SelectCmd = "SELECT Inout.CardID, InOut.OutNom, Inout.DateTime, Inout.Door, Inout.username,Inout.changed, InOut.KeyNum, InOut.Zavod,"+;
                                "Common.Name, Common.Description,Zavod.Ime AS ZavName, OrigRec, SPACE(20) AS ShowDate,"+;
                                "CASE InOut.Changed WHEN 9999 THEN 1 ELSE 0 END AS IzvKomp "+;
                                "FROM InOut "+;
                                "INNER JOIN Zavod  ON InOut.Zavod = Zavod.Kod "+;
                                "INNER JOIN Common ON  Inout.Door = Common.Number AND  Common.CatId = 110 "
        DO CASE
           CASE this.is_timechange == 1
                This.SelectCmd = This.SelectCmd + "WHERE Inout.DateTime BETWEEN ?fromData AND ?toData AND "+;
                                                  "(Inout.changed <  3 OR  Inout.changed IS NULL OR InOut.Changed = 9999)        AND "+;
                                                  "UPPER(LEFT(Common.Description,2))='IN' "+;
                                                  "ORDER BY Inout.DateTime"
           CASE this.is_timechange == 2
                This.SelectCmd = This.SelectCmd + "WHERE Inout.DateTime BETWEEN ?fromData AND ?toData AND "+;
                                                  "(Inout.changed <  3 OR  Inout.changed IS NULL OR InOut.Changed = 9999)        AND "+;
                                                  "UPPER(LEFT(Common.Description,3))='OUT' "+;
                                                  "ORDER BY Inout.DateTime"
           CASE this.is_timechange == 3
                This.SelectCmd = This.SelectCmd + "WHERE Inout.DateTime BETWEEN ?fromData AND ?toData                            AND "  +;
                                                  "(Inout.changed <  3 OR  Inout.changed IS NULL OR InOut.Changed = 9999)        AND "  +;
                                                  "(UPPER(LEFT(Common.Description,2))='IN' OR UPPER(LEFT(Common.Description,3))='OUT') "+;
                                                  "ORDER BY Inout.DateTime"

        OTHERWISE
                This.SelectCmd = This.SelectCmd + "WHERE Inout.OutNom = ?fromId AND Inout.DateTime BETWEEN ?fromData AND ?toData AND "  +;
                                                  "(Inout.changed <  3 OR  Inout.changed IS NULL OR InOut.Changed = 9999)        AND "  +;
                                                  "(UPPER(LEFT(Common.Description,2))='IN' OR UPPER(LEFT(Common.Description,3))='OUT') "+;
                                                  "ORDER BY Inout.DateTime"
        ENDCASE
*        STRTOFILE(this.SelectCmd, "Test.Txt")
        This.KeyFieldList   = "KEYNUM"
        This.UpdateNameList = "KEYNUM InOut.KeyNum, CARDID InOut.CARDID, OUTNOM InOut.OUTNOM, DATETIME InOut.DATETIME, DOOR InOut.DOOR, USERNAME InOut.USERNAME, CHANGED InOut.CHANGED, ZAVOD InOut.ZAVOD, ORIGREC InOut.ORIGREC"
        This.UpdatableFieldList = "KeyNum, CARDID, OUTNOM, DATETIME, DOOR, USERNAME, CHANGED, ZAVOD, ORIGREC"
        this.CursorSchema ="CARDID I, OUTNOM I, DATETIME T, DOOR I, USERNAME C(21), CHANGED I, KEYNUM I, ZAVOD I, NAME C(50), DESCRIPTION C(50), ZAVNAME C(30), ORIGREC I, SHOWDATE C(20), IZVKOMP I"

   CASE what_sys == 2 && New DataBase of  Masters
        SQLEXEC(d_src,"SELECT Id FROM Zone WHERE Is_External = 'Y'","cZone")
        this.AddProperty("ExternalZone",cZone.Id)
        USE IN cZone
        this.Tables    = "In_Out, Cards"
        this.WhereType = 1
        TEXT TO This.SelectCmd NOSHOW TEXTMERGE
                SELECT In_Out.Card_ID       AS CardId,
                       Cards.Label_Number   AS OutNom,
                       In_Out.DTime         AS DateTime,
                       In_Out.TZone,
                       In_Out.SZone,
                       In_Out.History_Id,
                       In_Out.Miscellanious AS Door,
                       ' '                  AS Name,
                       '<<m.frmName>>'      AS ZavName,
                       SPACE(20)            AS ShowDate,
                       CASE WHEN In_Out.SZone = <<this.ExternalZone>> THEN 'In '
                            WHEN In_Out.TZone = <<this.ExternalZone>> THEN 'Out'
                            ELSE '1In' END  AS Description
                FROM In_Out
                LEFT JOIN Cards  ON In_Out.Card_Id = Cards.Id
        ENDTEXT
        DO CASE
           CASE this.is_timechange == 1
        OTHERWISE
                TEXT TO This.SelectCmd NOSHOW TEXTMERGE ADDITIVE
                        WHERE (In_Out.TZone = <<this.ExternalZone>>        OR
                               In_Out.SZone = <<this.ExternalZone>>)       AND
                               In_Out.TZone <> In_Out.SZone                AND
                               In_Out.DTime BETWEEN ?fromData AND ?toData  AND
                               Cards.Label_Number = ?fromId
                        ORDER BY In_Out.DTime
                ENDTEXT
        
        ENDCASE
        This.KeyFieldList       = ""
        This.UpdateNameList     = ""
        This.UpdatableFieldList = ""
ENDCASE

*** End of Setup code: DO NOT REMOVE
if This.__VFPSetup = 1
    This.__VFPSetup = 2
endif
return llReturn
ENDPROC

PROCEDURE AutoOpen
*** Setup code: DO NOT REMOVE
if not pemstatus(This, '__VFPSetup', 5)
    This.AddProperty('__VFPSetup', 1)
    This.Init()
endif
*** End of Setup code: DO NOT REMOVE
ENDPROC

PROCEDURE AfterCursorFill(lUseCursorSchema, lnoDataOnLoad, cSelectCmd, lResult)
    IF this.is_timechange == 0
       SET SECONDS OFF
       REPLACE ALL ShowDate WITH LEFT(TTOC(DateTime),10)+"    "+RIGHT(TTOC(DateTime),5)
    ENDIF
ENDPROC

PROCEDURE AfterCursorRefresh(lUseCursorSchema, lnoDataOnLoad, cSelectCmd, lResult)
    IF this.is_timechange == 0
       SET SECONDS OFF
       REPLACE ALL ShowDate WITH LEFT(TTOC(DateTime),10)+"    "+RIGHT(TTOC(DateTime),5)
    ENDIF
ENDPROC

ENDDEFINE
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform