[C#] public class XmlFileDataAdapter : DbDataAdapter, IDbDataAdapter { XmlFileCommand selectCommand; XmlFileCommand insertCommand; XmlFileCommand updateCommand; XmlFileCommand deleteCommand; private bool disposed; private static readonly object EventRowUpdated = new object(); private static readonly object EventRowUpdating = new object(); public XmlFileDataAdapter() { disposed = false; } public XmlFileDataAdapter(XmlFileCommand cmd) : this() { selectCommand = cmd; } public XmlFileDataAdapter (String strCommand, XmlFileConnection conn) : this() { selectCommand = new XmlFileCommand(strCommand, conn); } public IDbCommand UpdateCommand { get { return updateCommand; } set { if (value.GetType() == typeof(XmlFileCommand)) updateCommand = (XmlFileCommand)value; else throw new ApplicationException (SR.ExceptionMustBeXmlFileCmmands); } } public IDbCommand SelectCommand { get { return selectCommand; } set { if (value.GetType() == typeof(XmlFileCommand)) selectCommand = (XmlFileCommand)value; else throw new ApplicationException (SR.ExceptionMustBeXmlFileCmmands); } } public IDbCommand DeleteCommand { get { return deleteCommand; } set { if (value.GetType() == typeof(XmlFileCommand)) deleteCommand = (XmlFileCommand)value; else throw new ApplicationException (SR.ExceptionMustBeXmlFileCmmands); } } public IDbCommand InsertCommand { get { return insertCommand; } set { if (value.GetType() == typeof(XmlFileCommand)) insertCommand = (XmlFileCommand)value; else throw new ApplicationException (SR.ExceptionMustBeXmlFileCmmands); } } public new int Update(DataSet dataSet) { dataSet.WriteXml(this.selectCommand.CommandText); return 0; } public new int Update(DataSet dataSet, string srcTable) { if (dataSet.Tables[srcTable] == dataSet.Tables[dataSet.Tables.Count]) dataSet.WriteXml(this.selectCommand.CommandText); return 0; } override protected RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) { return new XmlFileRowUpdatedEventArgs (dataRow, command, statementType, tableMapping); } override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) { return new XmlFileRowUpdatingEventArgs (dataRow, command, statementType, tableMapping); } ... } [Visual Basic] Public Class XmlFileDataAdapter : Inherits DbDataAdapter _ : Implements IDbDataAdapter Private _selectCommand As XmlFileCommand Private _insertCommand As XmlFileCommand Private _updateCommand As XmlFileCommand Private _deleteCommand As XmlFileCommand Private disposed As Boolean Private Shared ReadOnly EventRowUpdated As Object = _ New Object() Private Shared ReadOnly EventRowUpdating As Object = _ New Object() Public Sub New() disposed = False End Sub Public Sub New(ByVal cmd As XmlFileCommand) Me.New() _selectCommand = cmd End Sub Public Sub New(ByVal strCommand As String, _ ByVal conn As XmlFileConnection) Me.New() _selectCommand = _ New XmlFileCommand(strCommand, conn) End Sub Public Property UpdateCommand() As IDbCommand _ Implements IDbDataAdapter.UpdateCommand Get Return _updateCommand End Get Set If Value.GetType() Is GetType(XmlFileCommand) Then _updateCommand = _ CType(Value, XmlFileCommand) Else Throw New _ ApplicationException _ (SR.ExceptionMustBeXmlFileCmmands) End If End Set End Property Public Property SelectCommand() As IDbCommand _ Implements IDbDataAdapter.SelectCommand Get Return _selectCommand End Get Set If Value.GetType() Is GetType(XmlFileCommand) Then _selectCommand = CType(Value, XmlFileCommand) Else Throw New ApplicationException _ (SR.ExceptionMustBeXmlFileCmmands) End If End Set End Property Public Property DeleteCommand() As IDbCommand _ Implements IDbDataAdapter.DeleteCommand Get Return _deleteCommand End Get Set If Value.GetType() Is GetType(XmlFileCommand) Then _deleteCommand = CType(Value, XmlFileCommand) Else Throw New ApplicationException _ (SR.ExceptionMustBeXmlFileCmmands) End If End Set End Property Public Property InsertCommand() As IDbCommand _ Implements IDbDataAdapter.InsertCommand Get Return _insertCommand End Get Set If Value.GetType() Is GetType(XmlFileCommand) Then _insertCommand = CType(Value, XmlFileCommand) Else Throw New ApplicationException _ (SR.ExceptionMustBeXmlFileCmmands) End If End Set End Property Public Shadows Function Update(ByVal dataSet As DataSet) _ As Integer dataSet.WriteXml(Me._selectCommand.CommandText) Return 0 End Function Public Shadows Function Update(ByVal dataSet As DataSet, _ ByVal srcTable As String) As Integer If dataSet.Tables(srcTable) = _ dataSet.Tables(dataSet.Tables.Count) Then dataSet.WriteXml _ (Me._selectCommand.CommandText) End If Return 0 End Function Overrides Protected Function CreateRowUpdatedEvent _ (ByVal dataRow As DataRow, ByVal command As IDbCommand, _ ByVal statementType As StatementType, ByVal tableMapping _ As DataTableMapping) As RowUpdatedEventArgs Return New XmlFileRowUpdatedEventArgs _ (dataRow, command, statementType, tableMapping) End Function Overrides Protected Function CreateRowUpdatingEvent _ (ByVal dataRow As DataRow, ByVal command As IDbCommand, _ ByVal statementType As StatementType, ByVal tableMapping _ As DataTableMapping) As RowUpdatingEventArgs Return New XmlFileRowUpdatingEventArgs _ (dataRow, command, statementType, tableMapping) End Function ... End Class |