1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
|
//
// System.Web.UI.WebControls.SqlDataSourceView
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
// Sanjay Gupta (gsanjay@novell.com)
//
// (C) 2003 Ben Maurer
// (C) Novell, Inc. (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Data;
using System.ComponentModel;
using System.Data.Common;
namespace System.Web.UI.WebControls {
public class SqlDataSourceView : DataSourceView, IStateManager {
HttpContext context;
DbProviderFactory factory;
DbConnection connection;
public SqlDataSourceView (SqlDataSource owner, string name, HttpContext context)
: base (owner, name)
{
this.owner = owner;
this.name = name;
this.context = context;
}
void InitConnection ()
{
if (factory == null) factory = owner.GetDbProviderFactoryInternal ();
if (connection == null) {
connection = factory.CreateConnection ();
connection.ConnectionString = owner.ConnectionString;
}
}
public int Delete (IDictionary keys, IDictionary oldValues)
{
return ExecuteDelete (keys, oldValues);
}
protected override int ExecuteDelete (IDictionary keys, IDictionary oldValues)
{
if (!CanDelete)
throw new NotSupportedException("Delete operation is not supported");
if (oldValues == null && ConflictDetection == ConflictOptions.CompareAllValues)
throw new InvalidOperationException ("oldValues parameters should be specified when ConflictOptions is set to CompareAllValues");
InitConnection ();
DbCommand command = factory.CreateCommand ();
command.CommandText = DeleteCommand;
command.Connection = connection;
if (DeleteCommandType == SqlDataSourceCommandType.Text)
command.CommandType = CommandType.Text;
else
command.CommandType = CommandType.StoredProcedure;
IDictionary oldDataValues;
if (ConflictDetection == ConflictOptions.CompareAllValues) {
oldDataValues = new Hashtable ();
if (keys != null) {
foreach (DictionaryEntry de in keys)
oldDataValues [de.Key] = de.Value;
}
if (oldValues != null) {
foreach (DictionaryEntry de in oldValues)
oldDataValues [de.Key] = de.Value;
}
}
else
oldDataValues = keys;
InitializeParameters (command, DeleteParameters, null, oldDataValues, true);
SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
OnDeleting (args);
if (args.Cancel)
return -1;
bool closed = connection.State == ConnectionState.Closed;
if (closed)
connection.Open();
Exception exception = null;
int result = -1;;
try {
result = command.ExecuteNonQuery();
} catch (Exception e) {
exception = e;
}
if (closed)
connection.Close ();
OnDataSourceViewChanged (EventArgs.Empty);
SqlDataSourceStatusEventArgs deletedArgs =
new SqlDataSourceStatusEventArgs (command, result, exception);
OnDeleted (deletedArgs);
if (exception != null && !deletedArgs.ExceptionHandled)
throw exception;
return result;
}
public int Insert (IDictionary values)
{
return ExecuteInsert (values);
}
protected override int ExecuteInsert (IDictionary values)
{
if (!CanInsert)
throw new NotSupportedException ("Insert operation is not supported");
InitConnection ();
DbCommand command = factory.CreateCommand ();
command.CommandText = InsertCommand;
command.Connection = connection;
if (InsertCommandType == SqlDataSourceCommandType.Text)
command.CommandType = CommandType.Text;
else
command.CommandType = CommandType.StoredProcedure;
InitializeParameters (command, InsertParameters, values, null, false);
SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
OnInserting (args);
if (args.Cancel)
return -1;
bool closed = connection.State == ConnectionState.Closed;
if (closed)
connection.Open ();
Exception exception = null;
int result = -1;
try {
result = command.ExecuteNonQuery ();
}
catch (Exception e) {
exception = e;
}
if (closed)
connection.Close ();
OnDataSourceViewChanged (EventArgs.Empty);
OnInserted (new SqlDataSourceStatusEventArgs (command, result, exception));
if (exception != null)
throw exception;
return result;
}
public IEnumerable Select (DataSourceSelectArguments arguments)
{
return ExecuteSelect (arguments);
}
protected internal override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
{
if (SortParameterName.Length > 0 && SelectCommandType == SqlDataSourceCommandType.Text)
throw new NotSupportedException ("The SortParameterName property is only supported with stored procedure commands in SqlDataSource");
if (arguments.SortExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
throw new NotSupportedException ("SqlDataSource cannot sort. Set DataSourceMode to DataSet to enable sorting.");
if (arguments.StartRowIndex > 0 || arguments.MaximumRows > 0)
throw new NotSupportedException ("SqlDataSource does not have paging enabled. Set the DataSourceMode to DataSet to enable paging.");
if (FilterExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
throw new NotSupportedException ("SqlDataSource only supports filtering when the data source's DataSourceMode is set to DataSet.");
InitConnection ();
DbCommand command = factory.CreateCommand ();
command.CommandText = SelectCommand;
command.Connection = connection;
if (SelectCommandType == SqlDataSourceCommandType.Text)
command.CommandType = CommandType.Text;
else {
command.CommandType = CommandType.StoredProcedure;
if (SortParameterName.Length > 0 && arguments.SortExpression.Length > 0)
command.Parameters.Add (CreateDbParameter (SortParameterName, arguments.SortExpression));
}
if (SelectParameters.Count > 0)
InitializeParameters (command, SelectParameters, null, null, false);
Exception exception = null;
if (owner.DataSourceMode == SqlDataSourceMode.DataSet) {
DataView dataView = null;
if (owner.EnableCaching)
dataView = (DataView) owner.Cache.GetCachedObject (SelectCommand, SelectParameters);
if (dataView == null) {
SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
OnSelecting (selectingArgs);
if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
return null;
}
try {
DbDataAdapter adapter = factory.CreateDataAdapter ();
DataSet dataset = new DataSet ();
adapter.SelectCommand = command;
adapter.Fill (dataset, name);
dataView = dataset.Tables [0].DefaultView;
if (dataView == null)
throw new InvalidOperationException ();
}
catch (Exception e) {
exception = e;
}
int rowsAffected = (dataView == null) ? 0 : dataView.Count;
SqlDataSourceStatusEventArgs selectedArgs = new SqlDataSourceStatusEventArgs (command, rowsAffected, exception);
OnSelected (selectedArgs);
if (exception != null && !selectedArgs.ExceptionHandled)
throw exception;
if (owner.EnableCaching)
owner.Cache.SetCachedObject (SelectCommand, selectParameters, dataView);
}
if (SortParameterName.Length == 0 || SelectCommandType == SqlDataSourceCommandType.Text)
dataView.Sort = arguments.SortExpression;
if (FilterExpression.Length > 0) {
IOrderedDictionary fparams = FilterParameters.GetValues (context, owner);
SqlDataSourceFilteringEventArgs fargs = new SqlDataSourceFilteringEventArgs (fparams);
OnFiltering (fargs);
if (!fargs.Cancel) {
object [] formatValues = new object [fparams.Count];
for (int n = 0; n < formatValues.Length; n++) {
formatValues [n] = fparams [n];
if (formatValues [n] == null) return dataView;
}
dataView.RowFilter = string.Format (FilterExpression, formatValues);
}
}
return dataView;
}
else {
SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
OnSelecting (selectingArgs);
if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
return null;
}
DbDataReader reader = null;
bool closed = connection.State == ConnectionState.Closed;
if (closed)
connection.Open ();
try {
reader = command.ExecuteReader (closed ? CommandBehavior.CloseConnection : CommandBehavior.Default);
}
catch (Exception e) {
exception = e;
}
int rows = reader == null ? 0 : reader.RecordsAffected;
SqlDataSourceStatusEventArgs selectedArgs = new SqlDataSourceStatusEventArgs (command, rows, exception);
OnSelected (selectedArgs);
if (exception != null && !selectedArgs.ExceptionHandled)
throw exception;
return reader;
}
}
static bool PrepareNullParameters (DbCommand command, bool cancelIfHas)
{
for (int i = 0; i < command.Parameters.Count; i++) {
DbParameter param = command.Parameters [i];
if (param.Value == null && ((param.Direction & ParameterDirection.Input) != 0)) {
if (cancelIfHas)
return false;
else
param.Value = DBNull.Value;
}
}
return true;
}
public int Update (IDictionary keys, IDictionary values, IDictionary oldValues)
{
return ExecuteUpdate (keys, values, oldValues);
}
protected override int ExecuteUpdate (IDictionary keys, IDictionary values, IDictionary oldValues)
{
if (!CanUpdate)
throw new NotSupportedException ("Update operation is not supported");
if (oldValues == null && ConflictDetection == ConflictOptions.CompareAllValues)
throw new InvalidOperationException ("oldValues parameters should be specified when ConflictOptions is set to CompareAllValues");
InitConnection ();
DbCommand command = factory.CreateCommand ();
command.CommandText = UpdateCommand;
command.Connection = connection;
if (UpdateCommandType == SqlDataSourceCommandType.Text)
command.CommandType = CommandType.Text;
else
command.CommandType = CommandType.StoredProcedure;
IDictionary oldDataValues;
if (ConflictDetection == ConflictOptions.CompareAllValues) {
oldDataValues = new OrderedDictionary ();
if (keys != null) {
foreach (DictionaryEntry de in keys)
oldDataValues [de.Key] = de.Value;
}
if (oldValues != null) {
foreach (DictionaryEntry de in oldValues)
oldDataValues [de.Key] = de.Value;
}
}
else {
oldDataValues = keys;
}
IDictionary dataValues = values;
InitializeParameters (command, UpdateParameters, dataValues, oldDataValues, ConflictDetection == ConflictOptions.OverwriteChanges);
SqlDataSourceCommandEventArgs args = new SqlDataSourceCommandEventArgs (command);
OnUpdating (args);
if (args.Cancel)
return -1;
bool closed = connection.State == ConnectionState.Closed;
if (closed)
connection.Open ();
Exception exception = null;
int result = -1;
try {
result = command.ExecuteNonQuery ();
}
catch (Exception e) {
exception = e;
}
if (closed)
connection.Close ();
OnDataSourceViewChanged (EventArgs.Empty);
SqlDataSourceStatusEventArgs updatedArgs =
new SqlDataSourceStatusEventArgs (command, result, exception);
OnUpdated (updatedArgs);
if (exception != null && !updatedArgs.ExceptionHandled)
throw exception;
return result;
}
string FormatOldParameter (string name)
{
string f = OldValuesParameterFormatString;
if (f.Length > 0)
return String.Format (f, name);
else
return name;
}
object FindValueByName (string parameterName, IDictionary values, bool format)
{
if (values == null)
return null;
foreach (DictionaryEntry de in values) {
string valueName = format == true ? FormatOldParameter (de.Key.ToString ()) : de.Key.ToString ();
if (String.Compare(parameterName, valueName, StringComparison.InvariantCultureIgnoreCase) == 0)
return values [de.Key];
}
return null;
}
void InitializeParameters (DbCommand command, ParameterCollection parameters, IDictionary values, IDictionary oldValues, bool parametersMayMatchOldValues)
{
IOrderedDictionary parameterValues = parameters.GetValues (context, owner);
foreach (string parameterName in parameterValues.Keys) {
Parameter p = parameters [parameterName];
object value = FindValueByName (parameterName, values, false);
string valueName = parameterName;
if (value == null)
value = FindValueByName (parameterName, oldValues, true);
if (value == null && parametersMayMatchOldValues) {
value = FindValueByName (parameterName, oldValues, false);
valueName = FormatOldParameter (parameterName);
}
if (value != null) {
object dbValue = p.ConvertValue (value);
DbParameter newParameter = CreateDbParameter (valueName, dbValue, p.Direction, p.Size);
if (!command.Parameters.Contains (newParameter.ParameterName)) {
command.Parameters.Add (newParameter);
}
}
else {
command.Parameters.Add (CreateDbParameter (p.Name, parameterValues [parameterName], p.Direction, p.Size));
}
}
if (values != null) {
foreach (DictionaryEntry de in values)
if (!command.Parameters.Contains (ParameterPrefix + (string) de.Key))
command.Parameters.Add (CreateDbParameter ((string) de.Key, de.Value));
}
if (oldValues != null) {
foreach (DictionaryEntry de in oldValues)
if (!command.Parameters.Contains (ParameterPrefix + FormatOldParameter ((string) de.Key)))
command.Parameters.Add (CreateDbParameter (FormatOldParameter ((string) de.Key), de.Value));
}
}
DbParameter CreateDbParameter (string name, object value)
{
return CreateDbParameter (name, value, ParameterDirection.Input, -1);
}
DbParameter CreateDbParameter (string name, object value, ParameterDirection dir, int size)
{
DbParameter dbp = factory.CreateParameter ();
dbp.ParameterName = ParameterPrefix + name;
dbp.Value = value;
dbp.Direction = dir;
if (size != -1)
dbp.Size = size;
return dbp;
}
void IStateManager.LoadViewState (object savedState)
{
LoadViewState (savedState);
}
object IStateManager.SaveViewState ()
{
return SaveViewState ();
}
void IStateManager.TrackViewState ()
{
TrackViewState ();
}
NotSupportedException CreateNotSupportedException (string capabilityName)
{
return new NotSupportedException ("Data source does not have the '" + capabilityName + "' capability enabled.");
}
protected internal override void RaiseUnsupportedCapabilityError (DataSourceCapabilities capability)
{
if ((capability & DataSourceCapabilities.Sort) != 0 && !CanSort)
throw CreateNotSupportedException ("Sort");
if ((capability & DataSourceCapabilities.Page) != 0 && !CanPage)
throw CreateNotSupportedException ("Page");
if ((capability & DataSourceCapabilities.RetrieveTotalRowCount) != 0 && !CanRetrieveTotalRowCount)
throw CreateNotSupportedException ("RetrieveTotalRowCount");
}
protected virtual void LoadViewState (object savedState)
{
object [] vs = savedState as object [];
if (vs == null)
return;
if (vs [0] != null) ((IStateManager) deleteParameters).LoadViewState (vs [0]);
if (vs [1] != null) ((IStateManager) filterParameters).LoadViewState (vs [1]);
if (vs [2] != null) ((IStateManager) insertParameters).LoadViewState (vs [2]);
if (vs [3] != null) ((IStateManager) selectParameters).LoadViewState (vs [3]);
if (vs [4] != null) ((IStateManager) updateParameters).LoadViewState (vs [4]);
}
protected virtual object SaveViewState ()
{
object [] vs = new object [5];
if (deleteParameters != null) vs [0] = ((IStateManager) deleteParameters).SaveViewState ();
if (filterParameters != null) vs [1] = ((IStateManager) filterParameters).SaveViewState ();
if (insertParameters != null) vs [2] = ((IStateManager) insertParameters).SaveViewState ();
if (selectParameters != null) vs [3] = ((IStateManager) selectParameters).SaveViewState ();
if (updateParameters != null) vs [4] = ((IStateManager) updateParameters).SaveViewState ();
foreach (object o in vs)
if (o != null) return vs;
return null;
}
protected virtual void TrackViewState ()
{
tracking = true;
if (filterParameters != null) ((IStateManager) filterParameters).TrackViewState ();
if (selectParameters != null) ((IStateManager) selectParameters).TrackViewState ();
}
bool IStateManager.IsTrackingViewState {
get { return IsTrackingViewState; }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
bool cancelSelectOnNullParameter = true;
public bool CancelSelectOnNullParameter {
get { return cancelSelectOnNullParameter; }
set {
if (CancelSelectOnNullParameter == value)
return;
cancelSelectOnNullParameter = value;
OnDataSourceViewChanged (EventArgs.Empty);
}
}
public override bool CanDelete {
get { return DeleteCommand != null && DeleteCommand != ""; }
}
public override bool CanInsert {
get { return InsertCommand != null && InsertCommand != ""; }
}
public override bool CanPage {
/* according to MS, this is false in all cases */
get { return false; }
}
public override bool CanRetrieveTotalRowCount {
/* according to MS, this is false in all cases */
get { return false; }
}
public override bool CanSort {
get {
/* we can sort if we're a DataSet, regardless of sort parameter name.
we can sort if we're a DataReader, if the sort parameter name is not null/"".
*/
return (owner.DataSourceMode == SqlDataSourceMode.DataSet
|| (SortParameterName != null && SortParameterName != ""));
}
}
public override bool CanUpdate {
get { return UpdateCommand != null && UpdateCommand != ""; }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
ConflictOptions conflictDetection = ConflictOptions.OverwriteChanges;
public ConflictOptions ConflictDetection {
get { return conflictDetection; }
set {
if (ConflictDetection == value)
return;
conflictDetection = value;
OnDataSourceViewChanged (EventArgs.Empty);
}
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
string deleteCommand = String.Empty;
public string DeleteCommand {
get { return deleteCommand; }
set { deleteCommand = value; }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
SqlDataSourceCommandType deleteCommandType = SqlDataSourceCommandType.Text;
public SqlDataSourceCommandType DeleteCommandType {
get { return deleteCommandType; }
set { deleteCommandType = value; }
}
[DefaultValueAttribute (null)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
public ParameterCollection DeleteParameters {
get { return GetParameterCollection (ref deleteParameters, false, false); }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
string filterExpression;
public string FilterExpression {
get { return filterExpression ?? string.Empty; }
set {
if (FilterExpression == value)
return;
filterExpression = value;
OnDataSourceViewChanged (EventArgs.Empty);
}
}
[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
[DefaultValueAttribute (null)]
public ParameterCollection FilterParameters {
get { return GetParameterCollection (ref filterParameters, true, true); }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
string insertCommand = String.Empty;
public string InsertCommand {
get { return insertCommand; }
set { insertCommand = value; }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
SqlDataSourceCommandType insertCommandType = SqlDataSourceCommandType.Text;
public SqlDataSourceCommandType InsertCommandType {
get { return insertCommandType; }
set { insertCommandType = value; }
}
[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
[DefaultValueAttribute (null)]
public ParameterCollection InsertParameters {
get { return GetParameterCollection (ref insertParameters, false, false); }
}
protected bool IsTrackingViewState {
get { return tracking; }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
string oldValuesParameterFormatString = "{0}";
[DefaultValue ("{0}")]
public string OldValuesParameterFormatString {
get { return oldValuesParameterFormatString; }
set {
if (OldValuesParameterFormatString == value)
return;
oldValuesParameterFormatString = value;
OnDataSourceViewChanged (EventArgs.Empty);
}
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
string selectCommand;
public string SelectCommand {
get { return selectCommand != null ? selectCommand : string.Empty; }
set {
if (SelectCommand == value)
return;
selectCommand = value;
OnDataSourceViewChanged (EventArgs.Empty);
}
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
SqlDataSourceCommandType selectCommandType = SqlDataSourceCommandType.Text;
public SqlDataSourceCommandType SelectCommandType {
get { return selectCommandType; }
set { selectCommandType = value; }
}
public ParameterCollection SelectParameters {
get { return GetParameterCollection (ref selectParameters, true, true); }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
string sortParameterName = String.Empty;
public string SortParameterName {
get { return sortParameterName; }
set {
if (SortParameterName == value)
return;
sortParameterName = value;
OnDataSourceViewChanged (EventArgs.Empty);
}
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
string updateCommand = String.Empty;
public string UpdateCommand {
get { return updateCommand; }
set { updateCommand = value; }
}
// LAME SPEC: MSDN says value should be saved in ViewState but tests show otherwise.
SqlDataSourceCommandType updateCommandType = SqlDataSourceCommandType.Text;
public SqlDataSourceCommandType UpdateCommandType {
get { return updateCommandType; }
set { updateCommandType = value; }
}
[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
[DefaultValueAttribute (null)]
public ParameterCollection UpdateParameters {
get { return GetParameterCollection (ref updateParameters, false, false); }
}
void ParametersChanged (object source, EventArgs args)
{
OnDataSourceViewChanged (EventArgs.Empty);
}
ParameterCollection GetParameterCollection (ref ParameterCollection output, bool propagateTrackViewState, bool subscribeChanged)
{
if (output != null)
return output;
output = new ParameterCollection ();
if(subscribeChanged)
output.ParametersChanged += new EventHandler (ParametersChanged);
if (IsTrackingViewState && propagateTrackViewState)
((IStateManager) output).TrackViewState ();
return output;
}
protected virtual string ParameterPrefix {
get {
switch (owner.ProviderName) {
case "":
case "System.Data.SqlClient": return "@";
case "System.Data.OracleClient": return ":";
}
return "";
}
}
ParameterCollection deleteParameters;
ParameterCollection filterParameters;
ParameterCollection insertParameters;
ParameterCollection selectParameters;
ParameterCollection updateParameters;
bool tracking;
string name;
SqlDataSource owner;
#region OnDelete
static readonly object EventDeleted = new object ();
protected virtual void OnDeleted (SqlDataSourceStatusEventArgs e)
{
if (!HasEvents ()) return;
SqlDataSourceStatusEventHandler h = Events [EventDeleted] as SqlDataSourceStatusEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceStatusEventHandler Deleted {
add { Events.AddHandler (EventDeleted, value); }
remove { Events.RemoveHandler (EventDeleted, value); }
}
static readonly object EventDeleting = new object ();
protected virtual void OnDeleting (SqlDataSourceCommandEventArgs e)
{
if (!HasEvents ()) return;
SqlDataSourceCommandEventHandler h = Events [EventDeleting] as SqlDataSourceCommandEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceCommandEventHandler Deleting {
add { Events.AddHandler (EventDeleting, value); }
remove { Events.RemoveHandler (EventDeleting, value); }
}
#endregion
#region OnFiltering
static readonly object EventFiltering = new object ();
protected virtual void OnFiltering (SqlDataSourceFilteringEventArgs e)
{
if (!HasEvents ()) return;
SqlDataSourceFilteringEventHandler h = Events [EventFiltering] as SqlDataSourceFilteringEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceFilteringEventHandler Filtering {
add { Events.AddHandler (EventFiltering, value); }
remove { Events.RemoveHandler (EventFiltering, value); }
}
#endregion
#region OnInsert
static readonly object EventInserted = new object ();
protected virtual void OnInserted (SqlDataSourceStatusEventArgs e)
{
if (!HasEvents ()) return;
SqlDataSourceStatusEventHandler h = Events [EventInserted] as SqlDataSourceStatusEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceStatusEventHandler Inserted {
add { Events.AddHandler (EventInserted, value); }
remove { Events.RemoveHandler (EventInserted, value); }
}
static readonly object EventInserting = new object ();
protected virtual void OnInserting (SqlDataSourceCommandEventArgs e)
{
if (!HasEvents ()) return;
SqlDataSourceCommandEventHandler h = Events [EventInserting] as SqlDataSourceCommandEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceCommandEventHandler Inserting {
add { Events.AddHandler (EventInserting, value); }
remove { Events.RemoveHandler (EventInserting, value); }
}
#endregion
#region OnSelect
static readonly object EventSelected = new object ();
protected virtual void OnSelected (SqlDataSourceStatusEventArgs e)
{
if (!HasEvents ()) return;
SqlDataSourceStatusEventHandler h = Events [EventSelected] as SqlDataSourceStatusEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceStatusEventHandler Selected {
add { Events.AddHandler (EventSelected, value); }
remove { Events.RemoveHandler (EventSelected, value); }
}
static readonly object EventSelecting = new object ();
protected virtual void OnSelecting (SqlDataSourceSelectingEventArgs e)
{
if (!HasEvents ()) return;
SqlDataSourceSelectingEventHandler h = Events [EventSelecting] as SqlDataSourceSelectingEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceSelectingEventHandler Selecting {
add { Events.AddHandler (EventSelecting, value); }
remove { Events.RemoveHandler (EventSelecting, value); }
}
#endregion
#region OnUpdate
static readonly object EventUpdated = new object ();
protected virtual void OnUpdated (SqlDataSourceStatusEventArgs e)
{
if (owner.EnableCaching)
owner.Cache.Expire ();
if (!HasEvents ()) return;
SqlDataSourceStatusEventHandler h = Events [EventUpdated] as SqlDataSourceStatusEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceStatusEventHandler Updated {
add { Events.AddHandler (EventUpdated, value); }
remove { Events.RemoveHandler (EventUpdated, value); }
}
static readonly object EventUpdating = new object ();
protected virtual void OnUpdating (SqlDataSourceCommandEventArgs e)
{
if (!HasEvents ()) return;
SqlDataSourceCommandEventHandler h = Events [EventUpdating] as SqlDataSourceCommandEventHandler;
if (h != null)
h (this, e);
}
public event SqlDataSourceCommandEventHandler Updating {
add { Events.AddHandler (EventUpdating, value); }
remove { Events.RemoveHandler (EventUpdating, value); }
}
#endregion
}
}
|