Guidance
指路人
g.yi.org
software / rapidq / Examples / Database / qmysql.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'From: "edamian919" <edamian919@y...> Mon Jul 29, 2002  8:01 pm
'Subject:  A program that cound help someone. qmysql, printer, qstringgrid, qedit,

'qrichedit,
'I want to share with all of you this program. it could help someone
'who needs an example of using this components.
'The label and so on are in spanish because my native lenguage is it.

'PROGRAMA PARA LLEVAR EL CONTROL DE LAS TAREAS

     $INCLUDE "rapidq.inc"
     $INCLUDE "mysql.inc"
     $INCLUDE "win32api.inc"

     DIM fontcourier AS QFONT
     DIM fontcourier1 AS QFONT
     fontcourier.name = "Courier New"
     fontcourier.size = 9
     fontcourier1.name = "Courier New"
     fontcourier1.size = 10


     DECLARE SUB tabchange
     DECLARE SUB doalta
     DECLARE SUB docambio
     DECLARE SUB doborrar
     DECLARE SUB blanquearcampos
     DECLARE SUB cambiavista
     DECLARE SUB imprimirclick
     DECLARE SUB imprecomboboxchange(sender AS QCOMBOBOX)
     DECLARE SUB aceptarimpre
     DECLARE SUB cerrarimpre(Action AS INTEGER)
     DECLARE SUB cerrarimpre1

     SUB DummyProc:END SUB 'Esto sirve para que se minimize el formulario


     DIM db AS QMYSQL
     DIM fuente AS QFONT
     fuente.name = "Arial"
     fuente.size = 11


     CREATE frtareas AS QFORM
      center
      height= 400
      width = 450
      CAPTION = "Control de Tareas"
      delbordericons(2)
      WndProc = DummyProc 'Esto sirve para que se minimize el formulario es lo ultimo que se deba hacer
      CREATE tab AS QTABCONTROL
       addtabs "Listado","Datalle"
       width = frtareas.clientwidth
       height = frtareas.clientheight
       onchange = tabchange
       hottrack = true
       COLOR = &H00FFFF
       tabinactivecolor = clpurple
       CREATE plistado AS QPANEL
        top = 40
        left = 5
        width = tab.clientwidth - 10
        height = tab.clientheight - 50
        CAPTION = "Listado"
        bevelinner = vblowered
        COLOR = &H00FFFF
        CREATE desest AS QLABEL
         top = 1
         left = 2
         CAPTION = "Estado"
         font = fuente
        END CREATE
        CREATE estado AS QCOMBOBOX
         top = 1
         left = 50
         style = 2
         onchange = cambiavista
        END CREATE
        CREATE gridtareas AS QSTRINGGRID
         top = 20
         width = plistado.clientwidth
         height = plistado.clientheight - 20
         fixedrows = 1
         fixedcols = 0
         colcount = 2
         rowcount = 5
         defaultrowheight = 20
         colwidths(0) = 50
         colwidths(1) = 350
         cell(0,0) = "Nro."
         cell(1,0) = "Tarea"
         fixedcolor = clgreen
        END CREATE
       END CREATE
       CREATE pdetalle AS QPANEL
        top = 40
        left= 5
        width = tab.clientwidth -10
        height = tab.clientheight -50
        CAPTION = "Detalle"
        bevelinner = vblowered
        visible = false
        COLOR = &H00FFFF 'AMARILLO
        CREATE lbnro AS QLABEL
         left = 10
         top = 13
         CAPTION = "Nro."
        END CREATE
        CREATE txnro AS QEDIT
         left = 45
         top = 10
         width = 50
         maxlength = 4
         readonly = true
        END CREATE
        CREATE lbfecha AS QLABEL
         left = 110
         top = 13
         CAPTION = "Fecha:"
        END CREATE
        CREATE txfecha AS QEDIT
         left = 150
         top = 10
         width = 70
         inputmask = "00/00/0000"
        END CREATE
        CREATE lbestado AS QLABEL
         left = 230
         top = 13
         CAPTION = "Estado:"
        END CREATE
        CREATE estadodet AS QCOMBOBOX
         left = 270
         top = 10
         style = 2
        END CREATE

        CREATE lbtarea AS QLABEL
         left = 10
         top = 38
         CAPTION = "Tarea:"
        END CREATE
        CREATE txtarea AS QEDIT
         left = 45
         top = 35
         width = 370
        END CREATE
        CREATE richdestareas AS QRICHEDIT
         top = 60
         left = 45
         width = 370
         height = 200
         font = fontcourier
        END CREATE
        CREATE cambio AS QOVALBTN
         top = 265
         left = 5
         CAPTION = "Ca&mbio"
         COLOR = &H00FF00 'VERDE
         visible = true
         onclick = docambio
        END CREATE
        CREATE alta AS QOVALBTN
         top = 265
         left = 110
         CAPTION = "&Alta"
         COLOR = &H00FF00
         onclick = doalta
        END CREATE
        CREATE baja AS QOVALBTN
         top = 265
         left = 220
         CAPTION = "&Baja"
         COLOR = &h00ff00
         onclick = doborrar
        END CREATE
        CREATE cancelar AS QOVALBTN
         top = 265
         left = 330
         CAPTION = "&Cancelar"
         COLOR = &H00FF00
         visible = true
         onclick = blanquearcampos
        END CREATE
        CREATE imprimir AS QOVALBTN
         CAPTION = "&Print"
         top = 200
         left = 1
         width = 40
         COLOR = &H00FF00
         onclick = imprimirclick
        END CREATE

       END CREATE
      END CREATE
      CREATE impresoras1 AS QFORM
       CAPTION = "Impresión de tema"
       borderstyle = bsdialog
       center
       width = 250
       height = 100
       COLOR = &H00FFFF
       onclose = cerrarimpre
       CREATE imprecombobox AS QCOMBOBOX
        left = 1
        top = 1
        width = 243
        onchange = imprecomboboxchange
       END CREATE
       CREATE bcerrarimpre AS QOVALBTN
        CAPTION = "&Cerrar"
        top = 25
        left = 180
        width = 60
        COLOR = &H00FF00
        onclick = cerrarimpre1
       END CREATE
       CREATE baceptarimpre AS QOVALBTN
        CAPTION = "&Print"
        top = 25
        left = 1
        width = 60
        COLOR = &H00FF00
        onclick = aceptarimpre
       END CREATE

      END CREATE
     END CREATE


     FOR i = 0 TO printer.printerscount -1
      imprecombobox.additems(printer.printers(i))
     NEXT
     imprecombobox.itemindex = printer.printerindex

     SUB imprecomboboxchange(sender AS QCOMBOBOX)
      printer.printerindex = sender.itemindex
     END SUB

     SUB cerrarimpre(action AS INTEGER)
      frtareas.repaint
      action = 1
     END SUB

     SUB cerrarimpre1
      impresoras1.CLOSE
     END SUB

     SUB aceptarimpre
      printer.font = fontcourier1
      LPRINT txtarea.text
      tlinea = 1
      FOR i= -1 TO richdestareas.linecount
       LPRINT richdestareas.line(i)
       tlinea = tlinea + 1
       IF tlinea > 65 THEN
        printer.newpage
        LPRINT " "
        tlinea = 1
       END IF
      NEXT i
      LFLUSH
      printer.enddoc
     END SUB


     SUB imprimirclick
      impresoras1.SHOWMODAL
     END SUB

     SUB blanquearcampos
      txnro.text = ""
      txfecha.text = ""
      txtarea.text = ""
      richdestareas.text = ""
      estadodet.text = ""
     END SUB

     SUB doborrar
      tempo_row = gridtareas.row
      IF tempo_row = 0 THEN
       EXIT SUB
      END IF
      IF db.query("delete from tareas where nro = " & txnro.text) = 0 THEN
       SHOWMESSAGE "La transacción no se pudo realizar"
       EXIT SUB
      END IF
      gridtareas.deleterow(tempo_row)
      blanquearcampos
     END SUB

     SUB cargocampos
      IF gridtareas.row > 0 THEN
       db.query("select * from tareas where nro = " & gridtareas.cell(0,gridtareas.row))
       IF db.fetchrow THEN
        db.fieldseek(0)
        txnro.text = db.row(0)
        txtarea.text = db.row(2)
        txfecha.text = MID$(db.row(1),9,2) & "/" & MID$(db.row(1),6,2) & "/" & MID$(db.row(1),1,4)
        richdestareas.text = db.row(3)
        FOR i = 0 TO estadodet.itemcount - 1
         IF MID$(estadodet.item(i),1,2) = db.row(4) THEN
          estadodet.itemindex = i
          EXIT FOR
         END IF
        NEXT
       END IF
      END IF
     END SUB

     SUB docambio
      vfecha$ = MID$(txfecha.text,7,4) & "-" & MID$(txfecha.text,4,2) & "-" _
       & MID$(txfecha.text,1,2)
      IF db.query("update tareas set fecha = '" & vfecha$ & "', tarea = '" & txtarea.text & "', destarea = '" & richdestareas.text & "', nroestado = '" & MID$(estadodet.text,1,2) & "' where nro = " & txnro.text) = 0 THEN
       SHOWMESSAGE "La transacción no se pudo realizar"
       EXIT SUB
      END IF
      gridtareas.cell(1,gridtareas.row) = txtarea.text
     END SUB

     SUB doalta
      db.query("select max(nro) from tareas")
      IF db.fetchrow THEN
       db.fieldseek(0)
       temponro = VAL(db.row(0))
       temponro++
       txnro.text = STR$(temponro)
      ELSE
       txnro.text = 1
      END IF
      vfecha$ = MID$(txfecha.text,7,4) & "-" & MID$(txfecha.text,4,2) & "-" _
       & MID$(txfecha.text,1,2)
      IF db.query("Insert into tareas(nro,fecha,tarea,destarea,nroestado) values('" & txnro.text & "', '" & vfecha$ & "', '" & txtarea.text & "', '" & richdestareas.text & "', '" & MID$(estadodet.text,1,2) & "')") = 0 THEN
       SHOWMESSAGE "No se puede realizar la transacción"
       EXIT SUB
      END IF
      gridtareas.rowcount = gridtareas.rowcount + 1
      fila = gridtareas.rowcount - 1
      gridtareas.cell(0,fila) = txnro.text
      gridtareas.cell(1,fila) = txtarea.text
      blanquearcampos
     END SUB

     SUB tabchange
      SELECT CASE tab.tabindex
      CASE 0
       plistado.visible = true
       pdetalle.visible = false
       blanquearcampos
      CASE 1
       plistado.visible = false
       pdetalle.visible = true
       cargocampos
      END SELECT
     END SUB


     SUB llenargrilla
      db.query("Select * from tareas where nroestado = '" & MID$(estado.text,1,2) & "'" )
      gridtareas.rowcount = db.rowcount + 1
      j = 1
      WHILE db.fetchrow
       db.fieldseek(0)
       gridtareas.cell(0,j) = db.row(0)
       gridtareas.cell(1,j) = db.row(2)
       j++
      WEND
     END SUB

     SUB cambiavista
      llenargrilla
     END SUB





'*****************programa principal

     estado.additems "01-Iniciadas","02-Terminadas","03-Procedimientos"
     estadodet.additems "01-Iniciada","02-Terminada","03-Procedimientos"
     estado.itemindex = 0
     db.connect("192.168.0.1","root","password")
     IF db.connected THEN
      db.selectdb("tubase")
      llenargrilla
      frtareas.SHOWMODAL
     ELSE
      SHOWMESSAGE "No se puede establecer la conexion con la base dedatos"
      END
     END IF
     db.CLOSE
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2023-2-1  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-07-29 22:57:46