MESCIUS SPREAD for ASP.NET 10.0J サンプルコード集
データを階層表示する

連結したデータソースがマスター/ディテール(1対多)のリレーションを含む場合、データを階層で表示できます。

実行例:

FpSpread1.DataSource = new StorehouseList();
//コントロールのサイズを自動調整します
FpSpread1.ClientAutoCalculation = true;
FpSpread1.DataSource = New StorehouseList()
'コントロールのサイズを自動調整します
FpSpread1.ClientAutoCalculation = True

この例では、データソースとして以下のクラスを使用しています。

[Serializable]
public class Stock
{
    public string ProductCode { get; set; }
    public string ProductName { get; set; }
    public DateTime StockDate { get; set; }
    public string NoteNo { get; set; }
    public DateTime ExpireDate { get; set; }
    public string LotNo { get; set; }
    public int Quantity { get; set; }
    public string Term { get; set; }
    public double UnitPrice { get; set; }
    public string Section { get; set; }
    public string StoreID { get; set; }
}
[Serializable]
public class StockList : List<Stock>
{
    public StockList()
    {
        Add(new Stock
        {
            ProductCode = "0000001",
            ProductName = "スイートアーモンド",
            StockDate = DateTime.Today.AddDays(-9),
            NoteNo = "D040000004",
            ExpireDate = DateTime.Today.AddMonths(1),
            LotNo = "2011092001",
            Quantity = 200,
            Term = "本",
            UnitPrice = 90,
            Section = "仕入",
            StoreID = "MYG1001"
        });
        Add(new Stock
        {
            ProductCode = "0000001",
            ProductName = "スイートアーモンド",
            StockDate = DateTime.Today.AddDays(-9),
            NoteNo = "D040000004",
            ExpireDate = DateTime.Today.AddMonths(1),
            LotNo = "2011092003",
            Quantity = 400,
            Term = "本",
            UnitPrice = 90,
            Section = "仕入",
            StoreID = "MYG1001"
        });
        Add(new Stock
        {
            ProductCode = "0000001",
            ProductName = "スイートアーモンド",
            StockDate = DateTime.Today.AddDays(-6),
            NoteNo = "D040000001",
            ExpireDate = DateTime.Today.AddMonths(1),
            LotNo = "0000001",
            Quantity = 490,
            Term = "本",
            UnitPrice = 90,
            Section = "製造",
            StoreID = "MYG1001"
        });
        Add(new Stock
        {
            ProductCode = "0000002",
            ProductName = "グレープシード",
            StockDate = DateTime.Today.AddDays(-4),
            NoteNo = "D040000007",
            ExpireDate = DateTime.Today.AddMonths(2),
            LotNo = "20111119001",
            Quantity = 10,
            Term = "本",
            UnitPrice = 120,
            Section = "仕入",
            StoreID = "MYG1001"
        });
        Add(new Stock
        {
            ProductCode = "0000002",
            ProductName = "グレープシード",
            StockDate = DateTime.Today.AddDays(-5),
            NoteNo = "M040000002",
            ExpireDate = DateTime.Today.AddMonths(2),
            LotNo = "123",
            Quantity = 4,
            Term = "本",
            UnitPrice = 100,
            Section = "製造",
            StoreID = "MYG1001"
        });
        Add(new Stock
        {
            ProductCode = "0000003",
            ProductName = "オリーブ",
            StockDate = DateTime.Today.AddDays(-9),
            NoteNo = "D040000006",
            ExpireDate = DateTime.Today.AddMonths(3),
            LotNo = "20111119010",
            Quantity = 9,
            Term = "本",
            UnitPrice = 2000,
            Section = "仕入",
            StoreID = "MYG1002"
        });
        Add(new Stock
        {
            ProductCode = "0000005",
            ProductName = "馬油",
            StockDate = DateTime.Today.AddDays(-7),
            NoteNo = "D040000009",
            ExpireDate = DateTime.Today.AddYears(1),
            LotNo = "20111214002",
            Quantity = 84,
            Term = "Kg",
            UnitPrice = 3200,
            Section = "仕入",
            StoreID = "MYG1001"
        });
        Add(new Stock
        {
            ProductCode = "0000006",
            ProductName = "ビーワックス",
            StockDate = DateTime.Today.AddDays(-2),
            NoteNo = "D040000011",
            ExpireDate = DateTime.Today.AddYears(1),
            LotNo = "20111217004",
            Quantity = 150,
            Term = "Kg",
            UnitPrice = 1500,
            Section = "製造",
            StoreID = "MYG1002"
        });
        Add(new Stock
        {
            ProductCode = "0000010",
            ProductName = "えごま",
            StockDate = DateTime.Today.AddDays(-3),
            NoteNo = "D040000008",
            ExpireDate = DateTime.Today.AddMonths(1),
            LotNo = "20111120002",
            Quantity = 52,
            Term = "本",
            UnitPrice = 120,
            Section = "仕入",
            StoreID = "MYG1002"
        });
    }
}
<Serializable>
Public Class Stock
    Public Property ProductCode() As String
    Public Property ProductName() As String
    Public Property StockDate() As DateTime
    Public Property NoteNo() As String
    Public Property ExpireDate() As DateTime
    Public Property LotNo() As String
    Public Property Quantity() As Integer
    Public Property Term() As String
    Public Property UnitPrice() As Double
    Public Property Section() As String
    Public Property StoreID() As String
