VERSION 5.00
Begin VB.Form frmInformation 
   Caption         =   "Информация о фирме"
   ClientHeight    =   6795
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8475
   ForeColor       =   &H00C0C0C0&
   Icon            =   "frmInformation.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   6795
   ScaleWidth      =   8475
   StartUpPosition =   2  'CenterScreen
   Begin VB.HScrollBar HScroll 
      Height          =   255
      Left            =   5400
      Max             =   10
      TabIndex        =   17
      Top             =   5760
      Width           =   2895
   End
   Begin VB.CommandButton btnChangeRepresentatives 
      Caption         =   "Изменить"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6960
      TabIndex        =   9
      Top             =   4080
      Width           =   1335
   End
   Begin VB.CommandButton btnCancel 
      Caption         =   "Отмена"
      Height          =   375
      Left            =   5400
      TabIndex        =   18
      Top             =   6240
      Width           =   1335
   End
   Begin VB.TextBox aRemark 
      Height          =   1335
      Left            =   120
      MultiLine       =   -1  'True
      TabIndex        =   4
      Top             =   5280
      Width           =   3255
   End
   Begin VB.CommandButton btnDeleteRepresentatives 
      Caption         =   "Удалить"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6960
      TabIndex        =   11
      Top             =   4680
      Width           =   1335
   End
   Begin VB.CommandButton btnAddRepresentatives 
      Caption         =   "Добавить"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6960
      TabIndex        =   10
      Top             =   4320
      Width           =   1335
   End
   Begin VB.CommandButton btnPreviousRecord 
      Caption         =   "<< Назад"
      Height          =   375
      Left            =   5400
      TabIndex        =   15
      Top             =   5280
      Width           =   1455
   End
   Begin VB.CommandButton btnNextRecord 
      Caption         =   "Вперед >>"
      Height          =   375
      Left            =   6840
      TabIndex        =   16
      Top             =   5280
      Width           =   1455
   End
   Begin VB.CommandButton btnDeleteRecord 
      Caption         =   "Удалить"
      Height          =   375
      Left            =   3720
      TabIndex        =   14
      Top             =   6240
      Width           =   1335
   End
   Begin VB.CommandButton btnAddRecord 
      Caption         =   "Добавить"
      Height          =   375
      Left            =   3720
      TabIndex        =   13
      Top             =   5760
      Width           =   1335
   End
   Begin VB.TextBox aProperties 
      Height          =   1575
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   1
      Top             =   1200
      Width           =   4695
   End
   Begin VB.Frame Frame3 
      Caption         =   "Этап локализации"
      Enabled         =   0   'False
      Height          =   1575
      Left            =   5040
      TabIndex        =   24
      Top             =   2160
      Width           =   3255
      Begin VB.CheckBox Check3 
         Caption         =   "Осуществляется поставка материалов или комплектующих"
         Enabled         =   0   'False
         Height          =   615
         Left            =   120
         TabIndex        =   8
         Top             =   840
         Width           =   2895
      End
      Begin VB.CheckBox Check2 
         Caption         =   "Есть согласованные материалы или комплектующие"
         Enabled         =   0   'False
         Height          =   615
         Left            =   120
         TabIndex        =   7
         Top             =   240
         Width           =   2895
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Статус предприятия"
      Height          =   1335
      Left            =   5040
      TabIndex        =   23
      Top             =   360
      Width           =   3255
      Begin VB.OptionButton StatusOff 
         Caption         =   "Не представляет интереса для АП"
         Height          =   375
         Left            =   120
         TabIndex        =   6
         Top             =   840
         Width           =   3015
      End
      Begin VB.OptionButton StatusOn 
         Caption         =   "Представляет интерес для АП"
         Height          =   375
         Left            =   120
         TabIndex        =   5
         Top             =   360
         Value           =   -1  'True
         Width           =   2775
      End
   End
   Begin VB.CommandButton btnChangeRecord 
      Caption         =   "Изменить"
      Height          =   375
      Left            =   3720
      TabIndex        =   12
      Top             =   5280
      Width           =   1335
   End
   Begin VB.ListBox aRepresentatives 
      Height          =   840
      Left            =   120
      TabIndex        =   3
      Top             =   4080
      Width           =   6615
   End
   Begin VB.TextBox aProduction 
      Height          =   615
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   2
      Top             =   3120
      Width           =   4695
   End
   Begin VB.TextBox aFirmName 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   4695
   End
   Begin VB.CommandButton btnOK 
      Caption         =   "ОK"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   6960
      TabIndex        =   20
      Top             =   6240
      Width           =   1335
   End
   Begin VB.Label Label5 
      Caption         =   "Примечания"
      Height          =   255
      Left            =   120
      TabIndex        =   26
      Top             =   5040
      Width           =   975
   End
   Begin VB.Label Label4 
      Caption         =   "Реквизиты"
      Height          =   255
      Index           =   1
      Left            =   120
      TabIndex        =   25
      Top             =   960
      Width           =   975
   End
   Begin VB.Label Label3 
      Caption         =   "Представители"
      Height          =   255
      Left            =   120
      TabIndex        =   22
      Top             =   3840
      Width           =   1335
   End
   Begin VB.Label Label2 
      Caption         =   "Продукция"
      Height          =   255
      Left            =   120
      TabIndex        =   21
      Top             =   2880
      Width           =   975
   End
   Begin VB.Label Label1 
      Caption         =   "Наименование фирмы"
      Height          =   255
      Left            =   120
      TabIndex        =   19
      Top             =   240
      Width           =   1815
   End
