home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
demo
/
rec_lock
/
exmpl2_2.frm
< prev
next >
Wrap
Text File
|
1994-09-09
|
9KB
|
277 lines
VERSION 2.00
Begin Form frm_Cities
BackColor = &H00C0C0C0&
BorderStyle = 1 'Fixed Single
Caption = "Record Locking Pro 1.01 Demo - Example 2"
ClientHeight = 5130
ClientLeft = 1335
ClientTop = 1575
ClientWidth = 7365
ControlBox = 0 'False
Height = 5535
KeyPreview = -1 'True
Left = 1275
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5130
ScaleWidth = 7365
Top = 1230
Width = 7485
Begin CommandButton cmd_Exit
Cancel = -1 'True
Caption = "Ende"
Height = 435
Left = 2040
TabIndex = 4
Top = 4320
Width = 1515
End
Begin Data dat_Tab_Cities
Caption = "Tab_Cities"
Connect = ""
DatabaseName = "CITIES.MDB"
Exclusive = 0 'False
Height = 270
Left = 2040
Options = 0
ReadOnly = 0 'False
RecordSource = "Tab_Cities"
Top = 3660
Width = 4275
End
Begin TextBox txt_Continent
DataField = "Continent"
DataSource = "dat_Tab_Cities"
Height = 285
Left = 2040
MaxLength = 30
TabIndex = 3
Top = 2340
Width = 4275
End
Begin TextBox txt_Country
DataField = "Country"
DataSource = "dat_Tab_Cities"
Height = 285
Left = 2040
MaxLength = 30
TabIndex = 2
Top = 1860
Width = 4275
End
Begin TextBox txt_City
DataField = "City"
DataSource = "dat_Tab_Cities"
Height = 285
Left = 2040
MaxLength = 30
TabIndex = 1
Top = 1380
Width = 4275
End
Begin TextBox txt_City_ID
DataField = "City_ID"
DataSource = "dat_Tab_Cities"
Enabled = 0 'False
Height = 285
Left = 2040
TabIndex = 0
Top = 900
Width = 4275
End
Begin Label lab_User_Name
BackStyle = 0 'Transparent
Height = 195
Left = 2100
TabIndex = 11
Top = 420
Width = 4155
End
Begin Label lab_
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Benutzername"
Height = 255
Index = 4
Left = 600
TabIndex = 10
Top = 420
Width = 1335
End
Begin Shape sha_User_Name
FillColor = &H0080FFFF&
FillStyle = 0 'Solid
Height = 315
Left = 2040
Top = 360
Width = 4275
End
Begin Label lab_Status
Alignment = 2 'Center
BackStyle = 0 'Transparent
Height = 195
Left = 2100
TabIndex = 9
Top = 3060
Width = 4155
End
Begin Shape sha_Status
BackColor = &H0000FF00&
BackStyle = 1 'Opaque
Height = 315
Left = 2040
Top = 3000
Width = 4275
End
Begin Label lab_
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Kontinent"
Height = 255
Index = 3
Left = 1020
TabIndex = 5
Top = 2400
Width = 915
End
Begin Label lab_
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Land"
Height = 255
Index = 2
Left = 1380
TabIndex = 8
Top = 1920
Width = 555
End
Begin Label lab_
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Stadt"
Height = 255
Index = 1
Left = 1380
TabIndex = 7
Top = 1440
Width = 555
End
Begin Label lab_
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "Stadt-ID"
Height = 255
Index = 0
Left = 1140
TabIndex = 6
Top = 960
Width = 795
End
End
' Example 2 - Lock-by-Select Demo
Option Explicit
Sub cmd_Exit_Click ()
Done_Locking
Unload Me
End
End Sub
Sub dat_Tab_Cities_Reposition ()
Dim Record_ID As Long
Dim Lock_Timeout As Integer
Dim Result As Integer
Unlock_Edit_Controls Me
txt_City_ID.Enabled = False
Record_ID = txt_City_ID.Text
Lock_Timeout = 0 ' keine Zeitmarke fⁿr automatische Entsperrⁿberwachung
Result = Is_Record_Locked(glb_Table_Name, Record_ID)
Select Case Result
Case st_Record_Not_Locked ' Datensatz ist nicht gesperrt
Lock_Record glb_Table_Name, Record_ID, Lock_Timeout
If glb_Last_Status = st_No_Error Then ' Datensatz wurde gesperrt
sha_Status.BackColor = RGB(0, 255, 0)
lab_Status.Caption = "Datensatz vom akt. Benutzer gesperrt"
Else ' Fehler beim Sperren
sha_Status.BackColor = RGB(255, 255, 255)
lab_Status.Caption = "Fehler"
Show_Status
End If
Case st_Lock_By_Same, st_Lock_By_Same_Out ' Datensatz vom akt. Benutzer gesperrt
sha_Status.BackColor = RGB(0, 255, 0)
lab_Status.Caption = "Datensatz vom akt. Benutzer gesperrt"
Case st_Lock_By_Others, st_Lock_By_Others_Out ' Datensatz von einem anderen (fremden) Benutzer gesperrt
Lock_Edit_Controls Me
sha_Status.BackColor = RGB(255, 0, 0)
lab_Status.Caption = "Datensatz von einem anderen Benutzer gesperrt"
End Select
End Sub
Sub dat_Tab_Cities_Validate (Action As Integer, Save As Integer)
Const Move_Previous = 2
Const Move_Next = 3
Dim Record_ID As Long
Dim Result As Integer
Record_ID = txt_City_ID.Text
If Record_ID = glb_First_Record_ID Then ' Anfang der Datenbank-Tabelle
If Action = Move_Previous Then Exit Sub
End If
If Record_ID = glb_Last_Record_ID Then ' Ende der Datenbank-Tabelle
If Action = Move_Next Then Exit Sub
End If
Result = Is_Record_Locked(glb_Table_Name, Record_ID)
Select Case Result
Case st_Lock_By_Same, st_Lock_By_Same_Out ' Datensatz vom akt. Benutzer gesperrt
Unlock_Record glb_Table_Name, Record_ID
If glb_Last_Status = st_No_Error Then ' Datensatz wurde entsperrt
Unlock_Edit_Controls Me
txt_City_ID.Enabled = False
sha_Status.BackColor = RGB(0, 255, 0)
lab_Status.Caption = "Datensatz nicht gesperrt"
Else ' Fehler beim Entsperren
sha_Status.BackColor = RGB(255, 255, 255)
lab_Status.Caption = "Fehler"
Show_Status
End If
Case st_Lock_By_Others, st_Lock_By_Others_Out ' Datensatz von einem anderen (fremden) Benutzer gesperrt
Save = False
End Select
End Sub
Sub Form_Load ()
Center_Form Me
Draw_Form_Frame Me, 40, 40
Me.Show
lab_User_Name.Caption = glb_User_Name
dat_Tab_Cities.DatabaseName = glb_Database_Name
dat_Tab_Cities.RecordSource = glb_Table_Name
dat_Tab_Cities.Refresh
dat_Tab_Cities.Recordset.LockEdits = False ' Optimistic locking
dat_Tab_Cities.Refresh
End Sub