VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "IteratorLaw"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private index_ As InfoDatabase
Private row_ As Long
Private sheet_ As Excel.Worksheet

Public Function Init(theDB As InfoDatabase, target As Excel.Worksheet, Optional nRow& = HT03_DEFAULT_FIRST_LINE)
  Set index_ = theDB
  Set sheet_ = target
  row_ = nRow
End Function

Public Function Increment(Optional inc& = 1)
  If row_ + inc > 0 Then _
    row_ = row_ + inc
End Function

Public Function GoFirst()
  row_ = HT03_DEFAULT_FIRST_LINE
End Function

Public Function GoLast()
  row_ = sheet_.Columns(S_D_GARANT_ID).Find(vbNullString, LookAt:=xlWhole).Row - 1
  If row_ < HT03_DEFAULT_FIRST_LINE Then _
    row_ = HT03_DEFAULT_FIRST_LINE
End Function

Public Function IsDone() As Boolean
  IsDone = sheet_.Cells(row_, LawStruct.S_D_GARANT_ID) = vbNullString
End Function

Public Function HasInfoBlanks() As Boolean
  HasInfoBlanks = True
  
  If TypeText = vbNullString Then _
    Exit Function
  If Creator = vbNullString Then _
    Exit Function
  If CreationDate = vbNullString Then _
    Exit Function
  If Number = vbNullString Then _
    Exit Function
  If Header = vbNullString Then _
    Exit Function
  If Attachment = vbNullString Then _
    Exit Function
  If sheet_.Cells(row_, LawStruct.S_D_TIME_SCOPED) = vbNullString Then _
    Exit Function
    
  HasInfoBlanks = False
End Function

Public Function IsActive() As Boolean
  Dim theStatus As TLawStatus: theStatus = Status
  IsActive = theStatus = T_LAWS_FULL Or theStatus = T_LAWS_FRINGE Or theStatus = T_LAWS_OUTER
End Function

Public Function HasLinks() As Boolean
  Dim theStatus As TLawStatus: theStatus = Status
  HasLinks = theStatus = T_LAWS_FULL Or theStatus = T_LAWS_FRINGE
End Function

Public Function HasFile() As Boolean
  Dim sFile$: sFile = FileName
  HasFile = sFile <> HT03_FILE_NOT_LOADED And sFile <> vbNullString
End Function

Public Function IsLoaded() As Boolean
  Dim sTitle$: sTitle = Title
  IsLoaded = sTitle <> HT03_TITLE_NOT_LOADED And sTitle <> vbNullString And Not IsDummy
End Function

Public Function CreateIndexItem() As ItemCachedLaw
  Dim result As New ItemCachedLaw
  Call result.Init(Me)
  Set CreateIndexItem = result
End Function

Public Function Links() As IteratorLinkLaw
  Set Links = index_.LawLinks(ID)
End Function

Public Function Find(target$, colN As LawStruct) As Boolean
  Dim foundRng As Excel.Range:
  Set foundRng = sheet_.Columns(colN).Find(target, LookAt:=xlWhole)
  Find = Not foundRng Is Nothing
  If Find Then _
    row_ = foundRng.Row
End Function

'===== Get =====
Public Function GetVaueIn(colID&) As String
  GetVaueIn = sheet_.Cells(row_, colID)
End Function

Public Property Get Data() As ItemLaw
  Set Data = New ItemLaw
  With Data
    .gid_ = ID
    .status_ = Status
    .type_ = DType
    .fileName_ = FileName
    .title_ = Title
    .typeTxt_ = TypeText
    .creator_ = Creator
    .date_ = CreationDate
    .number_ = Number
    .header_ = Header
    .attach_ = Attachment
    .isScoped_ = IsScoped
    .isDummy_ = IsDummy
  End With
End Property

Public Property Get Row() As Long
  Row = row_
End Property

Public Property Get ID() As Long
  ID = CLng(sheet_.Cells(row_, LawStruct.S_D_GARANT_ID))
End Property

Public Property Get Status() As TLawStatus
  Status = CInt(sheet_.Cells(row_, LawStruct.S_D_STATUS))
End Property

Public Property Get DType() As TLawType
  DType = CInt(sheet_.Cells(row_, LawStruct.S_D_TYPE))
End Property

Public Property Get FileName() As String
  FileName = sheet_.Cells(row_, LawStruct.S_D_FILENAME)
End Property

Public Property Get Title() As String
  Title = sheet_.Cells(row_, LawStruct.S_D_TITLE)
End Property

Public Property Get TypeText() As String
  TypeText = sheet_.Cells(row_, LawStruct.S_D_TYPE_TXT)
End Property

Public Property Get Creator() As String
  Creator = sheet_.Cells(row_, LawStruct.S_D_CREATOR)
End Property

