SetColumnError() public method

Sets the error description for a column specified as a .
public SetColumnError ( DataColumn column, string error ) : void
column DataColumn
error string
return void
Exemplo n.º 1
0
        internal override bool IsConstraintViolated()
        {
            if (Index == null)
            {
                Index = Table.GetIndex(Columns, null, DataViewRowState.None, null, false);
            }

            if (Index.HasDuplicates)
            {
                int[] dups = Index.Duplicates;
                for (int i = 0; i < dups.Length; i++)
                {
                    DataRow   row     = Table.RecordCache[dups[i]];
                    ArrayList columns = new ArrayList();
                    ArrayList values  = new ArrayList();
                    foreach (DataColumn col in Columns)
                    {
                        columns.Add(col.ColumnName);
                        values.Add(row[col].ToString());
                    }

                    string columnNames  = String.Join(", ", (string[])columns.ToArray(typeof(string)));
                    string columnValues = String.Join(", ", (string[])values.ToArray(typeof(string)));

                    row.RowError = String.Format("Column '{0}' is constrained to be unique.  Value '{1}' is already present.", columnNames, columnValues);
                    for (int j = 0; j < Columns.Length; ++j)
                    {
                        row.SetColumnError(Columns [j], row.RowError);
                    }
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        internal void ProcessErrors(ArrayList dt, XmlReader ssync)
        {
            DataTable table;

            int iSsyncDepth = ssync.Depth;

            ssync.Read(); // pass the before node.

            while (iSsyncDepth < ssync.Depth)
            {
                table = GetTable(XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI);
                if (table == null)
                {
                    throw ExceptionBuilder.DiffgramMissingSQL();
                }

                string diffId = ssync.GetAttribute(Keywords.DIFFID, Keywords.DFFNS);

                DataRow row = (DataRow)table.RowDiffId[diffId];
                if (row == null)
                {
                    for (int i = 0; i < dt.Count; i++)
                    {
                        row = (DataRow)((DataTable)dt[i]).RowDiffId[diffId];
                        if (row != null)
                        {
                            table = row.Table;
                            break;
                        }
                    }
                }
                string rowError = ssync.GetAttribute(Keywords.MSD_ERROR, Keywords.DFFNS);
                if (rowError != null)
                {
                    row.RowError = rowError;
                }
                int iRowDepth = ssync.Depth;
                ssync.Read(); // we may be inside a column

                while (iRowDepth < ssync.Depth)
                {
                    if (XmlNodeType.Element == ssync.NodeType)
                    {
                        DataColumn col = table.Columns[XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI];
                        //if (col == null)
                        // throw exception here
                        string colError = ssync.GetAttribute(Keywords.MSD_ERROR, Keywords.DFFNS);
                        row.SetColumnError(col, colError);
                    }
                    ssync.Read();
                }
                while ((ssync.NodeType == XmlNodeType.EndElement) && (iSsyncDepth < ssync.Depth))
                {
                    ssync.Read();
                }
            }

            return;
        }
        private static bool ISSingleRowValid(DataRow dr)
        {
            dr.ClearErrors();
            bool isValid = true;
            if (dr["InventoryDamagedQuantity"] != DBNull.Value && ((Convert.ToDecimal(dr["InventoryDamagedQuantity"]) > 0) && (dr["DamagedPalletLocationID"] == DBNull.Value)))
            {
                dr.SetColumnError("DamagedPalletLocationID",
                                  Icons.YearEndProcess_ValidateBeforeCommit_DamagedPalletLocation_Can_not_be_left_empty_);
                isValid = false;
            }

            if (dr["InventorySoundQuantity"] != DBNull.Value && ((Convert.ToDecimal(dr["InventorySoundQuantity"]) > 0) && (dr["PalletLocationID"] == DBNull.Value)))
            {
                dr.SetColumnError("PalletLocationID",
                                  Icons.YearEndProcess_ValidateBeforeCommit_Normal_PalletLocation_Can_not_be_left_empty_);
                isValid = false;
            }

            return isValid;
        }
        internal void ProcessErrors(ArrayList dt, XmlReader ssync)
        {
            int depth = ssync.Depth;

            ssync.Read();
            while (depth < ssync.Depth)
            {
                DataTable table = this.GetTable(XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI);
                if (table == null)
                {
                    throw ExceptionBuilder.DiffgramMissingSQL();
                }
                string  attribute = ssync.GetAttribute("id", "urn:schemas-microsoft-com:xml-diffgram-v1");
                DataRow row       = (DataRow)table.RowDiffId[attribute];
                if (row == null)
                {
                    for (int i = 0; i < dt.Count; i++)
                    {
                        row = (DataRow)((DataTable)dt[i]).RowDiffId[attribute];
                        if (row != null)
                        {
                            table = row.Table;
                            break;
                        }
                    }
                }
                string str = ssync.GetAttribute("Error", "urn:schemas-microsoft-com:xml-diffgram-v1");
                if (str != null)
                {
                    row.RowError = str;
                }
                int num3 = ssync.Depth;
                ssync.Read();
                while (num3 < ssync.Depth)
                {
                    if (XmlNodeType.Element == ssync.NodeType)
                    {
                        DataColumn column = table.Columns[XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI];
                        string     error  = ssync.GetAttribute("Error", "urn:schemas-microsoft-com:xml-diffgram-v1");
                        row.SetColumnError(column, error);
                    }
                    ssync.Read();
                }
                while ((ssync.NodeType == XmlNodeType.EndElement) && (depth < ssync.Depth))
                {
                    ssync.Read();
                }
            }
        }
Exemplo n.º 5
0
        internal static void ProcessErrors(DataSet ds, XmlReader ssync)
        {
            DataTable?table;

            int iSsyncDepth = ssync.Depth;

            ssync.Read(); // pass the before node.

            while (iSsyncDepth < ssync.Depth)
            {
                table = ds.Tables.GetTable(XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI);
                if (table == null)
                {
                    throw ExceptionBuilder.DiffgramMissingSQL();
                }
                string  diffId   = ssync.GetAttribute(Keywords.DIFFID, Keywords.DFFNS) !;
                DataRow row      = (DataRow)table.RowDiffId[diffId] !;
                string? rowError = ssync.GetAttribute(Keywords.MSD_ERROR, Keywords.DFFNS);
                if (rowError != null)
                {
                    row.RowError = rowError;
                }
                int iRowDepth = ssync.Depth;
                ssync.Read(); // we may be inside a column
                while (iRowDepth < ssync.Depth)
                {
                    if (XmlNodeType.Element == ssync.NodeType)
                    {
                        DataColumn col = table.Columns[XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI] !;
                        //if (col == null)
                        // throw exception here
                        string colError = ssync.GetAttribute(Keywords.MSD_ERROR, Keywords.DFFNS) !;
                        row.SetColumnError(col, colError);
                    }

                    ssync.Read();
                }
                while ((ssync.NodeType == XmlNodeType.EndElement) && (iSsyncDepth < ssync.Depth))
                {
                    ssync.Read();
                }
            }

            return;
        }
Exemplo n.º 6
0
		internal void CopyErrors(DataRow row)
		{
			row.RowError = RowError;
			DataColumn[] errorColumns = GetColumnsInError();
			foreach(DataColumn col in errorColumns) {
				DataColumn targetColumn = row.Table.Columns[col.ColumnName];
				row.SetColumnError(targetColumn,GetColumnError(col));
			}
		}
 private void ApplyRowCellValueToBOProperty(DataRow row, UIGridColumn uiProperty, IBusinessObject changedBo)
 {
     string columnName = uiProperty.PropertyName;
     if (!uiProperty.Editable) return;
     IBOPropertyMapper boPropertyMapper = BOPropMapperFactory.CreateMapper(changedBo, columnName);
     boPropertyMapper.SetPropertyValue(row[columnName]);
     row.SetColumnError(columnName, boPropertyMapper.InvalidReason);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Valida un tcs_DomiciliosRow.
        /// </summary>
        public static bool RowIsValid(System.Data.DataRow row)
        {
            ApplicationAssert.Check(row != null, "El argumento row no debe ser nulo.", ApplicationAssert.LineNumber);
            bool   isValid = true;
            string mensaje;


            /*if ( !IdDomicilioIsValid( row.IdDomicilio, out mensaje) )
             * {
             *      row.SetColumnError( "IdDomicilio" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdTipoDomicilioIsValid( row.IdTipoDomicilio, out mensaje) )
             * {
             *      row.SetColumnError( "IdTipoDomicilio" , mensaje);
             *      isValid=false;
             *
             * }
             */
            if (!CalleIsValid(Convert.ToString(row["Calle"]), out mensaje))
            {
                row.SetColumnError("Calle", mensaje);
                isValid = false;
            }

            if (!NumeroIsValid(Convert.ToString(row["Numero"]), out mensaje))
            {
                row.SetColumnError("Numero", mensaje);
                isValid = false;
            }

            /*
             * if ( !SectorIsValid( row.Sector, out mensaje) )
             * {
             *      row.SetColumnError( "Sector" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !TorreIsValid( row.Torre, out mensaje) )
             * {
             *      row.SetColumnError( "Torre" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !PisoIsValid( row.Piso, out mensaje) )
             * {
             *      row.SetColumnError( "Piso" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !DepartamentoIsValid( row.Departamento, out mensaje) )
             * {
             *      row.SetColumnError( "Departamento" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !ManzanaIsValid( row.Manzana, out mensaje) )
             * {
             *      row.SetColumnError( "Manzana" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !CodigoPostalIsValid( row.CodigoPostal, out mensaje) )
             * {
             *      row.SetColumnError( "CodigoPostal" , mensaje);
             *      isValid=false;
             *
             * }*/

            /*if ( !IdLocalidadIsValid( Convert.ToString(row["IdLocalidad"]), out mensaje) )
             * {
             *      row.SetColumnError( "IdLocalidad" , mensaje);
             *      isValid=false;
             *
             * }*/
            /*
             * if ( !PartidoIsValid( row.Partido, out mensaje) )
             * {
             *      row.SetColumnError( "Partido" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdProvinciaIsValid( row.IdProvincia, out mensaje) )
             * {
             *      row.SetColumnError( "IdProvincia" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdPaisIsValid( row.IdPais, out mensaje) )
             * {
             *      row.SetColumnError( "IdPais" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdResponsableIsValid( row.IdResponsable, out mensaje) )
             * {
             *      row.SetColumnError( "IdResponsable" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !TelefonoIsValid( row.Telefono, out mensaje) )
             * {
             *      row.SetColumnError( "Telefono" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !FechaCreacionIsValid( row.FechaCreacion, out mensaje) )
             * {
             *      row.SetColumnError( "FechaCreacion" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdConexionCreacionIsValid( row.IdConexionCreacion, out mensaje) )
             * {
             *      row.SetColumnError( "IdConexionCreacion" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * /*if ( !UltimaModificacionIsValid( row.UltimaModificacion, out mensaje) )
             * {
             *      row.SetColumnError( "UltimaModificacion" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdConexionUltimaModificacionIsValid( row.IdConexionUltimaModificacion, out mensaje) )
             * {
             *      row.SetColumnError( "IdConexionUltimaModificacion" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdReservadoIsValid( row.IdReservado, out mensaje) )
             * {
             *      row.SetColumnError( "IdReservado" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !RowIdIsValid( row.RowId, out mensaje) )
             * {
             *      row.SetColumnError( "RowId" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdEmpresaIsValid( row.IdEmpresa, out mensaje) )
             * {
             *      row.SetColumnError( "IdEmpresa" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdSucursalIsValid( row.IdSucursal, out mensaje) )
             * {
             *      row.SetColumnError( "IdSucursal" , mensaje);
             *      isValid=false;
             *
             * }
             * ;*/

            return(isValid);
        }
 internal DataRow MergeRow(DataRow row, DataRow targetRow, bool preserveChanges, Index idxSearch)
 {
     if (targetRow == null)
     {
         targetRow = this.NewEmptyRow();
         targetRow.oldRecord = this.recordManager.ImportRecord(row.Table, row.oldRecord);
         targetRow.newRecord = targetRow.oldRecord;
         if (row.oldRecord != row.newRecord)
         {
             targetRow.newRecord = this.recordManager.ImportRecord(row.Table, row.newRecord);
         }
         this.InsertRow(targetRow, -1L);
     }
     else
     {
         int tempRecord = targetRow.tempRecord;
         targetRow.tempRecord = -1;
         try
         {
             int oldRecord;
             int newRecord;
             int num4;
             DataRowState rowState = targetRow.RowState;
             num4 = (rowState == DataRowState.Added) ? targetRow.newRecord : (num4 = targetRow.oldRecord);
             if ((targetRow.RowState == DataRowState.Unchanged) && (row.RowState == DataRowState.Unchanged))
             {
                 oldRecord = targetRow.oldRecord;
                 newRecord = preserveChanges ? this.recordManager.CopyRecord(this, oldRecord, -1) : targetRow.newRecord;
                 oldRecord = this.recordManager.CopyRecord(row.Table, row.oldRecord, targetRow.oldRecord);
                 this.SetMergeRecords(targetRow, newRecord, oldRecord, DataRowAction.Change);
             }
             else if (row.newRecord == -1)
             {
                 oldRecord = targetRow.oldRecord;
                 if (preserveChanges)
                 {
                     newRecord = (targetRow.RowState == DataRowState.Unchanged) ? this.recordManager.CopyRecord(this, oldRecord, -1) : targetRow.newRecord;
                 }
                 else
                 {
                     newRecord = -1;
                 }
                 oldRecord = this.recordManager.CopyRecord(row.Table, row.oldRecord, oldRecord);
                 if (num4 != ((rowState == DataRowState.Added) ? newRecord : oldRecord))
                 {
                     this.SetMergeRecords(targetRow, newRecord, oldRecord, (newRecord == -1) ? DataRowAction.Delete : DataRowAction.Change);
                     idxSearch.Reset();
                     num4 = (rowState == DataRowState.Added) ? newRecord : oldRecord;
                 }
                 else
                 {
                     this.SetMergeRecords(targetRow, newRecord, oldRecord, (newRecord == -1) ? DataRowAction.Delete : DataRowAction.Change);
                 }
             }
             else
             {
                 oldRecord = targetRow.oldRecord;
                 newRecord = targetRow.newRecord;
                 if (targetRow.RowState == DataRowState.Unchanged)
                 {
                     newRecord = this.recordManager.CopyRecord(this, oldRecord, -1);
                 }
                 oldRecord = this.recordManager.CopyRecord(row.Table, row.oldRecord, oldRecord);
                 if (!preserveChanges)
                 {
                     newRecord = this.recordManager.CopyRecord(row.Table, row.newRecord, newRecord);
                 }
                 this.SetMergeRecords(targetRow, newRecord, oldRecord, DataRowAction.Change);
             }
             if ((rowState == DataRowState.Added) && (targetRow.oldRecord != -1))
             {
                 idxSearch.Reset();
             }
         }
         finally
         {
             targetRow.tempRecord = tempRecord;
         }
     }
     if (row.HasErrors)
     {
         if (targetRow.RowError.Length == 0)
         {
             targetRow.RowError = row.RowError;
         }
         else
         {
             targetRow.RowError = targetRow.RowError + " ]:[ " + row.RowError;
         }
         DataColumn[] columnsInError = row.GetColumnsInError();
         for (int i = 0; i < columnsInError.Length; i++)
         {
             DataColumn column = targetRow.Table.Columns[columnsInError[i].ColumnName];
             targetRow.SetColumnError(column, row.GetColumnError(columnsInError[i]));
         }
         return targetRow;
     }
     if (!preserveChanges)
     {
         targetRow.ClearErrors();
     }
     return targetRow;
 }
Exemplo n.º 10
0
        internal DataRow MergeRow(DataRow row, DataRow targetRow, bool preserveChanges, Index idxSearch) {
             if (targetRow == null) {
                targetRow = this.NewEmptyRow();
                targetRow.oldRecord = recordManager.ImportRecord(row.Table, row.oldRecord);
                targetRow.newRecord = targetRow.oldRecord;
                if(row.oldRecord != row.newRecord) {
                    targetRow.newRecord = recordManager.ImportRecord(row.Table, row.newRecord);
                }
                InsertRow(targetRow, -1);
            }
            else {
                // SQLBU 500789: Record Manager corruption during Merge when target row in edit state
                // the newRecord would be freed and overwrite tempRecord (which became the newRecord)
                // this would leave the DataRow referencing a freed record and leaking memory for the now lost record
                int proposedRecord = targetRow.tempRecord; // by saving off the tempRecord, EndEdit won't free newRecord
                targetRow.tempRecord = -1;
                try {
                    DataRowState saveRowState = targetRow.RowState;
                    int saveIdxRecord = (saveRowState == DataRowState.Added) ? targetRow.newRecord : saveIdxRecord = targetRow.oldRecord;
                     int newRecord;
                     int oldRecord;
                    if (targetRow.RowState == DataRowState.Unchanged && row.RowState == DataRowState.Unchanged) {
                        // unchanged row merging with unchanged row
                        oldRecord = targetRow.oldRecord;
                        newRecord = (preserveChanges) ? recordManager.CopyRecord(this, oldRecord, -1) : targetRow.newRecord;
                        oldRecord = recordManager.CopyRecord(row.Table, row.oldRecord, targetRow.oldRecord);
                        SetMergeRecords(targetRow, newRecord, oldRecord, DataRowAction.Change);
                    }
                    else if (row.newRecord == -1) {
                        // Incoming row is deleted
                        oldRecord = targetRow.oldRecord;
                        if (preserveChanges) {
                          newRecord = (targetRow.RowState == DataRowState.Unchanged)? recordManager.CopyRecord(this, oldRecord, -1) : targetRow.newRecord;
                        }
                        else
                            newRecord = -1;
                        oldRecord = recordManager.CopyRecord(row.Table, row.oldRecord, oldRecord);

                        // Change index record, need to update index
                        if (saveIdxRecord != ((saveRowState == DataRowState.Added) ? newRecord : oldRecord)) {
                            SetMergeRecords(targetRow, newRecord, oldRecord, (newRecord == -1) ? DataRowAction.Delete : DataRowAction.Change);
                            idxSearch.Reset();
                            saveIdxRecord = ((saveRowState == DataRowState.Added) ? newRecord : oldRecord);
                        } else {
                            SetMergeRecords(targetRow, newRecord, oldRecord, (newRecord == -1) ? DataRowAction.Delete : DataRowAction.Change);
                        }
                    }
                    else {
                        // incoming row is added, modified or unchanged (targetRow is not unchanged)
                        oldRecord = targetRow.oldRecord;
                        newRecord = targetRow.newRecord;
                        if (targetRow.RowState == DataRowState.Unchanged) {
                            newRecord = recordManager.CopyRecord(this, oldRecord, -1);
                        }
                        oldRecord = recordManager.CopyRecord(row.Table, row.oldRecord, oldRecord);

                        if (!preserveChanges) {
                            newRecord = recordManager.CopyRecord(row.Table, row.newRecord, newRecord);
                        }
                        SetMergeRecords(targetRow, newRecord, oldRecord, DataRowAction.Change);
                    }

                    if (saveRowState == DataRowState.Added && targetRow.oldRecord != -1)
                        idxSearch.Reset();
                    Debug.Assert(saveIdxRecord == ((saveRowState == DataRowState.Added) ? targetRow.newRecord : targetRow.oldRecord), "oops, you change index record without noticing it");
                }
                finally {
                    targetRow.tempRecord = proposedRecord;
                }
            }

            // Merge all errors
            if (row.HasErrors) {
                if (targetRow.RowError.Length == 0) {
                    targetRow.RowError = row.RowError;
                } else {
                    targetRow.RowError += " ]:[ " + row.RowError;
                }
                DataColumn[] cols = row.GetColumnsInError();

                for (int i = 0; i < cols.Length; i++) {
                    DataColumn col = targetRow.Table.Columns[cols[i].ColumnName];
                    targetRow.SetColumnError(col, row.GetColumnError(cols[i]));
                }
            }else {
                if (!preserveChanges) {
                    targetRow.ClearErrors();
                }
            }

            return targetRow;
        }
        /// <summary>
        /// Valida un sy_PerfilesUsuariosEmpresasRow.
        /// </summary>
        public static bool RowIsValid(System.Data.DataRow row)
        {
            ApplicationAssert.Check(row != null, "El argumento row no debe ser nulo.", ApplicationAssert.LineNumber);
            bool   isValid = true;
            string mensaje;


            if (!IdUsuarioIsValid((string )row["IdUsuario"], out mensaje))
            {
                row.SetColumnError("IdUsuario", mensaje);
                isValid = false;
            }

            if (!IdPerfilIsValid((long)row["IdPerfil"], out mensaje))
            {
                row.SetColumnError("IdPerfil", mensaje);
                isValid = false;
            }

            if (!IdEmpresaIsValid((long)row["IdEmpresa"], out mensaje))
            {
                row.SetColumnError("IdEmpresa", mensaje);
                isValid = false;
            }

            /*if ( !ConexionDefaultIsValid( (byte)row["ConexionDefault"], out mensaje) )
             * {
             *      row.SetColumnError( "ConexionDefault" , mensaje);
             *      isValid=false;
             *
             * }*/

            /*if ( !FechaCreacionIsValid( (DateTime)row["FechaCreacion"], out mensaje) )
             * {
             *      row.SetColumnError( "FechaCreacion" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !IdConexionCreacionIsValid( (long)row["IdConexionCreacion"], out mensaje) )
             * {
             *      row.SetColumnError( "IdConexionCreacion" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * /*if ( !UltimaModificacionIsValid( (byte[])row["UltimaModificacion"], out mensaje) )
             * {
             *      row.SetColumnError( "UltimaModificacion" , mensaje);
             *      isValid=false;
             *
             * }*/

            /*if ( !IdConexionUltimaModificacionIsValid( (long)row["IdConexionUltimaModificacion"], out mensaje) )
             * {
             *      row.SetColumnError( "IdConexionUltimaModificacion" , mensaje);
             *      isValid=false;
             *
             * }
             *
             * if ( !RowIdIsValid( (Guid)row["RowId"], out mensaje) )
             * {
             *      row.SetColumnError( "RowId" , mensaje);
             *      isValid=false;
             *
             * }
             * ;*/

            return(isValid);
        }
        private void ValidandoColuna(DataRow row, DataColumn column, object proposedValue)
        {
            if (!_Validacoes.ContainsKey(column))
                return;

            Validacao validation = _Validacoes[column];
            if (validation != null)
            {
                string mensagem = validation.ObterMensagemValidacao(proposedValue);
                row.SetColumnError(column, mensagem);
            }
        }
Exemplo n.º 13
0
        private void populateRowWithImportData(DataRow dr, string[] fieldValues, System.Collections.Generic.Dictionary<string, int> columnNameMap, LookupTables lookupTables)
        {
            DataTable dt = dr.Table;
            foreach (string tableColumnName in columnNameMap.Keys)
            {
                // Only update the write enabled columns in this row...
                if (!dt.Columns[tableColumnName].ReadOnly)
                {
                    string newValue = "";
                    DataColumn dc = dt.Columns[tableColumnName];
                    int fieldIndex = columnNameMap[tableColumnName];
                    if (fieldValues.Length <= fieldIndex) continue;
                    // Perform a reverse lookup to get the key if this is a ForeignKey field...
                    if (lookupTables.IsValidFKField(dc))
                    {
                        if (!string.IsNullOrEmpty(fieldValues[fieldIndex].ToString().Trim()))
                        {
                            newValue = lookupTables.GetPKeyValueMember(dr, dc.ExtendedProperties["foreign_key_dataview_name"].ToString(),
                                                                            fieldValues[fieldIndex].ToString().Trim(),
                                                                            -1).ToString();
                            // If the lookup attempt returned the default value - indicate to the user that the lookup failed...
                            if (newValue.Equals("-1"))
                            {
                                dr.SetColumnError(tableColumnName, "\tCould not find lookup value: " + fieldValues[fieldIndex].ToString());
                            }
                        }
                    }
                    // Perform a reverse lookup to get the value if this is a Code_Value field...
                    else if (lookupTables.IsValidCodeValueField(dc))
                    {
                        if (!string.IsNullOrEmpty(fieldValues[fieldIndex].ToString().Trim()))
                        {
                            newValue = lookupTables.GetCodeValueValueMember(fieldValues[fieldIndex].ToString(),
                                                                            dc.ExtendedProperties["group_name"].ToString(),
                                                                            "!Error! - GetValueMember method failed to find display member");
                            // If the lookup attempt returned the default value - indicate to the user that the lookup failed...
                            if (newValue.Equals("!Error! - GetValueMember method failed to find display member"))
                            {
                                dr.SetColumnError(tableColumnName, "\tCould not find lookup value: " + fieldValues[fieldIndex].ToString());
                            }
                        }
                    }
                    // Doesn't require a lookup...
                    else
                    {
                        newValue = fieldValues[fieldIndex];
                    }

                    // If the newValue is null attempt to retrieve the default value before further processing...
                    if (string.IsNullOrEmpty(newValue) &&
                        dt.Columns[tableColumnName].ExtendedProperties.Contains("default_value") &&
                        dt.Columns[tableColumnName].ExtendedProperties["default_value"].ToString().Length > 0)
                    {
                        newValue = dt.Columns[tableColumnName].ExtendedProperties["default_value"].ToString();
                    }

                    // Set the newValue to a default value if it is empty or null...
                    if (string.IsNullOrEmpty(newValue) || newValue == "{DBNull.Value}")
                    {
                        if (dt.Columns[tableColumnName].ExtendedProperties.Contains("is_nullable") &&
                            dt.Columns[tableColumnName].ExtendedProperties["is_nullable"].ToString() == "Y")
                        {
                            if (!dr[tableColumnName].Equals(DBNull.Value) && !dr[tableColumnName].Equals(newValue)) dr[tableColumnName] = DBNull.Value;
                        }
                        else
                        {
                            dr.SetColumnError(tableColumnName, "\tThis value cannot be empty (null)");
                        }
                    }
                    // Convert the newValue string to the datatype for this column...
                    else if ((dt.Columns[tableColumnName].DataType == typeof(int) ||
                                dt.Columns[tableColumnName].DataType == typeof(Int16) ||
                                dt.Columns[tableColumnName].DataType == typeof(Int32) ||
                                dt.Columns[tableColumnName].DataType == typeof(Int64)) &&
                                !dr.GetColumnsInError().Contains(dt.Columns[tableColumnName]))
                    {
                        int tempValue = 0;
                        if (Int32.TryParse(newValue, out tempValue))
                        {
                            if (!dr[tableColumnName].Equals(tempValue)) dr[tableColumnName] = tempValue;
                        }
                        else
                        {
                            dr.SetColumnError(tableColumnName, "\tValue '" + newValue + "' cannot be converted to an integer");
                        }
                    }
                    else if (dt.Columns[tableColumnName].DataType == typeof(Decimal) && !dr.GetColumnsInError().Contains(dt.Columns[tableColumnName]))
                    {
                        Decimal tempValue = new Decimal();
                        if (Decimal.TryParse(newValue, out tempValue))
                        {
                            if (!dr[tableColumnName].Equals(tempValue)) dr[tableColumnName] = tempValue;
                        }
                        else
                        {
                            dr.SetColumnError(tableColumnName, "\tValue '" + newValue + "' cannot be converted to a decimal");
                        }
                    }
                    else if (dt.Columns[tableColumnName].DataType == typeof(DateTime) && !dr.GetColumnsInError().Contains(dt.Columns[tableColumnName]))
                    {
                        DateTime tempValue = new DateTime();
                        if (DateTime.TryParse(newValue, out tempValue))
                        {
                            if (!dr[tableColumnName].Equals(tempValue)) dr[tableColumnName] = tempValue;
                        }
                        else
                        {
                            // Basic DateTime conversion failed - look to see if the user provided a hint about how to interpret this date value...
                            // Look to see if there is a column provided that matches this current column name + "_code"...
                            if (dt.Columns.Contains(tableColumnName + "_code"))
                            {
                                string dateFormat = "MM/dd/yyyy";
                                dateFormat = lookupTables.GetCodeValueValueMember(fieldValues[columnNameMap[tableColumnName + "_code"]].ToString().Trim(), dr.Table.Columns[tableColumnName + "_code"].ExtendedProperties["group_name"].ToString(), dateFormat);
                                if (DateTime.TryParseExact(newValue, dateFormat, null, System.Globalization.DateTimeStyles.AssumeLocal, out tempValue))
                                {
                                    if (!dr[tableColumnName].Equals(tempValue)) dr[tableColumnName] = tempValue;
                                }
                                else
                                {
                                    dr.SetColumnError(tableColumnName, "\tValue '" + newValue + "' cannot be converted to a Date/Time");
                                }
                            }
                        }
                    }
                    else if (dt.Columns[tableColumnName].DataType == typeof(string) && !dr.GetColumnsInError().Contains(dt.Columns[tableColumnName]))
                    {
                        if (dc.ExtendedProperties.Contains("max_length") && !dr.GetColumnsInError().Contains(dt.Columns[tableColumnName]))
                        {
                            int maxLength = 0;
                            if (Int32.TryParse(dc.ExtendedProperties["max_length"].ToString(), out maxLength))
                            {
                                if (newValue.Length <= maxLength ||
                                    maxLength == -1)
                                {
                                    // Strip off leading and trailing double quotes - typically added by Excel when it embeds a new line character using the ALT-Enter keystroke...
                                    if (newValue.Trim().StartsWith("\"") && newValue.Trim().EndsWith("\""))
                                    {
                                        newValue = newValue.Trim().TrimStart('"').TrimEnd('"');
                                    }

                                    if (!dr[tableColumnName].Equals(newValue)) dr[tableColumnName] = newValue;
                                }
                                else
                                {
                                    dr.SetColumnError(tableColumnName, "\tValue exceeds maximum length - truncated to " + maxLength.ToString() + " characters");
                                    dr[tableColumnName] = newValue.Substring(0, maxLength); // Truncate the value (so the user can see what is legal to be pasted in)
                                }
                            }
                        }
                    }
                    else
                    {
                        // Not sure what datatype got us here - bailout...
                    }
                }
            }
        }
Exemplo n.º 14
0
 public static void SetError(DataRow Row, string FieldName, string ErrMsg, OutputError Output)
 {
     switch (Output)
     {
         case OutputError.ERROR_PROVIDER:
             Row.SetColumnError(FieldName, ErrMsg);
             break;
     }
 }
        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;
                }
            }
        }
Exemplo n.º 16
0
        /*
            Set the row and columns in error.
        */
        private void ConvertToRowError(DataRow row, int rowIndex)
        {
            Debug.Assert(row != null);
            Debug.Assert(_rowErrors != null);
            Debug.Assert(_colErrors != null);

            if (_rowErrors.ContainsKey(rowIndex))
            {
                row.RowError = (string)_rowErrors[rowIndex];
            }
            if (_colErrors.ContainsKey(rowIndex))
            {
                ArrayList list = (ArrayList)_colErrors[rowIndex];
                int[] columnsInError = (int[])list[0];
                string[] columnErrors = (string[])list[1];
                Debug.Assert(columnsInError.Length == columnErrors.Length);
                for (int i = 0; i < columnsInError.Length; i++)
                {
                    row.SetColumnError(columnsInError[i], columnErrors[i]);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Valida un sy_UsuariosRow.
        /// </summary>
        public static bool RowIsValid(System.Data.DataRow row)
        {
            ApplicationAssert.Check(row != null, "El argumento row no debe ser nulo.", ApplicationAssert.LineNumber);
            bool   isValid = true;
            string mensaje;

            isValid = !row.HasErrors;
            if (!IdUsuarioIsValid(row["IdUsuario"], out mensaje))
            {
                row.SetColumnError("IdUsuario", mensaje);
                isValid = false;
            }

            if (!NombreIsValid(row["Nombre"], out mensaje))
            {
                row.SetColumnError("Nombre", mensaje);
                isValid = false;
            }

            if (!ClaveIsValid(row["Clave"], out mensaje))
            {
                row.SetColumnError("Clave", mensaje);
                isValid = false;
            }

            if (!CantidadConexionesFallidaIsValid(row["CantidadConexionesFallida"], out mensaje))
            {
                row.SetColumnError("CantidadConexionesFallida", mensaje);
                isValid = false;
            }

            if (!UltimaConexionIsValid(row["UltimaConexion"], out mensaje))
            {
                row.SetColumnError("UltimaConexion", mensaje);
                isValid = false;
            }

            if (!ExpiracionIsValid(row["Expiracion"], out mensaje))
            {
                row.SetColumnError("Expiracion", mensaje);
                isValid = false;
            }

            if (!DiasValidezClaveIsValid(row["DiasValidezClave"], out mensaje))
            {
                row.SetColumnError("DiasValidezClave", mensaje);
                isValid = false;
            }

            if (!VencimientoClaveIsValid(row["VencimientoClave"], out mensaje))
            {
                row.SetColumnError("VencimientoClave", mensaje);
                isValid = false;
            }

            if (!BloqueadoIsValid(row["Bloqueado"], out mensaje))
            {
                row.SetColumnError("Bloqueado", mensaje);
                isValid = false;
            }

            if (!IntentosPermitidosConexionIsValid(row["IntentosPermitidosConexion"], out mensaje))
            {
                row.SetColumnError("IntentosPermitidosConexion", mensaje);
                isValid = false;
            }

            if (!HabilitacionCuentaIsValid(row["HabilitacionCuenta"], out mensaje))
            {
                row.SetColumnError("HabilitacionCuenta", mensaje);
                isValid = false;
            }

            if (!AdministradorIsValid(row["Administrador"], out mensaje))
            {
                row.SetColumnError("Administrador", mensaje);
                isValid = false;
            }

            if (!ClaveNuncaCaducaIsValid(row["ClaveNuncaCaduca"], out mensaje))
            {
                row.SetColumnError("ClaveNuncaCaduca", mensaje);
                isValid = false;
            }

            if (!PermiteCambioClaveIsValid(row["PermiteCambioClave"], out mensaje))
            {
                row.SetColumnError("PermiteCambioClave", mensaje);
                isValid = false;
            }

            if (!ResponsableUltimaModificacionIsValid(row["ResponsableUltimaModificacion"], out mensaje))
            {
                row.SetColumnError("ResponsableUltimaModificacion", mensaje);
                isValid = false;
            }

            if (!PerfilUtilizadoIsValid(row["PerfilUtilizado"], out mensaje))
            {
                row.SetColumnError("PerfilUtilizado", mensaje);
                isValid = false;
            }

            if (!ActivoIsValid(row["Activo"], out mensaje))
            {
                row.SetColumnError("Activo", mensaje);
                isValid = false;
            }

            if (!FechaCreacionIsValid(row["FechaCreacion"], out mensaje))
            {
                row.SetColumnError("FechaCreacion", mensaje);
                isValid = false;
            }

            if (!IdConexionCreacionIsValid(row["IdConexionCreacion"], out mensaje))
            {
                row.SetColumnError("IdConexionCreacion", mensaje);
                isValid = false;
            }

            /*	if ( !UltimaModificacionIsValid( row["UltimaModificacion"], out mensaje) )
             *      {
             *              row.SetColumnError( "UltimaModificacion" , mensaje);
             *              isValid=false;
             *
             *      }*/

            if (!IdConexionUltimaModificacionIsValid(row["IdConexionUltimaModificacion"], out mensaje))
            {
                row.SetColumnError("IdConexionUltimaModificacion", mensaje);
                isValid = false;
            }

            if (!RowIdIsValid(row["RowId"], out mensaje))
            {
                row.SetColumnError("RowId", mensaje);
                isValid = false;
            }

            if (!IdPersonaIsValid(row["IdPersona"], out mensaje))
            {
                row.SetColumnError("IdPersona", mensaje);
                isValid = false;
            }
            ;

            return(isValid);
        }
Exemplo n.º 18
0
 private void mergeRows(DataRow org, DataRow chg)
 {
     foreach (DataColumn dc in dtn.Columns)
     {
         if (bAbort)
             return;
         try
         {
             var o = org[dc.ColumnName];
             var c = chg[dc.ColumnName];
             bool bchanged = false;
             bool b = false;
             double d = 0;
             DateTime dt;
             bool ob = false;
             double od = 0;
             DateTime odt;
             if (bool.TryParse(c.ToString(), out b) && bool.TryParse(o.ToString(), out ob))
             {
                 if (!ob.Equals(b))
                 {
                     org[dc.ColumnName] = b;
                     bchanged = true;
                 }
             }
             else if (double.TryParse(c.ToString().Replace(".", ","), out d) && double.TryParse(o.ToString().Replace(".", ","), out od))
             {
                 if (!od.Equals(d))
                 {
                     org[dc.ColumnName] = d;
                     bchanged = true;
                 }
             }
             else if (DateTime.TryParse(c.ToString().Replace(".", ","), out dt) && DateTime.TryParse(o.ToString().Replace(".", ","), out odt))
             {
                 if (!odt.Equals(dt))
                 {
                     org[dc.ColumnName] = dt;
                     bchanged = true;
                 }
             }
             else if (!o.Equals(c))
             {
                 org[dc.ColumnName] = c;
                 bchanged = true;
             }
             continue;
             if (bchanged)
                 org.SetColumnError(dc.ColumnName, string.Format("{0}-{1}", org[dc.ColumnName], chg[dc.ColumnName]));
         }
         catch (ArgumentException ex)
         { }
     }
 }
Exemplo n.º 19
0
        bool Kiem_tra_dl(DataSet ds, DataRow row)
        {
            if (ds != null)
            {
                foreach (DataRow r in ds.Tables[0].Rows)
                {
                    if (r.RowState != DataRowState.Deleted)
                    {
                        if (r["CTCCV_ID"].ToString() != row["CTCCV_ID"].ToString())
                        {

                            if (row["LCV_ID"].ToString() == r["LCV_ID"].ToString() && row["MO_TA"].ToString().ToLower() == r["MO_TA"].ToString().ToLower())
                            {
                                row.SetColumnError("LCV_ID", "Công việc và mô tả công việc nhập bị trùng lặp!");
                                return false;
                            }
                        }
                    }
                }
            }
            return true;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Check wheather this DataRow is valid.
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private bool ValidateData(DataRow row)
        {
            bool valid = true;
            if(row.RowState == DataRowState.Deleted)
                return true;

            row.ClearErrors();

            if(row["UROLE_ID"] == DBNull.Value || row["UROLE_ID"].ToString().Length == 0)
            {
                row.SetColumnError("UROLE_ID", clsResources.GetMessage("errors.required", colURoleID.HeaderText));
                valid = false;
            }

            if(row["ROLE_NAME"] == DBNull.Value || row["ROLE_NAME"].ToString().Length == 0)
            {
                row.SetColumnError("ROLE_NAME", clsResources.GetMessage("errors.required", colRoleName.HeaderText));
                valid = false;
            }

            return valid;
        }
Exemplo n.º 21
0
        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;
                }
            }

        }
Exemplo n.º 22
0
        private void CheckErrorTimeCode(DataRow row, BandedGridColumn timeCodeIn, BandedGridColumn timeCodeOut)
        {
            if (row[timeCodeIn.FieldName].ToString() != "" &&
              (row[timeCodeOut.FieldName].ToString() == ""))
            {
                row.SetColumnError(timeCodeOut.FieldName, "Vui lòng vào thông tin \"" + timeCodeOut.Caption + "\"!");
            }
            else if (row[timeCodeIn.FieldName].ToString() == "" &&
                row[timeCodeOut.FieldName].ToString() != "")
            {
                row.SetColumnError(timeCodeIn.FieldName, "Vui lòng vào thông tin \"" + timeCodeIn.Caption + "\"!");

            }
            else if (row[timeCodeIn.FieldName].ToString() != "" &&
                 row[timeCodeOut.FieldName].ToString() != "")
            {
                var tIn = new TimeCode(row[timeCodeIn.FieldName].ToString());
                var tOut = new TimeCode(row[timeCodeOut.FieldName].ToString());
                if (tOut < tIn)
                    row.SetColumnError(timeCodeOut.FieldName, "Vui lòng vào thông tin \"" + timeCodeOut.Caption + "\" lớn hơn \"" + timeCodeIn.Caption + "\"!");
            }
        }