home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / sfi / vbxctdem / mainform.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-03-17  |  18.9 KB  |  619 lines

  1. VERSION 2.00
  2. Begin Form Mainform 
  3.    BackColor       =   &H00FFFFC0&
  4.    Caption         =   "Test SQL-Sombrero VBX - Author Application"
  5.    ClientHeight    =   4725
  6.    ClientLeft      =   1065
  7.    ClientTop       =   1470
  8.    ClientWidth     =   7680
  9.    Height          =   5130
  10.    Left            =   1005
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4725
  13.    ScaleWidth      =   7680
  14.    Top             =   1125
  15.    Width           =   7800
  16.    Begin DEMVBXCT SQLCTLIB1 
  17.       Left            =   240
  18.       Top             =   3900
  19.    End
  20.    Begin ComboBox author_list 
  21.       FontBold        =   -1  'True
  22.       FontItalic      =   0   'False
  23.       FontName        =   "Fixedsys"
  24.       FontSize        =   9
  25.       FontStrikethru  =   0   'False
  26.       FontUnderline   =   0   'False
  27.       Height          =   330
  28.       Left            =   240
  29.       Style           =   2  'Dropdown List
  30.       TabIndex        =   25
  31.       Top             =   120
  32.       Width           =   7095
  33.    End
  34.    Begin CommandButton delbut 
  35.       Caption         =   "Delete Author"
  36.       Height          =   615
  37.       Left            =   6000
  38.       TabIndex        =   24
  39.       Top             =   2040
  40.       Visible         =   0   'False
  41.       Width           =   1335
  42.    End
  43.    Begin CommandButton cancelbut 
  44.       Caption         =   "Cancel"
  45.       Height          =   495
  46.       Left            =   6240
  47.       TabIndex        =   23
  48.       Top             =   3840
  49.       Visible         =   0   'False
  50.       Width           =   855
  51.    End
  52.    Begin CommandButton newrec 
  53.       Caption         =   "Add New"
  54.       Height          =   615
  55.       Left            =   6000
  56.       TabIndex        =   22
  57.       Top             =   1320
  58.       Visible         =   0   'False
  59.       Width           =   1335
  60.    End
  61.    Begin CommandButton updbut 
  62.       Caption         =   "Update Info"
  63.       Height          =   615
  64.       Left            =   6000
  65.       TabIndex        =   21
  66.       Top             =   3120
  67.       Visible         =   0   'False
  68.       Width           =   1335
  69.    End
  70.    Begin CommandButton chgbut 
  71.       Caption         =   "Change Info"
  72.       Height          =   615
  73.       Left            =   6000
  74.       TabIndex        =   20
  75.       Top             =   600
  76.       Visible         =   0   'False
  77.       Width           =   1335
  78.    End
  79.    Begin TextBox Text1 
  80.       Enabled         =   0   'False
  81.       Height          =   285
  82.       Index           =   8
  83.       Left            =   1560
  84.       MaxLength       =   10
  85.       TabIndex        =   19
  86.       Top             =   3480
  87.       Visible         =   0   'False
  88.       Width           =   3855
  89.    End
  90.    Begin TextBox Text1 
  91.       Enabled         =   0   'False
  92.       Height          =   285
  93.       Index           =   7
  94.       Left            =   1560
  95.       MaxLength       =   12
  96.       TabIndex        =   18
  97.       Top             =   3120
  98.       Visible         =   0   'False
  99.       Width           =   3855
  100.    End
  101.    Begin TextBox Text1 
  102.       Enabled         =   0   'False
  103.       Height          =   285
  104.       Index           =   6
  105.       Left            =   1560
  106.       MaxLength       =   2
  107.       TabIndex        =   17
  108.       Top             =   2760
  109.       Visible         =   0   'False
  110.       Width           =   3855
  111.    End
  112.    Begin TextBox Text1 
  113.       Enabled         =   0   'False
  114.       Height          =   285
  115.       Index           =   5
  116.       Left            =   1560
  117.       MaxLength       =   20
  118.       TabIndex        =   16
  119.       Top             =   2400
  120.       Visible         =   0   'False
  121.       Width           =   3855
  122.    End
  123.    Begin TextBox Text1 
  124.       Enabled         =   0   'False
  125.       Height          =   285
  126.       Index           =   4
  127.       Left            =   1560
  128.       MaxLength       =   40
  129.       TabIndex        =   15
  130.       Top             =   2040
  131.       Visible         =   0   'False
  132.       Width           =   3855
  133.    End
  134.    Begin TextBox Text1 
  135.       Enabled         =   0   'False
  136.       Height          =   285
  137.       Index           =   3
  138.       Left            =   1560
  139.       MaxLength       =   12
  140.       TabIndex        =   14
  141.       Top             =   1680
  142.       Visible         =   0   'False
  143.       Width           =   3855
  144.    End
  145.    Begin TextBox Text1 
  146.       Enabled         =   0   'False
  147.       Height          =   285
  148.       Index           =   2
  149.       Left            =   1560
  150.       MaxLength       =   20
  151.       TabIndex        =   13
  152.       Top             =   1320
  153.       Visible         =   0   'False
  154.       Width           =   3855
  155.    End
  156.    Begin TextBox Text1 
  157.       Enabled         =   0   'False
  158.       Height          =   285
  159.       Index           =   1
  160.       Left            =   1560
  161.       MaxLength       =   40
  162.       TabIndex        =   12
  163.       Top             =   960
  164.       Visible         =   0   'False
  165.       Width           =   3855
  166.    End
  167.    Begin TextBox Text1 
  168.       Enabled         =   0   'False
  169.       Height          =   285
  170.       Index           =   0
  171.       Left            =   1560
  172.       MaxLength       =   11
  173.       TabIndex        =   11
  174.       Top             =   600
  175.       Visible         =   0   'False
  176.       Width           =   3855
  177.    End
  178.    Begin CommandButton exitbut 
  179.       Caption         =   "Exit"
  180.       Height          =   375
  181.       Left            =   4200
  182.       TabIndex        =   1
  183.       Top             =   3960
  184.       Width           =   1095
  185.    End
  186.    Begin CommandButton multibut 
  187.       Caption         =   "Logon"
  188.       Height          =   375
  189.       Left            =   1320
  190.       TabIndex        =   0
  191.       Top             =   3960
  192.       Width           =   1095
  193.    End
  194.    Begin Shape Shape2 
  195.       BorderWidth     =   3
  196.       Height          =   2295
  197.       Left            =   5880
  198.       Top             =   480
  199.       Visible         =   0   'False
  200.       Width           =   1575
  201.    End
  202.    Begin Shape Shape1 
  203.       BorderWidth     =   3
  204.       Height          =   1455
  205.       Left            =   5880
  206.       Top             =   3000
  207.       Visible         =   0   'False
  208.       Width           =   1575
  209.    End
  210.    Begin Label Label1 
  211.       Alignment       =   1  'Right Justify
  212.       BackColor       =   &H00FFFFC0&
  213.       Caption         =   "Postal Code :"
  214.       Height          =   255
  215.       Index           =   8
  216.       Left            =   120
  217.       TabIndex        =   10
  218.       Top             =   3480
  219.       Visible         =   0   'False
  220.       Width           =   1215
  221.    End
  222.    Begin Label Label1 
  223.       Alignment       =   1  'Right Justify
  224.       BackColor       =   &H00FFFFC0&
  225.       Caption         =   "Country :"
  226.       Height          =   255
  227.       Index           =   7
  228.       Left            =   120
  229.       TabIndex        =   9
  230.       Top             =   3120
  231.       Visible         =   0   'False
  232.       Width           =   1215
  233.    End
  234.    Begin Label Label1 
  235.       Alignment       =   1  'Right Justify
  236.       BackColor       =   &H00FFFFC0&
  237.       Caption         =   "State :"
  238.       Height          =   255
  239.       Index           =   6
  240.       Left            =   120
  241.       TabIndex        =   8
  242.       Top             =   2760
  243.       Visible         =   0   'False
  244.       Width           =   1215
  245.    End
  246.    Begin Label Label1 
  247.       Alignment       =   1  'Right Justify
  248.       BackColor       =   &H00FFFFC0&
  249.       Caption         =   "City :"
  250.       Height          =   255
  251.       Index           =   5
  252.       Left            =   120
  253.       TabIndex        =   7
  254.       Top             =   2400
  255.       Visible         =   0   'False
  256.       Width           =   1215
  257.    End
  258.    Begin Label Label1 
  259.       Alignment       =   1  'Right Justify
  260.       BackColor       =   &H00FFFFC0&
  261.       Caption         =   "Address :"
  262.       Height          =   255
  263.       Index           =   4
  264.       Left            =   120
  265.       TabIndex        =   6
  266.       Top             =   2040
  267.       Visible         =   0   'False
  268.       Width           =   1215
  269.    End
  270.    Begin Label Label1 
  271.       Alignment       =   1  'Right Justify
  272.       BackColor       =   &H00FFFFC0&
  273.       Caption         =   "Phone # :"
  274.       Height          =   255
  275.       Index           =   3
  276.       Left            =   120
  277.       TabIndex        =   5
  278.       Top             =   1680
  279.       Visible         =   0   'False
  280.       Width           =   1215
  281.    End
  282.    Begin Label Label1 
  283.       Alignment       =   1  'Right Justify
  284.       BackColor       =   &H00FFFFC0&
  285.       Caption         =   "First Name :"
  286.       Height          =   255
  287.       Index           =   2
  288.       Left            =   120
  289.       TabIndex        =   4
  290.       Top             =   1320
  291.       Visible         =   0   'False
  292.       Width           =   1215
  293.    End
  294.    Begin Label Label1 
  295.       Alignment       =   1  'Right Justify
  296.       BackColor       =   &H00FFFFC0&
  297.       Caption         =   "Last Name :"
  298.       Height          =   255
  299.       Index           =   1
  300.       Left            =   120
  301.       TabIndex        =   3
  302.       Top             =   960
  303.       Visible         =   0   'False
  304.       Width           =   1215
  305.    End
  306.    Begin Label Label1 
  307.       Alignment       =   1  'Right Justify
  308.       BackColor       =   &H00FFFFC0&
  309.       Caption         =   "Author Id :"
  310.       Height          =   255
  311.       Index           =   0
  312.       Left            =   120
  313.       TabIndex        =   2
  314.       Top             =   600
  315.       Visible         =   0   'False
  316.       Width           =   1215
  317.    End
  318. Dim t(1 To 3) As String
  319. Sub author_list_Click ()
  320.     show_author
  321.     chgbut.Visible = True
  322.     delbut.Visible = True
  323. End Sub
  324. Sub cancelbut_Click ()
  325.     author_list.Enabled = True
  326.     If author_list.ListIndex <> -1 Then
  327.     chgbut.Visible = True
  328.     delbut.Visible = True
  329.     End If
  330.     updbut.Visible = False
  331.     newrec.Visible = True
  332.     cancelbut.Visible = False
  333.     For i = 0 To 8
  334.     text1(i).Enabled = False
  335.     Next
  336.     show_author
  337. End Sub
  338. Sub chgbut_Click ()
  339.     For i = 1 To 8
  340.        text1(i).Enabled = True
  341.     Next
  342.     author_list.Enabled = False
  343.     chgbut.Visible = False
  344.     updbut.Visible = True
  345.     newrec.Visible = False
  346.     delbut.Visible = False
  347.     cancelbut.Visible = True
  348.     updflag = 1
  349.     text1(1).SetFocus
  350. End Sub
  351.     Sub delbut_Click ()
  352.     updflag = 3
  353.     updbut.Visible = True
  354.     chgbut.Visible = False
  355.     newrec.Visible = False
  356.     cancelbut.Visible = True
  357.     delbut.Visible = False
  358.     author_list.Enabled = False
  359. End Sub
  360. Sub exitbut_Click ()
  361.     If ctx_pointer <> 0 Then
  362.     ret = VBCT_close(con_pointer, CS_FORCE_CLOSE)
  363.     ret = VBCT_con_drop(con_pointer)
  364.     ret = VBCT_exit(ctx_pointer, CS_FORCE_EXIT)
  365.     ret = VBCS_ctx_drop(ctx_pointer)
  366.     End If
  367.     End
  368. End Sub
  369. Sub Form_Load ()
  370.     updflag = 0
  371.     ctx_pointer = 0
  372.     cd$ = CompileDate()
  373.     MsgBox "Compile Date - " & cd$
  374. End Sub
  375. Sub multibut_Click ()
  376.     Dim ncols As Long
  377.     Dim restype As Long
  378.     Dim rows_read As Long
  379.     logon.Show 1
  380.     If multibut.Visible = True Then
  381.     Exit Sub
  382.     End If
  383.     newrec.Visible = True
  384.      ret = VBCT_command_str(cmd_pointer, CS_LANG_CMD, "select 'Author Id' = au_id , 'Last Name' = au_lname , 'First Name' = au_fname  from authors", CS_UNUSED)
  385.      ret = VBCT_send(cmd_pointer)
  386.      
  387.      result_ret = VBCT_results(cmd_pointer, restype)
  388.      res$ = ""
  389.      While result_ret = CS_SUCCEED
  390.     Select Case restype
  391.         
  392.      Case CS_ROW_RESULT
  393. '   There are fetchable results available from 0 or more rows of tabular information
  394.         ret = VBCT_res_info(cmd_pointer, CS_NUMDATA, ncols)
  395.         ret = VBCT_do_binds(cmd_pointer)
  396.         While ret = CS_SUCCEED Or ret = CS_ROW_FAIL
  397.         ret = VBCT_fetch(cmd_pointer, 0, 0, 0, rows_read)
  398.         If ret = CS_SUCCEED Then
  399.             For i = 1 To ncols
  400.             t(i) = VBCT_data(cmd_pointer, i)
  401.             Next
  402.         End If
  403.         aitem$ = t(1) & Space(15 - Len(t(1))) & Left(t(2) & Space(41 - Len(t(2))), 20) & t(3)
  404.         author_list.AddItem aitem$
  405.         Wend
  406.         Case CS_CMD_DONE, CS_CMD_SUCCEED, CS_CMD_FAIL
  407.         Select Case restype
  408.         Case CS_CMD_DONE
  409.             rt$ = "CS_CMD_DONE"
  410.         Case CS_CMD_SUCCEED
  411.             rt$ = "CS_CMD_SUCCEED"
  412.         Case CS_CMD_FAIL
  413.             rt$ = "CS_CMD_FAIL"
  414.         End Select
  415. '                MsgBox "Command status " & rt$ & " recieved"
  416.         Case Else
  417.         MsgBox "this command should never go here"
  418.         End Select
  419.         result_ret = VBCT_results(cmd_pointer, restype)
  420.     Wend
  421.             
  422.     For i = 0 To 8
  423.     label1(i).Visible = True
  424.     text1(i).Visible = True
  425.     Next
  426.     author_list.Visible = True
  427.     newrec.Visible = True
  428.     shape1.Visible = True
  429.     shape2.Visible = True
  430. End Sub
  431. Sub newrec_Click ()
  432.     updflag = 2
  433.     updbut.Visible = True
  434.     chgbut.Visible = False
  435.     newrec.Visible = False
  436.     cancelbut.Visible = True
  437.     delbut.Visible = False
  438.     author_list.Enabled = False
  439.     For i = 0 To 8
  440.     text1(i).Enabled = True
  441.     text1(i).Text = ""
  442.     Next
  443.     text1(0).SetFocus
  444. End Sub
  445. Sub show_author ()
  446.     Dim restype As Long
  447.     Dim ncols As Long
  448.     Dim rows_read As Long
  449.     lc = author_list.ListIndex
  450.     If lc = -1 Then
  451.     Exit Sub
  452.     End If
  453.     d$ = RTrim(Left(author_list.List(lc), 15))
  454.     ret = VBCT_command_str(cmd_pointer, CS_LANG_CMD, "select * from authors where au_id = '" & d$ & "'", CS_UNUSED)
  455.     ret = VBCT_send(cmd_pointer)
  456.      
  457.      result_ret = VBCT_results(cmd_pointer, restype)
  458.      res$ = ""
  459.      While result_ret = CS_SUCCEED
  460.     Select Case restype
  461.         
  462.      Case CS_ROW_RESULT
  463. '   There are fetchable results available from 0 or more rows of tabular information
  464.         ret = VBCT_res_info(cmd_pointer, CS_NUMDATA, ncols)
  465.         ret = VBCT_do_binds(cmd_pointer)
  466.         While ret = CS_SUCCEED Or ret = CS_ROW_FAIL
  467.         ret = VBCT_fetch(cmd_pointer, 0, 0, 0, rows_read)
  468.         If ret = CS_SUCCEED Then
  469.             For i = 1 To ncols
  470.             dat$ = VBCT_data(cmd_pointer, i)
  471.             text1(i - 1).Text = dat$
  472.             Next
  473.         End If
  474.         Wend
  475.         Case CS_CMD_DONE, CS_CMD_SUCCEED, CS_CMD_FAIL
  476.         Select Case restype
  477.         Case CS_CMD_DONE
  478.             rt$ = "CS_CMD_DONE"
  479.         Case CS_CMD_SUCCEED
  480.             rt$ = "CS_CMD_SUCCEED"
  481.         Case CS_CMD_FAIL
  482.             rt$ = "CS_CMD_FAIL"
  483.         End Select
  484. '                MsgBox "Command status " & rt$ & " recieved"
  485.         Case Else
  486.         MsgBox "this command should never go here"
  487.         End Select
  488.         result_ret = VBCT_results(cmd_pointer, restype)
  489.     Wend
  490. End Sub
  491. Sub SQLCTLIB1_CLIENTMESSAGE (Context As Long, connection As Long)
  492.     Dim cmsg As CS_CLIENTMSG
  493.     Dim ret As Long
  494.     Dim layer As Long
  495.     Dim origin As Long
  496.     Dim severity  As Long
  497.     Dim number As Long
  498.     crlf$ = Chr(13) & Chr(10)
  499.     ret = VBCS_get_client_msg(cmsg)
  500.     VBCS_decode_message cmsg.msgnumber, layer, origin, severity, number
  501.     MsgBox "Client message # " & Str(number) & crlf$ & Left(cmsg.msgstring, cmsg.msgstringlen)
  502. End Sub
  503. Sub SQLCTLIB1_SERVERMESSAGE (Context As Long, connection As Long)
  504.     Dim cmsg As CS_SERVERMSG
  505.     Dim ret As Long
  506.     Dim layer As Long
  507.     Dim origin As Long
  508.     Dim severity  As Long
  509.     Dim number As Long
  510.     Dim outlen As Long
  511.     crlf$ = Chr(13) & Chr(10)
  512.     ret = VBCS_get_server_msg(cmsg)
  513.     Dim appl As String
  514.     appl = Space(50)
  515.     ret = VBCT_con_props_str(connection, CS_GET, CS_APPNAME, appl, outlen)
  516. '    MsgBox "Message Status is " & Str(cmsg.status)
  517.     If cmsg.status And CS_HASEED Then
  518.     Dim cc As Long
  519.     ret = VBCT_con_props_num(connection, CS_GET, CS_EED_CMD, cc, outlen)
  520.     extendederrordata (cc)
  521.     End If
  522.     VBCS_decode_message cmsg.msgnumber, layer, origin, severity, number
  523.     MsgBox "Server message # " & Str(number) & crlf$ & Left(cmsg.Text, cmsg.textlen)
  524. End Sub
  525. Sub Text1_KeyPress (index As Integer, keyascii As Integer)
  526.     If updflag = 0 Then
  527.     keyascii = 0
  528.     End If
  529. End Sub
  530. Sub updbut_Click ()
  531.     Dim sql As String
  532.     If updflag = 3 Then
  533.     GoTo dontcheck
  534.     End If
  535.     If text1(0).Text = "" Then
  536.     MsgBox "Author Id cannot be NULL"
  537.     Exit Sub
  538.     End If
  539.     If text1(1).Text = "" Then
  540.     MsgBox "Last name cannot be NULL"
  541.     Exit Sub
  542.     End If
  543.     If text1(2).Text = "" Then
  544.     MsgBox "First name cannot be NULL"
  545.     Exit Sub
  546.     End If
  547.     If text1(3).Text = "" Then
  548.     MsgBox "Phone # cannot be NULL"
  549.     Exit Sub
  550.     End If
  551. dontcheck:
  552.     If updflag = 1 Then
  553. '   In this application if the updflag is set to 1 then we are modifing the
  554. '   data for a particular row in the table authors. The following code will
  555. '   create a SQL Statement to 'UPDATE' the authors table where the au_id field
  556. '   is equal to the requested author id.
  557.     sql = "update authors set "
  558.     sql = sql & " au_lname = " & Chr(34) & text1(1).Text & Chr(34) & " ,"
  559.     sql = sql & " au_fname = " & Chr(34) & text1(2).Text & Chr(34) & " ,"
  560.     sql = sql & " phone = " & Chr(34) & text1(3).Text & Chr(34) & " ,"
  561.     sql = sql & " address = " & Chr(34) & text1(4).Text & Chr(34) & " ,"
  562.     sql = sql & " city = " & Chr(34) & text1(5).Text & Chr(34) & " ,"
  563.     sql = sql & " state = " & Chr(34) & text1(6).Text & Chr(34) & " ,"
  564.     sql = sql & " country = " & Chr(34) & text1(7).Text & Chr(34) & " ,"
  565.     sql = sql & " postalcode = " & Chr(34) & text1(8).Text & Chr(34)
  566.     sql = sql & " where au_id = " & Chr(34) & text1(0).Text & Chr(34)
  567.     Else
  568.     If updflag = 2 Then
  569. '   In this application if the updflag is set to 2 then we are adding
  570. '   data for a particular row in the table authors. The following code will
  571. '   create a SQL Statement to 'INSERT' a row into the authors table where the
  572. '   au_id field is equal to the requested author id.
  573.     sql = "insert authors values ("
  574.     For i = 0 To 7
  575.         sql = sql & Chr(34) & text1(i).Text & Chr(34) & " , "
  576.     Next
  577.     sql = sql & Chr(34) & text1(8).Text & Chr(34) & ")"
  578.       Else
  579. '   In this application if the updflag is set to 3 then we are deleting
  580. '   an author record from the table
  581. '   The SQL statement will delete a row from the table based on the
  582. '   primary key (au_id)
  583.         sql = "delete from authors where au_id = " & Chr(34) & text1(0).Text & Chr(34)
  584.     End If
  585.     End If
  586.     ret = process_no_rows(sql)
  587.     If ret = 99 Then
  588.     If updflag = 2 Then
  589.         aitem$ = text1(0).Text & Space(15 - Len(text1(0).Text)) & Left(text1(1).Text & Space(41 - Len(text1(1).Text)), 20) & text1(2).Text
  590.         author_list.AddItem aitem$
  591.         MsgBox "Information added for au_id " & text1(0).Text
  592.         author_list.ListIndex = author_list.ListCount - 1
  593.     Else
  594.         If updflag = 1 Then
  595.         aitem$ = text1(0).Text & Space(15 - Len(text1(0).Text)) & Left(text1(1).Text & Space(41 - Len(text1(1).Text)), 20) & text1(2).Text
  596.         MsgBox "Information changed for au_id " & text1(0).Text
  597.         lc = author_list.ListIndex
  598.         author_list.List(lc) = aitem$
  599.         Else
  600.         lc = author_list.ListIndex
  601.         author_list.RemoveItem lc
  602.         MsgBox "Information deleted for au_id " & text1(0).Text
  603.         author_list.ListIndex = 0
  604.         End If
  605.     End If
  606.     Else
  607.     Exit Sub
  608.     End If
  609.     author_list.Enabled = True
  610.     chgbut.Visible = True
  611.     updbut.Visible = False
  612.     newrec.Visible = True
  613.     cancelbut.Visible = False
  614.     delbut.Visible = True
  615.     For i = 0 To 8
  616.     text1(i).Enabled = False
  617.     Next
  618. End Sub
  619.