home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / browse_1 / frmcat.frm < prev    next >
Text File  |  1993-07-19  |  10KB  |  337 lines

  1. VERSION 2.00
  2. Begin Form frmCatalog 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Catalog Database"
  5.    ClientHeight    =   6444
  6.    ClientLeft      =   876
  7.    ClientTop       =   1296
  8.    ClientWidth     =   7284
  9.    ControlBox      =   0   'False
  10.    Height          =   6780
  11.    Left            =   828
  12.    LinkTopic       =   " "
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   6444
  15.    ScaleWidth      =   7284
  16.    Top             =   1008
  17.    Width           =   7380
  18.    Begin CommandButton comExit 
  19.       Caption         =   "E&xit"
  20.       Height          =   252
  21.       Left            =   5880
  22.       TabIndex        =   18
  23.       Top             =   6120
  24.       Width           =   1332
  25.    End
  26.    Begin CommandButton comDelete 
  27.       Caption         =   "&Delete "
  28.       Height          =   372
  29.       Left            =   5760
  30.       TabIndex        =   17
  31.       Top             =   840
  32.       Width           =   1452
  33.    End
  34.    Begin CommandButton comNew 
  35.       Caption         =   "&Add New"
  36.       Height          =   372
  37.       Left            =   5760
  38.       TabIndex        =   16
  39.       Top             =   480
  40.       Width           =   1452
  41.    End
  42.    Begin CommandButton comUpdate 
  43.       Caption         =   "&Update"
  44.       Enabled         =   0   'False
  45.       Height          =   372
  46.       Left            =   5760
  47.       TabIndex        =   15
  48.       Top             =   120
  49.       Width           =   1452
  50.    End
  51.    Begin TextBox txtEdt 
  52.       DataField       =   "TYPE"
  53.       DataSource      =   "dtaCatalog"
  54.       Enabled         =   0   'False
  55.       Height          =   288
  56.       Index           =   6
  57.       Left            =   4200
  58.       MaxLength       =   4
  59.       TabIndex        =   14
  60.       Top             =   840
  61.       Width           =   1332
  62.    End
  63.    Begin TextBox txtEdt 
  64.       DataField       =   "CODE"
  65.       DataSource      =   "dtaCatalog"
  66.       Enabled         =   0   'False
  67.       Height          =   288
  68.       Index           =   5
  69.       Left            =   4200
  70.       MaxLength       =   4
  71.       TabIndex        =   12
  72.       Top             =   480
  73.       Width           =   1332
  74.    End
  75.    Begin TextBox txtEdt 
  76.       DataField       =   "GROUP"
  77.       DataSource      =   "dtaCatalog"
  78.       Enabled         =   0   'False
  79.       Height          =   288
  80.       Index           =   4
  81.       Left            =   4200
  82.       MaxLength       =   4
  83.       TabIndex        =   10
  84.       Top             =   120
  85.       Width           =   1332
  86.    End
  87.    Begin TextBox txtEdt 
  88.       DataField       =   "DESCR"
  89.       DataSource      =   "dtaCatalog"
  90.       Height          =   288
  91.       Index           =   3
  92.       Left            =   1800
  93.       MaxLength       =   50
  94.       TabIndex        =   8
  95.       Top             =   1320
  96.       Width           =   5412
  97.    End
  98.    Begin TextBox txtEdt 
  99.       DataField       =   "LIST"
  100.       DataSource      =   "dtaCatalog"
  101.       Height          =   288
  102.       Index           =   2
  103.       Left            =   1800
  104.       MaxLength       =   12
  105.       TabIndex        =   6
  106.       Top             =   840
  107.       Width           =   1332
  108.    End
  109.    Begin TextBox txtEdt 
  110.       DataField       =   "CATNO"
  111.       DataSource      =   "dtaCatalog"
  112.       Height          =   288
  113.       Index           =   1
  114.       Left            =   1800
  115.       MaxLength       =   15
  116.       TabIndex        =   4
  117.       Top             =   480
  118.       Width           =   1332
  119.    End
  120.    Begin TextBox txtEdt 
  121.       DataField       =   "SYSNO"
  122.       DataSource      =   "dtaCatalog"
  123.       Height          =   288
  124.       Index           =   0
  125.       Left            =   1800
  126.       MaxLength       =   6
  127.       TabIndex        =   2
  128.       Top             =   120
  129.       Width           =   1092
  130.    End
  131.    Begin TBrowse Brw 
  132.       BorderStyle     =   0  'None
  133.       DataSource      =   "dtaCatalog"
  134.       Height          =   4332
  135.       Left            =   120
  136.       TabIndex        =   0
  137.       Top             =   1680
  138.       Width           =   7092
  139.    End
  140.    Begin Data dtaCatalog 
  141.       Caption         =   "Catalog Table Data Control"
  142.       Connect         =   ""
  143.       DatabaseName    =   "C:\VB\CDK\BRWA\DEMO\DEMO.MDB"
  144.       Exclusive       =   0   'False
  145.       Height          =   252
  146.       Left            =   120
  147.       Options         =   0
  148.       ReadOnly        =   0   'False
  149.       RecordSource    =   "CATALOG"
  150.       Top             =   6120
  151.       Width           =   5532
  152.    End
  153.    Begin Label Label1 
  154.       Caption         =   "&Type:"
  155.       Height          =   252
  156.       Index           =   6
  157.       Left            =   3240
  158.       TabIndex        =   13
  159.       Top             =   840
  160.       Width           =   852
  161.    End
  162.    Begin Label Label1 
  163.       Caption         =   "C&ode:"
  164.       Height          =   252
  165.       Index           =   5
  166.       Left            =   3240
  167.       TabIndex        =   11
  168.       Top             =   480
  169.       Width           =   852
  170.    End
  171.    Begin Label Label1 
  172.       Caption         =   "&Group:"
  173.       Height          =   252
  174.       Index           =   4
  175.       Left            =   3240
  176.       TabIndex        =   9
  177.       Top             =   120
  178.       Width           =   852
  179.    End
  180.    Begin Label Label1 
  181.       Caption         =   "D&escription"
  182.       Height          =   252
  183.       Index           =   3
  184.       Left            =   120
  185.       TabIndex        =   7
  186.       Top             =   1320
  187.       Width           =   1572
  188.    End
  189.    Begin Label Label1 
  190.       Caption         =   "&List price:"
  191.       Height          =   252
  192.       Index           =   2
  193.       Left            =   120
  194.       TabIndex        =   5
  195.       Top             =   840
  196.       Width           =   1572
  197.    End
  198.    Begin Label Label1 
  199.       Caption         =   "&Catalog number:"
  200.       Height          =   252
  201.       Index           =   1
  202.       Left            =   120
  203.       TabIndex        =   3
  204.       Top             =   480
  205.       Width           =   1572
  206.    End
  207.    Begin Label Label1 
  208.       Caption         =   "&Number:"
  209.       Height          =   252
  210.       Index           =   0
  211.       Left            =   120
  212.       TabIndex        =   1
  213.       Top             =   120
  214.       Width           =   1572
  215.    End
  216. End
  217. Option Explicit
  218.  
  219. ' lInitialize is required as a one time flag,
  220. ' see form_activate() for details
  221. Dim lInitialize As Integer
  222.  
  223. Sub Brw_EditValid (nCol As Integer, cField As String, lOk As Integer)
  224.    ' Edit validations, we need to check the primary key - SYSNO
  225.    ' and the list price
  226.    If nCol = 0 Then
  227.       ' SYSNO must be non-zero and positive
  228.       If Trim$(cField) = "" Or Val(cField) <= 0 Then
  229.          MsgBox "Wrong primary key!"
  230.          lOk = False
  231.       End If
  232.    ElseIf nCol = 5 Then
  233.       ' List price must be positive or zero
  234.       If Val(cField) < 0 Then
  235.          MsgBox "Wrong list price!"
  236.          lOk = False
  237.       End If
  238.    End If
  239. End Sub
  240.  
  241. Sub comDelete_Click ()
  242.    ' delete current record
  243.    ' IMPORTANT: YOU MUST ISSUE THE REFRESH, OTHERWISE THE CONTROL WILL CRASH!
  244.    dtaCatalog.Recordset.Delete
  245.    dtaCatalog.Refresh
  246. End Sub
  247.  
  248. Sub comExit_Click ()
  249.    ' pseudo-exit, we are just hidding ourselfs
  250.    Me.Hide
  251.    BrwDemo!comProducts.Enabled = True ' and re-enable the show button
  252. End Sub
  253.  
  254. Sub comNew_Click ()
  255.    ' add a new record
  256.    dtaCatalog.Recordset.AddNew
  257.    ' set the read-only fields, we must preserve
  258.    ' database relations
  259.    txtEdt(4).Text = BrwDemo!dtaPrdGroup.Recordset.Fields("GROUP").Value
  260.    txtEdt(5).Text = BrwDemo!dtaPrdGroup.Recordset.Fields("CODE").Value
  261.    txtEdt(6).Text = BrwDemo!dtaPrdGroup.Recordset.Fields("TYPE").Value
  262. End Sub
  263.  
  264. Sub comUpdate_Click ()
  265.    ' we must update explicitly after editing in one
  266.    ' of the text box bound controls
  267.    dtaCatalog.Recordset.Update
  268.    comUpdate.Enabled = False
  269. End Sub
  270.  
  271. Sub Form_Activate ()
  272.    Dim cFind As String
  273.  
  274.    ' We need to force the data control to refresh
  275.    ' after the form has been loaded (but not in
  276.    ' the form_load(), the objects are not yet initialized ).
  277.    ' This must be done also if the RecordSource
  278.    ' changes at run-time.
  279.    If Not lInitialize Then
  280.       lInitialize = True
  281.       cFind = "GROUP = '" + BrwDemo!dtaPrdGroup.Recordset.Fields("GROUP").Value + "' and "
  282.       cFind = cFind + "CODE = '" + BrwDemo!dtaPrdGroup.Recordset.Fields("CODE").Value + "' and "
  283.       cFind = cFind + "TYPE = '" + BrwDemo!dtaPrdGroup.Recordset.Fields("TYPE").Value + "'"
  284.       dtaCatalog.Recordset.FindFirst cFind
  285.    End If
  286. End Sub
  287.  
  288. Sub Form_Load ()
  289.    ' set form position
  290.    Me.Top = 0: Me.Left = Screen.Width - Me.Width
  291.    
  292.    ' initialize the browse control
  293.    Brw.Cols = 7            ' we need 7 columns
  294.    
  295.    ' set column width for each
  296.    Brw.ColWidth(0) = 6
  297.    Brw.ColWidth(1) = 4
  298.    Brw.ColWidth(2) = 4
  299.    Brw.ColWidth(3) = 4
  300.    Brw.ColWidth(4) = 15
  301.    Brw.ColWidth(5) = 12
  302.    Brw.ColWidth(6) = 50
  303.    
  304.    ' set header for each (if is not the default = field name)
  305.    Brw.Header(0) = "Sysno"
  306.    Brw.Header(1) = "Group"
  307.    Brw.Header(2) = "Code"
  308.    Brw.Header(3) = "Type"
  309.    Brw.Header(4) = "Catalog no"
  310.    Brw.Header(5) = "List price"
  311.    Brw.Header(6) = "Description"
  312.    
  313.    ' set the data field for each column
  314.    Brw.ColField(0) = "SYSNO"
  315.    Brw.ColField(1) = "GROUP"
  316.    Brw.ColField(2) = "CODE"
  317.    Brw.ColField(3) = "TYPE"
  318.    Brw.ColField(4) = "CATNO"
  319.    Brw.ColField(5) = "LIST"
  320.    Brw.ColField(6) = "DESCR"
  321.    
  322.    ' enable editing for the ones we want
  323.    Brw.ColEdit(0) = True
  324.    Brw.ColEdit(4) = True
  325.    Brw.ColEdit(5) = True
  326.    Brw.ColEdit(6) = True
  327.  
  328.    Brw.LeftFrozen = 1     ' freeze the SYSNO to the left
  329.    Brw.SpcColor(5) = True ' set the LIST column to a special color
  330. End Sub
  331.  
  332. Sub txtEdt_Change (Index As Integer)
  333.    ' enable the Update button if the user has changed something
  334.    If HasFocus(txtEdt(Index)) And Not comUpdate.Enabled Then comUpdate.Enabled = True
  335. End Sub
  336.  
  337.