• Welcome, Guest. Please login.
 
December 13, 2019, 07:39:13 pm

News:

Welcome to the SQLitening support forums!


Saving Images Remotely

Started by Fredrick Ughimi, August 12, 2017, 12:07:14 pm

Previous topic - Next topic

Fredrick Ughimi

Hello CJ,

Quote
What is the value of sFileName?


sFileName = "ImageName.jpg"

Using the much improved slPutFileLocal I got access denied.


#COMPILE EXE
#DIM ALL
#INCLUDE "DDOC_P32.INC"
#INCLUDE "SQLitening.INC"

%vbBlack = &H0&
'%vbRed = &HFF&
'%vbGreen = &HFF00&
'%vbYellow = &HFFFF&
'%vbBlue = &HFF0000
'%vbMagenta = &HFF00FF
'%vbCyan = &HFFFF00
'%vbWhite = &HFFFFFF
'%vbGrey = &HC0C0C0
'%LIGHT_SHADE = &HE0E0E0

%AddClients=20
%TestMode = 0  'messagebox each time switch between local and server mode
%ClientServerFlag = 9999
THREADED ClientServer,CurrentMode AS LONG 'need to know when switching local/remote at all times

FUNCTION PBDate(sDate AS STRING) AS STRING
     'MM-dd-yyyy to dd-MM-yyyy

     FUNCTION = MID$(sDate,4,2) & "-" & MID$(sDate,1,2) & "-" & MID$(sDate,7,4)

END FUNCTION

FUNCTION NigeriaDate(sDate AS STRING) AS STRING
     'yyyy-MM-dd  to dd-MM-yyyy
     FUNCTION = MID$(sDate,9,2) & "-" & MID$(sDate,6,2) & "-" & MID$(sDate,1,4)

END FUNCTION

FUNCTION SQLiteDate(sDate AS STRING) AS STRING
     'From dd-MM-yyyy To yyyy-MM-dd

     FUNCTION = MID$(sDate,7,4) & "-" & MID$(sDate,4,2) & "-" & MID$(sDate,1,2)

END FUNCTION


FUNCTION PBMAIN () AS LONG
    LOCAL sServer, sPort, sErr AS STRING

    sServer = "Server"

    sPort = "Default"

    slConnect(sServer, VAL(sPort))

    sErr = slGetError
    IF VAL(sErr) <> 0 THEN
         MSGBOX sErr, %MB_TASKMODAL OR %MB_ICONINFORMATION, EXE.PATH$
         EXIT FUNCTION
    END IF

    slOpen ("CharkinPRNTDB.db3","C")

   'OpitoRegistration
   slExe BUILD$("Create Table If Not Exists tblOpitoRegistration(Date TEXT, BatchNo TEXT, IDMeans TEXT, IDNo TEXT, FirstName TEXT, Surname TEXT, Othernames TEXT, CourseStartDate TEXT,", _
   "CourseEndDate TEXT, ExpiryDate TEXT, CourseCode TEXT, EmailAddress TEXT, CertificateNo TEXT, CorrAddress TEXT, BirthDate TEXT, BirthPlace TEXT, Sponsor TEXT, Department TEXT,", _
   "EmployeeIDNo TEXT, Nationality TEXT, Occupation TEXT, PhoneNo TEXT, KinName TEXT, KinPhoneNo TEXT, PixName TEXT, Picture BLOB)")

   slExe "Create UNIQUE Index If Not Exists OpitoRegistrationndx1 ON tblOpitoRegistration(CertificateNo)"

   slExe "Create Index If Not Exists OpitoRegistrationndx2 ON tblOpitoRegistration(CourseCode, BatchNo)"

   ReportCertificate()


END FUNCTION

FUNCTION slPutFileLocal(sTempFile AS STRING,sBlob AS STRING) THREADSAFE AS LONG

LOCAL ModeBeforeHere,result AS LONG
ModeBeforeHere = CurrentMode
IF ModeBeforeHere <> 0 THEN SwitchLocal 'we must be local mode
FUNCTION = slPutFile(sTempFile,sBlob,"CT E0")
IF slGetErrorNumber THEN ? slGetError,,FUNCNAME$

IF ModeBeforeHere = %ClientServerFlag THEN SwitchRemote 'switch back to remote

END FUNCTION

'-------------------------------------------------------------------------------------------------
SUB SwitchLocal THREADSAFE

IF CurrentMode = 0 THEN EXIT SUB 'aleady in local mode
IF %TestMode THEN ? FUNCNAME$
slPushDatabase
slSetProcessMods "L0"
currentMode = 0

END SUB
'-------------------------------------------------------------------------------------------------
SUB SwitchRemote THREADSAFE

IF CurrentMode = %ClientServerFlag THEN EXIT SUB 'already in remote mode
IF %TestMode THEN ? FUNCNAME$
slPopDatabase
slSetProcessMods "L1"
CurrentMode = %ClientServerFlag

END SUB

