internal void CompleteLastAdded(bool add) { DataRow dr = _lastAdded; if (add) { try { dataTable.Rows.Add(_lastAdded); //OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, Count - 1, -1)); _lastAdded = null; UpdateIndex(); } catch (Exception) { _lastAdded = dr; throw; } } else { _lastAdded.CancelEdit(); _lastAdded = null; UpdateIndex(); OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, Count, -1)); } }
public void CancelEdit() { // FIXME: if (this.Row == DataView._lastAdded) { DataView.CompleteLastAdded(false); } else { _dataRow.CancelEdit(); } }
/// <include file='doc\DataRowView.uex' path='docs/doc[@for="DataRowView.CancelEdit"]/*' /> /// <devdoc> /// <para> /// Cancels an edit procedure. /// </para> /// </devdoc> public void CancelEdit() { if (row == dataView.addNewRow) { dataView.FinishAddNew(this.index, false); } else { row.CancelEdit(); } dataView.SetDelayBeginEdit(row, false); }
public void CancelEdit() { DataRow tmpRow = Row; if (IsNew) { dataView.FinishAddNew(false); } else { tmpRow.CancelEdit(); } delayBeginEdit = false; }
public void CancelEdit() { DataRow row = this.Row; if (this.IsNew) { this.dataView.FinishAddNew(false); } else { row.CancelEdit(); } this.delayBeginEdit = false; }
private void SetDataRowWithLoadOption (DataRow dataRow, int recordNo, LoadOption loadOption, bool checkReadOnly) { bool hasError = false; if (checkReadOnly) { foreach(DataColumn dc in this.Columns) { if (dc.ReadOnly && !dc.Computed) { switch(loadOption) { case LoadOption.OverwriteChanges: if ((dataRow[dc, DataRowVersion.Current] != dc[recordNo]) ||(dataRow[dc, DataRowVersion.Original] != dc[recordNo])) hasError = true; break; case LoadOption.Upsert: if (dataRow[dc, DataRowVersion.Current] != dc[recordNo]) hasError = true; break; case LoadOption.PreserveChanges: if (dataRow[dc, DataRowVersion.Original] != dc[recordNo]) hasError = true; break; } } } } // No Event should be fired in SenNewRecord and SetOldRecord // fire rowChanging event here DataRowChangeEventArgs drcevent = null; DataRowAction action = DataRowAction.Nothing; int cacheTempRecord = dataRow.tempRecord; dataRow.tempRecord = recordNo; switch(loadOption) { case LoadOption.OverwriteChanges: action = DataRowAction.ChangeCurrentAndOriginal; break; case LoadOption.Upsert: switch(dataRow.RowState) { case DataRowState.Unchanged: // let see if the incomming value has the same values as existing row, so compare records foreach(DataColumn dc in dataRow.Table.Columns) { if (0 != dc.Compare(dataRow.newRecord, recordNo)) { action = DataRowAction.Change; break; } } break; case DataRowState.Deleted: Debug.Assert(false, "LoadOption.Upsert with deleted row, should not be here"); break; default : action = DataRowAction.Change; break; } break; case LoadOption.PreserveChanges: switch(dataRow.RowState) { case DataRowState.Unchanged: action = DataRowAction.ChangeCurrentAndOriginal; break; default: action = DataRowAction.ChangeOriginal; break; } break; default: throw ExceptionBuilder.ArgumentOutOfRange("LoadOption"); } try { drcevent = RaiseRowChanging(null, dataRow, action); if (action == DataRowAction.Nothing) { // RaiseRowChanging does not fire for DataRowAction.Nothing dataRow.inChangingEvent = true; try { drcevent = OnRowChanging(drcevent, dataRow, action); } finally { dataRow.inChangingEvent = false; } } } finally { Debug.Assert(dataRow.tempRecord == recordNo, "tempRecord has been changed in event handler"); if (DataRowState.Detached == dataRow.RowState) { // 'row.Table.Remove(row);' if (-1 != cacheTempRecord) { FreeRecord(ref cacheTempRecord); } } else { if (dataRow.tempRecord != recordNo) { // 'row.EndEdit(); row.BeginEdit(); ' if (-1 != cacheTempRecord) { FreeRecord(ref cacheTempRecord); } if (-1 != recordNo) { FreeRecord(ref recordNo); } recordNo = dataRow.tempRecord; } else { dataRow.tempRecord = cacheTempRecord; } } } if (dataRow.tempRecord != -1) { dataRow.CancelEdit(); } switch(loadOption) { case LoadOption.OverwriteChanges: this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false); this.SetOldRecord(dataRow, recordNo); break; case LoadOption.Upsert: if (dataRow.RowState == DataRowState.Unchanged) { this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false); if (!dataRow.HasChanges()) { this.SetOldRecord(dataRow, recordNo); } } else { if (dataRow.RowState == DataRowState.Deleted) dataRow.RejectChanges(); this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false); } break; case LoadOption.PreserveChanges: if (dataRow.RowState == DataRowState.Unchanged) { // SQLBU 500706: DataTable internal index is corrupted: '8' // if ListChanged event deletes dataRow this.SetOldRecord(dataRow, recordNo); // do not fire event this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false); } else { // if modified/ added / deleted we want this operation to fire event (just for LoadOption.PreserveCurrentValues) this.SetOldRecord(dataRow, recordNo); } break; default: throw ExceptionBuilder.ArgumentOutOfRange("LoadOption"); } if (hasError) { string error = Res.GetString(Res.Load_ReadOnlyDataModified); if (dataRow.RowError.Length == 0) { // WebData 112272, append the row error dataRow.RowError = error; } else { dataRow.RowError += " ]:[ " + error ; } foreach(DataColumn dc in this.Columns) { if (dc.ReadOnly && !dc.Computed) dataRow.SetColumnError(dc, error); } } drcevent = RaiseRowChanged(drcevent, dataRow, action); if (action == DataRowAction.Nothing) { // RaiseRowChanged does not fire for DataRowAction.Nothing dataRow.inChangingEvent = true; try { OnRowChanged(drcevent, dataRow, action); } finally { dataRow.inChangingEvent = false; } } }
internal void RollbackRow(DataRow row) { row.CancelEdit(); SetNewRecord(row, row.oldRecord, DataRowAction.Rollback, false, true); }
private void SetDataRowWithLoadOption(DataRow dataRow, int recordNo, LoadOption loadOption, bool checkReadOnly) { bool flag = false; if (checkReadOnly) { foreach (DataColumn column in this.Columns) { if (column.ReadOnly && !column.Computed) { switch (loadOption) { case LoadOption.OverwriteChanges: goto Label_0058; case LoadOption.PreserveChanges: if (dataRow[column, DataRowVersion.Original] != column[recordNo]) { flag = true; } break; case LoadOption.Upsert: if (dataRow[column, DataRowVersion.Current] != column[recordNo]) { flag = true; } break; } } continue; Label_0058: if ((dataRow[column, DataRowVersion.Current] != column[recordNo]) || (dataRow[column, DataRowVersion.Original] != column[recordNo])) { flag = true; } } } DataRowChangeEventArgs args = null; DataRowAction nothing = DataRowAction.Nothing; int tempRecord = dataRow.tempRecord; dataRow.tempRecord = recordNo; switch (loadOption) { case LoadOption.OverwriteChanges: nothing = DataRowAction.ChangeCurrentAndOriginal; break; case LoadOption.PreserveChanges: if (dataRow.RowState != DataRowState.Unchanged) { nothing = DataRowAction.ChangeOriginal; break; } nothing = DataRowAction.ChangeCurrentAndOriginal; break; case LoadOption.Upsert: switch (dataRow.RowState) { case DataRowState.Unchanged: foreach (DataColumn column3 in dataRow.Table.Columns) { if (column3.Compare(dataRow.newRecord, recordNo) != 0) { nothing = DataRowAction.Change; break; } } goto Label_01A4; } nothing = DataRowAction.Change; break; default: throw ExceptionBuilder.ArgumentOutOfRange("LoadOption"); } Label_01A4:; try { args = this.RaiseRowChanging(null, dataRow, nothing); if (nothing == DataRowAction.Nothing) { dataRow.inChangingEvent = true; try { args = this.OnRowChanging(args, dataRow, nothing); } finally { dataRow.inChangingEvent = false; } } } finally { if (DataRowState.Detached == dataRow.RowState) { if (-1 != tempRecord) { this.FreeRecord(ref tempRecord); } } else if (dataRow.tempRecord != recordNo) { if (-1 != tempRecord) { this.FreeRecord(ref tempRecord); } if (-1 != recordNo) { this.FreeRecord(ref recordNo); } recordNo = dataRow.tempRecord; } else { dataRow.tempRecord = tempRecord; } } if (dataRow.tempRecord != -1) { dataRow.CancelEdit(); } switch (loadOption) { case LoadOption.OverwriteChanges: this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false, false); this.SetOldRecord(dataRow, recordNo); break; case LoadOption.PreserveChanges: if (dataRow.RowState != DataRowState.Unchanged) { this.SetOldRecord(dataRow, recordNo); break; } this.SetOldRecord(dataRow, recordNo); this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false, false); break; case LoadOption.Upsert: if (dataRow.RowState != DataRowState.Unchanged) { if (dataRow.RowState == DataRowState.Deleted) { dataRow.RejectChanges(); } this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false, false); break; } this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false, false); if (!dataRow.HasChanges()) { this.SetOldRecord(dataRow, recordNo); } break; default: throw ExceptionBuilder.ArgumentOutOfRange("LoadOption"); } if (flag) { string error = System.Data.Res.GetString("Load_ReadOnlyDataModified"); if (dataRow.RowError.Length == 0) { dataRow.RowError = error; } else { dataRow.RowError = dataRow.RowError + " ]:[ " + error; } foreach (DataColumn column2 in this.Columns) { if (column2.ReadOnly && !column2.Computed) { dataRow.SetColumnError(column2, error); } } } args = this.RaiseRowChanged(args, dataRow, nothing); if (nothing == DataRowAction.Nothing) { dataRow.inChangingEvent = true; try { this.OnRowChanged(args, dataRow, nothing); } finally { dataRow.inChangingEvent = false; } } }
/// <summary> /// todoComment /// </summary> /// <param name="AChangingPartnerTypeRow"></param> /// <param name="AIsRemoval"></param> /// <returns></returns> public Boolean PerformPartnerTypeAddOrRemoval(DataRow AChangingPartnerTypeRow, out Boolean AIsRemoval) { const String TYPECODE_COSTCENTRE = "COSTCENTRE"; Boolean ReturnValue = false; AIsRemoval = false; String TypeCode; DataRow ExistingMatchingDataRow; PPartnerTypeTable PartnerTypeTable; PPartnerTypeRow TheNewRow; PTypeRow CheckTypeRow; DataRowView[] CheckTypeRows; DialogResult CheckTypeRowsAnswer; TRecalculateScreenPartsEventArgs RecalculateScreenPartsEventArgs; String CostCentreLink; PartnerTypeTable = FMainDS.PPartnerType; try { TypeCode = AChangingPartnerTypeRow["TypeCode"].ToString(); ExistingMatchingDataRow = PartnerTypeTable.Rows.Find(new Object[] { ((PPartnerRow)FMainDS.PPartner.Rows[0]).PartnerKey, TypeCode }); if (ExistingMatchingDataRow == null) { /* * Add Special Type */ // Check security permission if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapCREATE, PPartnerTypeTable.GetTableDBName())) { TMessages.MsgSecurityException(new ESecurityDBTableAccessDeniedException("", "create", PPartnerTypeTable.GetTableDBName()), this.GetType()); AChangingPartnerTypeRow.CancelEdit(); // reset to unchecked return false; } // Check: is this Partner Type assignable? // MessageBox.Show("Perform check: is PartnerType assignable? TypeCode: " + TypeCode); CheckTypeRows = FDataCache_PartnerTypeListDV.FindRows(TypeCode); if (CheckTypeRows.Length > 0) { CheckTypeRow = (PTypeRow)CheckTypeRows[0].Row; if (!CheckTypeRow.ValidType) { /*CheckTypeRowsAnswer = TMessages.MsgQuestion( * ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE, TypeCode), * this.GetType(), false);*/ CheckTypeRowsAnswer = MessageBox.Show( string.Format(StrTheCodeIsNoLongerActive, TypeCode), Catalog.GetString("Invalid Data Entered"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (CheckTypeRowsAnswer == DialogResult.No) { // reset to unchecked AChangingPartnerTypeRow.CancelEdit(); return false; } } } // add new row to PartnerType table PartnerTypeTable = FMainDS.PPartnerType; TheNewRow = PartnerTypeTable.NewRowTyped(); TheNewRow.PartnerKey = FMainDS.PPartner[0].PartnerKey; TheNewRow.TypeCode = TypeCode; TheNewRow.CreatedBy = UserInfo.GUserInfo.UserID; TheNewRow.DateCreated = DateTime.Now.Date; PartnerTypeTable.Rows.Add(TheNewRow); // Fire OnRecalculateScreenParts event RecalculateScreenPartsEventArgs = new TRecalculateScreenPartsEventArgs(); RecalculateScreenPartsEventArgs.ScreenPart = TScreenPartEnum.spCounters; OnRecalculateScreenParts(RecalculateScreenPartsEventArgs); ReturnValue = true; AIsRemoval = false; } else { /* * Remove Special Type */ // Check security permission if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapDELETE, PPartnerTypeTable.GetTableDBName())) { TMessages.MsgSecurityException(new ESecurityDBTableAccessDeniedException("", "delete", PPartnerTypeTable.GetTableDBName()), this.GetType()); // reset to checked AChangingPartnerTypeRow.CancelEdit(); return false; } // perform check: If COSTCENTRE is to be removed then check whether Partner has a link to costcentre set up if (TypeCode == TYPECODE_COSTCENTRE) { try { if (FPartnerEditUIConnector.HasPartnerCostCentreLink(out CostCentreLink)) { MessageBox.Show(String.Format(StrPartnerHasCostCentreLink, CostCentreLink, StrPartnerHasCostCentreLinkTitle)); // reset to checked AChangingPartnerTypeRow.CancelEdit(); return false; } } catch (ESecurityAccessDeniedException Exp) { TMessages.MsgSecurityException(Exp, this.GetType()); MessageBox.Show(StrSecurityPreventsRemoval, StrSecurityPreventsRemovalTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); // reset to checked AChangingPartnerTypeRow.CancelEdit(); return false; } catch (Exception) { throw; } } // Delete row from PartnerType table ExistingMatchingDataRow.Delete(); // Fire OnRecalculateScreenParts event RecalculateScreenPartsEventArgs = new TRecalculateScreenPartsEventArgs(); RecalculateScreenPartsEventArgs.ScreenPart = TScreenPartEnum.spCounters; OnRecalculateScreenParts(RecalculateScreenPartsEventArgs); ReturnValue = true; AIsRemoval = true; } /* * Check if this change could be applied to Family Members */ // TODO PartnerTypeFamilyMembersPropagationSelectionWinForm Dialog still missing #if TODO if (SharedTypes.PartnerClassStringToEnum(FMainDS.PPartner[0].PartnerClass) == TPartnerClass.FAMILY) { if (HasFamilyFamilyMembers()) { if (FDelegatePartnerTypePropagationSelection != null) { if (!AIsRemoval) { FMainDS.Merge(FDelegatePartnerTypePropagationSelection(TypeCode, "ADD")); } else { FMainDS.Merge(FDelegatePartnerTypePropagationSelection(TypeCode, "DELETE")); } } } } #endif } catch (Exception E) { MessageBox.Show(E.ToString()); ReturnValue = false; } return ReturnValue; }