Change Manager

This commit is contained in:
Rich 2011-08-01 20:16:23 +00:00
parent a38f0b0909
commit 14e3e15537
9 changed files with 1726 additions and 2 deletions

View File

@ -1,6 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using Csla;
using Csla.Data;
namespace VEPROMS.CSLA.Library
{
@ -10,6 +15,37 @@ namespace VEPROMS.CSLA.Library
{
return _SearchText;
}
#region JCB Annotation Status
private bool _IsAnnotationNew = false;
public bool IsAnnotationNew
{
get
{
ProcedureInfo pi = this.MyItem.MyProcedure;
if (pi != null)
//todo figure out audit count
_IsAnnotationNew = (this.DTS > pi.DTS);
return _IsAnnotationNew;
}
}
private bool _IsAnnotationChanged;
public bool IsAnnotationChanged
{
get
{
ProcedureInfo pi = this.MyItem.MyProcedure;
if (pi != null)
{
//todo figure out audit count
_IsAnnotationChanged = (this.DTS > pi.DTS);
}
return _IsAnnotationChanged;
}
}
#endregion
}
public partial class AnnotationType
{
@ -52,6 +88,100 @@ namespace VEPROMS.CSLA.Library
Save(true);
//Update();
}
public static void DeleteAnnotation(AnnotationInfo obj)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Annotation");
try
{
// ItemInfo nextItem = item.NextItem;
// ItemInfo prevItem = item.MyPrevious;
// item.OnBeforeDelete();
DataPortal.Delete(new DeleteCriteria(obj.AnnotationID, Volian.Base.Library.VlnSettings.UserID));
// if (nextItem != null) // Adjust PreviousID for NextItem
// {
// ItemInfo.RefreshPrevious(nextItem.ItemID, item.PreviousID);
// // The order of the next two methods was required to fix a null reference
// // when getting myparent. This bug was found when deleting a node from the
// // tree when the RTBItem was not open (i.e. in the step editor window).
// nextItem.RefreshItemParts();
// //nextItem.ResetOrdinal(); - UpdateTransitionText calls ResetOrdinal
// nextItem.UpdateTransitionText();
// }
// else if (prevItem != null)
// {
// prevItem.RefreshNextItems();
// if (prevItem.IsCaution || prevItem.IsNote) prevItem.ResetOrdinal();
// prevItem.UpdateTransitionText();
// }
// ItemInfo.DeleteItemInfoAndChildren(item.ItemID); // Dispose ItemInfo and Children
}
catch (Exception ex)
{
Console.WriteLine("AnnotationExt: Stacktrace = {0}", ex.StackTrace);
System.Data.SqlClient.SqlException exSQL = SqlException(ex);
if (exSQL != null && exSQL.Message.Contains("###Cannot Delete Item###"))
//return false;
throw exSQL;
else
throw new DbCslaException("Error on Annotation.Delete", ex);
}
}
private static System.Data.SqlClient.SqlException SqlException(Exception ex)
{
Type sqlExType = typeof(System.Data.SqlClient.SqlException);
while (ex != null)
{
if (ex.GetType() == sqlExType) return ex as System.Data.SqlClient.SqlException;
ex = ex.InnerException;
}
return null;
}
[Serializable()]
protected class DeleteCriteria
{
private int _AnnotationID;
public int AnnotationID
{ get { return _AnnotationID; } }
private string _UserID;
public string UserID
{
get { return _UserID; }
set { _UserID = value; }
}
public DeleteCriteria(int annotationID, String userID)
{
_AnnotationID = annotationID;
_UserID = userID;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DeleteCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "deleteAnnotationWithUserID";
cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID);
cm.Parameters.AddWithValue("@UserID", criteria.UserID);
cm.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Item.DataPortal_Delete", ex);
}
}
}
//public partial class AnnotationTypeAnnotations
//{

File diff suppressed because it is too large Load Diff

View File

