Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports PlexityHide.GTP
Imports PlexityHide.GTP.WEB

Namespace Sample1
	''' <summary>
	''' Summary description for WebForm1.
	''' </summary>
	Public Class WebForm1 : Inherits System.Web.UI.Page
	Protected gantt_ASPSettings1 As PlexityHide.GTP.WEB.Gantt_ASPSettings
	Protected WithEvents Gantt_ASP1 As PlexityHide.GTP.WEB.Gantt_ASP

		Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
			' Put user code to initialize the page here
		End Sub

		#Region "Web Form Designer generated code"
		Overrides Protected Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
	  Dim cellLayout1 As PlexityHide.GTP.CellLayout = New PlexityHide.GTP.CellLayout()
	  Dim lineOption1 As PlexityHide.GTP.LineOption = New PlexityHide.GTP.LineOption()
	  Dim lineOption2 As PlexityHide.GTP.LineOption = New PlexityHide.GTP.LineOption()
	  Dim lineOption3 As PlexityHide.GTP.LineOption = New PlexityHide.GTP.LineOption()
	  Dim lineOption4 As PlexityHide.GTP.LineOption = New PlexityHide.GTP.LineOption()
	  Dim gridColumn1 As PlexityHide.GTP.GridColumn = New PlexityHide.GTP.GridColumn()
	  Dim gridColumn2 As PlexityHide.GTP.GridColumn = New PlexityHide.GTP.GridColumn()
	  Dim gridNode1 As PlexityHide.GTP.GridNode = New PlexityHide.GTP.GridNode()
	  Dim gridNode2 As PlexityHide.GTP.GridNode = New PlexityHide.GTP.GridNode()
	  Dim gridNode3 As PlexityHide.GTP.GridNode = New PlexityHide.GTP.GridNode()
	  Me.gantt_ASPSettings1 = New PlexityHide.GTP.WEB.Gantt_ASPSettings()
'	  Me.Gantt_ASP1.OnTimeItem_ClientClick += New PlexityHide.GTP.TimeItemEvent(Me.Gantt_ASP1_OnTimeItem_ClientClick);
'	  Me.Gantt_ASP1.Load += New System.EventHandler(Me.Gantt_ASP1_Load);
'	  Me.Gantt_ASP1.OnNode_ClientClick += New PlexityHide.GTP.NodeEventHandler(Me.Gantt_ASP1_OnNode_ClientClick);
	  ' 
	  ' gantt_ASPSettings1
	  ' 
	  ' 
	  ' gantt_ASPSettings1.Gantt
	  ' 
	  Me.gantt_ASPSettings1.Gantt.BackColor = System.Drawing.Color.White
	  Me.gantt_ASPSettings1.Gantt.DateScalerHeight = 48
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.FishEyeColor = System.Drawing.Color.AliceBlue
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.FishEyeenabled = False
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.FishEyeMagnification = PlexityHide.GTP.FishEyeMagnification.M1
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.LowerBound = New System.DateTime(1000, 1, 1, 0, 0, 0, 0)
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.MarkerTextColor = System.Drawing.Color.Black
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.ResizeType = PlexityHide.GTP.ResizingType.StartAndStopLocked
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.ScaleMarkerColor = System.Drawing.Color.Black
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.ShowWeekNumbers = False
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.SpanTextColor = System.Drawing.Color.SlateGray
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.StartOfWeek = System.DayOfWeek.Sunday
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.StartTime = New System.DateTime(2003, 8, 5, 4, 40, 33, 773)
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.StopTime = New System.DateTime(2003, 9, 5, 7, 13, 44, 862)
	  Me.gantt_ASPSettings1.Gantt.DateScalerProperties.UpperBound = New System.DateTime(8000, 1, 1, 0, 0, 0, 0)
	  Me.gantt_ASPSettings1.Gantt.DrawPyjamas = False
	  Me.gantt_ASPSettings1.Gantt.FocusedTimeItem = Nothing
	  Me.gantt_ASPSettings1.Gantt.GridProperties.AutoCreateColumnsFromDataset = False
	  Me.gantt_ASPSettings1.Gantt.GridProperties.BackColor = System.Drawing.Color.White
	  Me.gantt_ASPSettings1.Gantt.GridProperties.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
	  Me.gantt_ASPSettings1.Gantt.GridProperties.BottomColor = System.Drawing.Color.White
	  cellLayout1.BackgroundColor = System.Drawing.Color.WhiteSmoke
	  cellLayout1.BackgroundUse = False
	  cellLayout1.DeSelectedColor = System.Drawing.SystemColors.Highlight
	  cellLayout1.EndEllipsis = False
	  cellLayout1.Font = New System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
	  cellLayout1.FontColor = System.Drawing.SystemColors.ControlText
	  cellLayout1.HeaderBackgroundColor = System.Drawing.Color.FromArgb((CByte(255)), (CByte(192)), (CByte(192)))
	  cellLayout1.HeaderBackgroundGradiantColor = System.Drawing.SystemColors.ControlLight
	  cellLayout1.HorzAlign = System.Drawing.StringAlignment.Near
	  cellLayout1.ImageIndex_Select = -1
	  cellLayout1.ImageIndex_UnSelect = -1
	  lineOption1.Color = System.Drawing.Color.LightGray
	  lineOption1.Use = True
	  lineOption1.Width = 1
	  cellLayout1.LineBottom = lineOption1
	  lineOption2.Color = System.Drawing.Color.LightGray
	  lineOption2.Use = False
	  lineOption2.Width = 1
	  cellLayout1.LineLeft = lineOption2
	  lineOption3.Color = System.Drawing.Color.LightGray
	  lineOption3.Use = True
	  lineOption3.Width = 1
	  cellLayout1.LineRight = lineOption3
	  lineOption4.Color = System.Drawing.Color.LightGray
	  lineOption4.Use = False
	  lineOption4.Width = 1
	  cellLayout1.LineTop = lineOption4
	  cellLayout1.MinHeight = 25
	  cellLayout1.Name = "Default"
	  cellLayout1.Padding = New System.Drawing.Rectangle(0, 0, 0, 0)
	  cellLayout1.SelectedColor = System.Drawing.SystemColors.Highlight
	  cellLayout1.Spacing = New System.Drawing.Rectangle(0, 0, 0, 0)
	  cellLayout1.VertAlign = System.Drawing.StringAlignment.Near
	  Me.gantt_ASPSettings1.Gantt.GridProperties.CellLayouts.Add(cellLayout1)
	  gridColumn1.AllowMove = True
	  gridColumn1.AllowResize = True
	  gridColumn1.ColumnDerivedFromDS = False
	  gridColumn1.DataSourceColumn = Nothing
	  gridColumn1.DataSourceColumnType = Nothing
	  gridColumn1.Hide = False
	  gridColumn1.LayoutName = "Default"
	  gridColumn1.ReadOnly = False
	  gridColumn1.Title = "First"
	  gridColumn1.Tree = True
	  gridColumn1.Type = PlexityHide.GTP.CellType.SingleText
	  gridColumn1.Width = 150
	  gridColumn2.AllowMove = True
	  gridColumn2.AllowResize = True
	  gridColumn2.ColumnDerivedFromDS = False
	  gridColumn2.DataSourceColumn = Nothing
	  gridColumn2.DataSourceColumnType = Nothing
	  gridColumn2.Hide = False
	  gridColumn2.LayoutName = "Default"
	  gridColumn2.ReadOnly = False
	  gridColumn2.Title = "second"
	  gridColumn2.Tree = False
	  gridColumn2.Type = PlexityHide.GTP.CellType.SingleText
	  gridColumn2.Width = 150
	  Me.gantt_ASPSettings1.Gantt.GridProperties.Columns.Add(gridColumn1)
	  Me.gantt_ASPSettings1.Gantt.GridProperties.Columns.Add(gridColumn2)
	  Me.gantt_ASPSettings1.Gantt.GridProperties.DrawPyjamas = True
	  Me.gantt_ASPSettings1.Gantt.GridProperties.HasHeader = True
	  Me.gantt_ASPSettings1.Gantt.GridProperties.ImageList = Nothing
	  Me.gantt_ASPSettings1.Gantt.GridProperties.PyjamasColor = System.Drawing.SystemColors.ControlLight
	  Me.gantt_ASPSettings1.Gantt.GridProperties.PyjamasGradientColor = System.Drawing.SystemColors.ControlLightLight
	  gridNode1.Expanded = False
	  gridNode1.ParentNode = Nothing
	  gridNode1.RowSelected = False
	  gridNode1.SubNodes_DataMember = Nothing
	  gridNode1.SubNodes_DataSource = Nothing
	  gridNode1.UserReference = Nothing
	  gridNode2.Expanded = False
	  gridNode2.ParentNode = Nothing
	  gridNode2.RowSelected = False
	  gridNode2.SubNodes_DataMember = Nothing
	  gridNode2.SubNodes_DataSource = Nothing
	  gridNode2.UserReference = Nothing
	  gridNode3.Expanded = False
	  gridNode3.ParentNode = Nothing
	  gridNode3.RowSelected = False
	  gridNode3.SubNodes_DataMember = Nothing
	  gridNode3.SubNodes_DataSource = Nothing
	  gridNode3.UserReference = Nothing
	  Me.gantt_ASPSettings1.Gantt.GridProperties.RootNodes.Add(gridNode1)
	  Me.gantt_ASPSettings1.Gantt.GridProperties.RootNodes.Add(gridNode2)
	  Me.gantt_ASPSettings1.Gantt.GridProperties.RootNodes.Add(gridNode3)
	  Me.gantt_ASPSettings1.Gantt.GridProperties.RootNodes_DataMember = Nothing
	  Me.gantt_ASPSettings1.Gantt.GridProperties.RootNodes_DataSource = Nothing
	  Me.gantt_ASPSettings1.Gantt.GridWidth = 200
	  Me.gantt_ASPSettings1.Gantt.ImageList = Nothing
	  Me.gantt_ASPSettings1.Gantt.Location = New System.Drawing.Point(0, 0)
	  Me.gantt_ASPSettings1.Gantt.Name = "Gantt"
	  Me.gantt_ASPSettings1.Gantt.PyjamasColor = System.Drawing.Color.BurlyWood
	  Me.gantt_ASPSettings1.Gantt.PyjamasGradientColor = System.Drawing.Color.FromArgb((CByte(255)), (CByte(192)), (CByte(192)))
	  Me.gantt_ASPSettings1.Gantt.Size = New System.Drawing.Size(632, 392)
	  Me.gantt_ASPSettings1.Gantt.TabIndex = 0
	  Me.gantt_ASPSettings1.Gantt.TodayLine = True
	  Me.gantt_ASPSettings1.Gantt.VerticalDayStripes = True
	  Me.gantt_ASPSettings1.Gantt.VerticalDayStripes_Days = New Boolean() { True, False, False, False, False, False, True}
	  Me.gantt_ASPSettings1.Gantt.VerticalLines = True
	  Me.gantt_ASPSettings1.Gantt_ASP = Me.Gantt_ASP1
'	  Me.Load += New System.EventHandler(Me.Page_Load);

		End Sub
		#End Region

	Private Sub Gantt_ASP1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Gantt_ASP1.Load
	  Gantt_ASP1.Gantt.Grid.GridStructure.RootNodes.Clear()
	  Gantt_ASP1.Gantt.CollisionDetectionSyncron=True
	  'Gantt_ASP1.Gantt.DateScalerHeight=0;


	  If (Not Me.IsPostBack) Then ' If this is not a postback then we init the datetime to Today + 15 days
		Gantt_ASP1.StartTime=DateTime.Today
		Gantt_ASP1.StopTime=DateTime.Today.AddDays(15)
	  End If

	  ' Note: Next row should not be needed. Will be fixed in future releases of GTP.NET.WEB	  
	  Gantt_ASP1.Gantt.DateScaler.TimeSpanSet(Gantt_ASP1.StartTime,Gantt_ASP1.StopTime)


	  Gantt_ASP1.Gantt.Grid.CellLayouts.GetFromName("Default").Font = New Font("Times",12)


	  Dim t1 As TimeItem=Nothing, t2 As TimeItem=Nothing
	  For i As Integer = 0 To 14
		Dim gn As GridNode=Gantt_ASP1.Gantt.Grid.GridStructure.RootNodes.AddNode()
		gn.GetCell(0).Content.Value="Hello"
		Dim gn2 As GridNode=gn.SubNodes.AddNode()
		gn2.GetCell(0).Content.Value="Sub Hello"

		Dim ti As TimeItem=GanttRow.FromGridNode(gn).Layers(0).AddNewTimeItem()
		ti.Start=DateTime.Today.AddDays(5)
		ti.Stop=ti.Start.AddDays(5)
		ti.TimeItemLayout = New TimeItemLayout()
		ti.TimeItemLayout.Color=Color.Red
		ti.TimeItemLayout.TimeItemStyle=TimeItemStyle.Square
		ti.TimeItemLayout.TopInset=10
		ti.TimeItemLayout.BottomInset=10
		If i=0 Then
		  t1=ti
		End If

		ti=GanttRow.FromGridNode(gn2).Layers(0).AddNewTimeItem()
		ti.Start=DateTime.Today.AddDays(15)
		ti.Stop=ti.Start.AddDays(5)
		ti.TimeItemLayout = New TimeItemLayout()
		ti.TimeItemLayout.Color=Color.Plum
		ti.TimeItemLayout.TimeItemStyle=TimeItemStyle.Square
		ti.TimeItemLayout.TopInset=10
		ti.TimeItemLayout.BottomInset=10
		If i=4 Then
		  t2=ti
		End If

		ti=GanttRow.FromGridNode(gn2).Layers(0).AddNewTimeItem()
		ti.Start=DateTime.Today.AddDays(7)
		ti.Stop=ti.Start.AddDays(14)
		ti.TimeItemLayout = New TimeItemLayout()
		ti.TimeItemLayout.Color=Color.CadetBlue
		ti.TimeItemLayout.TimeItemStyle=TimeItemStyle.Square
		ti.TimeItemLayout.TopInset=10
		ti.TimeItemLayout.BottomInset=10

'
		'Bitmap b=new Bitmap(Gantt_ASP1.Gantt.DateScaler.Bitmap);
		'Graphics g=Graphics.FromImage(b);
		'Gantt_ASP1.Gantt.DateScaler.DrawToGraphic(g);


		'b=new Bitmap(Gantt_ASP1.Gantt.TimeItemArea.Bitmap);
		'g=Graphics.FromImage(b);
		'Gantt_ASP1.Gantt.TimeItemArea.DrawToGraphic(g);
  '


		' Check TimeToPixel And GridHeight
		'Here test the Time to Pixel again ----Alway return 0
		Dim StartPixel As Integer=Gantt_ASP1.Gantt.DateScaler.TimeToPixel(ti.Start)
		Dim StopPixel As Integer=Gantt_ASP1.Gantt.DateScaler.TimeToPixel(ti.Stop)

		Dim StartPixe2 As Integer=Gantt_ASP1.Gantt.DateScaler.TimeToPixel(ti.Start)
		Dim StopPixe2 As Integer=Gantt_ASP1.Gantt.DateScaler.TimeToPixel(ti.Stop)

		'Try to get the GanttRow Highe ---always return 0
		Dim rowHight As Integer = GanttRow.FromGridNode(gn2).Rect().Height


	  Next i

	  If Not t1 Is Nothing AndAlso Not t2 Is Nothing Then
		Dim l1 As TimeItemLink=Gantt_ASP1.Gantt.TimeItemLinks.AddLink(t1,t2)
		l1.TimeItemLinkStyle=TimeItemLinkStyle.StopToStart
		l1.TimeItemLinkDrawStyle=TimeItemLinkDrawStyle.ZStyle
	  End If


	  ' Change total height so that exactly 5 rows show:
	  ' Workaround for GetRect problem
	  Dim b As Bitmap = New Bitmap(Gantt_ASP1.Gantt.Grid.Bitmap)
	  Dim g As Graphics=Graphics.FromImage(b)
	  Gantt_ASP1.Gantt.Grid.DrawToGraphic(g)
	  Dim toprowrect As Rectangle=GanttRow.FromGridNode(Gantt_ASP1.Gantt.Grid.GridStructure.TopNode).Rect()

      Dim newHeight As Unit

      newHeight = Unit.Pixel(toprowrect.Height * 5 + Gantt_ASP1.Gantt.DateScalerHeight + 5)
      Gantt_ASP1.Height = newHeight



	End Sub

	Private Sub Gantt_ASP1_OnTimeItem_ClientClick(ByVal aGantt As PlexityHide.GTP.Gantt, ByVal e As PlexityHide.GTP.TimeItemEventArgs) Handles Gantt_ASP1.OnTimeItem_ClientClick
	  e.TimeItem.TimeItemLayout.Color=Color.Blue
	End Sub

	Private Sub Gantt_ASP1_OnNode_ClientClick(ByVal aGrid As PlexityHide.GTP.Grid, ByVal e As PlexityHide.GTP.NodeEventArgs) Handles Gantt_ASP1.OnNode_ClientClick
	  'e.GridNode.Expanded=!e.GridNode.Expanded;
	End Sub
	End Class
End Namespace