End
Attribute VB_Name = "frmInformation"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub btnChangeRepresentatives_Click()
Dim Str As String
If aRepresentatives.ListIndex >= 0 Then
    Str = InputBox("Введите изменение", vbOKCancel, aRepresentatives.Text)
    If Str <> "" Then
        aRepresentatives.List(aRepresentatives.ListIndex) = Str
    End If
Else: MsgBox "Не выбрано ни одно из значений", vbCritical, "Ошибка"
End If

End Sub

Sub UpdateRepresentatives()
Dim a
a = "tblRepresentatives.fldIDFirm = '" & RcSetFirm("fldIDFirm") & "'"
On Error GoTo ERROR:
Set RcSetRepresentatives = db.OpenRecordset("SELECT tblRepresentatives.fldRepresentatives, tblRepresentatives.fldIDFirm FROM tblRepresentatives WHERE " & a, dbOpenDynaset)
Do While Not RcSetRepresentatives.EOF
    RcSetRepresentatives.MoveFirst
    RcSetRepresentatives.Delete
Loop
ERROR:
If aRepresentatives.ListCount > 0 Then
    For i = 0 To aRepresentatives.ListCount - 1
        RcSetRepresentatives.AddNew
        RcSetRepresentatives("fldIDFirm") = RcSetFirm("fldIDFirm")
        RcSetRepresentatives("fldRepresentatives") = aRepresentatives.List(i)
        RcSetRepresentatives.Update
    Next i
End If
End Sub

Private Sub Form_Load()
btnCancel.Visible = False
Set RcSetFirm = db.OpenRecordset("SELECT * FROM tblFirm" & SQLStatus & SQLSort, dbOpenDynaset)
RcSetFirm.MoveFirst
RcSetFirm.Move CurrentRecord - 1
OKButtonStatus = OK
Call UpdatePreviousNext
Call LockFields
HScroll.Min = 0
HScroll.Max = RecordQuantity - 1
Call ShowFields
End Sub

Sub SaveRepresentatives()
Dim a As Integer
For a = 0 To aRepresentatives.ListIndex
    RcSetFirmRepresentatives.AddNew
    RcSetFirmRepresentatives("fldIDFirm") = RcSetFirm("fldIDFirm")
    RcSetFirmRepresentatives("fldRepresentatives") = RcSetRepresentatives.Index
    RcSetFirmRepresentatives.Update
Next a
End Sub

Private Sub btnChangeRecord_Click()
WS.BeginTrans
Call UnLockFields
btnCancel.Visible = True
Call ButtonVisualisation(False)
frmInformation.Caption = "Изменение записи"
btnOK.Caption = "Изменить"
OKButtonStatus = Change
End Sub