@ -55,6 +55,126 @@ namespace VEPROMS.CSLA.Library
}
public partial class FormatInfo : IFormatOrFormatInfo
{
public static bool HasLatestChanges()
{
if (!HasTopMargin()) return false;
if (!HasWCN2_MacroB9()) return false;
return true;
}
private static bool HasTopMargin()
{
using (FormatInfo fi = FormatInfo.Get("WCN2"))
{
XmlDocument xd = new XmlDocument();
xd.LoadXml(fi.Data);
XmlNodeList xl = xd.SelectNodes("//DocStyle/Layout/@TopMargin");
if (xl.Count == 0)
{
System.Windows.Forms.MessageBox.Show("DocStyle TopMargin is missing", "Inconsistent Format Files", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
return false;
}
return true;
}
}
private static bool HasWCN2_MacroB9()
{
using (FormatInfo fi = FormatInfo.Get("WCN2"))
{
XmlDocument xd = new XmlDocument();
xd.LoadXml(fi.GenMac);
XmlNodeList xl = xd.SelectNodes("//*[@id='B9']");
if (xl.Count == 0)
{
System.Windows.Forms.MessageBox.Show("B9 macro is missing in WCN2 GenMac","Inconsistent Format Files", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
return false;
}
return true;
}
}
public static FormatInfo Get(string name)
{
try
{
FormatInfo tmp = DataPortal.Fetch<FormatInfo>(new NameCriteria(name));
//AddToCache(tmp);
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up FormatInfo
tmp = null;
}
return tmp;
}
catch (Exception ex1)
{
Exception ex = ex1;
while (ex.InnerException != null)
ex = ex.InnerException;
if (ex.Message.StartsWith("Could not find stored procedure"))
{
int formatID = 0;
using (FormatInfoList fil = FormatInfoList.Get())
{
foreach (FormatInfo fi in fil)
{
if (fi.Name == name)
{
formatID = fi.FormatID;
break;
}
}
}
if (formatID != 0) return FormatInfo.Get(formatID);
throw new DbCslaException("Format not found " + name, ex);
}
else
throw new DbCslaException("Error on FormatInfo.Get By Name", ex);
}
}
protected class NameCriteria
{
private string _Name;
public string Name
{ get { return _Name; } }
public NameCriteria(string name)
{
_Name = name;
}
}
private void DataPortal_Fetch(NameCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.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 = "getFormatByName";
cm.Parameters.AddWithValue("@Name", criteria.Name);
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("FormatInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex);
}
}
#region PlantFormat
[NonSerialized]
private PlantFormat _PlantFormat;

View File

@ -1702,6 +1702,8 @@ namespace VEPROMS.CSLA.Library
ItemInfo tmp = this;
while (tmp.ActiveParent != null && tmp.ActiveParent.GetType() != typeof(DocVersionInfo))
tmp = (ItemInfo)tmp.ActiveParent;
if (tmp is ProcedureInfo)
return tmp as ProcedureInfo;
return ProcedureInfo.Get(tmp.ItemID);
}
}
@ -1842,7 +1844,29 @@ namespace VEPROMS.CSLA.Library
//Console.WriteLine("Local {0}", (MyContent.MyFormat==null)?"MYformat is null": MyContent.MyFormat.Name);
return MyContent.MyFormat; }
}
private ConfigDynamicTypeDescriptor _MyConfig=null;
private bool _IsDeleted = false;
public bool IsDeleted
{
get { return _IsDeleted; }
set
{
_IsDeleted = value;
if (value == true)
UpdateCacheIsDeleted(ItemID);
}
}
private static void UpdateCacheIsDeleted(int itemID)
{
ConvertListToDictionary();
string key = itemID.ToString();
if (key != null && _CacheByPrimaryKey.ContainsKey(key))
{
ItemInfo[] items = _CacheByPrimaryKey[key].ToArray();
foreach (ItemInfo item in items)
item._IsDeleted = true;
}
}
private ConfigDynamicTypeDescriptor _MyConfig = null;
public ConfigDynamicTypeDescriptor MyConfig
{
get
@ -2336,6 +2360,30 @@ namespace VEPROMS.CSLA.Library
if (tmp.Count > 0) _MyMacros = tmp;
}
#endregion
#region JCB Item Status
private bool _IsItemNew = false;
public bool IsItemNew
{
get
{
ProcedureInfo pi = this.MyProcedure;
if (pi != null)
_IsItemNew = (this.DTS > pi.DTS);
return _IsItemNew;
}
}
private bool _IsItemChanged;
public bool IsItemChanged
{
get
{
ProcedureInfo pi = this.MyProcedure;
if (pi != null)
_IsItemChanged = (this.MyContent.DTS > pi.DTS);
return _IsItemChanged;
}
}
#endregion
}
#endregion ItemInfo
#region Tab

