VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} MergeLawsDlg 
   Caption         =   "Отождествить документы"
   ClientHeight    =   3480
   ClientLeft      =   120
   ClientTop       =   465
   ClientWidth     =   10695
   OleObjectBlob   =   "MergeLawsDlg.frx":0000
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "MergeLawsDlg"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public isCancelled_ As Boolean

Private database_ As InfoDatabase

Private Sub UserForm_Initialize()
  isCancelled_ = True
  Call PositionInMiddle(Me)
End Sub

Public Function Init(theDB As InfoDatabase)
  isCancelled_ = True
  Set database_ = theDB
End Function

Public Function GetMerge() As ItemMerge
  Set GetMerge = New ItemMerge
  With GetMerge
    .delete_ = tbDocument1.Value
    .substitute_ = tbDocument2.Value
  End With
End Function

' ============
Private Sub btnValidate1_Click()
  Dim iLaw As IteratorLaw: Set iLaw = ValidateGid(tbDocument1.Value)
  If iLaw Is Nothing Then
    tbTitle1.Text = "Документ отсутствует в Реестре"
  Else
    tbTitle1.Text = iLaw.Title
  End If
End Sub

Private Sub btnValidate2_Click()
  Dim iLaw As IteratorLaw: Set iLaw = ValidateGid(tbDocument2.Value)
  If iLaw Is Nothing Then
    tbTitle2.Text = "Документ отсутствует в Реестре"
  Else
    tbTitle2.Text = iLaw.Title
  End If
End Sub

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

Private Sub btnOK_Click()
  Dim sGid1$: sGid1 = tbDocument1.Value
  Dim sGid2$: sGid2 = tbDocument2.Value
  If sGid1 = sGid2 Or ValidateGid(sGid1) Is Nothing Or ValidateGid(sGid2) Is Nothing Then
    Call UserInteraction.ShowMessage(EM_MERGE_VALIDATION_FAILED)
    Exit Sub
  End If
  isCancelled_ = False
  Call Me.Hide
End Sub

' ============
Private Function ValidateGid(sGid$) As IteratorLaw
  If Not IsNumeric(sGid) Then
    Call UserInteraction.ShowMessage(EM_ID_INVALID_FORMAT)
    Exit Function
  End If
  
  Dim gid&: gid = CLng(sGid)
  If Not database_.Contains(gid) Then _
    Exit Function
    
  Set ValidateGid = database_.Data(gid)
End Function
