VERSION 5.00
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
Begin VB.Form frmContract 
   BackColor       =   &H00C0C0C0&
   Caption         =   "Обязательства/подробности"
   ClientHeight    =   6360
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8550
   Icon            =   "frmContract.frx":0000
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   ScaleHeight     =   6360
   ScaleWidth      =   8550
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton btnList 
      Caption         =   "Список"
      Height          =   375
      Left            =   6840
      TabIndex        =   35
      Top             =   2880
      Width           =   1455
   End
   Begin VB.ComboBox Combo3 
      Height          =   315
      ItemData        =   "frmContract.frx":08CA
      Left            =   240
      List            =   "frmContract.frx":08D1
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   480
      Width           =   3255
   End
   Begin VB.Frame Frame1 
      Caption         =   "Сортировать по"
      Height          =   1455
      Left            =   6840
      TabIndex        =   30
      Top             =   1200
      Width           =   1575
      Begin VB.OptionButton Option1 
         Caption         =   "Нет"
         Height          =   375
         Left            =   120
         TabIndex        =   32
         Top             =   240
         Width           =   1215
      End
      Begin VB.OptionButton Option3 
         Caption         =   "Убыванию"
         Height          =   255
         Left            =   120
         TabIndex        =   34
         Top             =   1080
         Width           =   1215
      End
      Begin VB.OptionButton Option2 
         Caption         =   "Возрастанию"
         Height          =   195
         Left            =   120
         TabIndex        =   33
         Top             =   720
         Width           =   1335
      End
   End
   Begin VB.ComboBox ComboPeriod 
      Height          =   315
      ItemData        =   "frmContract.frx":08DA
      Left            =   6840
      List            =   "frmContract.frx":08F0
      TabIndex        =   28
      Text            =   "Все"
      Top             =   480
      Width           =   1575
   End
   Begin VB.CommandButton aLast 
      Caption         =   ">|"
      Height          =   375
      Left            =   7560
      TabIndex        =   25
      Top             =   5160
      Width           =   735
   End
   Begin VB.CommandButton aFirst 
      Caption         =   "|<"
      Height          =   375
      Left            =   6840
      TabIndex        =   24
      Top             =   5160
      Width           =   735
   End
   Begin VB.CommandButton aNext 
      Caption         =   ">>"
      Height          =   375
      Left            =   7560
      TabIndex        =   23
      Top             =   4800
      Width           =   735
   End
   Begin VB.ComboBox Combo2 
      Height          =   315
      ItemData        =   "frmContract.frx":0927
      Left            =   3600
      List            =   "frmContract.frx":0934
      Style           =   2  'Dropdown List
      TabIndex        =   27
      Top             =   480
      Width           =   2895
   End
   Begin VB.TextBox aFirmName 
      BackColor       =   &H80000000&
      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            =   1320
      Locked          =   -1  'True
      TabIndex        =   26
      Top             =   1920
      Width           =   4815
   End
   Begin VB.CommandButton btnDelete 
      Caption         =   "Удалить"
      Height          =   375
      Left            =   6840
      TabIndex        =   13
      Top             =   3360
      Width           =   1455
   End
   Begin VB.CommandButton btnChange 
      Caption         =   "Изменить"
      Height          =   375
      Left            =   6840
      TabIndex        =   14
      Top             =   3840
      Width           =   1455
   End
   Begin VB.CommandButton btnAdd 
      Caption         =   "Добавить"
      Height          =   375
      Left            =   6840
      TabIndex        =   15
      Top             =   4320
      Width           =   1455
   End
   Begin VB.CommandButton aPrevious 
      Caption         =   "<<"
      Height          =   375
      Left            =   6840
      TabIndex        =   22
      Top             =   4800
      Width           =   735
   End
   Begin VB.TextBox aRemark 
      Height          =   855
      Left            =   600
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      TabIndex        =   5
      Top             =   4920
      Width           =   5535
   End
   Begin VB.TextBox aFact 
      Height          =   375
      Left            =   4440
      Locked          =   -1  'True
      TabIndex        =   6
      Top             =   2760
      Width           =   1695
   End
   Begin VB.TextBox aDescription 
      Height          =   1095
      Left            =   600
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      TabIndex        =   4
      Top             =   3480
      Width           =   5535
   End
   Begin VB.TextBox aDate 
      Height          =   375
      Left            =   600
      Locked          =   -1  'True
      TabIndex        =   3
      Top             =   2760
      Width           =   1575
   End
   Begin TabDlg.SSTab SSTab1 
      Height          =   4935
      Left            =   240
      TabIndex        =   2
      Top             =   1200
      Width           =   6255
      _ExtentX        =   11033
      _ExtentY        =   8705
      _Version        =   393216
      Tabs            =   2
      TabsPerRow      =   2
      TabHeight       =   520
      TabCaption(0)   =   "Обязательства собственные"
      TabPicture(0)   =   "frmContract.frx":0975
      Tab(0).ControlEnabled=   -1  'True
      Tab(0).Control(0)=   "Label1(0)"
      Tab(0).Control(0).Enabled=   0   'False
      Tab(0).Control(1)=   "Label2(0)"
      Tab(0).Control(1).Enabled=   0   'False
      Tab(0).Control(2)=   "Label3(0)"
      Tab(0).Control(2).Enabled=   0   'False
      Tab(0).Control(3)=   "Label4(0)"
      Tab(0).Control(3).Enabled=   0   'False
      Tab(0).Control(4)=   "Label7(0)"
      Tab(0).Control(4).Enabled=   0   'False
      Tab(0).ControlCount=   5
      TabCaption(1)   =   "Обязательства партнеров"
      TabPicture(1)   =   "frmContract.frx":0991
      Tab(1).ControlEnabled=   0   'False
      Tab(1).Control(0)=   "Label11(1)"
      Tab(1).Control(0).Enabled=   0   'False
      Tab(1).Control(1)=   "Label12(1)"
      Tab(1).Control(1).Enabled=   0   'False
      Tab(1).Control(2)=   "Label14(1)"
      Tab(1).Control(2).Enabled=   0   'False
      Tab(1).Control(3)=   "Label13(1)"
      Tab(1).Control(3).Enabled=   0   'False
      Tab(1).Control(4)=   "Label7(1)"
      Tab(1).Control(4).Enabled=   0   'False
      Tab(1).ControlCount=   5
      Begin VB.Label Label7 
         Caption         =   "Фирма"
         Height          =   255
         Index           =   1
         Left            =   -74640
         TabIndex        =   21
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label7 
         Caption         =   "Фирма"
         Height          =   255
         Index           =   0
         Left            =   360
         TabIndex        =   20
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label13 
         Caption         =   "Договорное обязательство"
         Height          =   255
         Index           =   1
         Left            =   -74640
         TabIndex        =   18
         Top             =   2040
         Width           =   2175
      End
      Begin VB.Label Label14 
         Caption         =   "Примечание"
         Height          =   255
         Index           =   1
         Left            =   -74640
         TabIndex        =   17
         Top             =   3480
         Width           =   975
      End
      Begin VB.Label Label4 
         Caption         =   "Примечание"
         Height          =   255
         Index           =   0
         Left            =   360
         TabIndex        =   16
         Top             =   3480
         Width           =   975
      End
      Begin VB.Label Label3 
         Caption         =   "Договорное обязательство"
         Height          =   255
         Index           =   0
         Left            =   360
         TabIndex        =   12
         Top             =   2040
         Width           =   2175
      End
      Begin VB.Label Label12 
         Caption         =   "Факт"
         Height          =   255
         Index           =   1
         Left            =   -70800
         TabIndex        =   11
         Top             =   1320
         Width           =   855
      End
      Begin VB.Label Label11 
         Caption         =   "Срок"
         Height          =   255
         Index           =   1
         Left            =   -74640
         TabIndex        =   10
         Top             =   1320
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "Факт"
         Height          =   255
         Index           =   0
         Left            =   4200
         TabIndex        =   9
         Top             =   1320
         Width           =   495
      End
      Begin VB.Label Label1 
         Caption         =   "Срок"
         Height          =   255
         Index           =   0
         Left            =   360
         TabIndex        =   8
         Top             =   1320
         Width           =   375
      End
   End
   Begin VB.CommandButton btnOK 
      Caption         =   "ОК"
      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            =   6840
      TabIndex        =   0
      Top             =   5760
      Width           =   1455
   End
   Begin VB.Line Line3 
      X1              =   6840
      X2              =   8400
      Y1              =   1080
      Y2              =   1080
   End
   Begin VB.Line Line2 
      X1              =   8400
      X2              =   8400
      Y1              =   840
      Y2              =   1080
   End
   Begin VB.Line Line1 
      DrawMode        =   1  'Blackness
      X1              =   6840
      X2              =   6840
      Y1              =   840
      Y2              =   1080
   End
   Begin VB.Label LabelDate 
      Alignment       =   2  'Center
      Height          =   255
      Left            =   6960
      TabIndex        =   31
      Top             =   840
      Width           =   1335
   End
   Begin VB.Label Label8 
      Caption         =   "Период (ввод в днях)"
      Height          =   255
      Left            =   6840
      TabIndex        =   29
      Top             =   240
      Width           =   1695
   End
   Begin VB.Label Label6 
      Caption         =   "Критерий отображения записей"
      Height          =   255
      Left            =   3600
      TabIndex        =   19
      Top             =   240
      Width           =   2535
   End
   Begin VB.Label Label5 
      Caption         =   "Отобразить данные по фирме"
      Height          =   255
      Left            =   240
      TabIndex        =   7
      Top             =   240
      Width           =   2415
   End
