1 // Copyright (c) 1999-2018 David Muse 2 // See the file COPYING for more information 3 4 using System; 5 using System.Data; 6 using System.Data.Common; 7 8 namespace SQLRClient 9 { 10 public class SQLRelayDataAdapter : DbDataAdapter, IDbDataAdapter 11 { 12 private SQLRelayCommand _selectcommand; 13 private SQLRelayCommand _insertcommand; 14 private SQLRelayCommand _updatecommand; 15 private SQLRelayCommand _deletecommand; 16 17 static private readonly Object EventRowUpdating = new Object(); 18 static private readonly Object EventRowUpdated = new Object(); 19 20 /** Initializes a new instance of the SQLRelayDataAdapter class. */ SQLRelayDataAdapter()21 public SQLRelayDataAdapter() 22 { 23 } 24 25 /** Gets or set the query used to select records in the data source. */ 26 new public SQLRelayCommand SelectCommand 27 { 28 get 29 { 30 return _selectcommand; 31 } 32 set 33 { 34 _selectcommand = value; 35 } 36 } 37 38 /** Gets or set the query used to select records in the data source. */ 39 IDbCommand IDbDataAdapter.SelectCommand 40 { 41 get 42 { 43 return _selectcommand; 44 } 45 set 46 { 47 _selectcommand = (SQLRelayCommand)value; 48 } 49 } 50 51 /** Gets or set the query used to insert records into the data 52 * source. */ 53 new public SQLRelayCommand InsertCommand 54 { 55 get 56 { 57 return _insertcommand; 58 } 59 set 60 { 61 _insertcommand = value; 62 } 63 } 64 65 /** Gets or set the query used to insert records into the data 66 * source. */ 67 IDbCommand IDbDataAdapter.InsertCommand 68 { 69 get 70 { 71 return _insertcommand; 72 } 73 set 74 { 75 _insertcommand = (SQLRelayCommand)value; 76 } 77 } 78 79 /** Gets or set the query used to update records in the data source. */ 80 new public SQLRelayCommand UpdateCommand 81 { 82 get 83 { 84 return _updatecommand; 85 } 86 set 87 { 88 _updatecommand = value; 89 } 90 } 91 92 /** Gets or set the query used to update records in the data source. */ 93 IDbCommand IDbDataAdapter.UpdateCommand 94 { 95 get 96 { 97 return _updatecommand; 98 } 99 set 100 { 101 _updatecommand = (SQLRelayCommand)value; 102 } 103 } 104 105 /** Gets or set the query used to delete records from the data 106 * source. */ 107 new public SQLRelayCommand DeleteCommand 108 { 109 get 110 { 111 return _deletecommand; 112 } 113 set 114 { 115 _deletecommand = value; 116 } 117 } 118 119 /** Gets or set the query used to delete records from the data 120 * source. */ 121 IDbCommand IDbDataAdapter.DeleteCommand 122 { 123 get 124 { 125 return _deletecommand; 126 } 127 set 128 { 129 _deletecommand = (SQLRelayCommand)value; 130 } 131 } 132 133 /** Initializes a new instance of the RowUpdatingEventArgs class. */ CreateRowUpdatingEvent(DataRow datarow, IDbCommand command, StatementType statementtype, DataTableMapping datatablemapping)134 override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow datarow, IDbCommand command, StatementType statementtype, DataTableMapping datatablemapping) 135 { 136 return new SQLRelayRowUpdatingEventArgs(datarow, command, statementtype, datatablemapping); 137 } 138 139 /** Initializes a new instance of the RowUpdatingEventArgs class. */ CreateRowUpdatedEvent(DataRow datarow, IDbCommand command, StatementType statementtype, DataTableMapping datatablemapping)140 override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow datarow, IDbCommand command, StatementType statementtype, DataTableMapping datatablemapping) 141 { 142 return new SQLRelayRowUpdatedEventArgs(datarow, command, statementtype, datatablemapping); 143 } 144 145 /** Raises the RowUpdating event of a .NET Framework data provider. */ OnRowUpdating(RowUpdatingEventArgs value)146 protected override void OnRowUpdating(RowUpdatingEventArgs value) 147 { 148 SQLRelayRowUpdatingEventHandler handler = (SQLRelayRowUpdatingEventHandler)Events[EventRowUpdating]; 149 if (handler != null && value is SQLRelayRowUpdatingEventArgs) 150 { 151 handler(this, (SQLRelayRowUpdatingEventArgs)value); 152 } 153 } 154 155 /** Raises the RowUpdated event of a .NET Framework data provider. */ OnRowUpdated(RowUpdatedEventArgs value)156 protected override void OnRowUpdated(RowUpdatedEventArgs value) 157 { 158 SQLRelayRowUpdatedEventHandler handler = (SQLRelayRowUpdatedEventHandler)Events[EventRowUpdated]; 159 if (handler != null && value is SQLRelayRowUpdatedEventArgs) 160 { 161 handler(this, (SQLRelayRowUpdatedEventArgs)value); 162 } 163 } 164 165 /** Occurs during Update before a command is executed against the 166 * data source. The attempt to update is made, so the even fires. */ 167 public event SQLRelayRowUpdatingEventHandler RowUpdating 168 { 169 add 170 { 171 Events.AddHandler(EventRowUpdating, value); 172 } 173 remove 174 { 175 Events.RemoveHandler(EventRowUpdating, value); 176 } 177 } 178 179 /** Occurs during Update after a command is executed against the 180 * data source. The attempt to update is made, so the even fires. */ 181 public event SQLRelayRowUpdatedEventHandler RowUpdated 182 { 183 add 184 { 185 Events.AddHandler(EventRowUpdated, value); 186 } 187 remove 188 { 189 Events.RemoveHandler(EventRowUpdated, value); 190 } 191 } 192 } 193 SQLRelayRowUpdatingEventHandler(Object sender, SQLRelayRowUpdatingEventArgs e)194 public delegate void SQLRelayRowUpdatingEventHandler(Object sender, SQLRelayRowUpdatingEventArgs e); SQLRelayRowUpdatedEventHandler(Object sender, SQLRelayRowUpdatedEventArgs e)195 public delegate void SQLRelayRowUpdatedEventHandler(Object sender, SQLRelayRowUpdatedEventArgs e); 196 197 public class SQLRelayRowUpdatingEventArgs : RowUpdatingEventArgs 198 { SQLRelayRowUpdatingEventArgs(DataRow datarow, IDbCommand command, StatementType statementtype, DataTableMapping datatablemapping)199 public SQLRelayRowUpdatingEventArgs(DataRow datarow, IDbCommand command, StatementType statementtype, DataTableMapping datatablemapping) 200 : base(datarow, command, statementtype, datatablemapping) 201 { 202 } 203 204 new public SQLRelayCommand Command 205 { 206 get 207 { 208 return (SQLRelayCommand)base.Command; 209 } 210 set 211 { 212 base.Command = value; 213 } 214 } 215 } 216 217 public class SQLRelayRowUpdatedEventArgs : RowUpdatedEventArgs 218 { SQLRelayRowUpdatedEventArgs(DataRow datarow, IDbCommand command, StatementType statementtype, DataTableMapping datatablemapping)219 public SQLRelayRowUpdatedEventArgs(DataRow datarow, IDbCommand command, StatementType statementtype, DataTableMapping datatablemapping) 220 : base(datarow, command, statementtype, datatablemapping) 221 { 222 } 223 224 new public SQLRelayCommand Command 225 { 226 get 227 { 228 return (SQLRelayCommand)base.Command; 229 } 230 } 231 } 232 } 233