From 79b0bf4c1bb22cfe86fc3fd200a82690c5e66cb1 Mon Sep 17 00:00:00 2001 From: Rich Date: Mon, 7 Dec 2009 15:55:31 +0000 Subject: [PATCH] Fixed code so that Deletes of Procedures and Sections would no cause steps to be resequenced. Added code to Just Get RODb and not all of it's children. Added code to create an RoImageFile (Temporary) to be used to view and print images Additional DEBUG info --- .../Extension/ItemInsertExt.cs | 5 +- .../VEPROMS.CSLA.Library/Extension/RODbExt.cs | 78 +++++++++ .../Extension/ROImageExt.cs | 161 ++++++++++++++++++ .../Generated/ContentInfo.cs | 4 +- 4 files changed, 244 insertions(+), 4 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index b34a2ddd..ed54912d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -308,7 +308,8 @@ namespace VEPROMS.CSLA.Library } public void UpdateTransitionText() { - // Update Ordinals from here down + // Update Ordinals from here down for Steps + if (!IsStep) return; ResetOrdinal(); // This returns a list of all of the transitions that may have been affected using(TransitionInfoList trans = TransitionInfoList.GetAffected(this.ItemID)) @@ -636,7 +637,7 @@ namespace VEPROMS.CSLA.Library // when getting myparent. This bug was found when deleting a node from the // tree when the stepitem was not open (i.e. in the step editor window). nextItem.RefreshItemParts(); - nextItem.ResetOrdinal(); + //nextItem.ResetOrdinal(); - UpdateTransitionText calls ResetOrdinal nextItem.UpdateTransitionText(); } else if (prevItem != null) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/RODbExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/RODbExt.cs index a64ab355..14bff67e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/RODbExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/RODbExt.cs @@ -16,6 +16,10 @@ using System.IO; using System.Xml.Serialization; using System.Xml; using System.Xml.XPath; +using Csla; +using Csla.Data; +using System.Data.SqlClient; +using System.Data; namespace VEPROMS.CSLA.Library { @@ -34,6 +38,80 @@ namespace VEPROMS.CSLA.Library } public partial class RODb { + public static RODb GetJustRoDb(int rODbID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a RODb"); + try + { + RODb tmp = DataPortal.Fetch(new PKCriteriaJustRoDb(rODbID)); + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RODb + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.Get", ex); + } + } + private void DataPortal_Fetch(PKCriteriaJustRoDb criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.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 = "getJustRODb"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // Don't load child objects + //dr.NextResult(); + //_RODbROFsts = RODbROFsts.Get(dr); + // load child objects + //dr.NextResult(); + //_RODbROImages = RODbROImages.Get(dr); + // load child objects + //dr.NextResult(); + //_RODbRoUsages = RODbRoUsages.Get(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("RODb.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.DataPortal_Fetch", ex); + } + } + [Serializable()] + protected class PKCriteriaJustRoDb + { + private int _RODbID; + public int RODbID + { get { return _RODbID; } } + public PKCriteriaJustRoDb(int rODbID) + { + _RODbID = rODbID; + } + } #region Log4Net private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ROImageExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ROImageExt.cs index b86b0b9c..3bd2216d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ROImageExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ROImageExt.cs @@ -5,6 +5,7 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; +using System.IO; namespace VEPROMS.CSLA.Library { @@ -82,4 +83,164 @@ namespace VEPROMS.CSLA.Library } } } + public class ROImageFile : IDisposable + { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #region Fields + private bool _IsDisposed; + private static string _TemporaryFolder = null; + #endregion + #region Properties + public static string TemporaryFolder + { + get + { + if (_TemporaryFolder == null) + { + // This will create a Temp\VE-PROMS folder in the LocalSettings Folder. + //XP - C:\Documents and Settings\{user}\Local Settings\Application Data\Temp\VE-PROMS + //Vista - C:\Users\{user}\AppData\Local\Temp\VE-PROMS + _TemporaryFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Temp"; + if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder); + _TemporaryFolder += @"\VE-PROMS"; + if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder); + } + return _TemporaryFolder; + } + } + private ROImageInfo _MyROImage = null; + public ROImageInfo MyROImage + { + get { return _MyROImage; } + set + { + TryDelete(); + _MyROImage = value; + CreateFile(); + } + } + private FileInfo _MyFile = null; + public FileInfo MyFile + { + get { return _MyFile; } + } + private string _Extension = "TIF"; + public string Extension + { + get { return _Extension; } + set { _Extension = value; } + } + #endregion + #region Private Methods + private void TryDelete() + { + if (_MyROImage == null) return; + if (_MyFile == null) return; + if (_MyFile.Exists) + { + try + { + _MyFile.Delete(); + } + catch (IOException ex) + { + _MyLog.Error("TryDelete", ex); + } + finally + { + _MyFile = null; + _MyROImage = null; + } + } + } + private bool _Created = false; + private int _Unique = 0; + private string Unique + { + get + { + string retval = ""; + if (_Unique != 0) retval = "_" + _Unique.ToString(); + _Unique++; + return retval; + } + } + private void CreateFile() + { + while (!_Created) + CreateTemporaryFile(); + } + + private void CreateTemporaryFile() + { + try + { + if (_MyROImage != null) + { + _MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}{2}", TemporaryFolder, Unique, MyROImage.FileName)); + FileStream fs = _MyFile.Create(); + fs.Write(MyROImage.Content, 0, MyROImage.Content.Length); + fs.Close(); + _MyFile.CreationTime = MyROImage.DTS; + _MyFile.LastWriteTime = MyROImage.DTS; + _Created = true; + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + public string FullName + { + get { return _MyFile.FullName; } + set + { + if (FullName != value) + _MyFile = new FileInfo(value); + } + } + public void SaveFile() + { + // TODO: Add Try & Catch logic + if (_MyROImage == null) return; + ROImage roImage = _MyROImage.Get(); + FileStream fs = _MyFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + Byte[] buf = new byte[_MyFile.Length]; + fs.Read(buf, 0, buf.Length); + fs.Close(); + //roImage.FileName; + roImage.Content = buf; + roImage.UserID = Environment.UserName; + roImage.DTS = _MyFile.LastWriteTime; + roImage.Save(); + } + #endregion + #region Constructors + public ROImageFile(ROImageInfo myROImage) + { + MyROImage = myROImage; + } + #endregion + #region Destructor + ~ROImageFile() + { + Dispose(false); + } + public void Dispose() + { + Dispose(false); + GC.SuppressFinalize(this); + } + + protected void Dispose(bool disposing) + { + if (!_IsDisposed) + { + _IsDisposed = true; + TryDelete(); + } + } + #endregion + } } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs index cd4d127f..77d3f763 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs @@ -34,12 +34,12 @@ namespace VEPROMS.CSLA.Library { //if (ContentItems[0].ItemID == 54) //Console.WriteLine("OnChange: ItemID = {0}, Unique = {1}", ContentItems[0].ItemID, ContentItems[0].MyItemInfoUnique); - Console.WriteLine("'Tab Bug','OnChange',{0},{1},{2},{3}", ContentItems[0].ItemID, ContentItems[0].MyItemInfoUnique, + Console.WriteLine("'Tab Bug','OnChange','{0}',{1},{2},{3},{4}", ContentItems[0].Path, ContentItems[0].ItemID, ContentItems[0].MyItemInfoUnique, ContentID,MyContentInfoUnique); Changed(this); } else - Console.WriteLine("'Tab Bug','OnChange NoChange',{0},{1},{2},{3}", ContentItems[0].ItemID, ContentItems[0].MyItemInfoUnique, + Console.WriteLine("'Tab Bug','OnChange NoChange','{0}',{1},{2},{3},{4}", ContentItems[0].Path, ContentItems[0].ItemID, ContentItems[0].MyItemInfoUnique, ContentID, MyContentInfoUnique); } private void OnChange()