End
Attribute VB_Name = "frmContract"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private IDFirm As String
Private SQLPeriod As String
Private SQLSort As String
Private SQLFirm As String

Private Function GetYear(ByVal D As Date) As Integer
If Year(D) < 2000 Then
    GetYear = Year(D) - 1900
Else
    GetYear = Year(D) - 2000
End If
End Function

Private Sub ComboPeriod_Change()
Dim D
If ComboPeriod.ListIndex = 0 Then
    SQLPeriod = ""
    LabelDate.Visible = False
Else
    D = Date + ComboPeriod.Text
    SQLPeriod = " AND fldDate <= #" & Month(D) & "/" & Day(D) & "/" & GetYear(D) & "#"
    LabelDate.Caption = "по " & D
    LabelDate.Visible = True
End If
Call NewRequest
End Sub

Private Sub ComboPeriod_Click()
Dim D
Select Case ComboPeriod.ListIndex
    Case 0
        SQLPeriod = ""
        LabelDate.Visible = False
        Call NewRequest
        Exit Sub
    Case 1
        D = Date + 15
    Case 2
        D = Date + 30
    Case 3
        D = Date + 91
    Case 4
        D = Date + 182
    Case 5
        D = Date + 365
End Select
SQLPeriod = " AND fldDate <= #" & Month(D) & "/" & Day(D) & "/" & GetYear(D) & "#"
LabelDate.Caption = "по " & D
LabelDate.Visible = True
Call NewRequest
End Sub

