Imports System.Data
Imports FarPoint.Win.Spread
Imports FarPoint.Win.Spread.Data
Imports Spread.Common.DataStore
Imports Spread.Common.Features.Spread.Common.Features.Sample

Namespace Features
    Partial Public Class IntroTable
        Inherits BaseSampleControl
        Private _dataSource As AccessDataSource

#Region "ctor"
        Public Sub New()
            InitializeComponent()
            Name = "Introduction"

            _dataSource = New DataService().AccessDataSource

            SetSheetProperties(fpSpread.ActiveSheet)
            AddSampleTable(fpSpread.ActiveSheet)
        End Sub
#End Region

#Region "Private methods"
        Private Sub SetSheetProperties(sheet As SheetView)
            fpSpread.StatusBarVisible = True
            sheet.DataAutoSizeColumns = True
            sheet.SetMultipleRowHeights(0, fpSpread.ActiveSheet.Rows.Count, 20)
        End Sub

        Private Sub AddSampleTable(sheet As SheetView)
            Dim dataTable As DataTable = _dataSource.GetDataFromTable("Nwind.mdb", "Products").Tables(0)
            Dim adapter As New SpreadDataBindingAdapter()
            adapter.Spread = fpSpread
            adapter.SheetName = "Sheet1"
            adapter.DataSource = dataTable
            adapter.MapperInfo = New MapperInfo(2, 1, 30, dataTable.Columns.Count)
            adapter.FillSpreadDataByDataSource()

            Dim col As Integer = 1
            For Each column As DataColumn In dataTable.Columns
                sheet.Cells(1, System.Math.Max(System.Threading.Interlocked.Increment(col), col - 1)).Text = (column.Caption)
            Next

            Dim table As TableView = sheet.AddTable("Table1", 1, 1, 31, dataTable.Columns.Count, TableStyle.TableStyleMedium2)

            For j As Integer = 1 To col - 1
                sheet.Columns(j).Width = sheet.Columns(j).GetPreferredWidth()
            Next

            table.HeaderRowVisible = True
            table.FirstColumn = True
            table.LastColumn = False
            table.TotalRowVisible = True
        End Sub
#End Region
    End Class
End Namespace

'
'IntroTable.Designer.vb
'

Namespace Features
	Partial Class IntroTable
		''' <summary> 
		''' Required designer variable.
		''' </summary>
		Private components As System.ComponentModel.IContainer = Nothing

        ''' <summary> 
        ''' Clean up any resources being used.
        ''' </summary>
        ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        Protected Overloads Sub Dispose(disposing As Boolean)
            If disposing AndAlso (components IsNot Nothing) Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub

#Region "Component Designer generated code"

        ''' <summary> 
        ''' Required method for Designer support - do not modify 
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
			Me.fpSpread = New FarPoint.Win.Spread.FpSpread()
			Me.fpSpread_Sheet1 = New FarPoint.Win.Spread.SheetView()
			Me.pnlMain.SuspendLayout()
			DirectCast(Me.fpSpread, System.ComponentModel.ISupportInitialize).BeginInit()
			DirectCast(Me.fpSpread_Sheet1, System.ComponentModel.ISupportInitialize).BeginInit()
			Me.SuspendLayout()
			' 
			' pnlMain
			' 
			Me.pnlMain.Controls.Add(Me.fpSpread)
			' 
			' fpSpread
			' 
			Me.fpSpread.Dock = System.Windows.Forms.DockStyle.Fill
			Me.fpSpread.Location = New System.Drawing.Point(0, 0)
			Me.fpSpread.Name = "fpSpread"
			Me.fpSpread.Sheets.AddRange(New FarPoint.Win.Spread.SheetView() {Me.fpSpread_Sheet1})
			Me.fpSpread.Size = New System.Drawing.Size(477, 487)
			Me.fpSpread.TabIndex = 0
			' 
			' fpSpread_Sheet1
			' 
			Me.fpSpread_Sheet1.Reset()
			Me.fpSpread_Sheet1.SheetName = "Sheet1"
			' Formulas and custom names must be loaded with R1C1 reference style
			Me.fpSpread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
			Me.fpSpread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
			' 
			' TableIntro
			' 
			Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
			Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
			Me.Name = "TableIntro"
			Me.pnlMain.ResumeLayout(False)
			DirectCast(Me.fpSpread, System.ComponentModel.ISupportInitialize).EndInit()
			DirectCast(Me.fpSpread_Sheet1, System.ComponentModel.ISupportInitialize).EndInit()
			Me.ResumeLayout(False)

		End Sub

		#End Region

		Private fpSpread As FarPoint.Win.Spread.FpSpread
		Private fpSpread_Sheet1 As FarPoint.Win.Spread.SheetView
	End Class
End Namespace
