'import global extract made with macros (has valid data sheet)
Option Explicit
Dim EXTRACTwb As Workbook
Dim EXTRACTws As Worksheet
Dim prjTitle As String
Dim xRows As Range
Dim xRowsA As Range
Dim xRow As Range
Dim DATAr As Range
Dim foundDATAr As Range
Dim xRowWithChanges() As Variant
Dim DATArWithChanges() As Variant
Dim changesType() As Variant
Dim newXrows() As Variant
Dim deletedDataRows() As Variant
Dim itemCount As Integer
Dim i As Integer
Dim frm As manageMLS2Import
Enum milestoneComparison
mcNew = 0
mcnewinclude = 1
mcNewunInclude = 2
mcDateChanges = 3
mcDeleted = 4
mcAllOK = 5
mcNA = 6
End Enum
'2015-03-26 / B.Agullo /
Public Sub importFromGlobalExtractM()
'import extract made with macros (has valid data sheet)
Dim awb As Workbook
Set awb = ActiveWorkbook
If Not initImportExtractM Then GoTo release
Call checkChangesInDataSheet
Call showMilestoneChanges
If formCancel Then GoTo release
Call processAcceptedMilestoneChanges
Call closeGPTMS
awb.Activate
release:
On Error Resume Next
EXTRACTwb.Close savechanges:=False
Set EXTRACTwb = Nothing
Set EXTRACTws = Nothing
Set frm = Nothing
On Error GoTo 0
If isAnswerOk("Refresh Render to see all changes?") Then
Call renderSchedule(awb)
End If
Set awb = Nothing
End Sub
'2015-03-26 / B.Agullo /
Public Function initImportExtractM() As Boolean
'open global extract with macros and initialize required variables and assure is a valid file
Dim filename As String
Dim PTMSIDs As Variant
Dim validID As String
Dim awb As Workbook
initImportExtractM = False
Set awb = ActiveWorkbook
If PTMS Is Nothing Then
MsgBox (PTMS_MSG12)
GoTo release
End If
filename = Application.GetOpenFilename(title:="Select a Global PTMS Extract")
If filename = "False" Or filename = "Falso" Then GoTo release
Set EXTRACTwb = openWorkbook(filename, readOnly:=False, enableMacros:=True, isVisible:=True, returnFocus:=True)
If EXTRACTwb Is Nothing Then GoTo release
Set EXTRACTws = getWorksheet(EXTRACTwb, "DATA")
If EXTRACTws Is Nothing Then GoTo release
initGPTMS
Call establishConnectionWithPTMSCentral(awb)
prjTitle = getProjectTitle
If getRow(EXTRACTws.Range("c_ptmstitle"), prjTitle) Is Nothing Then
MsgBox (GPTMSMSG010): GoTo release
End If
Erase xRowWithChanges
Erase DATArWithChanges
Erase changesType
Erase newXrows
Erase deletedDataRows
Set DATAr = Nothing
Set foundDATAr = Nothing
formCancel = False
Set frm = New manageMLS2Import
initImportExtractM = True
release:
End Function
'2015-03-25 / B.Agullo /
Public Sub checkChangesInDataSheet()
'description here
Call standardAutoFilter(EXTRACTws, "PTMStitle", prjTitle)
Set xRows = getVisibleCells(EXTRACTws.Range("c_ptmstitle"))
If xRows Is Nothing Then GoTo release
Set xRows = xRows.EntireRow
'for each frow in global ptms, check with equivalent in simple PTMS
'necessary to go by areas, as new milestones will be at the end of data sheet, regardless of project
For Each xRowsA In xRows.Areas
For Each xRow In xRowsA.Rows
Call checkChangesInDataRow
Next
Next
'(reverse comparison)
'check for included milestones which are not present in global ptms (very weird)
For Each DATAr In DATAws.Range("Datarows").Rows
If DATAr.Range("Include") = "O" Then
If Not overlap(DATAr, foundDATAr) Then
Call addObjectToArrayIfNecessary(deletedDataRows, DATAr)
End If
End If
Next
release:
Set xRows = Nothing
End Sub
'2015-03-25 / B.Agullo /
Public Sub checkChangesInDataRow()
'calls function to evaluate kind of changes, and stores in arrays accordingly
Dim mc As milestoneComparison
Set DATAr = getRow(DATAws.Range("c_item"), xRow.Range("item"))
mc = changesInDATAr
Select Case changesInDATAr
Case mcNew
Call addObjectToArrayIfNecessary(newXrows, xRow)
Case mcnewinclude, mcNewunInclude, mcDateChanges
Call addObjectToArrayIfNecessary(xRowWithChanges, xRow, checkIfPresent:=False)
Call addObjectToArrayIfNecessary(DATArWithChanges, DATAr, checkIfPresent:=False)
Call addToArrayIfNecessary(changesType, CStr(mc), checkIfPresent:=False) 'works with strings only
Set foundDATAr = unify(foundDATAr, DATAr)
Case mcAllOK, mcNA
Set foundDATAr = unify(foundDATAr, DATAr)
End Select
End Sub
'2015-03-26 / B.Agullo / check milestone dates
'2015-04-21 / B.Agullo / if both relative, don't even show
Public Function changesInDATAr() As milestoneComparison
'returns true if milestone is detected as different
'if row is not found in PTMS it is a milestone created in global PTMS
If DATAr Is Nothing Then
changesInDATAr = mcNew
GoTo release
End If
'if both relative, differnces will disapear once formulas arerecalculated
If DATAr.Range("dateMode") = "Relative" And xRow.Range("dateMode") = "Relative" Then
changesInDATAr = mcAllOK
GoTo release
End If
With DATAr
'if milestone is not included in either ptms or global ptms, do not even compare dates
If .Range("include") <> "O" And xRow.Range("include") <> "O" Then
changesInDATAr = mcNA
GoTo release
End If
'if milestone not included in ptms, but included in global ptms, mark as newInclude
If .Range("include") <> "O" And xRow.Range("include") = "O" Then
changesInDATAr = mcnewinclude
GoTo release
End If
'if milestone was included in ptms but not included in global ptms, mark as uninclude
If .Range("include") = "O" And xRow.Range("include") <> "O" Then
changesInDATAr = mcNewunInclude
GoTo release
End If
'if either start or end dates change, mark as dateChages
changesInDATAr = mcDateChanges
If .Range("startdate") <> xRow.Range("startdate") Then GoTo release
If .Range("enddate") <> xRow.Range("enddate") Then GoTo release
'if this point is reached, is included in both schedules without any change
changesInDATAr = mcAllOK
End With
release:
End Function
'2015-03-26 / B.Agullo /
Public Function showMilestoneChanges() As Boolean
'description here
'Dim frm As manageMLS2Import
Dim resolution As New API_Resolution
showMilestoneChanges = False
itemCount = 0
frm.top = (resolution.getScreenHeightInPoints - frm.height) / 2
frm.left = (resolution.getScreenWidthInPoints - frm.width) / 2
Call loadModifiedMilestonesToUserform
Call loadNewMilestonestoUserform
Call loadDeletedMilestonestoUserform
showMilestoneChanges = True
frm.show
If formCancel Then
showMilestoneChanges = False
GoTo release
End If
release:
Set resolution = Nothing
End Function
'2015-03-26 / B.Agullo /
Public Sub loadModifiedMilestonesToUserform()
'show all milestones in which differences have been deteced
Dim i As Integer
Dim mc As milestoneComparison
If Not arrayHasDimension(xRowWithChanges) Then GoTo release
For i = LBound(xRowWithChanges) To UBound(xRowWithChanges)
Set xRow = xRowWithChanges(i)
Set DATAr = DATArWithChanges(i)
mc = CInt(changesType(i))
With frm.milestonesLB
.AddItem (DATAr.Range("item").value)
.List(itemCount, 1) = DATAr.Range("processedDisplayName")
Select Case mc
Case mcNewunInclude, mcDateChanges
.List(itemCount, 2) = printDateString(DATAr.Range("startDate"))
.List(itemCount, 3) = printDateString(DATAr.Range("enddate"))
End Select
Select Case mc
Case mcDateChanges
.List(itemCount, 4) = "------->"
.List(itemCount, 7) = "CHANGES"
Case mcnewinclude
.List(itemCount, 4) = "INCLUDE"
.List(itemCount, 7) = "CHANGES"
Case mcNewunInclude
.List(itemCount, 4) = "REMOVE"
.List(itemCount, 7) = "CHANGES"
End Select
Select Case mc
Case mcDateChanges, mcnewinclude
.List(itemCount, 5) = printDateString(xRow.Range("startDate"))
.List(itemCount, 6) = printDateString(xRow.Range("enddate"))
End Select
.List(itemCount, 8) = i
itemCount = itemCount + 1
End With
Next
release:
End Sub
'2015-03-26 / B.Agullo /
Public Sub loadNewMilestonestoUserform()
'show milestons that where created in global PTMS
Dim i As Integer
If Not arrayHasDimension(newXrows) Then GoTo release
For i = LBound(newXrows) To UBound(newXrows)
Set xRow = newXrows(i)
With frm.milestonesLB
.AddItem (xRow.Range("item").value)
.List(itemCount, 1) = xRow.Range("processedDisplayName")
'.List(itemCount, 2) = printDateString(DATAr.Range("startDate"))
'.List(itemCount, 3) = printDateString(DATAr.Range("enddate"))
.List(itemCount, 4) = "--NEW--"
.List(itemCount, 5) = printDateString(xRow.Range("startDate"))
.List(itemCount, 6) = printDateString(xRow.Range("enddate"))
.List(itemCount, 7) = "NEW"
.List(itemCount, 8) = i
itemCount = itemCount + 1
End With
Next
release:
End Sub
'2015-03-26 / B.Agullo /
Public Sub loadDeletedMilestonestoUserform()
'show milestones that where deleted in global ptms
Dim i As Integer
If Not arrayHasDimension(deletedDataRows) Then GoTo release
For i = LBound(deletedDataRows) To UBound(deletedDataRows)
Set DATAr = deletedDataRows(i)
With frm.milestonesLB
.AddItem (DATAr.Range("item").value)
.List(itemCount, 1) = DATAr.Range("processedDisplayName")
.List(itemCount, 2) = printDateString(DATAr.Range("startDate"))
.List(itemCount, 3) = printDateString(DATAr.Range("enddate"))
.List(itemCount, 4) = "--DELETED--"
'.List(itemCount, 5) = printDateString(xRow.Range("startDate"))
'.List(itemCount, 6) = printDateString(xRow.Range("enddate"))
.List(itemCount, 7) = "DELETE MILESTONE"
.List(itemCount, 8) = i
itemCount = itemCount + 1
End With
Next
release:
End Sub
'2015-03-26 / B.Agullo /
'2015-03-30 / B.Agullo / fine tuning
Public Sub processAcceptedMilestoneChanges()
'actual actions after used has selected update
With frm.milestonesLB
For i = 0 To .ListCount - 1
If .Selected(i) Then
Select Case .List(i, 7)
Case "CHANGES"
Call updateMilestone
Case "NEW"
Call addMilestone
Case "DELETE MILESTONE"
Call deleteMilestone
End Select
End If
Next
End With
End Sub
'2015-03-27 / B.Agullo /
'2015-04-21 / B.Agullo / refresh render and move childs
Public Sub updateMilestone()
'updates fields in simple ptms from global extract milestone
Dim arrayP As Integer
Dim rnA As Variant
Dim rn As Variant
Dim DATAc As Range
Dim MLS As Milestone
arrayP = frm.milestonesLB.List(i, 8)
Set DATAr = DATArWithChanges(arrayP)
Set xRow = xRowWithChanges(arrayP)
'fields to update
For Each DATAc In DATAws.Range("Datacolumns").Columns
rn = GetColumnRangeName(DATAc)
If rangeNameExists(EXTRACTws, rn) Then
DATAr.Range(rn) = xRow.Range(rn)
End If
Next
' Set MLS = getMLS(DATAr.Range("item").value)
'
' If Not MLS Is Nothing Then
'
' MLS.refreshRender
' MLS.moveChilds
'
' End If
'Call simpleSetFormulasInRow(DATAr)
End Sub
'2015-03-27 / B.Agullo /
Public Sub addMilestone()
'add row with all the availabe information from global extract
Dim rn As String
Dim DATAc As Range
Dim arrayP As Integer
arrayP = frm.milestonesLB.List(i, 8)
Set xRow = newXrows(arrayP)
Set DATAr = DATAws.Range("firstEmptyRow")
For Each DATAc In DATAws.Range("Datacolumns").Columns
rn = GetColumnRangeName(DATAc)
If rangeNameExists(EXTRACTws, rn) Then
DATAr.Range(rn) = xRow.Range(rn)
End If
Next
Call simpleSetFormulasInRow(DATAr)
End Sub
'2015-03-27 / B.Agullo /
Public Sub deleteMilestone()
'removes rows that were physically deleted from global PTMS -- quite weird
Dim arrayP As Integer
arrayP = frm.milestonesLB.List(i, 8)
Set DATAr = deletedDataRows(arrayP)
DATAr.Delete xlShiftUp
End Sub
Bookmarks