Private Sub Combo2_Click()
Select Case Combo2.ListIndex
    Case 1
        SQLContract = " AND fldFact = #5/27/99#"
    Case 2
        SQLContract = " AND fldFact <> #5/27/99#"
    Case Else
        SQLContract = ""
End Select
Call NewRequest
End Sub

Private Sub Form_Load()
'Option3.SetFocus
Option1.Value = True
Combo2.ListIndex = 0
Combo3.ListIndex = 0
If FormStatus <> FSAdd Then Call ShowFields
RcSetFirmList.MoveFirst
While Not RcSetFirmList.EOF
    Combo3.AddItem RcSetFirmList("fldFirmName")
    RcSetFirmList.MoveNext
Wend
Call NewRequest
End Sub

Sub ShowFields()
On Error GoTo q
If RcSetContract("fldDate") <> #5/27/1999# Then aDate.Text = RcSetContract("fldDate") Else aDate.Text = ""
If RcSetContract("fldFact") <> #5/27/1999# Then aFact.Text = RcSetContract("fldFact") Else aFact.Text = ""
If RcSetContract("fldDescription") <> "" Then aDescription.Text = RcSetContract("fldDescription") Else aDescription.Text = ""
If RcSetContract("fldRemark") <> "" Then aRemark.Text = RcSetContract("fldRemark") Else aRemark.Text = ""
RcSetFirmList.FindFirst ("fldIDFirm = '" & RcSetContract("fldIDFirm") & "'")
aFirmName.Text = RcSetFirmList("fldFirmName")
GoTo qq
q: Call ClearFields
qq:
End Sub

