public override void Validate(object proposedValue, string columnName) { base.Validate(proposedValue, columnName); if (columnName == Strings.DATASHEET_DT_LOCATION_COLUMN_NAME) { if (!DTAnalyzer.IsValidLocation(proposedValue)) { throw new DataException(MessageStrings.ERROR_INVALID_CELL_ADDRESS); } } }
/// <summary> /// Overrides Validate /// </summary> /// <param name="data"></param> /// <param name="transferMethod"></param> /// <returns></returns> /// <remarks> /// While the incoming state class Ids can themselves be valid, they must also be valid within the context of the union of the /// incoming data and the existing data. In other words, each destination state class must point to a source state class within /// the same stratum. /// </remarks> public override void Validate(System.Data.DataTable proposedData, DataTransferMethod transferMethod) { base.Validate(proposedData, transferMethod); DataTable dtdata = this.GetData(); DTAnalyzer AnalyzerExisting = new DTAnalyzer(dtdata, this.Project); DTAnalyzer AnalyzerProposed = new DTAnalyzer(proposedData, this.Project); foreach (DataRow ProposedRow in proposedData.Rows) { int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetDTFieldValues(ProposedRow, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (!StateClassIdDest.HasValue) { return; } //If the state class is not part of the incoming data then we need to see if it is part of the existing data, and //if it isn't then we can't continue. Note that if the import option is 'Overwrite' then the state class //will not appear in the existing data! bool ClassInClip = AnalyzerProposed.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value); bool ClassInExisting = AnalyzerExisting.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value); bool IsOverwrite = (transferMethod == SyncroSim.Core.DataTransferMethod.Overwrite); if (!ClassInClip) { if (IsOverwrite || (!ClassInExisting)) { AnalyzerExisting.ThrowDataException(StateClassIdDest.Value, true); } } //Also validate the location if (!DTAnalyzer.IsValidLocation(ProposedRow[Strings.DATASHEET_DT_LOCATION_COLUMN_NAME])) { throw new DataException(MessageStrings.ERROR_INVALID_CELL_ADDRESS); } } }