作成日: 2015/09/14 最終更新日: 2015/09/14
文書種別
使用方法
詳細
DataSourceのDataProviderプロパティにExternalObjectを設定する場合や、C1Reportデザイナの接続のデータプロバイダに「外部アセンブリ内のオブジェクトへ接続」を設定する場合等では、ConnectionString(接続文字列)にIC1ReportExternalRecordsetインタフェースを実装するオブジェクトを作成し、そのオブジェクトを含むアセンブリを設定する必要があります。
IC1ReportExternalRecordsetインタフェースを実装するオブジェクトの実装例を以下に示します。
◎サンプルコード(Visual Basic)
◇ExtRecordset.vb
◇ExtRecordsetForm.vb
◎サンプルコード(C#)
◇ExtRecordset.cs
◇ExtRecordsetForm.cs
IC1ReportExternalRecordsetインタフェースを実装するオブジェクトの実装例を以下に示します。
◎サンプルコード(Visual Basic)
◇ExtRecordset.vb
Public Class ExtRecordset
Implements IC1ReportExternalRecordset
Private _recordset As Recordset
Public Sub New()
_recordset = New Recordset()
End Sub
Public Property RecCount() As Integer
Get
Return _recordset.RecCount
End Get
Set(value As Integer)
_recordset.RecCount = value
End Set
End Property
Public ReadOnly Property Caption As String Implements IC1ReportExternalRecordset.Caption
Get
Return "External recordset sample"
End Get
End Property
Public Sub EditParams() Implements IC1ReportExternalRecordset.EditParams
Using f As New ExtRecordsetForm()
f.Edit(Me)
End Using
End Sub
Public Function GetRecordset() As IC1ReportRecordset Implements IC1ReportExternalRecordset.GetRecordset
Return _recordset
End Function
Public Property Params As String Implements IC1ReportExternalRecordset.Params
Get
Return _recordset.RecCount.ToString()
End Get
Set(value As String)
Dim count As Integer
If (Integer.TryParse(value, count)) Then
_recordset.RecCount = count
End If
End Set
End Property
End Class
Public Class Recordset
Implements IC1ReportRecordset
Private _recNo As Integer
Private _items As List(Of RecordsetItem) = New List(Of RecordsetItem)()
Public Sub New()
RecCount = 60
End Sub
Private _recCount As Integer
Public Property RecCount() As Integer
Get
Return _items.Count
End Get
Set(value As Integer)
If _items.Count = value Then
Return
End If
For i As Integer = 1 To value
Dim item As RecordsetItem = New RecordsetItem()
item.ID = i
item.Caption = String.Format("Caption {0}", i)
_items.Add(item)
Next
End Set
End Property
Public Sub ApplyFilter(filter As String) Implements IC1ReportRecordset.ApplyFilter
End Sub
Public Sub ApplySort(sort As String) Implements IC1ReportRecordset.ApplySort
End Sub
Public Function BOF() As Boolean Implements IC1ReportRecordset.BOF
Return _recNo < 0
End Function
Public Function EOF() As Boolean Implements IC1ReportRecordset.EOF
Return _recNo >= _items.Count
End Function
Public Function GetBookmark() As Integer Implements IC1ReportRecordset.GetBookmark
Return _recNo
End Function
Public Function GetFieldNames() As String() Implements IC1ReportRecordset.GetFieldNames
Return New String() {"ID", "Caption"}
End Function
Public Function GetFieldTypes() As Type() Implements IC1ReportRecordset.GetFieldTypes
Return New Type() {GetType(Integer), GetType(String)}
End Function
Public Function GetFieldValue(fieldIndex As Integer) As Object Implements IC1ReportRecordset.GetFieldValue
Select Case fieldIndex
Case 0 : Return _items(_recNo).ID
Case 1 : Return _items(_recNo).Caption
Case Else : Return Nothing
End Select
End Function
Public Sub MoveFirst() Implements IC1ReportRecordset.MoveFirst
_recNo = 0
End Sub
Public Sub MoveLast() Implements IC1ReportRecordset.MoveLast
_recNo = _items.Count - 1
End Sub
Public Sub MoveNext() Implements IC1ReportRecordset.MoveNext
_recNo = _recNo + 1
End Sub
Public Sub MovePrevious() Implements IC1ReportRecordset.MovePrevious
_recNo = _recNo - 1
End Sub
Public Sub SetBookmark(bkmk As Integer) Implements IC1ReportRecordset.SetBookmark
_recNo = bkmk
End Sub
End Class
Public Class RecordsetItem
Public _id As Integer
Public Property ID() As Integer
Get
Return _id
End Get
Set(value As Integer)
_id = value
End Set
End Property
Public _caption As String
Public Property Caption() As String
Get
Return _caption
End Get
Set(value As String)
_caption = value
End Set
End Property
End Class
Implements IC1ReportExternalRecordset
Private _recordset As Recordset
Public Sub New()
_recordset = New Recordset()
End Sub
Public Property RecCount() As Integer
Get
Return _recordset.RecCount
End Get
Set(value As Integer)
_recordset.RecCount = value
End Set
End Property
Public ReadOnly Property Caption As String Implements IC1ReportExternalRecordset.Caption
Get
Return "External recordset sample"
End Get
End Property
Public Sub EditParams() Implements IC1ReportExternalRecordset.EditParams
Using f As New ExtRecordsetForm()
f.Edit(Me)
End Using
End Sub
Public Function GetRecordset() As IC1ReportRecordset Implements IC1ReportExternalRecordset.GetRecordset
Return _recordset
End Function
Public Property Params As String Implements IC1ReportExternalRecordset.Params
Get
Return _recordset.RecCount.ToString()
End Get
Set(value As String)
Dim count As Integer
If (Integer.TryParse(value, count)) Then
_recordset.RecCount = count
End If
End Set
End Property
End Class
Public Class Recordset
Implements IC1ReportRecordset
Private _recNo As Integer
Private _items As List(Of RecordsetItem) = New List(Of RecordsetItem)()
Public Sub New()
RecCount = 60
End Sub
Private _recCount As Integer
Public Property RecCount() As Integer
Get
Return _items.Count
End Get
Set(value As Integer)
If _items.Count = value Then
Return
End If
For i As Integer = 1 To value
Dim item As RecordsetItem = New RecordsetItem()
item.ID = i
item.Caption = String.Format("Caption {0}", i)
_items.Add(item)
Next
End Set
End Property
Public Sub ApplyFilter(filter As String) Implements IC1ReportRecordset.ApplyFilter
End Sub
Public Sub ApplySort(sort As String) Implements IC1ReportRecordset.ApplySort
End Sub
Public Function BOF() As Boolean Implements IC1ReportRecordset.BOF
Return _recNo < 0
End Function
Public Function EOF() As Boolean Implements IC1ReportRecordset.EOF
Return _recNo >= _items.Count
End Function
Public Function GetBookmark() As Integer Implements IC1ReportRecordset.GetBookmark
Return _recNo
End Function
Public Function GetFieldNames() As String() Implements IC1ReportRecordset.GetFieldNames
Return New String() {"ID", "Caption"}
End Function
Public Function GetFieldTypes() As Type() Implements IC1ReportRecordset.GetFieldTypes
Return New Type() {GetType(Integer), GetType(String)}
End Function
Public Function GetFieldValue(fieldIndex As Integer) As Object Implements IC1ReportRecordset.GetFieldValue
Select Case fieldIndex
Case 0 : Return _items(_recNo).ID
Case 1 : Return _items(_recNo).Caption
Case Else : Return Nothing
End Select
End Function
Public Sub MoveFirst() Implements IC1ReportRecordset.MoveFirst
_recNo = 0
End Sub
Public Sub MoveLast() Implements IC1ReportRecordset.MoveLast
_recNo = _items.Count - 1
End Sub
Public Sub MoveNext() Implements IC1ReportRecordset.MoveNext
_recNo = _recNo + 1
End Sub
Public Sub MovePrevious() Implements IC1ReportRecordset.MovePrevious
_recNo = _recNo - 1
End Sub
Public Sub SetBookmark(bkmk As Integer) Implements IC1ReportRecordset.SetBookmark
_recNo = bkmk
End Sub
End Class
Public Class RecordsetItem
Public _id As Integer
Public Property ID() As Integer
Get
Return _id
End Get
Set(value As Integer)
_id = value
End Set
End Property
Public _caption As String
Public Property Caption() As String
Get
Return _caption
End Get
Set(value As String)
_caption = value
End Set
End Property
End Class
◇ExtRecordsetForm.vb
Public Class ExtRecordsetForm
Public Sub New()
' この呼び出しはデザイナーで必要です。
InitializeComponent()
' InitializeComponent() 呼び出しの後で初期化を追加します。
Me.Label1 = New System.Windows.Forms.Label()
Me.tbRecCount = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(16, 17)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(97, 15)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Record count:"
Me.tbRecCount.Location = New System.Drawing.Point(132, 14)
Me.tbRecCount.Name = "tbRecCount"
Me.tbRecCount.Size = New System.Drawing.Size(126, 22)
Me.tbRecCount.TabIndex = 1
Me.Button1.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Button1.Location = New System.Drawing.Point(59, 69)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(100, 27)
Me.Button1.TabIndex = 2
Me.Button1.Text = "OK"
Me.Button1.UseVisualStyleBackColor = True
Me.Button2.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Button2.Location = New System.Drawing.Point(167, 69)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(100, 27)
Me.Button2.TabIndex = 3
Me.Button2.Text = "Cancel"
Me.Button2.UseVisualStyleBackColor = True
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.tbRecCount)
Me.Controls.Add(Me.Label1)
End Sub
Public Sub Edit(recordset As ExtRecordset)
tbRecCount.Text = recordset.RecCount.ToString()
If ShowDialog() = DialogResult.OK Then
recordset.RecCount = Integer.Parse(tbRecCount.Text)
End If
End Sub
End Class
Public Sub New()
' この呼び出しはデザイナーで必要です。
InitializeComponent()
' InitializeComponent() 呼び出しの後で初期化を追加します。
Me.Label1 = New System.Windows.Forms.Label()
Me.tbRecCount = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(16, 17)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(97, 15)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Record count:"
Me.tbRecCount.Location = New System.Drawing.Point(132, 14)
Me.tbRecCount.Name = "tbRecCount"
Me.tbRecCount.Size = New System.Drawing.Size(126, 22)
Me.tbRecCount.TabIndex = 1
Me.Button1.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Button1.Location = New System.Drawing.Point(59, 69)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(100, 27)
Me.Button1.TabIndex = 2
Me.Button1.Text = "OK"
Me.Button1.UseVisualStyleBackColor = True
Me.Button2.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Button2.Location = New System.Drawing.Point(167, 69)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(100, 27)
Me.Button2.TabIndex = 3
Me.Button2.Text = "Cancel"
Me.Button2.UseVisualStyleBackColor = True
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.tbRecCount)
Me.Controls.Add(Me.Label1)
End Sub
Public Sub Edit(recordset As ExtRecordset)
tbRecCount.Text = recordset.RecCount.ToString()
If ShowDialog() = DialogResult.OK Then
recordset.RecCount = Integer.Parse(tbRecCount.Text)
End If
End Sub
End Class
◎サンプルコード(C#)
◇ExtRecordset.cs
public class ExtRecordset : IC1ReportExternalRecordset
{
private Recordset _recordset;
public ExtRecordset()
{
_recordset = new Recordset();
}
public int RecCount
{
get { return _recordset.RecCount; }
set { _recordset.RecCount = value; }
}
public string Caption
{
get { return "External recordset sample"; }
}
public void EditParams()
{
using (ExtRecordsetForm f = new ExtRecordsetForm())
f.Edit(this);
}
public IC1ReportRecordset GetRecordset()
{
return _recordset;
}
public string Params
{
get
{
return _recordset.RecCount.ToString();
}
set
{
int count;
if (int.TryParse(value, out count))
_recordset.RecCount = count;
}
}
}
public class Recordset : IC1ReportRecordset
{
private int _recNo;
private List _items = new List();
public Recordset()
{
RecCount = 60;
}
public int RecCount
{
get { return _items.Count; }
set
{
if (_items.Count == value)
return;
_items.Clear();
for (int i = 1; i <= value; i++)
{
RecordsetItem item = new RecordsetItem();
item.ID = i;
item.Caption = string.Format("Caption {0}", i);
_items.Add(item);
}
}
}
public void ApplyFilter(string filter)
{
}
public void ApplySort(string sort)
{
}
public bool BOF()
{
return _recNo < 0;
}
public bool EOF()
{
return _recNo >= _items.Count;
}
public int GetBookmark()
{
return _recNo;
}
public string[] GetFieldNames()
{
return new string[] { "ID", "Caption" };
}
public Type[] GetFieldTypes()
{
return new Type[] { typeof(int), typeof(string) };
}
public object GetFieldValue(int fieldIndex)
{
switch (fieldIndex)
{
case 0: return _items[_recNo].ID;
case 1: return _items[_recNo].Caption;
default: return null;
}
}
public void MoveFirst()
{
_recNo = 0;
}
public void MoveLast()
{
_recNo = _items.Count - 1;
}
public void MoveNext()
{
_recNo++;
}
public void MovePrevious()
{
_recNo--;
}
public void SetBookmark(int bkmk)
{
_recNo = bkmk;
}
}
public class RecordsetItem
{
public int ID { get; set; }
public string Caption { get; set; }
}
{
private Recordset _recordset;
public ExtRecordset()
{
_recordset = new Recordset();
}
public int RecCount
{
get { return _recordset.RecCount; }
set { _recordset.RecCount = value; }
}
public string Caption
{
get { return "External recordset sample"; }
}
public void EditParams()
{
using (ExtRecordsetForm f = new ExtRecordsetForm())
f.Edit(this);
}
public IC1ReportRecordset GetRecordset()
{
return _recordset;
}
public string Params
{
get
{
return _recordset.RecCount.ToString();
}
set
{
int count;
if (int.TryParse(value, out count))
_recordset.RecCount = count;
}
}
}
public class Recordset : IC1ReportRecordset
{
private int _recNo;
private List
public Recordset()
{
RecCount = 60;
}
public int RecCount
{
get { return _items.Count; }
set
{
if (_items.Count == value)
return;
_items.Clear();
for (int i = 1; i <= value; i++)
{
RecordsetItem item = new RecordsetItem();
item.ID = i;
item.Caption = string.Format("Caption {0}", i);
_items.Add(item);
}
}
}
public void ApplyFilter(string filter)
{
}
public void ApplySort(string sort)
{
}
public bool BOF()
{
return _recNo < 0;
}
public bool EOF()
{
return _recNo >= _items.Count;
}
public int GetBookmark()
{
return _recNo;
}
public string[] GetFieldNames()
{
return new string[] { "ID", "Caption" };
}
public Type[] GetFieldTypes()
{
return new Type[] { typeof(int), typeof(string) };
}
public object GetFieldValue(int fieldIndex)
{
switch (fieldIndex)
{
case 0: return _items[_recNo].ID;
case 1: return _items[_recNo].Caption;
default: return null;
}
}
public void MoveFirst()
{
_recNo = 0;
}
public void MoveLast()
{
_recNo = _items.Count - 1;
}
public void MoveNext()
{
_recNo++;
}
public void MovePrevious()
{
_recNo--;
}
public void SetBookmark(int bkmk)
{
_recNo = bkmk;
}
}
public class RecordsetItem
{
public int ID { get; set; }
public string Caption { get; set; }
}
◇ExtRecordsetForm.cs
public partial class ExtRecordsetForm : Form
{
public ExtRecordsetForm()
{
InitializeComponent();
this.label1 = new System.Windows.Forms.Label();
this.tbRecCount = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(97, 15);
this.label1.TabIndex = 0;
this.label1.Text = "Record count:";
this.tbRecCount.Location = new System.Drawing.Point(132, 14);
this.tbRecCount.Name = "tbRecCount";
this.tbRecCount.Size = new System.Drawing.Size(126, 22);
this.tbRecCount.TabIndex = 1;
this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button1.Location = new System.Drawing.Point(59, 69);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(100, 27);
this.button1.TabIndex = 2;
this.button1.Text = "OK";
this.button1.UseVisualStyleBackColor = true;
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(167, 69);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(100, 27);
this.button2.TabIndex = 3;
this.button2.Text = "Cancel";
this.button2.UseVisualStyleBackColor = true;
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.tbRecCount);
this.Controls.Add(this.label1);
}
public void Edit(ExtRecordset recordset)
{
tbRecCount.Text = recordset.RecCount.ToString();
if (ShowDialog() == System.Windows.Forms.DialogResult.OK)
recordset.RecCount = int.Parse(tbRecCount.Text);
}
}
{
public ExtRecordsetForm()
{
InitializeComponent();
this.label1 = new System.Windows.Forms.Label();
this.tbRecCount = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(97, 15);
this.label1.TabIndex = 0;
this.label1.Text = "Record count:";
this.tbRecCount.Location = new System.Drawing.Point(132, 14);
this.tbRecCount.Name = "tbRecCount";
this.tbRecCount.Size = new System.Drawing.Size(126, 22);
this.tbRecCount.TabIndex = 1;
this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button1.Location = new System.Drawing.Point(59, 69);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(100, 27);
this.button1.TabIndex = 2;
this.button1.Text = "OK";
this.button1.UseVisualStyleBackColor = true;
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(167, 69);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(100, 27);
this.button2.TabIndex = 3;
this.button2.Text = "Cancel";
this.button2.UseVisualStyleBackColor = true;
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.tbRecCount);
this.Controls.Add(this.label1);
}
public void Edit(ExtRecordset recordset)
{
tbRecCount.Text = recordset.RecCount.ToString();
if (ShowDialog() == System.Windows.Forms.DialogResult.OK)
recordset.RecCount = int.Parse(tbRecCount.Text);
}
}
旧文書番号
81456