Sub ClearFields()
aDate.Text = ""
aFact.Text = ""
aDescription.Text = ""
aRemark.Text = ""
aFirmName.Text = ""
End Sub

Sub UpdateRecord()
If aDate.Text <> "" Then RcSetContract("fldDate") = aDate.Text Else RcSetContract("fldDate") = #5/27/1999#
If aFact.Text <> "" Then RcSetContract("fldFact") = aFact.Text Else RcSetContract("fldFact") = #5/27/1999#
If aDescription.Text <> "" Then RcSetContract("fldDescription") = aDescription.Text
If aRemark.Text <> "" Then RcSetContract("fldRemark") = aRemark.Text
End Sub

Private Sub aNext_Click()
If Combo3.ListIndex = 0 And FormStatus = FSAdd Then
    MsgBox "Задайте наименование фирмы", vbCritical, "Ошибка"
Else
    Call UpdateDataBase
    RcSetContract.MoveNext
    If RcSetContract.EOF Then RcSetContract.MoveLast
    Call ShowFields
End If
End Sub

Private Sub aPrevious_Click()
If Combo3.ListIndex = 0 And FormStatus = FSAdd Then
    MsgBox "Задайте наименование фирмы", vbCritical, "Ошибка"
Else
    Call UpdateDataBase
    RcSetContract.MovePrevious
    If RcSetContract.BOF Then RcSetContract.MoveFirst
    Call ShowFields
End If
End Sub

Private Sub aFirst_Click()
If Combo3.ListIndex = 0 And FormStatus = FSAdd Then
    MsgBox "Задайте наименование фирмы", vbCritical, "Ошибка"
Else
    Call UpdateDataBase
    RcSetContract.MoveFirst
    Call ShowFields
End If
End Sub

Private Sub aLast_Click()
If Combo3.ListIndex = 0 And FormStatus = FSAdd Then
    MsgBox "Задайте наименование фирмы", vbCritical, "Ошибка"
Else
    Call UpdateDataBase
    RcSetContract.MoveLast
    Call ShowFields
End If
End Sub

Private Sub btnChange_Click()
FormStatus = FSChange
btnOK.Caption = "Изменить"
Call UnLockFields
Call ActivateButton(FSChange)
End Sub

Sub UnLockFields()
aDate.Locked = False
aFact.Locked = False
aDescription.Locked = False
aRemark.Locked = False
End Sub

Sub LockFields()
aDate.Locked = True
aFact.Locked = True
aDescription.Locked = True
aRemark.Locked = True
End Sub

Private Sub btnAdd_Click()
FormStatus = FSAdd
btnOK.Caption = "Добавить"
Call UnLockFields
aDate.SetFocus
Call ActivateButton(FSAdd)
Call ClearFields
End Sub

Private Sub btnDelete_Click()
If MsgBox("Удалить запись ?", vbExclamation + vbYesNo, "Внимание") = vbYes Then
    RcSetContract.Delete
    Call NewRequest
End If
End Sub

Sub ActivateButton(Status As EFormStatus)
If Status = FSChange Or Status = FSAdd Or Status = FSNoRecord Then
    aNext.Enabled = False
    aPrevious.Enabled = False
    aFirst.Enabled = False
    aLast.Enabled = False
    Option1.Enabled = False
    Option2.Enabled = False
    Option3.Enabled = False
    btnChange.Enabled = False
    If Status <> FSNoRecord Then btnAdd.Enabled = False
    btnDelete.Enabled = False
    If Status = FSChange Or Status = FSAdd Then
        Combo2.Enabled = False
        ComboPeriod.Enabled = False
    End If