Sub UnLockFields()
aFirmName.Locked = False
aProperties.Locked = False
aProduction.Locked = False
aRemark.Locked = False
btnAddRepresentatives.Enabled = True
btnDeleteRepresentatives.Enabled = True
btnChangeRepresentatives.Enabled = True
End Sub

Sub LockFields()
aFirmName.Locked = True
aProperties.Locked = True
aProduction.Locked = True
aRemark.Locked = True
btnAddRepresentatives.Enabled = False
btnDeleteRepresentatives.Enabled = False
btnChangeRepresentatives.Enabled = False
End Sub

Private Sub btnDeleteRecord_Click()
If MsgBox("Удалить запись из базы данных?", vbExclamation + vbYesNo, "Внимание") = vbYes Then
    Dim i
    For i = 1 To aRepresentatives.ListCount
        RcSetRepresentatives.MoveFirst
        RcSetRepresentatives.Delete
    Next i
    RcSetFirm.Delete
    RcSetFirm.MovePrevious
    If RcSetFirm.BOF Then RcSetFirm.MoveFirst
    Call ShowFields
    RecordQuantity = RecordQuantity - 1
    CurrentRecord = RcSetFirm.AbsolutePosition + 1
    HScroll.Max = HScroll.Max - 1
    HScroll.Value = HScroll.Max
    Call UpdatePreviousNext
End If
End Sub

Private Sub btnAddRepresentatives_Click()
Dim Str
Str = InputBox("Введите имя и должность", "Добавить представителя", "")
If Str <> "" Then
    aRepresentatives.AddItem Str
End If
End Sub

Private Sub btnAddRecord_Click()
WS.BeginTrans
Call UnLockFields
btnCancel.Visible = True
Call ClearFields
Call ButtonVisualisation(False)
frmInformation.Caption = "Добавление новой фирмы в базу данных"
btnOK.Caption = "Добавить"
OKButtonStatus = Add
RcSetFirm.AddNew
RcSetFirm("fldIDFirm") = Now
StatusOn.Value = True
StatusOff.Value = False
Call FillZero
RcSetFirm.Update
RcSetFirm.MoveLast
End Sub

Sub UpdateRecord()
RcSetFirm("fldFirmName") = aFirmName.Text
RcSetFirm("fldProperties") = aProperties.Text
RcSetFirm("fldProduction") = aProduction.Text
RcSetFirm("fldRemark") = aRemark.Text
If StatusOn.Value = True Then RcSetFirm("fldStatus") = "+" Else RcSetFirm("fldStatus") = "-"
End Sub

Private Sub btnCancel_Click()
WS.Rollback
Call LockFields
Call ButtonVisualisation(True)
btnCancel.Visible = False
RcSetFirm.MoveLast
Call ShowFields
End Sub

Private Sub btnOK_Click()
Select Case OKButtonStatus
    Case OK
        Unload Me
    Case Change
        WS.CommitTrans
        Call UpdateRepresentatives
        RcSetFirm.Edit
        Call UpdateRecord
        Call FillZero
        RcSetFirm.Update
        Call ButtonVisualisation(True)
        btnCancel.Visible = False
        Call LockFields
    Case Add
        WS.CommitTrans
        Call UpdateRepresentatives
        RcSetFirm.Edit
        Call UpdateRecord
        Call FillZero
        RcSetFirm.Update
        RcSetFirm.MoveLast
        Call SaveRepresentatives
        RecordQuantity = RecordQuantity + 1
        CurrentRecord = RecordQuantity
        HScroll.Max = HScroll.Max + 1
        HScroll.Value = HScroll.Max
        Call ButtonVisualisation(True)
        btnCancel.Visible = False
        Call UpdatePreviousNext
        Call LockFields
End Select
End Sub

Sub UpdatePreviousNext()
btnPreviousRecord.Enabled = True
btnNextRecord.Enabled = True
If CurrentRecord = 1 Then btnPreviousRecord.Enabled = False
If CurrentRecord = RecordQuantity Then btnNextRecord.Enabled = False
End Sub

Sub FillZero()
    If aFirmName.Text = "" Then RcSetFirm("fldFirmName") = "-"
    If aProperties.Text = "" Then RcSetFirm("fldProperties") = "-"
    If aProduction.Text = "" Then RcSetFirm("fldProduction") = "-"
    If aRemark.Text = "" Then RcSetFirm("fldRemark") = "-"
