diff --git a/PROMS/VEPROMS User Interface/frmAnnotationsCleanup.cs b/PROMS/VEPROMS User Interface/frmAnnotationsCleanup.cs index 2cc1999c..ac21d9d7 100644 --- a/PROMS/VEPROMS User Interface/frmAnnotationsCleanup.cs +++ b/PROMS/VEPROMS User Interface/frmAnnotationsCleanup.cs @@ -59,7 +59,7 @@ namespace VEPROMS private string getAnnotationProcItems(List pil2) { - + procList = ""; foreach (var p in pil2) { if (p.IsProcedure) @@ -80,7 +80,7 @@ namespace VEPROMS private string getAnnotationDocvItems(List dvil2) { - + docvList = ""; foreach (var d in dvil2) { if (d.IsDocVersion) @@ -109,7 +109,9 @@ namespace VEPROMS { TextBox frm2 = mainForm.GettxtProcess(); frm2.AppendText(p.DisplayNumber + ' ' + p.DisplayText); - Annotation.DeleteAnnotationProcByGroup(lbAnnotationTypes.SelectedIndex, p.ItemID); + AnnotationTyp = System.Convert.ToInt32(((KeyValuePair)lbAnnotationTypes.SelectedItem).Key); + Annotation.DeleteAnnotationProcByType(AnnotationTyp, p.ItemID.ToString()); + lblCountNumber.Text = "0"; } } @@ -118,8 +120,10 @@ namespace VEPROMS if (d.IsDocVersion) { TextBox frm2 = mainForm.GettxtProcess(); - //frm2.AppendText(p); - Annotation.DeleteAnnotationByGroup(lbAnnotationTypes.SelectedIndex, d.VersionID); + frm2.AppendText(d.ActiveParent.ToString()); + AnnotationTyp = System.Convert.ToInt32(((KeyValuePair)lbAnnotationTypes.SelectedItem).Key); + Annotation.DeleteAnnotationDocvByType(AnnotationTyp, d.VersionID.ToString()); + lblCountNumber.Text = "0"; } } } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs index c4fb1889..7f108de3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs @@ -226,13 +226,32 @@ namespace VEPROMS.CSLA.Library } } - public static void DeleteAnnotationProcByGroup(int typID, int itemID) + public static void DeleteAnnotationProcByType(int typID, string procList) { if (!CanDeleteObject()) throw new System.Security.SecurityException("User not authorized to remove a Annotation"); try { - DataPortal.Delete(new AnnotationsByGroupCriteria(typID, itemID)); + DataPortal.Delete(new DeleteAnnotationProcByTypeCriteria(typID, procList)); + AnnotationInfo.StaticOnInfoChanged(); + } + catch (Exception ex) + { + System.Data.SqlClient.SqlException exSQL = SqlException(ex); + if (exSQL != null && exSQL.Message.Contains("###Cannot Delete Item###")) + throw exSQL; + Console.WriteLine("AnnotationExt: Stacktrace = {0}", ex.StackTrace); + throw new DbCslaException("Error on Annotation.Delete", ex); + } + } + + public static void DeleteAnnotationDocvByType(int typID, string versionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Annotation"); + try + { + DataPortal.Delete(new DeleteAnnotationDocvByTypeCriteria(typID, versionID)); AnnotationInfo.StaticOnInfoChanged(); } catch (Exception ex) @@ -343,7 +362,7 @@ namespace VEPROMS.CSLA.Library } [Serializable()] - protected class AnnotationsByGroupCriteria + protected class DeleteAnnotationProcByTypeCriteria { private int _typeID; public int TypeID @@ -352,14 +371,14 @@ namespace VEPROMS.CSLA.Library private string _procList; public string ProcList { get { return _procList; } } - public AnnotationsByGroupCriteria(int typeID, int itemID) + public DeleteAnnotationProcByTypeCriteria(int typeID, string procList) { _typeID = typeID; - _procList = ProcList; + _procList = procList; } } [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(AnnotationsByGroupCriteria criteria) + private void DataPortal_Delete(DeleteAnnotationProcByTypeCriteria criteria) { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Delete", GetHashCode()); try @@ -385,6 +404,49 @@ namespace VEPROMS.CSLA.Library } } + [Serializable()] + protected class DeleteAnnotationDocvByTypeCriteria + { + private int _typeID; + public int TypeID + { get { return _typeID; } } + + private string _versionID; + public string VersionID + { get { return _versionID; } } + public DeleteAnnotationDocvByTypeCriteria(int typeID, string versionID) + { + _typeID = typeID; + _versionID = versionID; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(DeleteAnnotationDocvByTypeCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Delete Annotations by Type Docv", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteAnnotationsDocvByType"; + cm.Parameters.AddWithValue("@typeid", criteria.TypeID); + cm.Parameters.AddWithValue("@docvList", criteria.VersionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Item.DataPortal_Delete Annotations by type Docv", ex); + } + } + private static int _procCnt; public static int ProcCnt {