Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms

Imports Spread.Common.DataStore
Imports FarPoint.Win.Spread.CellType
Imports Spread.Common.Features.Spread.Common.Features.Sample

Partial Public Class SheetDataSource
    Inherits BaseSampleControl
    Public Sub New()
        InitializeComponent()
        Name = "Sheet Data Source"

        Dim dataSource = New DataService().AccessDataSource
        Dim data = dataSource.GetDataFrom("Nwind.mdb", "SELECT Products.ProductID, Products.ProductName, Suppliers.CompanyName, Categories.CategoryName, Products.QuantityPerUnit, Products.UnitPrice, Products.UnitsInStock, Products.UnitsOnOrder, Products.Discontinued FROM Suppliers INNER JOIN (Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID) ON Suppliers.SupplierID = Products.SupplierID ORDER BY Products.ProductID")

        'Default Binding
        _svDefaltBin.DataAutoSizeColumns = False
        _svDefaltBin.SetColumnWidth(-1, 120)
        _svDefaltBin.DataSource = data

        'Custom Binding
        _svCustomBin.DataAutoSizeColumns = False
        _svCustomBin.SetColumnWidth(-1, 120)
        _svCustomBin.DataSource = data
        _svCustomBin.BindDataColumn(2, "CategoryName")
        _svCustomBin.BindDataColumn(3, "CompanyName")
        _svCustomBin.BindDataColumn(4, "QuantityPerUnit")
        _svCustomBin.BindDataColumn(5, "UnitPrice")
        _svCustomBin.BindDataColumn(6, "Discontinued")
        _svCustomBin.BindDataColumn(7, "UnitsInStock")
        _svCustomBin.BindDataColumn(8, "UnitsOnOrder")

        _svCustomBin.Columns(0).Label = "ID"
        _svCustomBin.Columns(1).Label = "Name"
        _svCustomBin.Columns(2).Label = "Category"
        _svCustomBin.Columns(3).Label = "Supplier Company"
        _svCustomBin.Columns(4).Label = "Quantity"
        _svCustomBin.Columns(5).Label = "Unit Price"

        _svCustomBin.Columns(5).CellType = New CurrencyCellType()
        'Show title of sheet to make column names meaningful.
        _svCustomBin.TitleInfo = New FarPoint.Win.Spread.TitleInfo() With {
             .Text = "Products Detail",
             .HorizontalAlign = FarPoint.Win.Spread.CellHorizontalAlignment.Center,
             .Height = 20,
             .BackColor = Color.DarkGreen,
             .ForeColor = Color.White,
             .Font = New Font("Segoi UI", 12, FontStyle.Bold),
             .Visible = True
        }
    End Sub
End Class

'
'
'

Partial Class SheetDataSource
	''' <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 Shadows 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.fpSpread1 = New FarPoint.Win.Spread.FpSpread()
		Me._svCustomBin = New FarPoint.Win.Spread.SheetView()
		Me._svDefaltBin = New FarPoint.Win.Spread.SheetView()
		Me.pnlMain.SuspendLayout()
		DirectCast(Me.fpSpread1, System.ComponentModel.ISupportInitialize).BeginInit()
		DirectCast(Me._svCustomBin, System.ComponentModel.ISupportInitialize).BeginInit()
		DirectCast(Me._svDefaltBin, System.ComponentModel.ISupportInitialize).BeginInit()
		Me.SuspendLayout()
		' 
		' pnlMain
		' 
		Me.pnlMain.Controls.Add(Me.fpSpread1)
		' 
		' fpSpread1
		' 
		Me.fpSpread1.Dock = System.Windows.Forms.DockStyle.Fill
		Me.fpSpread1.Location = New System.Drawing.Point(0, 0)
		Me.fpSpread1.Name = "fpSpread1"
		Me.fpSpread1.Sheets.AddRange(New FarPoint.Win.Spread.SheetView() {Me._svDefaltBin, Me._svCustomBin})
		Me.fpSpread1.Size = New System.Drawing.Size(477, 487)
		Me.fpSpread1.TabIndex = 0
		' 
		' _svCustomBin
		' 
		Me._svCustomBin.Reset()
		Me._svCustomBin.SheetName = "Custom Binding"
		' Formulas and custom names must be loaded with R1C1 reference style
		Me._svCustomBin.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
		Me._svCustomBin.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
		' 
		' _svDefaltBin
		' 
		Me._svDefaltBin.Reset()
		Me._svDefaltBin.SheetName = "Default Binding"
		' Formulas and custom names must be loaded with R1C1 reference style
		Me._svDefaltBin.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
		Me._svDefaltBin.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
		' 
		' DataBinding
		' 
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.Name = "DataBinding"
		Me.pnlMain.ResumeLayout(False)
		DirectCast(Me.fpSpread1, System.ComponentModel.ISupportInitialize).EndInit()
		DirectCast(Me._svCustomBin, System.ComponentModel.ISupportInitialize).EndInit()
		DirectCast(Me._svDefaltBin, System.ComponentModel.ISupportInitialize).EndInit()
		Me.ResumeLayout(False)

	End Sub

	#End Region

	Private fpSpread1 As FarPoint.Win.Spread.FpSpread
	Private _svCustomBin As FarPoint.Win.Spread.SheetView
	Private _svDefaltBin As FarPoint.Win.Spread.SheetView
End Class
