VERSION 5.00
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form fClienti
BorderStyle = 1 'Fixed Single
Caption = "Clienti"
ClientHeight = 5490
ClientLeft = 45
ClientTop = 435
ClientWidth = 9480
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5490
ScaleWidth = 9480
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Align = 2 'Align Bottom
BorderStyle = 0 'None
Height = 615
Left = 0
ScaleHeight = 615
ScaleWidth = 9480
TabIndex = 9
TabStop = 0 'False
Top = 4875
Width = 9480
Begin VB.CommandButton Command1
Cancel = -1 'True
Caption = "Chiudi"
Height = 375
Index = 9
Left = 4260
TabIndex = 6
Top = 120
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "Cancella"
Height = 375
Index = 2
Left = 2880
TabIndex = 5
Top = 120
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "Salva"
Default = -1 'True
Height = 375
Index = 1
Left = 1500
TabIndex = 4
Top = 120
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "Nuovo"
Height = 375
Index = 0
Left = 120
TabIndex = 3
Top = 120
Width = 1215
End
End
Begin VB.TextBox Text1
Height = 285
Index = 1
Left = 1500
MaxLength = 40
TabIndex = 2
Top = 4560
Width = 4830
End
Begin VB.TextBox Text1
Height = 285
Index = 0
Left = 1500
MaxLength = 10
TabIndex = 1
Top = 4200
Width = 1230
End
Begin MSHierarchicalFlexGridLib.MSHFlexGrid MSHFlexGrid1
Height = 3975
Left = 120
TabIndex = 0
Top = 120
Width = 9255
_ExtentX = 16325
_ExtentY = 7011
_Version = 393216
FixedCols = 0
FocusRect = 0
HighLight = 2
_NumberOfBands = 1
_Band(0).Cols = 2
End
Begin VB.Label Label1
Caption = "Denominazione"
Height = 195
Index = 1
Left = 120
TabIndex = 8
Top = 4620
Width = 1215
End
Begin VB.Label Label1
Caption = "Codice"
Height = 195
Index = 0
Left = 120
TabIndex = 7
Top = 4260
Width = 855
End
End
Attribute VB_Name = "fClienti"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private cnn As ADODB.Connection
Private rst As ADODB.Recordset
Private Sub Form_Load()
ReadPos Me
Set cnn = New ADODB.Connection
cnn.Open GetCnnStr()
Set rst = New ADODB.Recordset
rst.Open "Select * from Clienti order by Denominazione", cnn, adOpenDynamic, adLockOptimistic, adCmdText
SetGrid
End Sub
Private Sub Form_Unload(Cancel As Integer)
SavePos Me
rst.Close
cnn.Close
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
NewRecord
Case 1
SaveRecord
Case 2
DeleteRecord
Case 9
Unload Me
End Select
End Sub
Private Sub MSHFlexGrid1_GotFocus()
Call MSHFlexGrid1_RowColChange
End Sub
Private Sub MSHFlexGrid1_RowColChange()
If rst.EOF Then Exit Sub
Text1(0).Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 0)
Text1(1).Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 1)
End Sub
Private Sub SetGrid()
If rst.EOF Then
MSHFlexGrid1.Clear
MSHFlexGrid1.Rows = 2
MSHFlexGrid1.Cols = 2
Else
Set MSHFlexGrid1.DataSource = rst
End If
MSHFlexGrid1.ColWidth(0) = (90 * 20)
MSHFlexGrid1.ColWidth(1) = (90 * 40)
If MSHFlexGrid1.Visible Then MSHFlexGrid1.SetFocus
End Sub
Private Sub ClearInput()
Text1(0).Text = ""
Text1(1).Text = ""
End Sub
Private Sub NewRecord()
ClearInput
Text1(0).SetFocus
End Sub
Private Sub SaveRecord()
Dim rst1 As ADODB.Recordset
If Text1(0).Text = "" Or Text1(1).Text = "" Then
MsgBox "I campi non possono essere lasciati vuoti"
Exit Sub
End If
Set rst1 = New ADODB.Recordset
rst1.Open "Select * from Clienti where codice = '" & Trim(Text1(0).Text) & "'", cnn, adOpenDynamic, adLockOptimistic, adCmdText
If rst1.EOF Then rst1.AddNew
rst1!Codice = Trim(Text1(0).Text)
rst1!Denominazione = Trim(Text1(1).Text)
rst1.Update
rst1.Close
Set rst1 = Nothing
rst.Requery
SetGrid
For lRow = 1 To MSHFlexGrid1.Rows - 1
If MSHFlexGrid1.TextMatrix(lRow, 0) = Trim(Text1(0).Text) Then
MSHFlexGrid1.Row = lRow
MSHFlexGrid1.Col = 0
End If
Next
ClearInput
End Sub
Private Sub DeleteRecord()
Dim rst1 As ADODB.Recordset
Dim lRet As Long
If rst.EOF Then Exit Sub
lRet = MsgBox("Confermi la cancellazione?", vbExclamation + vbYesNo + vbDefaultButton2, "Cancella Record")
If lRet = vbYes Then
Set rst1 = New ADODB.Recordset
rst1.Open "Select * from Clienti where codice = '" & Trim(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 0)) & "'", cnn, adOpenDynamic, adLockOptimistic, adCmdText
If Not rst1.EOF Then rst1.Delete
rst1.Close
Set rst1 = Nothing
rst.Requery
SetGrid
ClearInput
End If
End Sub