FUNCTION ReportCertificate() AS LONG
      LOCAL LineSpacing!,iHandle&,Row!,TopMargin!,PageSize!,PageNumber&
      LOCAL detailline AS ASCIIZ * 200
      LOCAL sBatchNo AS STRING
      LOCAL hpix AS LONG
      LOCAL sData AS STRING
      'Dim zTemp As Asciiz * 300
      DIM iPrinted%
      DIM zText AS ASCIIZ * 2000
      DIM lh!
      LOCAL sFileName AS STRING
      LOCAL eCode AS LONG


      lh! = .17
      LineSpacing = .2
      TopMargin   = 0
      PAGESIZE    = 10

      ihandle = dpStartDoc(0,"Mega-Net CharkinPRNT - Print A50 Tropical Bosiet Travel Safely By Boat Certificate","",%DDOC_INCH, _
      %DDOC_PAPER_CUSTOM, %DDOC_PORTRAIT, %DDOC_SYSTEM_DEFAULT, %DDOC_BIN_AUTO OR %DDOC_ALLOWSMTP OR %DDOC_ALLOWSAVE OR %DDOC_ZOOMFIT)
      IF ihandle < 1 THEN
           MSGBOX "Could not StartDoc. Error number" + STR$(Ihandle),,FUNCNAME$
           EXIT FUNCTION
      END IF

      dpPaperSize iHandle, 8.2,11.7

      ROW = PAGESIZE                            'force new heading

      sBatchNo = "23"

     slSEL "SELECT * FROM tblOpitoRegistration WHERE BatchNo = '" + sBatchNo + "'"

     DO WHILE slGetRow()

        sData = slFN("Picture")
        eCode = slPutFileLocal(sFileName, sData)

        IF eCode THEN ? "PutLocalFile error" + STR$(eCode),%MB_SYSTEMMODAL,"PutLocalFile":EXIT FUNCTION

        IF ROW => PAGESIZE THEN
           IF PageNumber THEN      'If first page don't need a new page
              dpNewPage iHandle, %DDOC_PAPER_CUSTOM, %DDOC_PORTRAIT, %DDOC_BIN_AUTO
           END IF
           INCR PageNumber
           'dpText IHandle, 4.3,1.6, %DDOC_LEFT, "" + slFN("CertificateNo")
           dpFont ihandle, %DDOC_FONTNORMAL + %DDOC_FONTBOLD, 20, %vbBlack, "Arial"
           dpText IHandle, 2.0, 4.3, %DDOC_LEFT, "" + slFN("FirstName") & " " & slFN("Surname")  & " " &  slFN("Othernames")
           dpFont ihandle, %DDOC_FONTNORMAL + %DDOC_FONTBOLD, 12, %vbBlack, "Arial"
           dpText IHandle, 1.0, 8.9, %DDOC_LEFT, "" + NigeriaDate(slFN("CertificateNo"))
           dpText IHandle, 4.0,8.9, %DDOC_LEFT, "" + NigeriaDate(slFN("CourseStartDate"))
           dpText IHandle, 6.5,8.9, %DDOC_LEFT, "" + NigeriaDate(slFN("ExpiryDate"))

           hpix = dpAddGraphic(ihandle, sFileName+$NUL)

           ''Kill sFileName
           IF hpix THEN
              dpDrawGraphic ihandle, hpix,7.0,4.0,7.9,5.1
           ELSE
            ? "image not found",%MB_SYSTEMMODAL, EXE.NAME$
           END IF
           ROW =  ROW + LineSpacing * 2
        END IF

      zText = "The course covers modules on Helicopter Underwater "
      zText = zText + "Escape Training (HUET), Sea Survival, Fire Fighting & Self  "
      zText = zText + "Rescue, First Aid  & Hypothermia and Boat Transfers."

      iPrinted% = dpWrapText(IHandle, 1, 1, 3, 3, lh!, zText)

        ROW = ROW + LineSpacing                    'increment line counter
      LOOP

   dpEndDoc iHandle, %DDOC_END_VIEW + %DDOC_END_PRINT

  END FUNCTION


Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

PutFileLocal replaced slPutFileLocal which was removed from this BBS.
PutFileLocal eliminates the need to switch modes.

Fredrick Ughimi

Hello CJ,

Thanks alot! It works now. I used PutFileLocal and I noticed it was fast. I wonder why it not work earlier on. Greatful!
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

Yes it is fast.
Cache reading back "temp.jpg" into ddoc and no loading/unloading DLL's switching modes.


Note:
I didn't check for the possibility of an error using PutLocalFile

'get picture
slsel "select picture from picturetable where picturekey = 'heidi'"
IF slGetErrorNumber = 0 AND slGetRow THEN
   sdata = slfn("picture")
   result = PutLocalFile($tempfile,sdata)
   IF result THEN
     ? USING$("PutLocalFile error #",result),%MB_ICONERROR,FUNCNAME$
   ELSE
    ShellExecute (0, "OPEN", $tempfile+$NUL, BYVAL 0, CURDIR$, %SW_SHOWNORMAL)
   END IF
END IF