Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Import data from text file
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01242133
Message ID:
01242199
Views:
26
>default checked but user maybe deselect someones if dont want to import
oForm = CREATEOBJECT([Form1])
oForm.Show(1) 

**************************************************
*-- Form:         form1 (d:\works\test.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   07/20/07 01:39:10 AM
*
DEFINE CLASS form1 AS form


    Top = 0
    Left = 2
    Height = 250
    Width = 319
    DoCreate = .T.
    Caption = "Form1"
    Name = "Form1"


    ADD OBJECT grid1 AS grid WITH ;
        ColumnCount = 2, ;
        DeleteMark = .F., ;
        Height = 200, ;
        Left = 7, ;
        Panel = 1, ;
        RecordMark = .F., ;
        ScrollBars = 2, ;
        SplitBar = .F., ;
        Top = 2, ;
        Width = 305, ;
        Name = "Grid1", ;
        Column1.Width = 43, ;
        Column1.Sparse = .F., ;
        Column1.Name = "Column1", ;
        Column2.Width = 233, ;
        Column2.ReadOnly = .T., ;
        Column2.Name = "Column2"



    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 205, ;
        Left = 7, ;
        Height = 17, ;
        Width = 305, ;
        Caption = "Select folder", ;
        Name = "Command1"


    ADD OBJECT command2 AS commandbutton WITH ;
        Top = 224, ;
        Left = 7, ;
        Height = 17, ;
        Width = 305, ;
        Caption = "Import", ;
        Enabled = .F., ;
        Name = "Command2"


    PROCEDURE Load
        SET SAFETY OFF
        SET DELETED ON
        CREATE CURSOR crsReadedFiles(ToImport L, FileName C(254))
    ENDPROC

    PROCEDURE Init
        WITH thisform.Grid1
             .Column1.Header1.Caption = [Import]
             .Column2.Header1.Caption = ["File Name"]
             .Column1.RemoveObject([text1])
             .Column1.NewObject([Check1],[CheckBox])
             .Column1.Check1.Caption = []
             .Column1.Check1.Visible = .t.
        ENDWITH
        
        
        
    PROCEDURE command1.Click
        thisform.LockScreen = .t.
        SELECT crsReadedFiles
        ZAP
        lcDirForImport = GETDIR([],[],[],64)
        IF NOT EMPTY(lcDirForImport)
           lnFiles = ADIR(laFiles,ADDBS(lcDirForImport)+[*.001])
           FOR lnFor = 1 TO lnFiles
               lcFileToImport = ADDBS(lcDirForImport)+laFiles[lnFor,1]
               INSERT INTO crsReadedFiles VALUES (.t., lcFileToImport)
           NEXT 
        ENDIF
        GO TOP
        thisform.Grid1.Refresh()
        thisform.Command2.Enabled = RECCOUNT([crsReadedFiles]) > 0
        thisform.LockScreen = .f.
    ENDPROC


    PROCEDURE command2.Click
        lcCreate = [CREATE CURSOR crsImport (Fld1 C(20)]
        FOR lnFor = 2 TO 19
            lcCreate  = lcCreate + [, Fld]+TRANSFORM(lnFor)+[ C(20)]
        NEXT
        lcCreate  = lcCreate + [)]
        &lcCreate
        SELECT crsReadedFiles
        SCAN
            IF ToImport 
               lcFileToImport = ALLTRIM(FileName)
               SELECT crsImport
               APPEND FROM (lcFileToImport) DELIMITED
               RENAME (lcFileToImport) TO FORCEEXT(lcFileToImport,[TRN])
               SELECT crsReadedFiles
               DELETE
            ENDIF 
        ENDSCAN

        SELECT crsImport
        SCAN
             IF ALLTRIM(Fld1) == [01]
                *** Manage header record
                *** with proper transformation of the types
                *** between C(20) and the real Header table type
            ELSE
                *** Manage detail records
                *** with proper transformation of the types
                *** between C(20) and the real Detail table type
            ENDIF 
        ENDSCAN

        SELECT crsReadedFiles
        GO TOP
        thisform.Grid1.Refresh()
    ENDPROC


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

Click here to load this message in the networking platform