Ejemplo n.º 1
0
        /// <summary>
        /// Sets a value for a particular column in the record
        /// </summary>
        /// <param name="columnName">Name of the column, as defined in the database</param>
        /// <param name="oValue">The value to set the type to</param>
        public void SetColumnValue(string columnName, object oValue)
        {
            columnSettings = columnSettings ?? new TableSchema.TableColumnSettingCollection();

            // add the column to the DirtyColumns
            // if this instance has already been loaded
            // and this is a change to existing values
            if (IsLoaded && !IsNew)
            {
                TableSchema.Table schema      = GetSchema();
                object            oldValue    = null;
                string            oldValueMsg = "NULL";
                string            newValueMsg = "NULL";
                bool areEqualOrBothNull       = false;

                try
                {
                    oldValue = columnSettings.GetValue(columnName);
                }
                catch {}

                if (oldValue == null && oValue == null)
                {
                    areEqualOrBothNull = true;
                }
                else
                {
                    if (oldValue != null)
                    {
                        oldValueMsg        = oldValue.ToString();
                        areEqualOrBothNull = oldValue.Equals(oValue);
                    }

                    if (oValue != null)
                    {
                        newValueMsg = oValue.ToString();
                    }
                }

                TableSchema.TableColumn dirtyCol = schema.GetColumn(columnName);

                if (dirtyCol != null && !areEqualOrBothNull)
                {
                    string auditMessage = String.Format("Value changed from {0} to {1}{2}", oldValueMsg, newValueMsg, Environment.NewLine);
                    TableSchema.TableColumn dirtyEntry = DirtyColumns.GetColumn(columnName);
                    if (dirtyEntry != null)
                    {
                        DirtyColumns.Remove(dirtyEntry);
                        auditMessage = String.Concat(dirtyCol.AuditMessage, auditMessage);
                    }

                    dirtyCol.AuditMessage = auditMessage;
                    DirtyColumns.Add(dirtyCol);
                }
            }

            columnSettings.SetValue(columnName, oValue);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns the current value of the primary key
 /// </summary>
 /// <returns></returns>
 public object GetPrimaryKeyValue()
 {
     return(columnSettings.GetValue <object>(BaseSchema.PrimaryKey.ColumnName));
 }