Author Topic: SQLitening 的慣常使用方式(程式碼取自QrCodeXtra)  (Read 5206 times)

admin

  • Administrator
  • *****
  • Posts: 0
    • View Profile
SQLitening 的慣常使用方式(程式碼取自QrCodeXtra)
« on: December 08, 2011, 06:58:59 PM »
載入記錄
Code: [Select]
Sub FRMMAIN_LoadQrDataRecord (ByVal tmpAction As Integer)
    Local tmpSQL As String
    Local lngErrNum As Long
   
    Select Case tmpaction
      Case -1
        tmpsql="select * from qrdatarecord where autoid<" & Str$(pudtqrdatarecord.AutoID ) & " order by autoid desc limit 1"
       
      Case -2
        tmpsql="select * from qrdatarecord order by autoid asc limit 1"
     
      Case 1
         tmpsql="select * from qrdatarecord where autoid>" & Str$(pudtqrdatarecord.AutoID) & " order by autoid asc limit 1"
                 
      Case 2
         tmpsql="select * from qrdatarecord order by autoid desc limit 1"
                 
      Case Else
         tmpsql="select * from qrdatarecord where autoid=" & Str$(glngSelectedAutoID)
     
    End Select
   
    slSel tmpsql
   
    lngErrNum = slGetErrorNumber
    If lngErrNum <> 0 Then
        MsgBox "Error Number is: " & Str$(lngErrNum), 0, "Error"
    Else
       If slGetRow Then
          pudtQrDataRecord.AutoID = Val( slFN("autoid"))
          pudtqrdatarecord.DataType =Val(slFN("datatype"))
          pudtqrdatarecord.OutputType =Val(slFN("outputtype"))
          pudtqrdatarecord.Contents = Trim$(Utf8ToChr$(slFN("contents")))
          pudtqrdatarecord.LastUpdate = Val(slFN("lastupdate"))
       
       Else
          If tmpaction=0 Then
            pudtQrDataRecord.AutoID =  -1
            pudtqrdatarecord.DataType =  0
            pudtqrdatarecord.OutputType =0
            pudtqrdatarecord.Contents =""
            pudtqrdatarecord.LastUpdate = 0
         
          End If
       End If
   
    End If
 
    slCloseSet

End Sub

儲存新增記錄
Code: [Select]
Sub FRMMAIN_SaveNewRecord
  On Error GoTo errhandler
  Local tmpSQL As String
  Local tmpNow As IPowerTime 
  Local tmpLastUpdate As Double
 
  tmpNow = Class "PowerTime"
  tmpnow.now
  tmplastupdate=PwttoDbl(tmpnow)
   
  ' Begin transaction
  slExe "Begin"

  tmpsql="insert into qrdatarecord(datatype,outputtype,contents,lastupdate) values ("
  tmpsql=tmpsql & Str$(pudtqrdatarecord.DataType)
  tmpsql=tmpsql & "," & Str$(pudtqrdatarecord.OutputType)
  tmpsql=tmpsql & ",'" & ChrToUtf8$(Trim$(pudtqrdatarecord.contents))
  tmpsql=tmpsql & "'," &  Str$(tmplastupdate) & ")"

  slExe tmpsql
 
  pudtqrdatarecord.LastUpdate =tmplastupdate   
  pudtqrdatarecord.AutoID =slgetinsertid
  FF_Control_SetText( HWND_FRMMAIN_LBLAUTOID, Str$(pudtqrdatarecord.AutoID) )
 
  ' End transaction
  slExe "End"
 
  pintformmode=0

  Exit Sub
 

ErrHandler:



End Sub

儲存修改記錄
Code: [Select]
Sub FRMMAIN_SaveEditRecord
  On Error GoTo errhandler
  Local tmpSQL As String
  Local tmpNow As IPowerTime 
  Local tmpLastUpdate As Double
   
  tmpNow = Class "PowerTime"
  tmpnow.now
  tmplastupdate=PwttoDbl(tmpnow)
   
  ' Begin transaction
  slExe "Begin"
               
  tmpsql="update qrdatarecord set datatype=" & Str$(pudtqrdatarecord.DataType)
  tmpsql=tmpsql & ",outputtype=" & Str$(pudtqrdatarecord.OutputType)
  tmpsql=tmpsql & ",contents='" & ChrToUtf8$(Trim$(pudtqrdatarecord.contents))
  tmpsql=tmpsql & "',lastupdate=" & Str$(tmplastupdate)
  tmpsql=tmpsql & " where autoid=" & Str$(pudtqrdatarecord.autoid)
   
  slExe tmpsql
 
  pudtqrdatarecord.LastUpdate =tmplastupdate 
   
  ' End transaction
  slExe "End"

  pintformmode=0
 
  Exit Sub 

ErrHandler:


End Sub

刪除記錄
Code: [Select]
Sub FRMBROWSEDATA_DeleteRecord (tmpAutoID As Long)
    Local tmpSQL As String
    Local lngErrNum As Long
   
    If tmpautoid >-1 Then
      ' Begin transaction
      slExe "Begin"
   
      tmpsql="delete from qrdatarecord where autoid=" &  Str$(tmpAutoID)
   
      slExe tmpsql
       
      lngErrNum = slGetErrorNumber
      If lngErrNum <> 0 Then
        MsgBox "Error Number is: " & Str$(lngErrNum), 0, "Error"
       
        slExe "Rollback"
       
      Else
        ' End transaction
        slExe "End"
   
      End If
   
    End If

End Sub