End Class
<Serializable>
Public Class StockList
    Inherits List(Of Stock)
    Public Sub New()
        Add(New Stock() With {
            .ProductCode = "0000001",
            .ProductName = "スイートアーモンド",
            .StockDate = DateTime.Today.AddDays(-9),
            .NoteNo = "D040000004",
            .ExpireDate = DateTime.Today.AddMonths(1),
            .LotNo = "2011092001",
            .Quantity = 200,
            .Term = "本",
            .UnitPrice = 90,
            .Section = "仕入",
            .StoreID = "MYG1001"
        })
        Add(New Stock() With {
            .ProductCode = "0000001",
            .ProductName = "スイートアーモンド",
            .StockDate = DateTime.Today.AddDays(-9),
            .NoteNo = "D040000004",
            .ExpireDate = DateTime.Today.AddMonths(1),
            .LotNo = "2011092003",
            .Quantity = 400,
            .Term = "本",
            .UnitPrice = 90,
            .Section = "仕入",
            .StoreID = "MYG1001"
        })
        Add(New Stock() With {
            .ProductCode = "0000001",
            .ProductName = "スイートアーモンド",
            .StockDate = DateTime.Today.AddDays(-6),
            .NoteNo = "D040000001",
            .ExpireDate = DateTime.Today.AddMonths(1),
            .LotNo = "0000001",
            .Quantity = 490,
            .Term = "本",
            .UnitPrice = 90,
            .Section = "製造",
            .StoreID = "MYG1001"
        })
        Add(New Stock() With {
            .ProductCode = "0000002",
            .ProductName = "グレープシード",
            .StockDate = DateTime.Today.AddDays(-4),
            .NoteNo = "D040000007",
            .ExpireDate = DateTime.Today.AddMonths(2),
            .LotNo = "20111119001",
            .Quantity = 10,
            .Term = "本",
            .UnitPrice = 120,
            .Section = "仕入",
            .StoreID = "MYG1001"
        })
        Add(New Stock() With {
            .ProductCode = "0000002",
            .ProductName = "グレープシード",
            .StockDate = DateTime.Today.AddDays(-5),
            .NoteNo = "M040000002",
            .ExpireDate = DateTime.Today.AddMonths(2),
            .LotNo = "123",
            .Quantity = 4,
            .Term = "本",
            .UnitPrice = 100,
            .Section = "製造",
            .StoreID = "MYG1001"
        })
        Add(New Stock() With {
            .ProductCode = "0000003",
            .ProductName = "オリーブ",
            .StockDate = DateTime.Today.AddDays(-9),
            .NoteNo = "D040000006",
            .ExpireDate = DateTime.Today.AddMonths(3),
            .LotNo = "20111119010",
            .Quantity = 9,
            .Term = "本",
            .UnitPrice = 2000,
            .Section = "仕入",
            .StoreID = "MYG1002"
        })
        Add(New Stock() With {
            .ProductCode = "0000005",
            .ProductName = "馬油",
            .StockDate = DateTime.Today.AddDays(-7),
            .NoteNo = "D040000009",
            .ExpireDate = DateTime.Today.AddYears(1),
            .LotNo = "20111214002",
            .Quantity = 84,
            .Term = "Kg",
            .UnitPrice = 3200,
            .Section = "仕入",
            .StoreID = "MYG1002"
        })
        Add(New Stock() With {
            .ProductCode = "0000006",
            .ProductName = "ビーワックス",
            .StockDate = DateTime.Today.AddDays(-2),
            .NoteNo = "D040000011",
            .ExpireDate = DateTime.Today.AddYears(1),
            .LotNo = "20111217004",
            .Quantity = 150,
            .Term = "Kg",
            .UnitPrice = 1500,
            .Section = "製造",
            .StoreID = "MYG1002"
        })
        Add(New Stock() With {
            .ProductCode = "0000010",
            .ProductName = "えごま",
            .StockDate = DateTime.Today.AddDays(-3),
            .NoteNo = "D040000008",
            .ExpireDate = DateTime.Today.AddMonths(1),
            .LotNo = "20111120002",
            .Quantity = 52,
            .Term = "本",
            .UnitPrice = 120,
            .Section = "仕入",
            .StoreID = "MYG1002"
        })
    End Sub
End Class
[Serializable]
public class Storehouse
{
    public string StoreID { get; set; }
    public string StoreName { get; set; }
    public List<Stock> Stocks { get; set; }      
}
[Serializable]
public class StorehouseList : List<Storehouse>
{
    public StorehouseList()
    {
        var stocks = new StockList();
        Add(new Storehouse() { StoreID = "MYG1001", StoreName = "宮城第1倉庫", Stocks = stocks.FindAll(s => s.StoreID == "MYG1001") });
        Add(new Storehouse() { StoreID = "MYG1002", StoreName = "宮城第2倉庫", Stocks = stocks.FindAll(s => s.StoreID == "MYG1002") });
        Add(new Storehouse() { StoreID = "MYG1003", StoreName = "宮城第3倉庫", Stocks = stocks.FindAll(s => s.StoreID == "MYG1003") });
    }
}
<Serializable>
Public Class Storehouse
    Public Property StoreID() As String
    Public Property StoreName() As String
    Public Property Stocks() As List(Of Stock)
End Class
<Serializable>
Public Class StorehouseList
    Inherits List(Of Storehouse)
    Public Sub New()
        Dim stocks = New StockList()
        Add(New Storehouse() With {
            .StoreID = "MYG1001",
            .StoreName = "宮城第1倉庫",
            .Stocks = stocks.FindAll(Function(s) s.StoreID = "MYG1001")
        })
        Add(New Storehouse() With {
            .StoreID = "MYG1002",
            .StoreName = "宮城第2倉庫",
            .Stocks = stocks.FindAll(Function(s) s.StoreID = "MYG1002")
        })
        Add(New Storehouse() With {
            .StoreID = "MYG1003",
            .StoreName = "宮城第3倉庫",
            .Stocks = stocks.FindAll(Function(s) s.StoreID = "MYG1003")
        })
    End Sub
End Class

 

 


© MESCIUS inc. All rights reserved.