VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} NewDocumentDlg 
   Caption         =   "Параметры документа"
   ClientHeight    =   8670.001
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   9210.001
   OleObjectBlob   =   "NewDocumentDlg.frx":0000
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "NewDocumentDlg"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Const OPT_LEVEL_PRE = "optLevel"
Private Const OPT_STATUS_PRE = "OBStatus"

Private isNewID_ As Boolean
Private isDummy_ As Boolean

Public isCancelled_ As Boolean

Private Sub UserForm_Initialize()
  isCancelled_ = True
  isNewID_ = False
  
  Call cbDocType.AddItem("01. Не определен")
  Call cbDocType.AddItem("02. Международное законодательство")
  Call cbDocType.AddItem("03. Конституция")
  Call cbDocType.AddItem("04. Федеральный конституционный закон")
  Call cbDocType.AddItem("05. Кодекс")
  Call cbDocType.AddItem("06. Президент")
  Call cbDocType.AddItem("07. Федеральный закон")
  Call cbDocType.AddItem("08. Правительство")
  Call cbDocType.AddItem("09. Верховный суд")
  Call cbDocType.AddItem("10. Генеральная прокуратура")
  Call cbDocType.AddItem("11. Министерство")
  Call cbDocType.AddItem("12. Агентство, служба, ведомство")
  
  Call cbDocStatus.AddItem("1. ВНУТРЕННИЙ: рассматривать все связи")
  Call cbDocStatus.AddItem("2. ГРАНИЧНЫЙ: только связи внутри Реестра")
  Call cbDocStatus.AddItem("3. СПРАВОЧНЫЙ: без исходящих связей")
  Call cbDocStatus.AddItem("4. ИГНОРИРУЕМЫЙ: игнорировать все связи")
  
  Call cbPrefixType.AddItem("Мобильный")
  Call cbPrefixType.AddItem("Локально")
  Call cbPrefixType.AddItem("Интернет")
  
  tbType.Value = 1
  tbStatus.Value = 1

  Call PositionInMiddle(Me)
End Sub

Public Function Init(iLaw As ItemLaw, nSystem As TLinkSystem, bEdit As Boolean)
  isCancelled_ = True
  isNewID_ = iLaw.gid_ = HT03_INVALID_GID
  isDummy_ = iLaw.isDummy_
  
  tbGID.Text = CStr(iLaw.gid_)
  tbType.Value = iLaw.type_
  cbDocType.ListIndex = iLaw.type_ - 1
  tbStatus.Value = iLaw.status_
  cbDocStatus.ListIndex = iLaw.status_ - 1
  tbFileName.Text = iLaw.fileName_
  tbTitle.Text = iLaw.title_
  tbTypeText.Text = iLaw.typeTxt_
  tbCreator.Text = iLaw.creator_
  tbDate.Text = iLaw.date_
  tbNumber.Text = iLaw.number_
  tbHeader.Text = iLaw.header_
  tbAttach.Text = iLaw.attach_
  cbImmediate.Value = iLaw.isScoped_
  
  cbPrefixType.ListIndex = SystemIndexFor(nSystem)
  
  cbDeleteSource.Enabled = Not bEdit
  tbFileName.Enabled = Not bEdit
  
  Call UpdateGID
End Function

Property Get Properties() As ItemDocumentProperties
  Set Properties = New ItemDocumentProperties
  With Properties
    .data_.gid_ = CLng(tbGID.Text)
    .data_.type_ = cbDocType.ListIndex + 1
    .data_.status_ = cbDocStatus.ListIndex + 1
    .data_.title_ = SubstituteWhitespace(tbTitle.Text)
    .data_.fileName_ = Trim(tbFileName.Text)
    .data_.typeTxt_ = Trim(tbTypeText.Text)
    .data_.creator_ = Trim(tbCreator.Text)
    .data_.date_ = Trim(tbDate.Text)
    .data_.number_ = Trim(tbNumber.Text)
    .data_.header_ = Trim(tbHeader.Text)
    .data_.attach_ = Trim(tbAttach.Text)
    .data_.isScoped_ = cbImmediate.Value
    .data_.isDummy_ = isDummy_
    
    .linkSystem_ = SystemTypeFor(cbPrefixType.ListIndex)
    .mods_.deleteRevision_ = CBDeleteChange.Value
    .mods_.deleteComment_ = CBDelComment.Value
    .mods_.deleteImages_ = CBDeleteImages.Value
    .killSource_ = cbDeleteSource.Value
  End With
End Property

' ===================
Private Sub tbTitle_Change()
  Call UpdateGID
End Sub

Private Sub btnOK_Click()
  If tbTitle.Text = vbNullString Or tbFileName.Text = vbNullString Then
    Call UserInteraction.ShowMessage(EM_FILENAME_EMPTY)
    Exit Sub
  End If
  
  If VBA.Len(tbFileName.Text) + Len(AccessDatabase.docsLocation_) > 250 Then
    Call UserInteraction.ShowMessage(EM_FILENAME_TOO_LONG)
    Exit Sub
  End If
  
  isCancelled_ = False
  Call Me.Hide
End Sub

Private Sub btnCancel_Click()
  isCancelled_ = True
  Call Me.Hide
End Sub

Private Sub tbStatus_Change()
  Dim sStatus$: sStatus = tbStatus.Text
  If Not IsNumeric(sStatus) Then _
    Exit Sub
  Dim val&: val = CLng(sStatus)
  If val < 1 Or val > cbDocStatus.ListCount Then _
    Exit Sub
  cbDocStatus.ListIndex = val - 1
End Sub

Private Sub tbType_Change()
  Dim sType$: sType = tbType.Text
  If Not IsNumeric(sType) Then _
    Exit Sub
    
  Dim val&: val = CLng(sType)
  If val < 1 Or val > cbDocType.ListCount Then _
    Exit Sub
    
  cbDocType.ListIndex = val - 1
End Sub

Private Sub cbDocStatus_Change()
  tbStatus.Value = cbDocStatus.ListIndex + 1
End Sub

Private Sub cbDocType_Change()
  tbType.Value = cbDocType.ListIndex + 1
End Sub

' =================
Private Function UpdateGID()
  If Not isNewID_ Then _
    Exit Function
  
  tbGID.Text = AccessDatabase.GenerateID(tbTitle.Text)
End Function

Private Function SystemIndexFor(pType As TLinkSystem) As Long
  Select Case pType
    Case PT_MOBILE: SystemIndexFor = 0
    Case PT_LOCAL: SystemIndexFor = 1
    Case PT_INTERNET: SystemIndexFor = 2
  End Select
End Function

Private Function SystemTypeFor(nIndex&) As TLinkSystem
  Select Case nIndex
    Case 0: SystemTypeFor = PT_MOBILE
    Case 1: SystemTypeFor = PT_LOCAL
    Case 2: SystemTypeFor = PT_INTERNET
  End Select
End Function