View File

@ -179,10 +179,13 @@ namespace VEPROMS.CSLA.Library
}
}
}
public static event ItemInfoEvent ItemDeleted;
public event ItemInfoEvent Deleted;
internal void OnDeleted(object sender)
{
if (Deleted != null) Deleted(sender);
if (ItemDeleted != null) ItemDeleted(sender);
if (MyParent != null)
{
MyParent.OnChildrenDeleted(sender);
@ -411,7 +414,10 @@ namespace VEPROMS.CSLA.Library
{
content.FixTransitionText(tran);
if (content.IsDirty)
{
content.DTS = DateTime.Now;
content.Save();
}
else // Update ContentInfo objects to reflect the change in the transition
ContentInfo.Refresh(content);
}
@ -776,6 +782,7 @@ namespace VEPROMS.CSLA.Library
//Console.WriteLine("\r\n\r\n'Deleting Item {0}'\r\n{0}'Type ','ParentID','ParentUnique','ItemID','Unique'",itemID);
foreach (ItemInfo item in items)
{
item.IsDeleted = true;
item.OnDeleted(item);
item.DeleteItemInfoAndChildren(" ");
}

View File

@ -352,12 +352,17 @@ namespace VEPROMS.CSLA.Library
{
content.FixContentText(roUsg, roch, origROFstInfo);
if (content.IsDirty)
{
// Update UserID and DTS when RO Value is updated.
content.UserID = Volian.Base.Library.VlnSettings.UserID;
content.DTS = DateTime.Now;
content.Save();
}
}
}
}
}
}
activeRoids = BuildActiveROIDsForDRoUsages(RoidList);
foreach (string chg in chgList)
{

View File

@ -30,6 +30,7 @@ namespace VEPROMS.CSLA.Library
}
public string ResolvePathTo()
{
MyContent.RefreshContentItems();
ItemInfo item = MyContent.ContentItems[0];
//Console.WriteLine("Format = {0}", item.ActiveFormat);
//Console.WriteLine("item = {0}", item.ItemID);
@ -387,6 +388,8 @@ namespace VEPROMS.CSLA.Library
}
public static string GetResolvedText(FormatInfo formatInfo, ItemInfo fromInfo, int tranType, ItemInfo toItem, ItemInfo rangeItem)
{
if (toItem == null || rangeItem == null || toItem.IsDeleted || rangeItem.IsDeleted)
return "Invalid Transition Destination";
TransitionBuilder tb = SetupTransitionBuilder(formatInfo, fromInfo, tranType, toItem,
toItem.ItemID==rangeItem.ItemID && !toItem.IsHigh?toItem.LastSibling:rangeItem);
if(_AppendMethods==null)

View File

@ -1287,6 +1287,7 @@ namespace VEPROMS.CSLA.Library
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("ContentID={0}", _ContentID.ToString());
cm.CommandText = "updateContent";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", _ContentID);

View File

@ -27,11 +27,20 @@ namespace VEPROMS.CSLA.Library
[TypeConverter(typeof(ContentInfoConverter))]
public partial class ContentInfo : ReadOnlyBase<ContentInfo>, IDisposable
{
public static event ContentInfoEvent InfoChanged;
private void OnInfoChanged(ContentInfo contentInfo)
{
if (InfoChanged != null)
InfoChanged(this);
}
public event ContentInfoEvent Changed;
private void OnChange(ContentInfo contentInfo)
{
if (Changed != null)
{
Changed(this);
OnInfoChanged(this);
}
}
private void OnChange()
{