Public Property Get CreationDate() As String
  CreationDate = sheet_.Cells(row_, LawStruct.S_D_DATE)
End Property

Public Property Get Number() As String
  Number = sheet_.Cells(row_, LawStruct.S_D_NUMBER)
End Property

Public Property Get Header() As String
  Header = sheet_.Cells(row_, LawStruct.S_D_HEADER)
End Property

Public Property Get Attachment() As String
  Attachment = sheet_.Cells(row_, LawStruct.S_D_ATTACH)
End Property

Public Property Get IsScoped() As Boolean
  IsScoped = sheet_.Cells(row_, LawStruct.S_D_TIME_SCOPED) = 1
End Property

Public Property Get IsDummy() As Boolean
  IsDummy = sheet_.Cells(row_, LawStruct.S_D_IS_DUMMY) = 1
End Property

Public Property Get LinkBase() As Long
  LinkBase = CLng(sheet_.Cells(row_, LawStruct.S_D_LINKBASE))
End Property

'===== Let =====
Public Function SetData(dataItem As ItemLaw, nLinkBase&)
' Добавление данных на лист (без обновления индекса)
  With sheet_
    .Cells(row_, S_D_GARANT_ID) = dataItem.gid_
    .Cells(row_, S_D_STATUS) = dataItem.status_
    .Cells(row_, S_D_TYPE) = dataItem.type_
    .Cells(row_, S_D_TITLE) = dataItem.title_
    .Cells(row_, S_D_TYPE_TXT) = dataItem.typeTxt_
    .Cells(row_, S_D_CREATOR) = dataItem.creator_
    .Cells(row_, S_D_DATE) = dataItem.date_
    .Cells(row_, S_D_NUMBER) = dataItem.number_
    .Cells(row_, S_D_HEADER) = dataItem.header_
    .Cells(row_, S_D_ATTACH) = dataItem.attach_
    .Cells(row_, S_D_TIME_SCOPED) = IIf(dataItem.isScoped_, 1, 0)
    .Cells(row_, S_D_IS_DUMMY) = IIf(dataItem.isDummy_, 1, 0)
    .Cells(row_, S_D_LINKBASE) = nLinkBase
  End With
  FileName = dataItem.fileName_
End Function

Public Function SetVaueIn(colID&, val As Variant)
  sheet_.Cells(row_, colID) = val
End Function

Public Property Let Row(theRow&)
  row_ = theRow
End Property

Public Property Let ID(nID&)
  sheet_.Cells(row_, LawStruct.S_D_GARANT_ID) = nID
End Property

Public Property Let Status(nStat As TLawStatus)
   sheet_.Cells(row_, LawStruct.S_D_STATUS) = nStat
End Property

Public Property Let DType(nType As TLawType)
  sheet_.Cells(row_, LawStruct.S_D_TYPE) = nType
End Property

Public Property Let FileName(sNewFile$)
  Dim aCell As Excel.Range: Set aCell = sheet_.Cells(row_, LawStruct.S_D_FILENAME)
  
  aCell = sNewFile
  Call aCell.Hyperlinks.Delete
  If sNewFile = vbNullString Or sNewFile = HT03_FILE_NOT_LOADED Then _
    Exit Property
    
  Call aCell.Hyperlinks.Add(aCell, index_.DocumentsRelativePath & sNewFile)
End Property

Public Property Let Title(ntitle$)
  sheet_.Cells(row_, LawStruct.S_D_TITLE) = ntitle
End Property

Public Property Let TypeText(sType$)
  sheet_.Cells(row_, LawStruct.S_D_TYPE_TXT) = sType
End Property

Public Property Let Creator(sCreator$)
  sheet_.Cells(row_, LawStruct.S_D_CREATOR) = sCreator
End Property

Public Property Let CreationDate(sDate$)
  sheet_.Cells(row_, LawStruct.S_D_DATE) = sDate
End Property

Public Property Let Number(sNumber$)
  sheet_.Cells(row_, LawStruct.S_D_NUMBER) = sNumber
End Property

Public Property Let Header(sHeader$)
  sheet_.Cells(row_, LawStruct.S_D_HEADER) = sHeader
End Property

Public Property Let Attachment(sTitle$)
  sheet_.Cells(row_, LawStruct.S_D_ATTACH) = sTitle
End Property

Public Property Let IsScoped(bValue As Boolean)
  sheet_.Cells(row_, LawStruct.S_D_TIME_SCOPED) = IIf(bValue, 1, 0)
End Property

Public Property Let IsDummy(bValue As Boolean)
  sheet_.Cells(row_, LawStruct.S_D_IS_DUMMY) = IIf(bValue, 1, 0)
End Property

Public Property Let LinkBase(nRowN&)
  sheet_.Cells(row_, LawStruct.S_D_LINKBASE) = nRowN
End Property
