public object GetValue(IRowLink rowLink) { if (rowLink == null) return null; object rawValue = rowLink.GetValue(FieldName); if (rawValue == DBNull.Value || rawValue == null) return null; if (ToGridValue != null) return ToGridValue(rawValue); return rawValue; }
public void SetPrimaryKey(IRowLink newRow) { if (currentPrimaryKey == -1) { object rawMaxPrimaryKey = dbConnection.GetScalar(database, string.Format("Select Max({0}) From {1}", fieldName, tableName)); int? maxPrimaryKey = DataBaseHlp.ConvertToInt(rawMaxPrimaryKey); currentPrimaryKey = maxPrimaryKey != null ? maxPrimaryKey.Value : 0; } currentPrimaryKey++; primaryKeyField.Set(newRow, currentPrimaryKey); }
public void SetValue(IRowLink rowLink, object value) { if (rowLink == null) return; object rawValue = value; if (ToDataBaseValue != null) rawValue = ToDataBaseValue(value); if (rawValue == null) rawValue = DBNull.Value; rowLink.SetValue(FieldName, rawValue); }
public void SetPrimaryKey(IRowLink newRow) { if (currentPrimaryKey >= maxPrimaryKey) { object rawNewPrimaryKey = dbConnection.GetScalar("", string.Format(@" update {0} set max_primary_key = max_primary_key + {1} where table_name = '{2}'; select max_primary_key from {0} where table_name = '{2}';", primaryKeyTableName, reservationStep, tableName)); int? newPrimaryKey = DataBaseHlp.ConvertToInt(rawNewPrimaryKey); if (newPrimaryKey == null) throw new Exception(string.Format("Ошибка получения нового primary_key для таблицы '{0}'", tableName)); maxPrimaryKey = newPrimaryKey.Value; currentPrimaryKey = maxPrimaryKey - reservationStep + 1; } primaryKeyField.Set(newRow, currentPrimaryKey); currentPrimaryKey++; }
//Extension public void Copy(IRowLink destRow, IRowLink sourceRow) { object sourceValue = GetValue(sourceRow); if (!ObjectHlp.IsEquals(destRow.GetValue(FieldName), sourceValue)) SetValue(destRow, sourceValue); }
public void SetDefaultValue(IRowLink rowLink) { SetValue(rowLink, DefaultValue); }
public UniversalKey CreateKey(TableLink tableLink, IRowLink rowLink) { object[] partKeys = new object[IndexColumns.Length]; for (int i = 0; i < partKeys.Length; ++i) { FieldLink fieldLink = tableLink.GetFieldLink(IndexColumns[i]); partKeys[i] = fieldLink.FieldBlank.GetValue(rowLink); } return new UniversalKey(partKeys); }