This commit is contained in:
2009-01-27 15:40:02 +00:00
parent 08e529bf26
commit 55166e2cb3
7 changed files with 2895 additions and 4 deletions

View File

@@ -32,15 +32,24 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Refresh
private List<DocVersion> _RefreshDocVersions = new List<DocVersion>();
private void AddToRefreshList(List<DocVersion> refreshDocVersions)
private List<DocVersionAssociation> _RefreshDocVersionAssociations = new List<DocVersionAssociation>();
private void AddToRefreshList(List<DocVersion> refreshDocVersions, List<DocVersionAssociation> refreshDocVersionAssociations)
{
if (IsDirty)
refreshDocVersions.Add(this);
if (_DocVersionAssociations != null && _DocVersionAssociations.IsDirty)
{
foreach (DocVersionAssociation tmp in _DocVersionAssociations)
{
if (tmp.IsDirty) refreshDocVersionAssociations.Add(tmp);
}
}
}
private void BuildRefreshList()
{
_RefreshDocVersions = new List<DocVersion>();
AddToRefreshList(_RefreshDocVersions);
_RefreshDocVersionAssociations = new List<DocVersionAssociation>();
AddToRefreshList(_RefreshDocVersions, _RefreshDocVersionAssociations);
}
private void ProcessRefreshList()
{
@@ -51,6 +60,10 @@ namespace VEPROMS.CSLA.Library
if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat);
if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem);
}
foreach (DocVersionAssociation tmp in _RefreshDocVersionAssociations)
{
AssociationInfo.Refresh(tmp);
}
}
#endregion
#region Collection
@@ -335,13 +348,50 @@ namespace VEPROMS.CSLA.Library
}
}
private byte[] _LastChanged = new byte[8];//timestamp
private int _DocVersionAssociationCount = 0;
/// <summary>
/// Count of DocVersionAssociations for this DocVersion
/// </summary>
public int DocVersionAssociationCount
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocVersionAssociationCount", true);
return _DocVersionAssociationCount;
}
}
private DocVersionAssociations _DocVersionAssociations = null;
/// <summary>
/// Related Field
/// </summary>
[TypeConverter(typeof(DocVersionAssociationsConverter))]
public DocVersionAssociations DocVersionAssociations
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocVersionAssociations", true);
if (_DocVersionAssociationCount < 0 || (_DocVersionAssociationCount > 0 && _DocVersionAssociations == null))
_DocVersionAssociations = DocVersionAssociations.GetByVersionID(VersionID);
if (_DocVersionAssociationCount < 0 )
_DocVersionAssociationCount = _DocVersionAssociations == null ? 0 : _DocVersionAssociations.Count;
if (_DocVersionAssociations == null)
_DocVersionAssociations = DocVersionAssociations.New();
return _DocVersionAssociations;
}
}
public void Reset_DocVersionAssociations()
{
_DocVersionAssociationCount = -1;
}
public override bool IsDirty
{
get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); }
get { return base.IsDirty || (_DocVersionAssociations == null ? false : _DocVersionAssociations.IsDirty) || (_MyFolder == null ? false : _MyFolder.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); }
}
public override bool IsValid
{
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); }
get { return true;} // (IsNew && !IsDirty ? true : base.IsValid) && (_DocVersionAssociations == null ? true : _DocVersionAssociations.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); }
}
// TODO: Replace base DocVersion.ToString function as necessary
/// <summary>
@@ -375,6 +425,7 @@ namespace VEPROMS.CSLA.Library
{
_CheckingBrokenRules = true;
IVEHasBrokenRules hasBrokenRules = null;
if (_DocVersionAssociations != null && (hasBrokenRules = _DocVersionAssociations.HasBrokenRules) != null) return hasBrokenRules;
if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules;
if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules;
if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules;
@@ -494,6 +545,19 @@ namespace VEPROMS.CSLA.Library
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _DocVersionAssociationCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// TODO: CanEdit Authorization
@@ -723,6 +787,7 @@ namespace VEPROMS.CSLA.Library
_DTS = dr.GetDateTime("DTS");
_UserID = dr.GetString("UserID");
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
_DocVersionAssociationCount = dr.GetInt32("AssociationCount");
MarkOld();
}
catch (Exception ex)
@@ -753,6 +818,9 @@ namespace VEPROMS.CSLA.Library
return;
}
ReadData(dr);
// load child objects
dr.NextResult();
_DocVersionAssociations = DocVersionAssociations.Get(dr);
}
}
// removing of item only needed for local data portal
@@ -831,6 +899,7 @@ namespace VEPROMS.CSLA.Library
}
MarkOld();
// update child objects
if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -944,6 +1013,7 @@ namespace VEPROMS.CSLA.Library
}
MarkOld();
// use the open connection to update child objects
if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this);
}
catch (Exception ex)
{
@@ -964,6 +1034,7 @@ namespace VEPROMS.CSLA.Library
_LastChanged = DocVersion.Update(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged);
MarkOld();
}
if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int versionID, Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID, ref byte[] lastChanged)