home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / demo / rec_lock / exmpl2_2.frm < prev    next >
Text File  |  1994-09-09  |  9KB  |  277 lines

  1. VERSION 2.00
  2. Begin Form frm_Cities 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Record Locking Pro 1.01 Demo - Example 2"
  6.    ClientHeight    =   5130
  7.    ClientLeft      =   1335
  8.    ClientTop       =   1575
  9.    ClientWidth     =   7365
  10.    ControlBox      =   0   'False
  11.    Height          =   5535
  12.    KeyPreview      =   -1  'True
  13.    Left            =   1275
  14.    LinkTopic       =   "Form2"
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   5130
  18.    ScaleWidth      =   7365
  19.    Top             =   1230
  20.    Width           =   7485
  21.    Begin CommandButton cmd_Exit 
  22.       Cancel          =   -1  'True
  23.       Caption         =   "Ende"
  24.       Height          =   435
  25.       Left            =   2040
  26.       TabIndex        =   4
  27.       Top             =   4320
  28.       Width           =   1515
  29.    End
  30.    Begin Data dat_Tab_Cities 
  31.       Caption         =   "Tab_Cities"
  32.       Connect         =   ""
  33.       DatabaseName    =   "CITIES.MDB"
  34.       Exclusive       =   0   'False
  35.       Height          =   270
  36.       Left            =   2040
  37.       Options         =   0
  38.       ReadOnly        =   0   'False
  39.       RecordSource    =   "Tab_Cities"
  40.       Top             =   3660
  41.       Width           =   4275
  42.    End
  43.    Begin TextBox txt_Continent 
  44.       DataField       =   "Continent"
  45.       DataSource      =   "dat_Tab_Cities"
  46.       Height          =   285
  47.       Left            =   2040
  48.       MaxLength       =   30
  49.       TabIndex        =   3
  50.       Top             =   2340
  51.       Width           =   4275
  52.    End
  53.    Begin TextBox txt_Country 
  54.       DataField       =   "Country"
  55.       DataSource      =   "dat_Tab_Cities"
  56.       Height          =   285
  57.       Left            =   2040
  58.       MaxLength       =   30
  59.       TabIndex        =   2
  60.       Top             =   1860
  61.       Width           =   4275
  62.    End
  63.    Begin TextBox txt_City 
  64.       DataField       =   "City"
  65.       DataSource      =   "dat_Tab_Cities"
  66.       Height          =   285
  67.       Left            =   2040
  68.       MaxLength       =   30
  69.       TabIndex        =   1
  70.       Top             =   1380
  71.       Width           =   4275
  72.    End
  73.    Begin TextBox txt_City_ID 
  74.       DataField       =   "City_ID"
  75.       DataSource      =   "dat_Tab_Cities"
  76.       Enabled         =   0   'False
  77.       Height          =   285
  78.       Left            =   2040
  79.       TabIndex        =   0
  80.       Top             =   900
  81.       Width           =   4275
  82.    End
  83.    Begin Label lab_User_Name 
  84.       BackStyle       =   0  'Transparent
  85.       Height          =   195
  86.       Left            =   2100
  87.       TabIndex        =   11
  88.       Top             =   420
  89.       Width           =   4155
  90.    End
  91.    Begin Label lab_ 
  92.       Alignment       =   1  'Right Justify
  93.       BackStyle       =   0  'Transparent
  94.       Caption         =   "Benutzername"
  95.       Height          =   255
  96.       Index           =   4
  97.       Left            =   600
  98.       TabIndex        =   10
  99.       Top             =   420
  100.       Width           =   1335
  101.    End
  102.    Begin Shape sha_User_Name 
  103.       FillColor       =   &H0080FFFF&
  104.       FillStyle       =   0  'Solid
  105.       Height          =   315
  106.       Left            =   2040
  107.       Top             =   360
  108.       Width           =   4275
  109.    End
  110.    Begin Label lab_Status 
  111.       Alignment       =   2  'Center
  112.       BackStyle       =   0  'Transparent
  113.       Height          =   195
  114.       Left            =   2100
  115.       TabIndex        =   9
  116.       Top             =   3060
  117.       Width           =   4155
  118.    End
  119.    Begin Shape sha_Status 
  120.       BackColor       =   &H0000FF00&
  121.       BackStyle       =   1  'Opaque
  122.       Height          =   315
  123.       Left            =   2040
  124.       Top             =   3000
  125.       Width           =   4275
  126.    End
  127.    Begin Label lab_ 
  128.       Alignment       =   1  'Right Justify
  129.       BackStyle       =   0  'Transparent
  130.       Caption         =   "Kontinent"
  131.       Height          =   255
  132.       Index           =   3
  133.       Left            =   1020
  134.       TabIndex        =   5
  135.       Top             =   2400
  136.       Width           =   915
  137.    End
  138.    Begin Label lab_ 
  139.       Alignment       =   1  'Right Justify
  140.       BackStyle       =   0  'Transparent
  141.       Caption         =   "Land"
  142.       Height          =   255
  143.       Index           =   2
  144.       Left            =   1380
  145.       TabIndex        =   8
  146.       Top             =   1920
  147.       Width           =   555
  148.    End
  149.    Begin Label lab_ 
  150.       Alignment       =   1  'Right Justify
  151.       BackStyle       =   0  'Transparent
  152.       Caption         =   "Stadt"
  153.       Height          =   255
  154.       Index           =   1
  155.       Left            =   1380
  156.       TabIndex        =   7
  157.       Top             =   1440
  158.       Width           =   555
  159.    End
  160.    Begin Label lab_ 
  161.       Alignment       =   1  'Right Justify
  162.       BackStyle       =   0  'Transparent
  163.       Caption         =   "Stadt-ID"
  164.       Height          =   255
  165.       Index           =   0
  166.       Left            =   1140
  167.       TabIndex        =   6
  168.       Top             =   960
  169.       Width           =   795
  170.    End
  171. End
  172. ' Example 2 - Lock-by-Select Demo
  173.  
  174. Option Explicit
  175.  
  176. Sub cmd_Exit_Click ()
  177.  
  178.     Done_Locking
  179.     Unload Me
  180.     End
  181.  
  182. End Sub
  183.  
  184. Sub dat_Tab_Cities_Reposition ()
  185.  
  186.     Dim Record_ID As Long
  187.     Dim Lock_Timeout As Integer
  188.     Dim Result As Integer
  189.  
  190.     Unlock_Edit_Controls Me
  191.     txt_City_ID.Enabled = False
  192.  
  193.     Record_ID = txt_City_ID.Text
  194.     Lock_Timeout = 0 ' keine Zeitmarke fⁿr automatische Entsperrⁿberwachung
  195.  
  196.     Result = Is_Record_Locked(glb_Table_Name, Record_ID)
  197.  
  198.     Select Case Result
  199.         Case st_Record_Not_Locked ' Datensatz ist nicht gesperrt
  200.             Lock_Record glb_Table_Name, Record_ID, Lock_Timeout
  201.             If glb_Last_Status = st_No_Error Then ' Datensatz wurde gesperrt
  202.                 sha_Status.BackColor = RGB(0, 255, 0)
  203.                 lab_Status.Caption = "Datensatz vom akt. Benutzer gesperrt"
  204.             Else ' Fehler beim Sperren
  205.                 sha_Status.BackColor = RGB(255, 255, 255)
  206.                 lab_Status.Caption = "Fehler"
  207.                 Show_Status
  208.             End If
  209.         Case st_Lock_By_Same, st_Lock_By_Same_Out ' Datensatz vom akt. Benutzer gesperrt
  210.             sha_Status.BackColor = RGB(0, 255, 0)
  211.             lab_Status.Caption = "Datensatz vom akt. Benutzer gesperrt"
  212.         Case st_Lock_By_Others, st_Lock_By_Others_Out ' Datensatz von einem anderen (fremden) Benutzer gesperrt
  213.             Lock_Edit_Controls Me
  214.             sha_Status.BackColor = RGB(255, 0, 0)
  215.             lab_Status.Caption = "Datensatz von einem anderen Benutzer gesperrt"
  216.     End Select
  217.  
  218. End Sub
  219.  
  220. Sub dat_Tab_Cities_Validate (Action As Integer, Save As Integer)
  221.  
  222.     Const Move_Previous = 2
  223.     Const Move_Next = 3
  224.  
  225.     Dim Record_ID As Long
  226.     Dim Result As Integer
  227.  
  228.     Record_ID = txt_City_ID.Text
  229.  
  230.     If Record_ID = glb_First_Record_ID Then ' Anfang der Datenbank-Tabelle
  231.         If Action = Move_Previous Then Exit Sub
  232.     End If
  233.  
  234.     If Record_ID = glb_Last_Record_ID Then ' Ende der Datenbank-Tabelle
  235.         If Action = Move_Next Then Exit Sub
  236.     End If
  237.  
  238.     Result = Is_Record_Locked(glb_Table_Name, Record_ID)
  239.  
  240.     Select Case Result
  241.         Case st_Lock_By_Same, st_Lock_By_Same_Out ' Datensatz vom akt. Benutzer gesperrt
  242.             Unlock_Record glb_Table_Name, Record_ID
  243.             If glb_Last_Status = st_No_Error Then ' Datensatz wurde entsperrt
  244.                 Unlock_Edit_Controls Me
  245.                 txt_City_ID.Enabled = False
  246.                 sha_Status.BackColor = RGB(0, 255, 0)
  247.                 lab_Status.Caption = "Datensatz nicht gesperrt"
  248.             Else ' Fehler beim Entsperren
  249.                 sha_Status.BackColor = RGB(255, 255, 255)
  250.                 lab_Status.Caption = "Fehler"
  251.                 Show_Status
  252.             End If
  253.         Case st_Lock_By_Others, st_Lock_By_Others_Out ' Datensatz von einem anderen (fremden) Benutzer gesperrt
  254.             Save = False
  255.     End Select
  256.  
  257. End Sub
  258.  
  259. Sub Form_Load ()
  260.  
  261.     Center_Form Me
  262.     Draw_Form_Frame Me, 40, 40
  263.  
  264.     Me.Show
  265.  
  266.     lab_User_Name.Caption = glb_User_Name
  267.  
  268.     dat_Tab_Cities.DatabaseName = glb_Database_Name
  269.     dat_Tab_Cities.RecordSource = glb_Table_Name
  270.     dat_Tab_Cities.Refresh
  271.     
  272.     dat_Tab_Cities.Recordset.LockEdits = False ' Optimistic locking
  273.     dat_Tab_Cities.Refresh
  274.  
  275. End Sub
  276.  
  277.