From ab03dfd2ff8a33894fa367e49b084f55ae7e42fe Mon Sep 17 00:00:00 2001 From: Kathy Date: Thu, 14 May 2015 14:39:05 +0000 Subject: [PATCH] Enhancements for handling checkout/modifications at folder and session level --- .../Extension/MultiUserExt.cs | 91 ++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs index ac24bbc0..4ff4475b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs @@ -12,7 +12,7 @@ namespace VEPROMS.CSLA.Library #region Enum stuff public enum CheckOutType : int { - Procedure = 0, Document = 1, DocVersion = 2, Folder = 3 + Procedure = 0, Document = 1, DocVersion = 2, Folder = 3, Session = 4 } #endregion #region SessionInfoList stuff @@ -132,7 +132,7 @@ namespace VEPROMS.CSLA.Library SessionInfoList sil = DataPortal.Fetch(new SessionInfoList.CanCheckOutItemCriteria(objectID, objectType)); if (sil.Count == 0) return true; - if (objectType == CheckOutType.Folder) + if (objectType == CheckOutType.Session) { if (sil.Count == 1) { @@ -166,6 +166,7 @@ namespace VEPROMS.CSLA.Library } else if (si.SessionID != this.SessionID && objectType == CheckOutType.DocVersion) { + // gets here if other session has working draft open & click on sam working draft. OwnerInfo oi = OwnerInfo.GetBySessionIDandVersionID(si.SessionID, objectID); if(oi.OwnerType == 0) message = message + string.Format("The procedure {0} is already checked out to {1}", ItemInfo.Get(oi.OwnerItemID).MyProcedure.DisplayNumber, si.UserID) + Environment.NewLine; @@ -175,6 +176,24 @@ namespace VEPROMS.CSLA.Library message = message + string.Format("The working draft is already checked out to {0}", si.UserID); rv = rv && false; } + else if (si.SessionID != this.SessionID && objectType == CheckOutType.Folder) + { + // gets here if other session has working draft open & click on folder above. Gets here + // if other session has wd open and click on top folder - query returns empty. + OwnerInfo oi = OwnerInfo.GetBySessionIDandFolderID(si.SessionID, objectID); + if (oi != null) + { + if (oi.OwnerType == 0) + message = message + string.Format("The procedure {0} is already checked out to {1}", ItemInfo.Get(oi.OwnerItemID).MyProcedure.DisplayNumber, si.UserID) + Environment.NewLine; + else if (oi.OwnerType == 1) + message = message + string.Format("The document {0} is already checked out to {1}", DocumentInfo.Get(oi.OwnerItemID).DocumentEntries[0].MyContent.Text, si.UserID) + Environment.NewLine; + else if (oi.OwnerType == 2) + message = message + string.Format("The working draft is already checked out to {0}", si.UserID); + else if (oi.OwnerType == 3) + message = message + string.Format("The folder is already checked out to {0}", si.UserID); + rv = rv && false; + } + } } return rv; } @@ -756,6 +775,74 @@ namespace VEPROMS.CSLA.Library } public partial class OwnerInfo { + public static OwnerInfo GetBySessionIDandFolderID(int sessionID, int folderID) + { + try + { + OwnerInfo tmp = DataPortal.Fetch(new GetBySessionIDandFolderIDCriteria(sessionID, folderID)); + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up SessionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on OwnerInfo.GetBySessionIDandFolderID", ex); + } + } + [Serializable()] + protected class GetBySessionIDandFolderIDCriteria + { + private int _SessionID; + public int SessionID + { get { return _SessionID; } } + private int _FolderID; + public int FolderID + { get { return _FolderID; } } + public GetBySessionIDandFolderIDCriteria(int sessionID, int folderID) + { + _SessionID = sessionID; + _FolderID = folderID; + } + } + private void DataPortal_Fetch(GetBySessionIDandFolderIDCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getOwnerBySessionIDandFolderID"; + cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("OwnerInfo.DataPortal_Fetch", ex); + } + } public static OwnerInfo GetBySessionIDandVersionID(int sessionID, int versionID) { try