End Sub

Sub ButtonVisualisation(aVisible As Boolean)
    If aVisible = True Then
        btnPreviousRecord.Visible = True
        btnNextRecord.Visible = True
        btnChangeRecord.Visible = True
        btnAddRecord.Visible = True
        btnDeleteRecord.Visible = True
        HScroll.Visible = True
        frmInformation.Caption = "Информация о фирме"
        btnOK.Caption = "OK"
        OKButtonStatus = OK
    Else
        btnPreviousRecord.Visible = False
        btnNextRecord.Visible = False
        btnChangeRecord.Visible = False
        btnAddRecord.Visible = False
        btnDeleteRecord.Visible = False
        HScroll.Visible = False
    End If
End Sub

Private Sub btnNextRecord_Click()
btnPreviousRecord.Enabled = True
If CurrentRecord < RecordQuantity Then
    If CurrentRecord + 1 = RecordQuantity Then btnNextRecord.Enabled = False
    RcSetFirm.MoveNext
    CurrentRecord = RcSetFirm.AbsolutePosition + 1
    HScroll.Value = RcSetFirm.AbsolutePosition
End If
Call ShowFields
End Sub

Private Sub btnPreviousRecord_Click()
btnNextRecord.Enabled = True
If CurrentRecord > 1 Then
    If CurrentRecord - 1 = 1 Then btnPreviousRecord.Enabled = False
    RcSetFirm.MovePrevious
    CurrentRecord = RcSetFirm.AbsolutePosition + 1
    HScroll.Value = RcSetFirm.AbsolutePosition
End If
Call ShowFields
End Sub

Private Sub btnDeleteRepresentatives_Click()
If aRepresentatives.ListIndex >= 0 Then
    RcSetRepresentatives.MoveFirst
    RcSetRepresentatives.Move aRepresentatives.ListIndex
    RcSetRepresentatives.Edit
    RcSetRepresentatives.Delete
    aRepresentatives.RemoveItem (aRepresentatives.ListIndex)
Else: MsgBox "Не выбрано ни одно из значений", vbCritical, "Ошибка"
End If
End Sub

Sub ShowFields()
If RcSetFirm("fldFirmName") = "-" Then aFirmName.Text = "" Else aFirmName.Text = RcSetFirm("fldFirmName")
If RcSetFirm("fldProperties") = "-" Then aProperties.Text = "" Else aProperties.Text = RcSetFirm("fldProperties")
If RcSetFirm("fldProduction") = "-" Then aProduction.Text = "" Else aProduction.Text = RcSetFirm("fldProduction")
If RcSetFirm("fldRemark") = "-" Then aRemark.Text = "" Else aRemark.Text = RcSetFirm("fldRemark")
If RcSetFirm("fldStatus") = "+" Then StatusOn.Value = True Else StatusOn.Value = False
StatusOff.Value = Not StatusOn.Value
Dim a As String, aa As String, aaa As String
aa = RcSetFirm("fldIDFirm")
a = "tblRepresentatives.fldIDFirm = '" & aa & "'"
On Error GoTo ERROR:
Set RcSetRepresentatives = db.OpenRecordset("SELECT tblRepresentatives.fldRepresentatives, tblRepresentatives.fldIDFirm FROM tblRepresentatives WHERE " & a, dbOpenDynaset)
aRepresentatives.Clear
Do While Not RcSetRepresentatives.EOF
    aRepresentatives.AddItem RcSetRepresentatives("fldRepresentatives")
    RcSetRepresentatives.MoveNext
Loop
GoTo END_P
ERROR:
    aRepresentatives.Clear
END_P:
End Sub

Sub ClearFields()
aFirmName.Text = ""
aProperties.Text = ""
aProduction.Text = ""
aRemark.Text = ""
aRepresentatives.Clear
End Sub

Private Sub HScroll_Change()
RcSetFirm.MoveFirst
RcSetFirm.Move HScroll.Value
Call ShowFields
CurrentRecord = HScroll.Value + 1
Call UpdatePreviousNext
End Sub