End If
If Status = FSNone Then
    aNext.Enabled = True
    aPrevious.Enabled = True
    aFirst.Enabled = True
    aLast.Enabled = True
    Combo2.Enabled = True
    ComboPeriod.Enabled = True
    Option1.Enabled = True
    Option2.Enabled = True
    Option3.Enabled = True
    btnChange.Enabled = True
    btnAdd.Enabled = True
    btnDelete.Enabled = True
End If
'If Status = FSNoRecord Then Combo2.Enabled = False
End Sub

Sub UpdateDataBase()
If FormStatus = FSAdd Then
    RcSetContract.AddNew
    Call UpdateRecord
    'RcSetContract("fldIDContract") = Now
    RcSetContract("fldResponsible") = SSTab1.Tab
    RcSetFirmList.FindFirst ("fldFirmName = '" & Combo3.Text & "'")
    IDFirm = RcSetFirmList("fldIDFirm")
    RcSetContract("fldIDFirm") = IDFirm
    RcSetContract("fldResponsible") = SSTab1.Tab
    RcSetContract.Update
    ActivateButton (None)
End If
If FormStatus = FSChange Then
    RcSetContract.Edit
    Call UpdateRecord
    RcSetContract.Update
End If
If FormStatus = FSAdd Then btnOK.Caption = "ОК"
FormStatus = FSNone
'Call ActivateObject(FSAdd)
'If RcSetContract.EOF Then RcSetContract.MoveLast
End Sub

Private Sub btnOK_Click()
If Combo3.ListIndex = 0 And FormStatus = FSAdd Then
    MsgBox "Задайте наименование фирмы", vbCritical, "Ошибка"
    Exit Sub
Else
    If FormStatus = FSAdd Or FormStatus = FSChange Then
        Call LockFields
        btnOK.Caption = "OK"
        Call UpdateDataBase
        Call NewRequest
        FormStatus = FSNone
        ActivateButton (None)
    Else
        Unload Me
    End If
End If
End Sub

Sub NewRequest()
Dim aa
On Error GoTo q
SQLMainContract = "SELECT fldIDFirm, fldDescription, fldRemark, fldDate, fldFact, fldResponsible FROM tblContract WHERE fldResponsible = '" & SSTab1.Tab & "'" & SQLFirm & SQLContract & SQLPeriod & SQLSort
Set RcSetContract = db.OpenRecordset(SQLMainContract, dbOpenDynaset)
RcSetContract.MoveFirst
Call ShowFields
GoTo qq
q:
ActivateButton (FSNoRecord)
Call ClearFields
    GoTo qqq
qq:
ActivateButton (None)
qqq:
End Sub

Private Sub Option1_Click()
SQLSort = ""
Call NewRequest
End Sub

Private Sub Option2_Click()
SQLSort = " ORDER BY fldDate"
Call NewRequest
End Sub

Private Sub Option3_Click()
SQLSort = " ORDER BY fldDate DESC"
Call NewRequest
End Sub

Private Sub SSTab1_Click(PreviousTab As Integer)
Call NewRequest
'Call ShowFields
End Sub

Private Sub Combo3_Click()
Dim IDFirm
If Combo3.ListIndex <> 0 Then
    RcSetFirmList.FindFirst ("fldFirmName = '" & Combo3.Text & "'")
    IDFirm = RcSetFirmList("fldIDFirm")
    SQLFirm = " AND fldIDFirm = '" & IDFirm & "'"
Else
    SQLFirm = ""
End If
If Combo3.ListIndex <> 0 Then aFirmName.Text = Combo3.Text
If FormStatus = FSAdd Then
    RcSetFirmList.FindFirst ("fldFirmName = '" & Combo3.Text & "'")
    IDFirm = RcSetFirmList("fldIDFirm")
    SQLFirm = " AND fldIDFirm = '" & IDFirm & "'"
Else
    Call NewRequest
End If
End Sub

Private Sub btnList_Click()
frmContractChild.Show 1
End Sub
