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

Private data_ As Excel.Worksheet
Private attributes_ As Excel.Worksheet

Public Function Init(iData As Excel.Worksheet, iAttributes As Excel.Worksheet)
  Set data_ = iData
  Set attributes_ = iAttributes
End Function

Public Function Attributes() As IteratorAttribute
  Set Attributes = New IteratorAttribute
  Call Attributes.Init(attributes_)
End Function

Public Function IBegin() As IteratorContent
  Set IBegin = New IteratorContent
  Call IBegin.Init(data_)
End Function

Public Function ILast() As IteratorContent
  Set ILast = New IteratorContent
  Call ILast.Init(data_)
  Call ILast.GoLast
End Function

Public Function INew() As IteratorContent
  Set INew = New IteratorContent
  Call INew.Init(data_)
  Call INew.GoLast
  Call INew.Increment
End Function

Public Property Get Count() As Long
  Count = ILast.row_ - IBegin.row_ + 1
End Property

Public Function FindTaskID(sID$) As IteratorContent
  Dim iResult As IteratorContent: Set iResult = IBegin
  If iResult.FindTaskID(sID) Then _
    Set FindTaskID = iResult
End Function

Public Function FindContentName(sName$, sType$) As IteratorContent
  Dim iResult As IteratorContent: Set iResult = IBegin
  If iResult.FindContentName(sName, sType) Then _
    Set FindContentName = iResult
End Function

Public Function EnsureDataVisible()
  Call XLShowAllData(data_, bKeepColumns:=True)
  Call XLShowAllData(attributes_)
End Function

Public Function ImportCSVTasks(iInput As IteratorCSVTasks)
  Call iInput.GoFirst
  Dim iOutput As IteratorContent
  Do While Not iInput.IsDone
    Set iOutput = FindPlaceFor(iInput.TaskID, iInput.ContentName, iInput.TaskType)
    If Not iInput.IsCanceled Or iOutput.TaskType <> "" Then
      Call iOutput.SyncCSVTasks(iInput)
    End If
    If CSE_ProgressBar.Visible Then _
      Call CSE_ProgressBar.IncrementA
    Call iInput.Increment
  Loop
End Function

Public Function ImportCSVContent(iInput As IteratorCSVContent)
  Call iInput.GoFirst
  Dim iOutput As IteratorContent
  Do While Not iInput.IsDone
    Set iOutput = FindPlaceFor(iInput.TaskID)
    Call iOutput.SyncCSVContent(iInput)
    If CSE_ProgressBar.Visible Then _
      Call CSE_ProgressBar.IncrementA
    Call iInput.Increment
  Loop
End Function

Public Function ImportDB(iData As DB_Content)
  Dim iInput As IteratorContent: Set iInput = iData.IBegin()
  Dim iOutput As IteratorContent
  Do While Not iInput.IsDone
    Set iOutput = FindPlaceFor(iInput.TaskID, iInput.ContentName, iInput.TaskType)
    If Not iInput.IsCanceled Or iOutput.TaskType <> "" Then _
      Call iOutput.SyncContent(iInput)
    If CSE_ProgressBar.Visible Then _
      Call CSE_ProgressBar.IncrementA
    Call iInput.Increment
  Loop
  Call ImportAttributes(iData.Attributes)
End Function

' =======
Private Function FindPlaceFor(sID$, Optional sName$ = "", Optional sType$ = "") As IteratorContent
  Dim iWhere As IteratorContent: Set iWhere = IBegin
  If Not iWhere.FindTaskID(sID) Then _
    If Not iWhere.FindContentName(sName, sType) Or iWhere.TaskID <> "" Then _
      Call iWhere.GoEmpty
  Set FindPlaceFor = iWhere
End Function

Private Function ImportAttributes(iInput As IteratorAttribute)
  Dim iOutput As IteratorAttribute: Set iOutput = Attributes
  Call iOutput.GoEmpty
  Do While Not iInput.IsDone
    Call iOutput.SyncWith(iInput)
    Call iOutput.Increment
    Call iInput.Increment
  Loop
  Call DeleteAttributeDuplicates
End Function

Private Function DeleteAttributeDuplicates()
  
End Function
